1 #include <boost/lexical_cast.hpp> 4 #include "../icedb/defs.h" 5 #include "../private/options.hpp" 6 #include "../icedb/logging.hpp" 7 #include "../icedb/error.hpp" 13 std::map<std::string, std::string>
_mapStr;
19 auto res = std::shared_ptr<options>(
new options);
return res;
24 for (
const auto &v : p->_mapStr)
26 if (v.first !=
"password")
28 out <<
"\t" << v.first <<
":\t" << v.second << std::endl;
31 out <<
"\t" << v.first <<
":\t" <<
"********" << std::endl;
36 if (p->_mapStr.count(key))
return true;
41 if (!hasVal(key))
return boost::lexical_cast<T>(std::string(
""));
44 std::string valS = p->_mapStr.at(key);
45 T res = boost::lexical_cast<T>(valS);
48 template <
class T> T
options::getVal(
const std::string &key,
const T& defaultval)
const 50 if (!hasVal(key))
return defaultval;
51 return getVal<T>(key);
55 std::string valS = boost::lexical_cast<std::string>(value);
56 p->_mapStr[key] = valS;
57 return this->shared_from_this();
62 .add<std::string>(
"key", key)
63 .add<T>(
"newValue", value);
64 return this->setVal<T>(key, value);
67 #define DOTYPES(f) f(int); f(float); f(double); f(long); f(long long); \ 68 f(unsigned int); f(unsigned long); f(unsigned long long); f(std::string); f(bool); f(std::complex<double>); 70 #define IMPL_OPTS_SETVAL(T) template options_ptr options::setVal<T>(const std::string&, const T&); 71 #define IMPL_OPTS_ADD(T) template options_ptr options::add<T>(const std::string&, const T&); 72 #define IMPL_OPTS_GETVAL_A(T) template T options::getVal<T>(const std::string&) const; 73 #define IMPL_OPTS_GETVAL_B(T) template T options::getVal<T>(const std::string&, const T&) const; 74 #define IMPL_OPTS(T) IMPL_OPTS_SETVAL(T); IMPL_OPTS_GETVAL_A(T);IMPL_OPTS_GETVAL_B(T);IMPL_OPTS_ADD(T); void enumVals(std::ostream &out) const
options_ptr setVal(const std::string &key, const T &value)
Adds or replaces an option.
bool hasVal(const std::string &key) const
static std::shared_ptr< options > generate()
T getVal(const std::string &key) const
Retrieves an option. Throws if nonexistant.
options_ptr add(const std::string &key, const T &value)
Adds an option. Throws if the same name already exists.
std::shared_ptr< options > options_ptr
std::map< std::string, std::string > _mapStr