X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/4271ab433cd55bbd2612292bcf39e4dc3d7274f1..0907aa4037b12b6b88ee24495d4577a064d4f8db:/projects/sgconf/utils.h diff --git a/projects/sgconf/utils.h b/projects/sgconf/utils.h new file mode 100644 index 00000000..6168cbf2 --- /dev/null +++ b/projects/sgconf/utils.h @@ -0,0 +1,45 @@ +#pragma once + +#include "stg/common.h" +#include "stg/optional.h" + +#include +#include + +namespace SGCONF +{ + +template +inline +void MaybeSet(const std::map & options, const std::string & name, STG::Optional & 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, STG::Optional & res) +{ +std::map::const_iterator it(options.find(name)); +if (it == options.end()) + return; +res = it->second; +} + +} // namespace SGCONF