VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
rwPropertiesMap.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2013 MAK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 
8 
9 #pragma once
10 
12 
42 {
43 private:
46 
47 public:
48 
51  DtRwPropertiesMap(const DtString& name, DtReaderWriterRegistry* parentRegistry = 0);
52  DtRwPropertiesMap(const DtString& name, const DtString& keyType,
53  const DtPropertyInterface* prototype, DtReaderWriterRegistry* parentRegistry = 0);
54  DtRwPropertiesMap(const DtString& name, const DtRwPropertiesMap& orig,
55  DtReaderWriterRegistry* parentRegistry = 0);
56  virtual ~DtRwPropertiesMap();
58 
61 
71  virtual DtPropertyInterface* findItem(const DtString& key);
72 
74  virtual DtPropertyInterface* findItem(int key);
75 
77  virtual DtPropertyInterface* findItem(double key);
78 
81  virtual const DtPropertyInterface* findItem(const DtString& key) const;
82 
84  virtual const DtPropertyInterface* findItem(int key) const;
85 
87  virtual const DtPropertyInterface* findItem(double key) const;
88 
96  template <typename ValueType>
97  boost::optional<ValueType> findItemValue(const DtString& key) const;
98 
100  template <typename ValueType>
101  boost::optional<ValueType> findItemValue(int key) const;
102 
104  template <typename ValueType>
105  boost::optional<ValueType> findItemValue(double key) const;
107 
110 
120  virtual bool insert(const DtString& key, DtPropertyInterface* item);
121  virtual bool insert(int key, DtPropertyInterface* item);
122  virtual bool insert(double key, DtPropertyInterface* item);
124 
127 
137  virtual DtPropertyInterface* addItem(const DtString& key);
138  virtual DtPropertyInterface* addItem(int key);
139  virtual DtPropertyInterface* addItem(double key);
141 
144 
150  virtual bool erase(const DtString& key);
151  virtual bool erase(int key);
152  virtual bool erase(double key);
154 
171  DtPropertyInterface& operator[](const DtString& key);
172  const DtPropertyInterface& operator[](const DtString& key) const;
173  DtPropertyInterface& operator[](double key);
174  const DtPropertyInterface& operator[](double key) const;
175  DtPropertyInterface& operator[](int key);
176  const DtPropertyInterface& operator[](int key) const;
178 
182  virtual const char* readerWriterType() const;
183 
185  static const char* theXmlType();
186 
187  virtual const char* xmlType() const
188  {
189  return theXmlType();
190  }
191 
193 
196  virtual void setKeyType(const DtString&);
197  virtual const DtReaderWriter* keyType() const;
199 
202  virtual bool keyIsInt() const;
203  virtual bool keyIsReal() const;
204  virtual bool keyIsString() const;
206 
208  virtual bool isSimilarProperty(const DtPropertyInterface* rhs, bool strict = true) const;
209 
211  virtual int hlaAlignment() const;
212 
213  bool operator==(const DtRwPropertiesMap&) const;
214 
215 protected:
216 
218  virtual bool convertKeyToString(int key, DtString& str) const;
219 
221  virtual bool convertKeyToString(double key, DtString& str) const;
222 
224  virtual bool convertStringToKey(const DtString& str, int& key) const;
225 
227  virtual bool convertStringToKey(const DtString& str, double& key) const;
228 
230  virtual DtPropertyInterface* createPrototype(DtlObjPtr args);
231  virtual DtlObjPtr variablesStart(DtlObjPtr args) const;
232 
233  virtual void createListEntry(DtPropertyInterface* iFace, DtlObjPtr variableItem,
234  const DtReaderWriter::SearchPaths& searchPaths,
235  const DtVariableBindingsList& variableBindings);
236 
238  virtual void getSize(const DtPropertyInterface*, int& size) const;
239 
241  virtual char* encode(const DtPropertyInterface*, char* buf) const;
242 
244  virtual const char* decode(DtPropertyInterface* iFace, const char* buf);
245 
248  virtual int requiredPadding(const char* buf, const DtPropertyInterface* field) const;
249 
250  virtual void getData(const DtEnvironmentSP env, const DtEnvValueSP root,
251  const DtReaderWriter::SearchPaths& searchPaths,
252  const DtVariableBindingsList& varBindings);
253  virtual void putData(DtEnvironmentSP env, DtEnvValueSP value) const;
254  virtual void postWriteItem(std::string& fp, DtReaderWriter* rw, int indentLevel);
255  virtual void preWriteItem(std::string& fp, DtReaderWriter* rw, int indentLevel);
256 
257  virtual DtPropertyInterface* scratchItem() const;
258 
263  virtual const DtPropertyInterface* findPropertyInterfaceByStringKey(const DtString& keyStr) const;
264  virtual DtPropertyInterface* findPropertyInterfaceByStringKey(const DtString& keyStr);
266 
267 protected:
269 
271 };
272 
273 template <typename ValueType>
274 boost::optional<ValueType> DtRwPropertiesMap::findItemValue(const DtString& key) const
275 {
276  if (keyIsString())
277  {
278  return findPropertyValue<ValueType>(key);
279  }
280 
281  return boost::optional<ValueType>();
282 }
283 
284 template <typename ValueType>
285 boost::optional<ValueType> DtRwPropertiesMap::findItemValue(int key) const
286 {
287  DtString keyStr;
288  if (convertKeyToString(key, keyStr))
289  {
290  return findPropertyValue<ValueType>(keyStr);
291  }
292 
293  return boost::optional<ValueType>();
294 }
295 
296 template <typename ValueType>
297 boost::optional<ValueType> DtRwPropertiesMap::findItemValue(double key) const
298 {
299  DtString keyStr;
300  if (convertKeyToString(key, keyStr))
301  {
302  return findPropertyValue<ValueType>(keyStr);
303  }
304 
305  return boost::optional<ValueType>();
306 }
#define DT_DLL_readerWriter
This file is used to determine how to build Disable inconsistent dll linkage warning Visual Studio 6...
Definition: readerWriterDefines.h:34
virtual DtlObjPtr variablesStart(DtlObjPtr args) const
virtual void createListEntry(DtPropertyInterface *iFace, DtlObjPtr variableItem, const DtReaderWriter::SearchPaths &searchPaths, const DtVariableBindingsList &variableBindings)
virtual void putData(DtEnvironmentSP, DtEnvValueSP value) const
Override to add attributes of actual data.
DtPropertyInterface * myScratchItem
Definition: rwPropertiesMap.h:270
DT_DLL_readerWriter DtBoost::shared_ptr< DtEnvironment > DtEnvironmentSP
Definition: readerWriter.h:30
virtual bool convertKeyToString(int key, DtString &str) const
Convert the given int key to a DtString. If not possible, returns false.
voidpf void uLong size
Definition: ioapi.h:39
virtual void preWriteItem(std::string &fp, DtReaderWriter *rw, int indentLevel)
Definition: readerWriter.h:85
virtual void postWriteItem(std::string &fp, DtReaderWriter *rw, int indentLevel)
Definition: readerWriterRegistry.h:39
virtual DtlObjPtr getData(DtlObjPtr variableList, const DtReaderWriter::SearchPaths &searchPaths, const DtVariableBindingsList &variableBindings)
Override to allow a variable to be assigned to a property of derived type.
voidpf void * buf
Definition: ioapi.h:39
virtual const char * xmlType() const
Definition: rwPropertiesMap.h:187
Interface class used to define minimal interface for a property. The DtPropertyInterface class provid...
Definition: propertyInterface.h:48
virtual bool keyIsString() const
Returns the type of key.
virtual bool isSimilarProperty(const DtPropertyInterface *rhs, bool strict=true) const
Returns true prototype is the same.
boost::optional< ValueType > findItemValue(const DtString &key) const
Finds the value of the item with the specified key. Will fail if the type of the key does not match t...
Definition: rwPropertiesMap.h:274
virtual char * encode(char *) const
Encodes the property into the supplied buffer. Does not align the property. Buffer must already be al...
virtual DtPropertyInterface * createPrototype(DtlObjPtr)
DtPropertyInterface * myKeyType
Definition: rwPropertiesMap.h:268
std::list< const DtRwVariableBindings * > DtVariableBindingsList
Definition: readerWriterRegistry.h:29
std::vector< DtFilename > SearchPaths
Definition: readerWriter.h:92
virtual const char * decode(const char *)
Decodes the property from the specified buffer. Assumes buffer is the start of the property and prece...
int getSize() const
Returns the network size of this item in bytes. This does not include any upfront padding for alignme...
Acts as a map for properties. A map is a definition that has a key and a prototype, with values being the key and prototype pair. The key can only be a string (DtRwStringType), int (DtRwIntType, DtRwInt8Type, DtRwInt16Type, DtRwInt32Type), or real (DtRwRealType, DtRwReal32Type, DtRwReal64Type).
Definition: rwPropertiesMap.h:41
virtual int requiredPadding(const char *buf, const DtPropertyInterface *field) const
The number of padding bytes required before writing the given field to the buffer for HLA encoding...
bool operator==(const DtRwPropertiesList &) const
DtRwPropertiesList & operator=(const DtRwPropertiesList &)
virtual void erase(DtPropertyInterface *item)
Erases the specified item.
virtual const char * readerWriterType() const
Used to supply a string type that this reader writer type is. This can be used in place of dynamic-ca...
Acts as a DtRwList for properties. Only real difference between this class and a DtRwProperties class...
Definition: rwPropertiesList.h:38
virtual int hlaAlignment() const
The required byte alignment of this property when encoding to HLA.
virtual DtPropertyInterface * addItem()
Adds a new item to the end of the list of the same type as myPrototype. Returns this item so that it ...
static const char * theXmlType()
The type that is used when archiving to an XML stream.

Document ID: Generated on Wed Mar 27 22:49:11 EDT 2024 from SVN revision 264633
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)