Skip to content

Commit

Permalink
env var as type
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipDeegan committed Sep 29, 2024
1 parent 34bbc60 commit 8260255
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
bin
.mkn
.clangd
15 changes: 15 additions & 0 deletions inc/mkn/kul/env.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "mkn/kul/string.hpp"

#include <string>
#include <sstream>

#if KUL_IS_WIN
#include "mkn/kul/os/win/env.hpp"
#else
Expand All @@ -43,6 +46,18 @@ namespace mkn {
namespace kul {
namespace env {

template <typename T>
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 };
Expand Down

0 comments on commit 8260255

Please sign in to comment.