mirror of
https://github.com/opencv/opencv.git
synced 2025-01-19 06:53:50 +08:00
Merge pull request #18858 from fegorsch:improve-persistence-doc
This commit is contained in:
commit
049b50d9c0
@ -403,8 +403,8 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Simplified writing API to use with bindings.
|
* @brief Simplified writing API to use with bindings.
|
||||||
* @param name Name of the written object
|
* @param name Name of the written object. When writing to sequences (a.k.a. "arrays"), pass an empty string.
|
||||||
* @param val Value of the written object
|
* @param val Value of the written object.
|
||||||
*/
|
*/
|
||||||
CV_WRAP void write(const String& name, int val);
|
CV_WRAP void write(const String& name, int val);
|
||||||
/// @overload
|
/// @overload
|
||||||
@ -437,9 +437,10 @@ public:
|
|||||||
CV_WRAP void writeComment(const String& comment, bool append = false);
|
CV_WRAP void writeComment(const String& comment, bool append = false);
|
||||||
|
|
||||||
/** @brief Starts to write a nested structure (sequence or a mapping).
|
/** @brief Starts to write a nested structure (sequence or a mapping).
|
||||||
@param name name of the structure (if it's a member of parent mapping, otherwise it should be empty
|
@param name name of the structure. When writing to sequences (a.k.a. "arrays"), pass an empty string.
|
||||||
@param flags type of the structure (FileNode::MAP or FileNode::SEQ (both with optional FileNode::FLOW)).
|
@param flags type of the structure (FileNode::MAP or FileNode::SEQ (both with optional FileNode::FLOW)).
|
||||||
@param typeName usually an empty string
|
@param typeName optional name of the type you store. The effect of setting this depends on the storage format.
|
||||||
|
I.e. if the format has a specification for storing type information, this parameter is used.
|
||||||
*/
|
*/
|
||||||
CV_WRAP void startWriteStruct(const String& name, int flags, const String& typeName=String());
|
CV_WRAP void startWriteStruct(const String& name, int flags, const String& typeName=String());
|
||||||
|
|
||||||
|
@ -1640,6 +1640,32 @@ TEST(Core_InputOutput, FileStorage_free_file_after_exception)
|
|||||||
ASSERT_EQ(0, std::remove(fileName.c_str()));
|
ASSERT_EQ(0, std::remove(fileName.c_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(Core_InputOutput, FileStorage_write_to_sequence)
|
||||||
|
{
|
||||||
|
const std::vector<std::string> formatExts = { ".yml", ".json", ".xml" };
|
||||||
|
const std::string fileName = "FileStorage_write_to_sequence";
|
||||||
|
|
||||||
|
for (const auto& ext : formatExts)
|
||||||
|
{
|
||||||
|
FileStorage fs(fileName + ext, FileStorage::WRITE);
|
||||||
|
std::vector<int> in = { 23, 42 };
|
||||||
|
fs.startWriteStruct("some_sequence", cv::FileNode::SEQ);
|
||||||
|
for (int i : in)
|
||||||
|
fs.write("", i);
|
||||||
|
fs.endWriteStruct();
|
||||||
|
fs.release();
|
||||||
|
|
||||||
|
FileStorage fsIn(fileName + ext, FileStorage::READ);
|
||||||
|
FileNode seq = fsIn["some_sequence"];
|
||||||
|
FileNodeIterator it = seq.begin(), it_end = seq.end();
|
||||||
|
std::vector<int> out;
|
||||||
|
for (; it != it_end; ++it)
|
||||||
|
out.push_back((int)*it);
|
||||||
|
|
||||||
|
EXPECT_EQ(in, out);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TEST(Core_InputOutput, FileStorage_YAML_parse_multiple_documents)
|
TEST(Core_InputOutput, FileStorage_YAML_parse_multiple_documents)
|
||||||
{
|
{
|
||||||
const std::string filename = "FileStorage_YAML_parse_multiple_documents.yml";
|
const std::string filename = "FileStorage_YAML_parse_multiple_documents.yml";
|
||||||
|
Loading…
Reference in New Issue
Block a user