From 8260255d53b95c9355d91f06fb919ee5c580ae55 Mon Sep 17 00:00:00 2001 From: PhilipDeegan Date: Sun, 29 Sep 2024 19:32:58 +0200 Subject: [PATCH] env var as type --- .gitignore | 1 + inc/mkn/kul/env.hpp | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/.gitignore b/.gitignore index 34d04f5..ef5af5b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ bin .mkn +.clangd diff --git a/inc/mkn/kul/env.hpp b/inc/mkn/kul/env.hpp index dc3308c..6d66a9e 100644 --- a/inc/mkn/kul/env.hpp +++ b/inc/mkn/kul/env.hpp @@ -33,6 +33,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "mkn/kul/string.hpp" +#include +#include + #if KUL_IS_WIN #include "mkn/kul/os/win/env.hpp" #else @@ -43,6 +46,18 @@ namespace mkn { namespace kul { namespace env { +template +auto GET_AS(std::string const& s, T const& def) { + if (EXISTS(s.c_str())) { + T t; + std::stringstream ss(GET(s.c_str())); + if (ss.fail()) KTHROW(Exception); + ss >> t; + return t; + } + return def; +} + class Var { public: enum Mode { APPE = 0, PREP, REPL };