VR-Forces 5.0.1 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 
70  virtual DtPropertyInterface* findItem(const DtString& key);
71 
73  virtual DtPropertyInterface* findItem(int key);
74 
76  virtual DtPropertyInterface* findItem(double key);
77 
80  virtual const DtPropertyInterface* findItem(const DtString& key) const;
81 
83  virtual const DtPropertyInterface* findItem(int key) const;
84 
86  virtual const DtPropertyInterface* findItem(double key) const;
87 
95  template <typename ValueType>
96  boost::optional<ValueType> findItemValue(const DtString& key) const;
97 
99  template <typename ValueType>
100  boost::optional<ValueType> findItemValue(int key) const;
101 
103  template <typename ValueType>
104  boost::optional<ValueType> findItemValue(double key) const;
106 
118  virtual bool insert(const DtString& key, DtPropertyInterface* item);
119  virtual bool insert(int key, DtPropertyInterface* item);
120  virtual bool insert(double key, DtPropertyInterface* item);
122 
134  virtual DtPropertyInterface* addItem(const DtString& key);
135  virtual DtPropertyInterface* addItem(int key);
136  virtual DtPropertyInterface* addItem(double key);
138 
146  virtual bool erase(const DtString& key);
147  virtual bool erase(int key);
148  virtual bool erase(double key);
150 
167  DtPropertyInterface& operator[](const DtString& key);
168  const DtPropertyInterface& operator[](const DtString& key) const;
169  DtPropertyInterface& operator[](double key);
170  const DtPropertyInterface& operator[](double key) const;
171  DtPropertyInterface& operator[](int key);
172  const DtPropertyInterface& operator[](int key) const;
174 
178  virtual const char* readerWriterType() const;
179 
181  static const char* theXmlType();
182 
183  virtual const char* xmlType() const
184  {
185  return theXmlType();
186  }
187 
189 
192  virtual void setKeyType(const DtString&);
193  virtual const DtReaderWriter* keyType() const;
195 
198  virtual bool keyIsInt() const;
199  virtual bool keyIsReal() const;
200  virtual bool keyIsString() const;
202 
204  virtual bool isSimilarProperty(const DtPropertyInterface* rhs, bool strict = true) const;
205 
207  virtual int hlaAlignment() const;
208 
209  bool operator==(const DtRwPropertiesMap&) const;
210 
211 protected:
212 
214  virtual bool convertKeyToString(int key, DtString& str) const;
215 
217  virtual bool convertKeyToString(double key, DtString& str) const;
218 
220  virtual bool convertStringToKey(const DtString& str, int& key) const;
221 
223  virtual bool convertStringToKey(const DtString& str, double& key) const;
224 
226  virtual DtPropertyInterface* createPrototype(DtlObjPtr args);
227  virtual DtlObjPtr variablesStart(DtlObjPtr args) const;
228 
229  virtual void createListEntry(DtPropertyInterface* iFace, DtlObjPtr variableItem,
230  const DtReaderWriter::SearchPaths& searchPaths,
231  const DtVariableBindingsList& variableBindings);
232 
234  virtual void getSize(const DtPropertyInterface*, int& size) const;
235 
237  virtual char* encode(const DtPropertyInterface*, char* buf) const;
238 
240  virtual const char* decode(DtPropertyInterface* iFace, const char* buf);
241 
244  virtual int requiredPadding(const char* buf, const DtPropertyInterface* field) const;
245 
246  virtual void getData(const DtEnvironmentSP env, const DtEnvValueSP root,
247  const DtReaderWriter::SearchPaths& searchPaths,
248  const DtVariableBindingsList& varBindings);
249  virtual void putData(DtEnvironmentSP env, DtEnvValueSP value) const;
250  virtual void postWriteItem(std::string& fp, DtReaderWriter* rw, int indentLevel);
251  virtual void preWriteItem(std::string& fp, DtReaderWriter* rw, int indentLevel);
252 
253  virtual DtPropertyInterface* scratchItem() const;
254 
259  virtual const DtPropertyInterface* findPropertyInterfaceByStringKey(const DtString& keyStr) const;
260  virtual DtPropertyInterface* findPropertyInterfaceByStringKey(const DtString& keyStr);
262 
263 protected:
265 
267 };
268 
269 template <typename ValueType>
270 boost::optional<ValueType> DtRwPropertiesMap::findItemValue(const DtString& key) const
271 {
272  if (keyIsString())
273  {
274  return findPropertyValue<ValueType>(key);
275  }
276 
277  return boost::optional<ValueType>();
278 }
279 
280 template <typename ValueType>
281 boost::optional<ValueType> DtRwPropertiesMap::findItemValue(int key) const
282 {
283  DtString keyStr;
284  if (convertKeyToString(key, keyStr))
285  {
286  return findPropertyValue<ValueType>(keyStr);
287  }
288 
289  return boost::optional<ValueType>();
290 }
291 
292 template <typename ValueType>
293 boost::optional<ValueType> DtRwPropertiesMap::findItemValue(double key) const
294 {
295  DtString keyStr;
296  if (convertKeyToString(key, keyStr))
297  {
298  return findPropertyValue<ValueType>(keyStr);
299  }
300 
301  return boost::optional<ValueType>();
302 }
#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:266
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:183
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:270
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:264
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 item at the specified iterator position.
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 Mon Jun 20 00:38:30 EDT 2022 from SVN revision 244029
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)