add std::string overload for cv::read()
authorPkLab.net <info@pklab.net>
Fri, 26 May 2017 17:14:58 +0000 (19:14 +0200)
committerVladislav Sovrasov <sovrasov.vlad@gmail.com>
Wed, 12 Jul 2017 12:51:11 +0000 (15:51 +0300)
modules/core/include/opencv2/core/cvstd.inl.hpp
modules/core/include/opencv2/core/persistence.hpp
modules/core/src/persistence.cpp

index c8c7ba9..c77f02a 100644 (file)
@@ -156,9 +156,7 @@ FileNode::operator std::string() const
 template<> inline
 void operator >> (const FileNode& n, std::string& value)
 {
-    String val;
-    read(n, val, val);
-    value = val;
+    read(n, value, std::string());
 }
 
 template<> inline
index 90da60d..ac53ca3 100644 (file)
@@ -714,6 +714,7 @@ CV_EXPORTS void read(const FileNode& node, int& value, int default_value);
 CV_EXPORTS void read(const FileNode& node, float& value, float default_value);
 CV_EXPORTS void read(const FileNode& node, double& value, double default_value);
 CV_EXPORTS void read(const FileNode& node, String& value, const String& default_value);
+CV_EXPORTS void read(const FileNode& node, std::string& value, const std::string& default_value);
 CV_EXPORTS void read(const FileNode& node, Mat& mat, const Mat& default_mat = Mat() );
 CV_EXPORTS void read(const FileNode& node, SparseMat& mat, const SparseMat& default_mat = SparseMat() );
 CV_EXPORTS void read(const FileNode& node, std::vector<KeyPoint>& keypoints);
index 90ebb77..bb4d953 100644 (file)
@@ -7396,6 +7396,11 @@ void read(const FileNode& node, String& value, const String& default_value)
     value = !node.node ? default_value : CV_NODE_IS_STRING(node.node->tag) ? String(node.node->data.str.ptr) : String();
 }
 
+void read(const FileNode& node, std::string& value, const std::string& default_value)
+{
+    value = !node.node ? default_value : CV_NODE_IS_STRING(node.node->tag) ? std::string(node.node->data.str.ptr) : default_value;
+}
+
 }