Created
November 2, 2015 22:59
-
-
Save johnmcfarlane/194729e80ddf16224242 to your computer and use it in GitHub Desktop.
For yaml-cpp: `bool isEqual(YAML::Node const &lhs, YAML::Node const &rhs)`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool isEqual(YAML::Node const &lhs, YAML::Node const &rhs) { | |
if (lhs == rhs) { | |
return true; | |
} | |
YAML::NodeType::value lhs_type = lhs.Type(); | |
if (lhs_type != rhs.Type()) { | |
return false; | |
} | |
if (lhs.size() != rhs.size()) { | |
return false; | |
} | |
switch (lhs_type) { | |
case YAML::NodeType::Scalar: { | |
std::string const &lhs_as_string = lhs.as<std::string>(); | |
std::string const &rhs_as_string = rhs.as<std::string>(); | |
return lhs_as_string == rhs_as_string; | |
} | |
case YAML::NodeType::Sequence: | |
return lhs.size() == rhs.size() | |
&& std::equal(boost::begin(lhs), boost::end(lhs), boost::begin(rhs), isEqual); | |
case YAML::NodeType::Map: | |
BOOST_FOREACH(yaml_map_pair const &lhs_element, lhs) { | |
std::string key = lhs_element.first.as<std::string>(); | |
if (!isEqual(lhs_element.second, rhs[key])) { | |
return false; | |
} | |
} | |
return true; | |
default: | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment