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) 2025 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() override;
58 
61  struct Key
62  {
63  Key(const Key& rhs) :
64  myStr(rhs.myStr), myInt(rhs.myInt), myDbl(rhs.myDbl), myType(rhs.myType) {};
65 
66  Key(const DtString& str) : myStr(str), myInt(0), myDbl(0), myType(StrType) {};
67 
68  Key(int i) : myStr(), myInt(i), myDbl(0), myType(IntType) {};
69 
70  Key(double d) : myStr(), myInt(0), myDbl(d), myType(DoubleType) {};
71 
72  bool operator==(const Key& rhs) const
73  {
74  switch (myType)
75  {
76  case IntType:
77  return myInt == rhs.myInt;
78  break;
79  case DoubleType:
80  return myDbl == rhs.myDbl;
81  break;
82  case StrType:
83  default:
84  return myStr == rhs.myStr;
85  break;
86  }
87  }
88 
89  bool operator<(const Key& rhs) const
90  {
91  switch (myType)
92  {
93  case IntType:
94  return myInt < rhs.myInt;
95  break;
96  case DoubleType:
97  return myDbl < rhs.myDbl;
98  break;
99  case StrType:
100  default:
101  return myStr < rhs.myStr;
102  break;
103  }
104  }
105 
106  DtString string() const
107  {
108  switch (myType)
109  {
110  case IntType:
111  return DtString(myInt);
112  break;
113  case DoubleType:
114  return DtString(myDbl);
115  break;
116  case StrType:
117  default:
118  return myStr;
119  break;
120  }
121  }
122 
124  int myInt;
125  double myDbl;
126 
127  enum KeyType
128  {
131  DoubleType
132  };
134  };
135 
136 
139 
149  virtual DtPropertyInterface* findItem(const DtString& key);
150 
152  virtual DtPropertyInterface* findItem(int key);
153 
155  virtual DtPropertyInterface* findItem(double key);
156 
158  virtual DtPropertyInterface* findItem(const Key& key);
159 
162  virtual const DtPropertyInterface* findItem(const DtString& key) const;
163 
165  virtual const DtPropertyInterface* findItem(int key) const;
166 
168  virtual const DtPropertyInterface* findItem(double key) const;
169 
171  virtual const DtPropertyInterface* findItem(const Key& key) const;
172 
180  template <typename ValueType>
181  boost::optional<ValueType> findItemValue(const DtString& key) const;
182 
184  template <typename ValueType>
185  boost::optional<ValueType> findItemValue(int key) const;
186 
188  template <typename ValueType>
189  boost::optional<ValueType> findItemValue(double key) const;
190 
192  template <typename ValueType>
193  boost::optional<ValueType> findItemValue(const Key& key) const;
195 
198 
208  virtual bool insert(const DtString& key, DtPropertyInterface* item);
209  virtual bool insert(int key, DtPropertyInterface* item);
210  virtual bool insert(double key, DtPropertyInterface* item);
211  virtual bool insert(const Key& key, DtPropertyInterface* item);
213 
216 
226  virtual DtPropertyInterface* addItem(const DtString& key);
227  virtual DtPropertyInterface* addItem(int key);
228  virtual DtPropertyInterface* addItem(double key);
229  virtual DtPropertyInterface* addItem(const Key& key);
231 
234 
240  virtual bool erase(const DtString& key);
241  virtual bool erase(int key);
242  virtual bool erase(double key);
243  virtual bool erase(const Key& key);
245 
262  DtPropertyInterface& operator[](const DtString& key);
263  const DtPropertyInterface& operator[](const DtString& key) const;
264  DtPropertyInterface& operator[](double key);
265  const DtPropertyInterface& operator[](double key) const;
266  DtPropertyInterface& operator[](int key);
267  const DtPropertyInterface& operator[](int key) const;
268  DtPropertyInterface& operator[](const Key& key);
269  const DtPropertyInterface& operator[](const Key& key) const;
271 
275  virtual const char *readerWriterType() const override;
276 
278  static const char* theXmlType();
279 
280  virtual const char *xmlType() const override {
281  return theXmlType();
282  }
283 
285 
288  virtual void setKeyType(const DtString&);
289  virtual const DtReaderWriter* keyType() const;
291 
294  virtual bool keyIsInt() const;
295  virtual bool keyIsReal() const;
296  virtual bool keyIsString() const;
298 
301  virtual Key keyOfItem(const DtPropertyInterface* item) const;
302 
304  virtual std::set<Key> allKeys() const;
305 
307  virtual bool isSimilarProperty(const DtPropertyInterface *rhs,
308  bool strict = true) const override;
309 
311  virtual int hlaAlignment() const override;
312 
313  bool operator==(const DtRwPropertiesMap&) const;
314 
315 protected:
316 
318  virtual bool convertKeyToString(int key, DtString& str) const;
319 
321  virtual bool convertKeyToString(double key, DtString& str) const;
322 
324  virtual bool convertStringToKey(const DtString& str, int& key) const;
325 
327  virtual bool convertStringToKey(const DtString& str, double& key) const;
328 
330  virtual DtPropertyInterface *createPrototype(DtlObjPtr args) override;
331  virtual DtlObjPtr variablesStart(DtlObjPtr args) const override;
332 
333  virtual void createListEntry(DtPropertyInterface *iFace, DtlObjPtr variableItem,
334  const DtReaderWriter::SearchPaths &searchPaths,
335  const DtVariableBindingsList &variableBindings) override;
336 
338  virtual void getSize(const DtPropertyInterface *, int &size) const override;
339 
341  virtual char *encode(const DtPropertyInterface *, char *buf) const override;
342 
344  virtual const char *decode(DtPropertyInterface *iFace,
345  const char *buf) override;
346 
349  virtual int requiredPadding(const char *buf,
350  const DtPropertyInterface *field) const override;
351 
352  virtual void writePrototype(const DtReaderWriter* rw, std::string& fp, int indentLevel, bool writeHeader) const override;
353 
354  virtual void getData(const DtEnvironmentSP env, const DtEnvValueSP root,
355  const DtReaderWriter::SearchPaths &searchPaths,
356  const DtVariableBindingsList &varBindings) override;
357  virtual void putData(DtEnvironmentSP env, DtEnvValueSP value) const override;
358  virtual void postWriteItem(std::string &fp, DtReaderWriter *rw,
359  int indentLevel) override;
360  virtual void preWriteItem(std::string &fp, DtReaderWriter *rw,
361  int indentLevel) override;
362 
363  virtual DtPropertyInterface* scratchItem() const;
364 
369  virtual const DtPropertyInterface* findPropertyInterfaceByStringKey(const DtString& keyStr) const;
370  virtual DtPropertyInterface* findPropertyInterfaceByStringKey(const DtString& keyStr);
372 
373 protected:
375 
377 };
378 
379 template <typename ValueType>
380 boost::optional<ValueType> DtRwPropertiesMap::findItemValue(const DtString& key) const
381 {
382  if (keyIsString())
383  {
384  return findPropertyValue<ValueType>(key);
385  }
386 
387  return boost::optional<ValueType>();
388 }
389 
390 template <typename ValueType>
391 boost::optional<ValueType> DtRwPropertiesMap::findItemValue(int key) const
392 {
393  DtString keyStr;
394  if (convertKeyToString(key, keyStr))
395  {
396  return findPropertyValue<ValueType>(keyStr);
397  }
398 
399  return boost::optional<ValueType>();
400 }
401 
402 template <typename ValueType>
403 boost::optional<ValueType> DtRwPropertiesMap::findItemValue(double key) const
404 {
405  DtString keyStr;
406  if (convertKeyToString(key, keyStr))
407  {
408  return findPropertyValue<ValueType>(keyStr);
409  }
410 
411  return boost::optional<ValueType>();
412 }
413 
414 template <typename ValueType>
415 boost::optional<ValueType>
417 {
418  return findPropertyValue<ValueType>(key.string());
419 }
virtual void putData(DtEnvironmentSP, DtEnvValueSP value) const override
Override to add attributes of actual data.
Definition: rwPropertiesMap.h:130
DtString string() const
Definition: rwPropertiesMap.h:106
#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)
double myDbl
Definition: rwPropertiesMap.h:125
Wrapper for the map key. Makes it easier to write code that doesn&#39;t necessarily need to worry about t...
Definition: rwPropertiesMap.h:61
virtual char * encode(char *) const override
Encodes the property into the supplied buffer. Does not align the property. Buffer must already be al...
DtPropertyInterface * myScratchItem
Definition: rwPropertiesMap.h:376
virtual const char * decode(const char *) override
Decodes the property from the specified buffer. Assumes buffer is the start of the property and prece...
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 DtlObjPtr getData(DtlObjPtr variableList, const DtReaderWriter::SearchPaths &searchPaths, const DtVariableBindingsList &variableBindings) override
Override to allow a variable to be assigned to a property of derived type.
virtual void preWriteItem(std::string &fp, DtReaderWriter *rw, int indentLevel)
Definition: readerWriter.h:85
virtual int hlaAlignment() const override
The required byte alignment of this property when encoding to HLA.
virtual void postWriteItem(std::string &fp, DtReaderWriter *rw, int indentLevel)
Key(const Key &rhs)
Definition: rwPropertiesMap.h:63
Definition: readerWriterRegistry.h:39
KeyType
Definition: rwPropertiesMap.h:127
voidpf void * buf
Definition: ioapi.h:39
bool operator<(const Key &rhs) const
Definition: rwPropertiesMap.h:89
Interface class used to define minimal interface for a property. The DtPropertyInterface class provid...
Definition: propertyInterface.h:53
virtual void writePrototype(const DtReaderWriter *, std::string &fp, int indentLevel, bool writeHeader=true) const
virtual bool keyIsString() const
Returns the type of key.
virtual const char * xmlType() const override
Definition: rwPropertiesMap.h:280
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:380
virtual DtPropertyInterface * createPrototype(DtlObjPtr)
DtPropertyInterface * myKeyType
Definition: rwPropertiesMap.h:374
virtual bool isSimilarProperty(const DtPropertyInterface *rhs, bool strict=true) const override
Returns true prototype is the same.
std::list< const DtRwVariableBindings * > DtVariableBindingsList
Definition: readerWriterRegistry.h:29
std::vector< DtFilename > SearchPaths
Definition: readerWriter.h:92
bool operator==(const Key &rhs) const
Definition: rwPropertiesMap.h:72
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
Key(double d)
Definition: rwPropertiesMap.h:70
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...
KeyType myType
Definition: rwPropertiesMap.h:133
int myInt
Definition: rwPropertiesMap.h:124
bool operator==(const DtRwPropertiesList &) const
DtString myStr
Definition: rwPropertiesMap.h:123
DtRwPropertiesList & operator=(const DtRwPropertiesList &)
virtual void erase(DtPropertyInterface *item)
Erases the specified item.
Acts as a DtRwList for properties. Only real difference between this class and a DtRwProperties class...
Definition: rwPropertiesList.h:38
Key(int i)
Definition: rwPropertiesMap.h:68
DT_DLL_readerWriter std::shared_ptr< DtEnvironment > DtEnvironmentSP
Definition: readerWriter.h:30
Key(const DtString &str)
Definition: rwPropertiesMap.h:66
Definition: rwPropertiesMap.h:129
virtual const char * readerWriterType() const override
Used to supply a string type that this reader writer type is. This can be used in place of dynamic-ca...
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 Thu Oct 23 22:29:17 EDT 2025 from SVN revision 280951
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)