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