16 pj = std::shared_ptr<JSON>(
new JSON());
20 std::ifstream ifs(input);
24 std::cout <<
"Invalid file: " << input;
30 std::stringstream sstr(input);
34 std::cout <<
"Invalid string: " << input;
49template <
typename T,
bool Require = false>
55 " Type<", as_str<T>(),
">",
64 " Type<", as_str<T>(),
">",
74 switch ((*
pj)[key].type()) {
75 case configor::config_value_type::string: {
76 if (std::is_same<T, std::string>::value) {
77 return (*
pj)[key].get<T>();
78 }
else if (std::is_same<T, double>::value) {
81 double qval = phys::au::as(qdim, uv);
86 ss << std::setiosflags(std::ios::scientific)
87 << std::setprecision(32) << qval;
93 case configor::config_value_type::boolean: {
94 if (std::is_same<T, bool>::value)
return (*
pj)[key].get<T>();
97 case configor::config_value_type::number_float: {
99 if (std::is_same<T, double>::value) {
100 q = (*pj)[key].as_float();
105 case configor::config_value_type::number_integer: {
107 if (std::is_same<T, double>::value) {
108 q = (*pj)[key].as_float();
110 }
else if (std::is_same<T, int>::value) {
111 return (*
pj)[key].get<T>();
119 " Type<", as_str<T>(),
">",
122 (*
pj)[key].dump(4,
' '),
"}",
123 " : Converting fatal")
129bool Param::get_bool(
const std::string &key,
const std::string &loc,
const bool &default_value) {
130 return get<bool, false>(key, loc,
phys::none_d, default_value);
136int Param::get_int(
const std::string &key,
const std::string &loc,
const int &default_value) {
137 return get<int, false>(key, loc,
phys::none_d, default_value);
143std::string
Param::get_string(
const std::string &key,
const std::string &loc,
const std::string &default_value) {
144 return get<std::string, false>(key, loc,
phys::none_d, default_value);
147 return get<std::string, true>(key, loc,
phys::none_d, std::string());
151 const double &default_value) {
152 return get<double, false>(key, loc, qdim, default_value);
154double Param::get_double(
const std::string &key,
const std::string &loc,
const double &default_value) {
155 return get<double, false>(key, loc,
phys::none_d, default_value);
158 return get<double, true>(key, loc,
phys::none_d,
double());
provide Exception structs
Provide struct and interfaces for input parameters.
definition of types in the project and some utiles for types
T get(const std::string &key, const std::string &loc, const phys::dimension7 &qdim, const T &default_value)
get parameter
@ fromString
construct Param from string
@ fromFile
construct Param from file
Param(const std::string &input, LoadOption option)
double get_double(const std::string &key, const std::string &loc, const phys::dimension7 &qdim, const double &default_value=double())
configor::configor_exception JSON_Exception
std::shared_ptr< JSON > pjson()
std::string get_string(const std::string &key, const std::string &loc, const std::string &default_value)
int get_int(const std::string &key, const std::string &loc, const int &default_value)
bool get_bool(const std::string &key, const std::string &loc, const bool &default_value)
std::shared_ptr< JSON > pj
bool has_key(const std::string &key)
Param &operator[](const std::string &key) { if (!has_key(key)) { throw param_illegal_key_error(key); ...
static uval parse(const std::string &str)
< http://warp.povusers.org/FunctionParser/fparser.html
constexpr dimension7 none_d
std::basic_string< CharT > concat(const separator_t< CharT > &sep, Args &&... seq)