diff options
author | imarom <imarom@cisco.com> | 2016-06-29 10:35:54 +0300 |
---|---|---|
committer | imarom <imarom@cisco.com> | 2016-07-03 13:40:21 +0300 |
commit | 1dfd42ceb79677e171d5dedcac34900776574000 (patch) | |
tree | ed1dfd5964d6fb2cde139a55f4ef482005edb13e /src/utl_yaml.h | |
parent | f03fa158116cfd65659d14698c91446dc9bdb4c4 (diff) |
added enhanced parsing for the YAML wrapper module
Diffstat (limited to 'src/utl_yaml.h')
-rwxr-xr-x | src/utl_yaml.h | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/src/utl_yaml.h b/src/utl_yaml.h index 1ada1d66..8088c497 100755 --- a/src/utl_yaml.h +++ b/src/utl_yaml.h @@ -24,16 +24,13 @@ limitations under the License. #include <stdint.h> #include <yaml-cpp/yaml.h> - + +/* static methods - please prefer the wrapper over those */ bool utl_yaml_read_ip_addr(const YAML::Node& node, const std::string &name, uint32_t & val); -bool utl_yaml_read_mac_addr(const YAML::Node &node, - const std::string &name, - uint64_t &val); - bool utl_yaml_read_uint32(const YAML::Node& node, const std::string &name, uint32_t & val); @@ -42,9 +39,33 @@ bool utl_yaml_read_uint16(const YAML::Node& node, const std::string &name, uint16_t & val); -bool utl_yaml_read_bool(const YAML::Node& node, - const std::string &name, - bool & val); +/* a thin wrapper to customize errors */ +class YAMLParserWrapper { +public: + /* a header that will start every error message */ + YAMLParserWrapper(const std::string &header) : m_header(header) { + } + + /* bool */ + bool parse_bool(const YAML::Node &node, const std::string &name); + bool parse_bool(const YAML::Node &node, const std::string &name, bool def); + + const YAML::Node & parse_list(const YAML::Node &node, const std::string &name); + const YAML::Node & parse_map(const YAML::Node &node, const std::string &name); + + uint32_t parse_ip(const YAML::Node &node, const std::string &name); + uint64_t parse_mac_addr(const YAML::Node &node, const std::string &name); + + uint64_t parse_uint(const YAML::Node &node, const std::string &name, uint64_t low = 0, uint64_t high = UINT64_MAX); + + +public: + void parse_err(const std::string &err, const YAML::Node &node) const; + + +private: + std::string m_header; +}; #endif |