File tree Expand file tree Collapse file tree 2 files changed +31
-4
lines changed Expand file tree Collapse file tree 2 files changed +31
-4
lines changed Original file line number Diff line number Diff line change @@ -403,8 +403,8 @@ class CV_EXPORTS_W FileStorage
403
403
404
404
/* *
405
405
* @brief Simplified writing API to use with bindings.
406
- * @param name Name of the written object
407
- * @param val Value of the written object
406
+ * @param name Name of the written object. When writing to sequences (a.k.a. "arrays"), pass an empty string.
407
+ * @param val Value of the written object.
408
408
*/
409
409
CV_WRAP void write (const String& name, int val);
410
410
// / @overload
@@ -437,9 +437,10 @@ class CV_EXPORTS_W FileStorage
437
437
CV_WRAP void writeComment (const String& comment, bool append = false );
438
438
439
439
/* * @brief Starts to write a nested structure (sequence or a mapping).
440
- @param name name of the structure (if it's a member of parent mapping, otherwise it should be empty
440
+ @param name name of the structure. When writing to sequences (a.k.a. "arrays"), pass an empty string.
441
441
@param flags type of the structure (FileNode::MAP or FileNode::SEQ (both with optional FileNode::FLOW)).
442
- @param typeName usually an empty string
442
+ @param typeName optional name of the type you store. The effect of setting this depends on the storage format.
443
+ I.e. if the format has a specification for storing type information, this parameter is used.
443
444
*/
444
445
CV_WRAP void startWriteStruct (const String& name, int flags, const String& typeName=String());
445
446
Original file line number Diff line number Diff line change @@ -1640,6 +1640,32 @@ TEST(Core_InputOutput, FileStorage_free_file_after_exception)
1640
1640
ASSERT_EQ (0 , std::remove (fileName.c_str ()));
1641
1641
}
1642
1642
1643
+ TEST (Core_InputOutput, FileStorage_write_to_sequence)
1644
+ {
1645
+ const std::vector<std::string> formatExts = { " .yml" , " .json" , " .xml" };
1646
+ const std::string fileName = " FileStorage_write_to_sequence" ;
1647
+
1648
+ for (const auto & ext : formatExts)
1649
+ {
1650
+ FileStorage fs (fileName + ext, FileStorage::WRITE);
1651
+ std::vector<int > in = { 23 , 42 };
1652
+ fs.startWriteStruct (" some_sequence" , cv::FileNode::SEQ);
1653
+ for (int i : in)
1654
+ fs.write (" " , i);
1655
+ fs.endWriteStruct ();
1656
+ fs.release ();
1657
+
1658
+ FileStorage fsIn (fileName + ext, FileStorage::READ);
1659
+ FileNode seq = fsIn[" some_sequence" ];
1660
+ FileNodeIterator it = seq.begin (), it_end = seq.end ();
1661
+ std::vector<int > out;
1662
+ for (; it != it_end; ++it)
1663
+ out.push_back ((int )*it);
1664
+
1665
+ EXPECT_EQ (in, out);
1666
+ }
1667
+ }
1668
+
1643
1669
TEST (Core_InputOutput, FileStorage_YAML_parse_multiple_documents)
1644
1670
{
1645
1671
const std::string filename = " FileStorage_YAML_parse_multiple_documents.yml" ;
You can’t perform that action at this time.
0 commit comments