Unverified Commit e31eb461 authored by Alexander Alekhin's avatar Alexander Alekhin Committed by GitHub

Merge pull request #13123 from dkurt:fs_keys

parents 326be0d7 a7f30391
...@@ -526,6 +526,11 @@ public: ...@@ -526,6 +526,11 @@ public:
*/ */
CV_WRAP_AS(at) FileNode operator[](int i) const; CV_WRAP_AS(at) FileNode operator[](int i) const;
/** @brief Returns keys of a mapping node.
@returns Keys of a mapping node.
*/
CV_WRAP std::vector<String> keys() const;
/** @brief Returns type of the node. /** @brief Returns type of the node.
@returns Type of the node. See FileNode::Type @returns Type of the node. See FileNode::Type
*/ */
......
...@@ -2083,6 +2083,19 @@ FileNode FileNode::operator[](int i) const ...@@ -2083,6 +2083,19 @@ FileNode FileNode::operator[](int i) const
return *it; return *it;
} }
std::vector<String> FileNode::keys() const
{
CV_Assert(isMap());
std::vector<String> res;
res.reserve(size());
for (FileNodeIterator it = begin(); it != end(); ++it)
{
res.push_back((*it).name());
}
return res;
}
int FileNode::type() const int FileNode::type() const
{ {
const uchar* p = ptr(); const uchar* p = ptr();
......
...@@ -1565,6 +1565,12 @@ TEST(Core_InputOutput, FileStorage_json_bool) ...@@ -1565,6 +1565,12 @@ TEST(Core_InputOutput, FileStorage_json_bool)
ASSERT_EQ((int)fs["map_value"]["bool_true"], 1); ASSERT_EQ((int)fs["map_value"]["bool_true"], 1);
ASSERT_EQ((std::string)fs["map_value"]["str_false"], "false"); ASSERT_EQ((std::string)fs["map_value"]["str_false"], "false");
ASSERT_EQ((int)fs["bool_false"], 0); ASSERT_EQ((int)fs["bool_false"], 0);
std::vector<String> keys = fs["map_value"].keys();
ASSERT_EQ((int)keys.size(), 3);
ASSERT_EQ(keys[0], "int_value");
ASSERT_EQ(keys[1], "bool_true");
ASSERT_EQ(keys[2], "str_false");
fs.release(); fs.release();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment