MAK Data Logger API Documentation for DIS
runtimeValue.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 1992-2010 VT MAK
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 
10 #ifndef runtimeValue_H_
11 #define runtimeValue_H_
12 
13 #include "lgrUtil.h"
14 #include "absoluteTime.h"
15 #include "base64Data.h"
16 
17 #include <vlutil/vlString.h>
18 #include <vlutil/vlSmartPointers.h>
19 
20 #include <ctype.h>
21 #include <cstring>
22 #include <cstdio>
23 #include <string>
24 #include <vector>
25 
26 namespace MAKLogger
27 {
31  {
32  public:
33 
34 
37 
39  virtual ~DtAnyValue() {}
40 
41  virtual DtAnyValue* clone() const = 0;
42 
44  virtual bool sameType(const DtAnyValue* const base) const
45  { return this->typeId() == base->typeId(); }
46 
47  virtual const DtString& type() const = 0;
48  virtual DtString serialize() const = 0;
49 
50  virtual int typeId() const = 0;
51  };
52 
53  typedef DtBoost::shared_ptr<DtAnyValue> DtAnyValueSP;
54 
60  template <typename T>
61  class DtValue : public DtAnyValue
62  {
63  public:
64 
66  DtValue(const T& value);
67 
69  virtual ~DtValue();
70 
72  virtual DtAnyValue* clone() const;
73 
75  static DtValue<T>* cast(DtAnyValue* base);
76 
78  static const DtValue<T>* cast(const DtAnyValue* base);
79 
81  static bool isType(const DtAnyValue* base);
82 
85  static DtValue<T>* deserialize(const DtString& value);
86 
88  operator T();
89 
91  operator const T() const;
92 
94  virtual int typeId() const;
95 
97  virtual const DtString& type() const;
98 
100  virtual DtString serialize() const;
101 
103  static int theTypeId();
104 
106  static const DtString& theType();
107 
109  DT_DLL_LGRUTIL static DtString (*theSerializeFunction)(const T&);
110 
112  DT_DLL_LGRUTIL static T (*theDeserializeFunction)(const DtString&);
113 
116 
117  };
118 
119 
121  DT_DLL_LGRUTIL std::vector<DtString> deserializeList(const DtString&);
122 
124  template <typename T>
126  {
127  public:
128 
129  static DtValue<std::vector<T> > deserialize(const DtString&);
130 
132  static std::vector<T> deserializeMembers(const std::vector<DtString>& values);
133 
135  static DtValue<std::vector<T> >* deserializeMembersToPtr(const std::vector<DtString>& values);
136 
138  static std::vector<T> deserializeListMembers(const DtString&);
139 
140  static DtString serializeList(const std::vector<T>& list);
141  };
142 
143  template <typename T>
144  DtAnyValue* DtWrapValue(const T& input)
145  {
146  return new DtValue<T>(input);
147  }
148 
149 
151  DT_DLL_LGRUTIL unsigned int hash( const char *k);
152 
154  #define DT_UNIQUE_INT (hash(__FILE__)+__LINE__)
155 
157 
161 
162  #define DtDeclareRuntimeType(type)\
163  template<> \
164  DT_DLL_LGRUTIL int DtValue< type >::theTypeId(); \
165  template<> \
166  DT_DLL_LGRUTIL const DtString& DtValue< type >::theType();\
167  template<> \
168  DT_DLL_LGRUTIL int DtValue< std::vector<type> >::theTypeId(); \
169  template<> \
170  DT_DLL_LGRUTIL const DtString& DtValue< std::vector<type> >::theType();
171 
172 
175  #define DtDefineRuntimeType(type) \
176  template<> \
177  int DtValue<type>::theTypeId() \
178  { \
179  static int id = DT_UNIQUE_INT; return id; \
180  } \
181  \
182  template<> \
183  const DtString& DtValue<type>::theType() \
184  { \
185  static DtString typeName(#type); \
186  return typeName; \
187  } \
188  \
189  template<> \
190  DtString (*DtValue<type>::theSerializeFunction)(const type&) = 0; \
191  template<> \
192  type (*DtValue<type>::theDeserializeFunction)(const DtString&) = 0; \
193  \
194  template<> \
195  int DtValue<std::vector<type> >::theTypeId() \
196  { \
197  static int id = DT_UNIQUE_INT; return id; \
198  } \
199  \
200  template<> \
201  const DtString& DtValue<std::vector<type> >::theType() \
202  { \
203  static DtString typeName("std::vector<" #type ">"); \
204  return typeName; \
205  } \
206  \
207  template<> \
208  DtString (*DtValue<std::vector<type> >::theSerializeFunction)( \
209  const std::vector<type>&) = 0; \
210  \
211  template<> \
212  std::vector<type> (*DtValue<std::vector<type> >::theDeserializeFunction) \
213  (const DtString&) = 0;
214 
215 
216  #define DtDefineSerializableRuntimeType(type) \
217  template<> \
218  int DtValue<type>::theTypeId() \
219  { \
220  static int id = DT_UNIQUE_INT; return id; \
221  } \
222  \
223  template<> \
224  const DtString& DtValue<type>::theType() \
225  { \
226  static DtString typeName(#type); \
227  return typeName; \
228  } \
229  template<> \
230  int DtValue<std::vector<type> >::theTypeId() \
231  { \
232  static int id = DT_UNIQUE_INT; return id; \
233  } \
234  \
235  template<> \
236  const DtString& DtValue<std::vector<type> >::theType() \
237  { \
238  static DtString typeName("std::vector<" #type ">" ); \
239  return typeName; \
240  } \
241  \
242  DtString serializeList##type(const std::vector<type>& input) \
243  { \
244  return DtValueList<type>::serializeList(input); \
245  } \
246  \
247  \
248  std::vector<type> deserializeList##type(const DtString& input) \
249  { \
250  return DtValueList<type>::deserializeListMembers(input); \
251  } \
252  \
253 template<> \
254 DtString (*DtValue<std::vector<type> >::theSerializeFunction)( \
255 const std::vector<type>&) = serializeList##type; \
256  \
257 template<> \
258 std::vector<type> (*DtValue<std::vector<type> >::theDeserializeFunction) \
259 (const DtString&) = deserializeList##type;
260 
264 
266  DtDeclareRuntimeType(unsigned char)
269 
272 
273  #define runtimeValue_INC_
274  #include "runtimeValue.inl"
275  #undef runtimeValue_INC_
276 
277 }
278 
279 #endif

Document ID: Generated on Thu Apr 10 18:53:01 EDT 2014 from SVN revision 138105
Copyright © 2005-2012 VT MÄK. All Rights Reserved (www.mak.com)