KIDS  ver-0.0.1
KIDS : Kernel Integrated Dynamics Simulator
Loading...
Searching...
No Matches
Param.h
Go to the documentation of this file.
1
37#ifndef KIDS_PARAM_H
38#define KIDS_PARAM_H
39
40#include <cstring>
41#include <fstream>
42#include <iomanip>
43#include <memory>
44#include <sstream>
45#include <string>
46
47#include "configor/json.hpp"
48#include "kids/phys.h"
49
53inline const char *basename(const char *filepath) {
54 const char *base = strrchr(filepath, '/');
55#ifdef _WIN32 // windows system
56 if (!base) base = strrchr(filepath, '\\');
57#endif
58 return base ? (base + 1) : filepath;
59}
60
64#define LOC() (std::string(basename(__FILE__)) + ":" + std::to_string(__LINE__))
65
66namespace PROJECT_NS {
67
82class Param final {
83 public:
84 using JSON = configor::json;
85 using JSON_Exception = configor::configor_exception;
86
93
111 Param(const std::string &input, LoadOption option);
112
127 bool has_key(const std::string &key);
128
129 std::shared_ptr<JSON> pjson();
130
131 std::string repr();
132
133 bool get_bool(const std::string &key, const std::string &loc, const bool &default_value);
134 bool get_bool(const std::string &key, const std::string &loc = "__loc__");
135
136 int get_int(const std::string &key, const std::string &loc, const int &default_value);
137 int get_int(const std::string &key, const std::string &loc = "__loc__");
138
139 std::string get_string(const std::string &key, const std::string &loc, const std::string &default_value);
140 std::string get_string(const std::string &key, const std::string &loc = "__loc__");
141
142 double get_double(const std::string &key, const std::string &loc, const phys::dimension7 &qdim,
143 const double &default_value = double());
144 double get_double(const std::string &key, const std::string &loc, const double &default_value);
145 double get_double(const std::string &key, const std::string &loc = "__loc__");
146
147 private:
148 std::shared_ptr<JSON> pj;
149
158 template <typename T, bool Require = false>
159 T get(const std::string &key, const std::string &loc, const phys::dimension7 &qdim, const T &default_value);
160};
161
162}; // namespace PROJECT_NS
163
164#endif // KIDS_PARAM_H
const char * basename(const char *filepath)
return the base of filename
Definition Param.h:53
this class provides an interface wrapper for the parameter data.
Definition Param.h:82
T get(const std::string &key, const std::string &loc, const phys::dimension7 &qdim, const T &default_value)
get parameter
Definition Param.cpp:50
configor::json JSON
Definition Param.h:84
@ fromString
construct Param from string
Definition Param.h:90
@ fromFile
construct Param from file
Definition Param.h:91
Param(const std::string &input, LoadOption option)
Definition Param.cpp:15
double get_double(const std::string &key, const std::string &loc, const phys::dimension7 &qdim, const double &default_value=double())
Definition Param.cpp:150
configor::configor_exception JSON_Exception
Definition Param.h:85
std::string repr()
Definition Param.cpp:46
std::shared_ptr< JSON > pjson()
Definition Param.cpp:44
std::string get_string(const std::string &key, const std::string &loc, const std::string &default_value)
Definition Param.cpp:143
int get_int(const std::string &key, const std::string &loc, const int &default_value)
Definition Param.cpp:136
bool get_bool(const std::string &key, const std::string &loc, const bool &default_value)
Definition Param.cpp:129
std::shared_ptr< JSON > pj
Definition Param.h:148
bool has_key(const std::string &key)
Param &operator[](const std::string &key) { if (!has_key(key)) { throw param_illegal_key_error(key); ...
Definition Param.cpp:42
< http://warp.povusers.org/FunctionParser/fparser.html
Definition Context.h:39