File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -403,8 +403,8 @@ class CV_EXPORTS_W FileStorage
403403
404404 /* *
405405 * @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.
408408 */
409409 CV_WRAP void write (const String& name, int val);
410410 // / @overload
@@ -437,9 +437,10 @@ class CV_EXPORTS_W FileStorage
437437 CV_WRAP void writeComment (const String& comment, bool append = false );
438438
439439 /* * @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.
441441 @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.
443444 */
444445 CV_WRAP void startWriteStruct (const String& name, int flags, const String& typeName=String());
445446
Original file line number Diff line number Diff line change @@ -1640,6 +1640,32 @@ TEST(Core_InputOutput, FileStorage_free_file_after_exception)
16401640 ASSERT_EQ (0 , std::remove (fileName.c_str ()));
16411641}
16421642
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+
16431669TEST (Core_InputOutput, FileStorage_YAML_parse_multiple_documents)
16441670{
16451671 const std::string filename = " FileStorage_YAML_parse_multiple_documents.yml" ;
You can’t perform that action at this time.
0 commit comments