MAK Data Logger API Documentation for HLA
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 <lgrUtil/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 
110 
113 
116 
117  };
118 
121  DT_DLL_LGRUTIL std::vector<DtString> deserializeList(const DtString&);
122 
124  template <typename T>
126  {
127  public:
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);
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
static DtString serializeList(const std::vector< T > &list)
Definition: runtimeValue.h:152
DtValue(const T &value)
Constructor pass in value.
Definition: runtimeValue.h:20
static const DtString & theType()
Static string which defines the type.
DtBoost::shared_ptr< DtAnyValue > DtAnyValueSP
Definition: lgrCommand.h:103
static DtValue< std::vector< T > > * deserializeMembersToPtr(const std::vector< DtString > &values)
Deserialize value list into a T type list pointer.
Definition: runtimeValue.h:145
virtual ~DtValue()
Destructor, no opp.
Definition: runtimeValue.h:27
#define DT_DLL_LGRUTIL
Definition: lgrUtil.h:19
static DT_DLL_LGRUTIL DtString(* theSerializeFunction)(const T &)
Pointer to serializeFunction.
Definition: runtimeValue.h:109
static int theTypeId()
Static function which defines the type.
virtual DtAnyValue * clone() const
Create a new copy of the DtValue;.
Definition: runtimeValue.h:32
DT_DLL_LGRUTIL unsigned int hash(const char *k)
Necessary non-coliding Hash function.
DtAnyValue()
Inline function provided to work around solaris compiler issue.
Definition: runtimeValue.h:36
DtAnyValue is a base class for Any Value type.
Definition: runtimeValue.h:30
T myValue
Storage of value;.
Definition: runtimeValue.h:115
DT_DLL_LGRUTIL std::vector< DtString > deserializeList(const DtString &)
Deserialize string value into string list.
static bool isType(const DtAnyValue *base)
Static boolean check if base value pointer is specific type.
Definition: runtimeValue.h:82
#define DtDeclareRuntimeType(type)
Helper macros.
Definition: runtimeValue.h:162
static DtValue< T > * deserialize(const DtString &value)
Deserialize value into a T type.
Definition: runtimeValue.h:51
static DtValue< std::vector< T > > deserialize(const DtString &)
Definition: runtimeValue.h:112
Contains MAKLogger::DtAbsoluteTime and MAKLogger::DtRelativeTime classes.
virtual int typeId() const =0
Contains IMPORT/EXPORT macros for lgrUtil library.
virtual const DtString & type() const
Get the type string.
Definition: runtimeValue.h:94
static DT_DLL_LGRUTIL T(* theDeserializeFunction)(const DtString &)
Pointer to deserializeFunction.
Definition: runtimeValue.h:112
static DtValue< T > * cast(DtAnyValue *base)
Cast to point of this type. If not valid type, returns 0.
Definition: runtimeValue.h:73
virtual ~DtAnyValue()
Inline function provided to work around solaris compiler issue.
Definition: runtimeValue.h:39
static std::vector< T > deserializeListMembers(const DtString &)
Deserialize a list to an array of native members.
Definition: runtimeValue.h:119
virtual bool sameType(const DtAnyValue *const base) const
Inline function provided to work around solaris compiler issue.
Definition: runtimeValue.h:44
Contains MAKLogger::DtBase64Data class.
virtual int typeId() const
Get the type id.
Definition: runtimeValue.h:88
virtual DtString serialize() const
Serialize the value into a string.
Definition: runtimeValue.h:38
A list of values.
Definition: runtimeValue.h:125
DtValue is a template class that provide value access.
Definition: runtimeValue.h:61
static std::vector< T > deserializeMembers(const std::vector< DtString > &values)
Deserialize string values into a T type list.
Definition: runtimeValue.h:128
DtAnyValue * DtWrapValue(const T &input)
Definition: runtimeValue.h:144

Document ID: Generated on Thu Sep 2 15:35:22 EDT 2021 from SVN revision 233992
Copyright © 2021 MAK Technologies. All Rights Reserved (www.mak.com)