00001
00002
00003
00004 #ifndef DMLITE_CPP_UTILS_EXTENSIBLE_H
00005 #define DMLITE_CPP_UTILS_EXTENSIBLE_H
00006
00007 #include <boost/any.hpp>
00008 #include <boost/property_tree/ptree.hpp>
00009 #include <dmlite/common/errno.h>
00010 #include <dmlite/cpp/exceptions.h>
00011 #include <map>
00012 #include <stdexcept>
00013 #include <string>
00014 #include <vector>
00015
00016 namespace dmlite {
00017
00018
00019 struct Extensible {
00020 private:
00021 typedef std::map<std::string, boost::any> DictType_;
00022 DictType_ dictionary_;
00023
00024 void populate(const boost::property_tree::ptree& root);
00025
00026 public:
00027
00028 static bool anyToBoolean (const boost::any& any);
00029
00030 static unsigned anyToUnsigned(const boost::any& any);
00031
00032 static long anyToLong (const boost::any& any);
00033
00034 static double anyToDouble (const boost::any& any);
00035
00036 static std::string anyToString (const boost::any& any);
00037
00038
00039 bool hasField(const std::string& key) const;
00040
00041
00042
00043 const boost::any& operator [] (const std::string& key) const throw (DmException);
00044
00045
00046
00047 boost::any& operator [] (const std::string& key);
00048
00049
00050 bool operator == (const Extensible&) const;
00051 bool operator != (const Extensible&) const;
00052 bool operator > (const Extensible&) const;
00053 bool operator < (const Extensible&) const;
00054
00055
00056 unsigned long size() const;
00057
00058
00059 void clear();
00060
00061
00062 void copy(const Extensible& s);
00063
00064
00065 void erase(const std::string&);
00066
00067
00068 std::string serialize(void) const;
00069
00070
00071 void deserialize(const std::string& serial) throw (DmException);
00072
00073
00074 std::vector<std::string> getKeys(void) const throw (DmException);
00075
00076
00077 bool getBool(const std::string& key) const throw (DmException);
00078
00079
00080 long getLong(const std::string& key) const throw (DmException);
00081
00082
00083 unsigned long getUnsigned(const std::string& key) const throw (DmException);
00084
00085
00086 double getDouble(const std::string& key) const throw (DmException);
00087
00088
00089 std::string getString(const std::string& key) const throw (DmException);
00090
00091
00092 Extensible getExtensible(const std::string& key) const throw (DmException);
00093
00094
00095 std::vector<boost::any> getVector(const std::string& key) const throw (DmException);
00096 };
00097
00098 };
00099
00100 #endif // DMLITE_CPP_UTILS_TYPES_H