Go to the documentation of this file.00001
00002
00003
00004
00005
00009
00010 #ifndef runtimeValue_H_
00011 #define runtimeValue_H_
00012
00013 #include "lgrUtil.h"
00014 #include "absoluteTime.h"
00015 #include "base64Data.h"
00016
00017 #include <vlutil/vlString.h>
00018 #include <vlutil/vlSmartPointers.h>
00019
00020 #include <ctype.h>
00021 #include <string>
00022 #include <vector>
00023
00024 namespace MAKLogger
00025 {
00028 class DT_DLL_LGRUTIL DtAnyValue
00029 {
00030 public:
00031
00032
00034 DtAnyValue() {}
00035
00037 virtual ~DtAnyValue() {}
00038
00039 virtual DtAnyValue* clone() const = 0;
00040
00042 virtual bool sameType(const DtAnyValue* const base) const
00043 { return this->typeId() == base->typeId(); }
00044
00045 virtual const DtString& type() const = 0;
00046 virtual DtString serialize() const = 0;
00047
00048 virtual int typeId() const = 0;
00049 };
00050
00051 typedef DtBoost::shared_ptr<DtAnyValue> DtAnyValueSP;
00052
00058 template <typename T>
00059 class DtValue : public DtAnyValue
00060 {
00061 public:
00062
00064 DtValue(const T& value);
00065
00067 virtual ~DtValue();
00068
00070 virtual DtAnyValue* clone() const;
00071
00073 static DtValue<T>* cast(DtAnyValue* base);
00074
00076 static const DtValue<T>* cast(const DtAnyValue* base);
00077
00079 static bool isType(const DtAnyValue* base);
00080
00083 static DtValue<T>* deserialize(const DtString& value);
00084
00086 operator T();
00087
00089 operator const T() const;
00090
00092 virtual int typeId() const;
00093
00095 virtual const DtString& type() const;
00096
00098 virtual DtString serialize() const;
00099
00101 static int theTypeId();
00102
00104 static const DtString& theType();
00105
00107 DT_DLL_LGRUTIL static DtString (*theSerializeFunction)(const T&);
00108
00110 DT_DLL_LGRUTIL static T (*theDeserializeFunction)(const DtString&);
00111
00113 T myValue;
00114
00115 };
00116
00117
00119 DT_DLL_LGRUTIL std::vector<DtString> deserializeList(const DtString&);
00120
00122 template <typename T>
00123 class DtValueList
00124 {
00125 public:
00126
00127 static DtValue<std::vector<T> > deserialize(const DtString&);
00128
00130 static std::vector<T> deserializeMembers(const std::vector<DtString>& values);
00131
00133 static DtValue<std::vector<T> >* deserializeMembersToPtr(const std::vector<DtString>& values);
00134
00136 static std::vector<T> deserializeListMembers(const DtString&);
00137
00138 static DtString serializeList(const std::vector<T>& list);
00139 };
00140
00141 template <typename T>
00142 DtAnyValue* DtWrapValue(const T& input)
00143 {
00144 return new DtValue<T>(input);
00145 }
00146
00147
00149 DT_DLL_LGRUTIL unsigned int hash( const char *k);
00150
00152 #define DT_UNIQUE_INT (hash(__FILE__)+__LINE__)
00153
00155
00159
00160 #define DtDeclareRuntimeType(type)\
00161 template<> \
00162 DT_DLL_LGRUTIL int DtValue< type >::theTypeId(); \
00163 template<> \
00164 DT_DLL_LGRUTIL const DtString& DtValue< type >::theType();\
00165 template<> \
00166 DT_DLL_LGRUTIL int DtValue< std::vector<type> >::theTypeId(); \
00167 template<> \
00168 DT_DLL_LGRUTIL const DtString& DtValue< std::vector<type> >::theType();
00169
00170
00173 #define DtDefineRuntimeType(type) \
00174 template<> \
00175 int DtValue<type>::theTypeId() \
00176 { \
00177 static int id = DT_UNIQUE_INT; return id; \
00178 } \
00179 \
00180 template<> \
00181 const DtString& DtValue<type>::theType() \
00182 { \
00183 static DtString typeName(#type); \
00184 return typeName; \
00185 } \
00186 \
00187 template<> \
00188 DtString (*DtValue<type>::theSerializeFunction)(const type&) = 0; \
00189 template<> \
00190 type (*DtValue<type>::theDeserializeFunction)(const DtString&) = 0; \
00191 \
00192 template<> \
00193 int DtValue<std::vector<type> >::theTypeId() \
00194 { \
00195 static int id = DT_UNIQUE_INT; return id; \
00196 } \
00197 \
00198 template<> \
00199 const DtString& DtValue<std::vector<type> >::theType() \
00200 { \
00201 static DtString typeName("std::vector<" #type ">"); \
00202 return typeName; \
00203 } \
00204 \
00205 template<> \
00206 DtString (*DtValue<std::vector<type> >::theSerializeFunction)( \
00207 const std::vector<type>&) = 0; \
00208 \
00209 template<> \
00210 std::vector<type> (*DtValue<std::vector<type> >::theDeserializeFunction) \
00211 (const DtString&) = 0;
00212
00213
00214 #define DtDefineSerializableRuntimeType(type) \
00215 template<> \
00216 int DtValue<type>::theTypeId() \
00217 { \
00218 static int id = DT_UNIQUE_INT; return id; \
00219 } \
00220 \
00221 template<> \
00222 const DtString& DtValue<type>::theType() \
00223 { \
00224 static DtString typeName(#type); \
00225 return typeName; \
00226 } \
00227 template<> \
00228 int DtValue<std::vector<type> >::theTypeId() \
00229 { \
00230 static int id = DT_UNIQUE_INT; return id; \
00231 } \
00232 \
00233 template<> \
00234 const DtString& DtValue<std::vector<type> >::theType() \
00235 { \
00236 static DtString typeName("std::vector<" #type ">" ); \
00237 return typeName; \
00238 } \
00239 \
00240 DtString serializeList##type(const std::vector<type>& input) \
00241 { \
00242 return DtValueList<type>::serializeList(input); \
00243 } \
00244 \
00245 \
00246 std::vector<type> deserializeList##type(const DtString& input) \
00247 { \
00248 return DtValueList<type>::deserializeListMembers(input); \
00249 } \
00250 \
00251 template<> \
00252 DtString (*DtValue<std::vector<type> >::theSerializeFunction)( \
00253 const std::vector<type>&) = serializeList##type; \
00254 \
00255 template<> \
00256 std::vector<type> (*DtValue<std::vector<type> >::theDeserializeFunction) \
00257 (const DtString&) = deserializeList##type;
00258
00262
00264 DtDeclareRuntimeType(unsigned char)
00267
00270
00271 #define runtimeValue_INC_
00272 #include "runtimeValue.inl"
00273 #undef runtimeValue_INC_
00274
00275 }
00276
00277 #endif