VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
rwTemplatedMap.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2016 MAK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 
8 
9 #pragma once
10 
11 #include <readerWriter/rwList.h>
12 #include "vrfutil/iteratorBase.h"
14 
15 template <typename FirstType, typename SecondType>
17 {
18 public:
19 
21 
23 
25  DtReaderWriterRegistry* const parentRegistry = NULL,
26  const DtString& firstName = "first", const DtString& secondName = "second");
28  DtReaderWriterRegistry* const parentRegistry = NULL,
29  const DtString& firstName = "first", const DtString& secondName = "second");
30 
32  DtReaderWriterRegistry* const parentRegistry = NULL);
34 
36  virtual ~DtRwTemplatedPair() {};
37 
40 
42  bool operator==(const DtRwTemplatedPair&) const;
43 
45  virtual const FirstType& first() const { return myFirst; }
46 
48  virtual void setFirst(const FirstType& f);
49 
51  virtual const SecondType& second() const { return mySecond; }
52 
54  virtual void setSecond(const SecondType& s);
55 
57 
58  virtual DtString firstName() const { return myFirst.name().c_str(); }
59  virtual void setFirstName(const DtString& n) { myFirst.setName(n); }
61 
63 
64  virtual DtString secondName() const { return mySecond.name().c_str(); }
65  virtual void setSecondName(const DtString& n) { mySecond.setName(n); }
67 
68 protected:
69 
70  FirstType myFirst;
71  SecondType mySecond;
72 };
73 
74 namespace DtBufferSerialize
75 {
78  template <typename FirstType, typename SecondType>
80 
84  template <typename FirstType, typename SecondType>
85  char *encode(const DtRwTemplatedPair<FirstType, SecondType>& val, char *buffer);
86 
91  template <typename FirstType, typename SecondType>
92  const char *decode(DtRwTemplatedPair<FirstType, SecondType>& val, const char *buffer);
93 };
94 
95 
96 template <typename KeyType, typename ValType>
98 {
99 public:
101  typedef typename std::map<KeyType, ValType>::iterator iterator;
102  typedef typename std::map<KeyType, ValType>::const_iterator const_iterator;
103 
106 
108 
110  DtReaderWriterRegistry* parentRegistry = NULL,
111  const DtString& keyName = "key", const DtString& valueName = "value", const DtString& elementName = "item");
113  DtReaderWriterRegistry* parentRegistry = NULL,
114  const DtString& keyName = "key", const DtString& valueName = "value", const DtString& elementName = "item");
116 
119 
121  DtReaderWriterRegistry* parentRegistry = NULL);
122 
124  DtReaderWriterRegistry* parentRegistry = NULL);
126 
129  DtReaderWriterRegistry* parentRegistry = NULL);
130 
133 
135  virtual ~DtRwTemplatedMapPtr();
136 
138  virtual void removeAndDeleteAll();
139 
140  DtlObjPtr getData(DtlObjPtr args, const DtReaderWriter::SearchPaths& searchPaths,
141  const DtVariableBindingsList& variableBindings);
142 
144  virtual void prePutSelf();
145 
147  virtual void postGetSelf();
148 
151  virtual void setFromMap(const std::map<KeyType, ValType> sourceMap);
152 
154  virtual void swap(DtRwTemplatedMapPtr& other);
155 
157  virtual const std::map<KeyType, ValType>& convertToMap() const;
158 
160  virtual void clear() { return myMap.clear(); }
161 
163  virtual unsigned size() const { return myMap.size(); }
164 
166 
167  virtual iterator begin() { return myMap.begin(); }
168  virtual const_iterator begin() const { return myMap.begin(); }
170 
172 
173  virtual iterator end() { return myMap.end(); }
174  virtual const_iterator end() const { return myMap.end(); }
176 
178 
179  std::pair<iterator, bool> insert(const RwPairType& item);
180  std::pair<iterator, bool> insert(const KeyType& key, const ValType& val);
182 
184 
185  void erase(iterator pos) { myMap.erase(pos); }
186  void erase(const KeyType& key) { myMap.erase(key); }
188 
190 
191  virtual iterator find(const KeyType& key) { return myMap.find(key); }
192  virtual const_iterator find(const KeyType& key) const { return myMap.find(key); }
194 
196 
197  virtual iterator lower_bound(const KeyType& key) { return myMap.lower_bound(key); }
198  virtual const_iterator lower_bound(const KeyType& key) const { return myMap.lower_bound(key); }
200 
202 
203  virtual iterator upper_bound(const KeyType& key) { return myMap.upper_bound(key); }
204  virtual const_iterator upper_bound(const KeyType& key) const { return myMap.upper_bound(key); }
206 
207 
209 
210  bool operator==(const DtRwTemplatedMapPtr&) const;
211  bool operator!=(const DtRwTemplatedMapPtr&) const;
213 
215 
216  virtual const DtString& keyName() const { return myKeyName; }
217  virtual void setKeyName(const DtString& keyName) { myKeyName = keyName; }
219 
222  virtual const DtString& elementName() const { return myElementName; }
223  virtual void setElementName(const DtString& e) { myElementName = e; };
225 
227 
228  virtual const DtString& valueName() const { return myValueName; }
229  virtual void setValueName(const DtString& valName) { myValueName = valName; }
231 
232  static const char* theXmlType()
233  {
234  static DtString xmlType(DtString(KeyType::theXmlType()) + "-" +
235  DtString(ValType::theXmlType()) + "-map");
236  return xmlType.c_str();
237  }
238 
239  virtual const char* xmlType() const
240  {
241  return theXmlType();
242  }
243 
244 
245  virtual DtString prettyPrint() const;
246 
247 public:
248 
249  const char* readerWriterType() const;
250 
251  static const char* ListReaderWriterType();
252 
253 protected:
255 
256  std::map<KeyType, ValType> myMap;
257 
261 
264 };
265 
266 namespace DtBufferSerialize
267 {
270  template <typename KeyType, typename ValType>
272 
276  template <typename KeyType, typename ValType>
277  char *encode(const DtRwTemplatedMapPtr<KeyType, ValType>& m, char *buffer);
278 
283  template <typename KeyType, typename ValType>
284  const char *decode(DtRwTemplatedMapPtr<KeyType, ValType>& m, const char *buffer);
285 };
286 
287 #include "vrfutil/rwTemplatedMap.inl"
DtRwTemplatedPair & operator=(const DtRwTemplatedPair &orig)
Assignment.
virtual void setSecondName(const DtString &n)
The RW name of the second item in this pair.
Definition: rwTemplatedMap.h:65
DT_DLL_readerWriter int getSize(const DtString &val)
The number of bytes required to encode the value.
void erase(iterator pos)
Removes an existing item from the map.
Definition: rwTemplatedMap.h:185
virtual const SecondType & second() const
Accessor for second.
Definition: rwTemplatedMap.h:51
virtual const DtString & valueName() const
The RW name of the values in this map.
Definition: rwTemplatedMap.h:228
virtual void setSecond(const SecondType &s)
Mutator for second.
This class allows one to collect and compare strings using an index number instead of having to do st...
Definition: symbolString.h:27
virtual void setFirstName(const DtString &n)
The RW name of the first item in this pair.
Definition: rwTemplatedMap.h:59
virtual void setKeyName(const DtString &keyName)
The RW name of the keys in this map.
Definition: rwTemplatedMap.h:217
static const char * theXmlType()
Definition: rwTemplatedMap.h:232
virtual void setFirst(const FirstType &f)
Mutator for first.
std::map< KeyType, ValType >::iterator iterator
Definition: rwTemplatedMap.h:101
std::map< KeyType, ValType > myMap
Definition: rwTemplatedMap.h:256
A Readable, Writable version of DtList. This class cannot be used directly, but must be inherited to ...
Definition: rwList.h:26
virtual const_iterator end() const
Returns an iterator to the element following the last element in the map.
Definition: rwTemplatedMap.h:174
virtual void postGetSelf()
After getting self, update internal map to match our RwList.
std::pair< iterator, bool > insert(const RwPairType &item)
Insert a new item into the map.
static const char * ListReaderWriterType()
virtual iterator end()
Returns an iterator to the element following the last element in the map.
Definition: rwTemplatedMap.h:173
virtual DtString prettyPrint() const
Routine to return a human readable form of the reader/writer variable. Not all reader/writer classes ...
virtual const_iterator lower_bound(const KeyType &key) const
Finds the first element that is not less than the key.
Definition: rwTemplatedMap.h:198
DtlObjPtr getData(DtlObjPtr args, const DtReaderWriter::SearchPaths &searchPaths, const DtVariableBindingsList &variableBindings)
This method must be overridden by a subclass. Within this method, new instances of the DtReaderWriter...
Definition: readerWriter.h:85
DtString myXmlType
Definition: rwTemplatedMap.h:254
virtual void clear()
Clears all elements from the map.
Definition: rwTemplatedMap.h:160
virtual iterator find(const KeyType &key)
Finds the element with the key equivalent to the key.
Definition: rwTemplatedMap.h:191
Definition: readerWriterRegistry.h:39
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...
virtual const char * xmlType() const
Routines to archive/dearchive from an XML Environment.
Definition: rwTemplatedMap.h:239
DtString myElementName
The name to write out for each element. By default this is &quot;item&quot; but, when reading this from a file...
Definition: rwTemplatedMap.h:260
virtual void prePutSelf()
Before putting self, update RwList to match our internal map.
Definition: rwTemplatedMap.h:16
virtual iterator begin()
Returns an iterator to the first element in the map.
Definition: rwTemplatedMap.h:167
virtual void setValueName(const DtString &valName)
The RW name of the values in this map.
Definition: rwTemplatedMap.h:229
virtual void removeAndDeleteAll()
Removes and deletes all entries in the rwlist.
bool operator==(const DtRwTemplatedPair &) const
Equality.
std::list< const DtRwVariableBindings * > DtVariableBindingsList
Definition: readerWriterRegistry.h:29
virtual void swap(DtRwTemplatedMapPtr &other)
Swaps the contents of this map with the other map.
Definition: rwTemplatedMap.h:97
std::vector< DtFilename > SearchPaths
Definition: readerWriter.h:92
virtual const DtString & keyName() const
The RW name of the keys in this map.
Definition: rwTemplatedMap.h:216
virtual ~DtRwTemplatedPair()
Destructor.
Definition: rwTemplatedMap.h:36
DT_DLL_readerWriter char * encode(const DtFilename &val, char *buffer)
Serializes the provided value val into buffer. buffer must have at least the number of bytes returned...
virtual const_iterator upper_bound(const KeyType &key) const
Finds the first element that is greater than the key.
Definition: rwTemplatedMap.h:204
bool operator==(const DtRwTemplatedMapPtr &) const
Equivalence operators.
void erase(const KeyType &key)
Removes an existing item from the map.
Definition: rwTemplatedMap.h:186
DtRwTemplatedMapPtr()
default constructor
DtString myKeyName
Definition: rwTemplatedMap.h:262
virtual void setFromMap(const std::map< KeyType, ValType > sourceMap)
Clears the contents of this map, and sets new contents from the values in the std::map.
virtual DtString firstName() const
The RW name of the first item in this pair.
Definition: rwTemplatedMap.h:58
FirstType myFirst
Definition: rwTemplatedMap.h:70
virtual const DtString & elementName() const
Accessor/mutator for myElementName.
Definition: rwTemplatedMap.h:222
virtual const FirstType & first() const
Accessor for first.
Definition: rwTemplatedMap.h:45
DtRwTemplatedMapPtr & operator=(const DtRwTemplatedMapPtr &orig)
Assignment operator.
virtual const_iterator find(const KeyType &key) const
Finds the element with the key equivalent to the key.
Definition: rwTemplatedMap.h:192
virtual iterator upper_bound(const KeyType &key)
Finds the first element that is greater than the key.
Definition: rwTemplatedMap.h:203
virtual const_iterator begin() const
Returns an iterator to the first element in the map.
Definition: rwTemplatedMap.h:168
virtual const std::map< KeyType, ValType > & convertToMap() const
The current contents of this map as a std::map.
SecondType mySecond
Definition: rwTemplatedMap.h:71
virtual unsigned size() const
Returns the size of the map.
Definition: rwTemplatedMap.h:163
DtRwTemplatedPair< KeyType, ValType > RwPairType
Definition: rwTemplatedMap.h:100
DT_DLL_readerWriter const char * decode(DtString &val, const char *buffer)
Decodes a value from buffer and places the result in val of the type specified by val...
DtRwTemplatedPair()
Constructors.
std::map< KeyType, ValType >::const_iterator const_iterator
Definition: rwTemplatedMap.h:102
virtual ~DtRwTemplatedMapPtr()
Destructor.
virtual DtSymbolString name() const
Accessor for name of this readable/writable object.
virtual DtString secondName() const
The RW name of the second item in this pair.
Definition: rwTemplatedMap.h:64
virtual iterator lower_bound(const KeyType &key)
Finds the first element that is not less than the key.
Definition: rwTemplatedMap.h:197
bool operator!=(const DtRwTemplatedMapPtr &) const
Equivalence operators.
virtual void setElementName(const DtString &e)
Accessor/mutator for myElementName.
Definition: rwTemplatedMap.h:223
DtString myValueName
Definition: rwTemplatedMap.h:263

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)