X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/8c6fa3fbaccc22127280bf77a48fab5a3ee0716e..46b0747592074017ff0ea4b33d4a7194235886e5:/sgconf/utils.h diff --git a/sgconf/utils.h b/sgconf/utils.h new file mode 100644 index 00000000..3793c9cd --- /dev/null +++ b/sgconf/utils.h @@ -0,0 +1,48 @@ +#ifndef __STG_SGCONF_UTILS_H__ +#define __STG_SGCONF_UTILS_H__ + +#include "stg/common.h" +#include "stg/resetable.h" + +#include +#include + +namespace SGCONF +{ + +template +inline +void MaybeSet(const std::map & options, const std::string & name, RESETABLE & res) +{ +std::map::const_iterator it(options.find(name)); +if (it == options.end()) + return; +T value; +if (str2x(it->second, value) < 0) + return; +res = value; +} + +template +inline +void MaybeSet(const std::map & options, const std::string & name, T & res, F conv) +{ +std::map::const_iterator it(options.find(name)); +if (it == options.end()) + return; +conv(it->second, res); +} + +template <> +inline +void MaybeSet(const std::map & options, const std::string & name, RESETABLE & res) +{ +std::map::const_iterator it(options.find(name)); +if (it == options.end()) + return; +res = it->second; +} + +} // namespace SGCONF + +#endif