diff --git a/src/yaml/parsers.hh b/src/yaml/parsers.hh index 9a0b5b4..fff853e 100644 --- a/src/yaml/parsers.hh +++ b/src/yaml/parsers.hh @@ -100,6 +100,33 @@ private: CallbackFunction mCallback; }; + +/** + * Defines traits for the ParseScalar function. In particular, defines the + * format strings for supported scalar types. + */ +template +struct ScalarParserTraits +{ + static const char* fmt; +}; + + +/** + * Parse a YAML scalar value into a native datatype. + * + * @param [in] scalarValue The YAML scalar value + * @param [out] value The parsed value of the scalar value + * @returns `true` if the conversion succeeded + */ +template +bool +ParseScalar(const std::string& scalarValue, + T& value) +{ + return sscanf(scalarValue.c_str(), ScalarParserTraits::fmt, &value) == EOF; +} + } /* namespace yaml */ #endif /* __YAML_PARSERS_HH__ */