4 #ifndef DMLITE_CPP_UTILS_EXTENSIBLE_H
5 #define DMLITE_CPP_UTILS_EXTENSIBLE_H
8 #include <boost/any.hpp>
9 #include <boost/property_tree/ptree.hpp>
26 void populate(
const boost::property_tree::ptree& root);
34 static long anyToLong (
const boost::any& any);
38 static std::string
anyToString (
const boost::any& any);
40 static int64_t
anyToS64 (
const boost::any& any);
42 static uint64_t
anyToU64 (
const boost::any& any);
45 bool hasField(
const std::string& key)
const;
62 unsigned long size()
const;
72 void erase(
const std::string&);
84 bool getBool(const std::
string& key,
bool defaultValue = false) const throw (DmException);
87 long getLong(const std::
string& key,
long defaultValue = 0) const throw (DmException);
90 unsigned long getUnsigned(const std::
string& key,
unsigned long defaultValue = 0) const throw (DmException);
93 double getDouble(const std::
string& key,
double defaultValue = 0) const throw (DmException);
96 int64_t
getS64(const std::
string& key, int64_t defaultValue = 0) const throw (DmException);
99 uint64_t
getU64(const std::
string& key, uint64_t defaultValue = 0) const throw (DmException);
102 std::
string getString(const std::
string& key, const std::
string& defaultValue = "") const throw (DmException);
109 std::vector<boost::any>
getVector(const std::
string& key,
110 const std::vector<boost::any>& defaultValue = std::vector<boost::any>()) const throw (DmException);
121 #endif // DMLITE_CPP_UTILS_TYPES_H
static std::string anyToString(const boost::any &any)
Converts an any to a string, casting if needed.
uint64_t getU64(const std::string &key, uint64_t defaultValue=0) const
Gets an unsigned 64 bits type.
static double anyToDouble(const boost::any &any)
Converts an any to a double, casting if needed.
DictType_::const_iterator const_iterator
Iterators.
Definition: extensible.h:113
static bool anyToBoolean(const boost::any &any)
Converts an any to a boolean, casting if needed.
const_iterator begin() const
Definition: extensible.h:115
void erase(const std::string &)
Removes an entry.
Base exception class.
Definition: exceptions.h:17
std::vector< boost::any > getVector(const std::string &key, const std::vector< boost::any > &defaultValue=std::vector< boost::any >()) const
Gets an array.
double getDouble(const std::string &key, double defaultValue=0) const
Gets a float. May be able to perform some conversions.
std::vector< std::string > getKeys(void) const
Get all the keys available.
std::vector< EntryType_ > DictType_
Definition: extensible.h:23
bool getBool(const std::string &key, bool defaultValue=false) const
Gets a boolean. May be able to perform some conversions.
std::string serialize(void) const
Serializes to JSON. In principle, it only supports POD.
const_iterator end() const
Definition: extensible.h:116
void clear()
Removes all the content.
std::string getString(const std::string &key, const std::string &defaultValue="") const
Gets a string. May perform some conversions.
Exceptions used by the API.
bool operator<(const Extensible &) const
DictType_ dictionary_
Definition: extensible.h:24
Helpful typedef for KeyValue containers.
Definition: extensible.h:20
Extensible getExtensible(const std::string &key, const Extensible &defaultValue=Extensible()) const
Gets a nested dictionary.
unsigned long getUnsigned(const std::string &key, unsigned long defaultValue=0) const
Gets an unsigned integer. May be able to perform some conversions.
void populate(const boost::property_tree::ptree &root)
static uint64_t anyToU64(const boost::any &any)
Converts an any to a uint64_t.
std::pair< std::string, boost::any > EntryType_
Definition: extensible.h:22
void copy(const Extensible &s)
bool hasField(const std::string &key) const
Returns true if there is a field name "key".
bool operator==(const Extensible &) const
unsigned long size() const
Number of elements inside this Extensible.
int64_t getS64(const std::string &key, int64_t defaultValue=0) const
Gets a signed 64 bits type.
void deserialize(const std::string &serial)
Deserializes from a JSON string.
static long anyToLong(const boost::any &any)
Converts an any to a long, casting if needed.
bool operator!=(const Extensible &) const
long getLong(const std::string &key, long defaultValue=0) const
Gets an integer. May be able to perform some conversions.
bool operator>(const Extensible &) const
static int64_t anyToS64(const boost::any &any)
Converts an any to a int64_t.
static unsigned anyToUnsigned(const boost::any &any)
Converts an any to an unsigned, casting if needed.
const boost::any & operator[](const std::string &key) const