VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
rwProperties.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 #include <vlutil/vlString.h>
15 
16 namespace tbb
17 {
18  class spin_mutex;
19 }
20 
21 class DtRwProperties;
22 
26 {
27 public:
28 
32 
34 
35  bool operator==(const DtPropertiesIterator& other) const;
36  bool operator!=(const DtPropertiesIterator& other) const;
37 
38  DtPropertiesIterator& operator=(const DtPropertiesIterator& other);
39 
40  DtPropertiesIterator& operator++();
41  DtPropertiesIterator operator++(int);
42  DtPropertiesIterator& operator--();
43  DtPropertiesIterator operator--(int);
44 
45  DtPropertyInterface& operator*();
46  DtPropertyInterface* operator->();
47 
48  DtPropertyInterface* property();
49  const DtPropertyInterface* property() const;
50 
51  template <typename KeyType>
52  KeyType key() const;
53 
54  const DtRwProperties* properties() const;
55 
57  void setRegistryIterator(std::vector<DtReaderWriterRegistryData*>::iterator iter);
58 
59  std::vector<DtReaderWriterRegistryData*>::iterator registryIterator() const;
60 
61 protected:
62 
64  std::vector<DtReaderWriterRegistryData*>::iterator myRegIter;
65 };
66 
70 {
71 public:
72 
77 
79 
80  bool operator==(const DtPropertiesConstIterator& other) const;
81  bool operator!=(const DtPropertiesConstIterator& other) const;
82 
84  DtPropertiesConstIterator& operator=(const DtPropertiesIterator& other);
85 
86  DtPropertiesConstIterator& operator++();
87  DtPropertiesConstIterator operator++(int);
88  DtPropertiesConstIterator& operator--();
89  DtPropertiesConstIterator operator--(int);
90 
91  const DtPropertyInterface& operator*() const;
92  const DtPropertyInterface* operator->() const;
93 
94  const DtPropertyInterface* property() const;
95 
96  template <typename KeyType>
97  KeyType key() const;
98 
99  const DtRwProperties* properties() const;
100 
102  void setRegistryIterator(std::vector<DtReaderWriterRegistryData*>::const_iterator iter);
103 
104  std::vector<DtReaderWriterRegistryData*>::const_iterator registryIterator() const;
105 
106 protected:
107 
109  std::vector<DtReaderWriterRegistryData*>::const_iterator myRegIter;
110 };
111 
127 {
128 private:
130  DtRwProperties();
131 
132 public:
133 
136 
139  DtRwProperties(const DtString& name, DtReaderWriterRegistry* parentRegistry = 0);
140  DtRwProperties(const DtString& name, const DtRwProperties& orig,
141  DtReaderWriterRegistry* parentRegistry = 0);
142  DtRwProperties(const DtRwProperties& orig,
143  DtReaderWriterRegistry* parentRegistry = 0);
145 
147  virtual ~DtRwProperties();
148 
152  virtual const_iterator begin() const;
153  virtual iterator begin();
155 
159  virtual const_iterator end() const;
160  virtual iterator end();
162 
164  virtual unsigned size() const;
165 
169  virtual const DtPropertyInterface* findPropertyInterface(const DtString& propertyName) const;
170  virtual DtPropertyInterface* findPropertyInterface(const DtString& propertyName);
172 
174  virtual bool addProperty(DtPropertyInterface*);
175 
177  virtual bool addPropertyAtIndex(DtPropertyInterface*, unsigned index);
178 
182  virtual bool removeProperty(const DtString& propertyName);
183  virtual bool removeProperty(const DtPropertyInterface* property);
185 
190  virtual void copy(const DtPropertyInterface& rhs);
191 
193  virtual void getSelf(DtlObjPtr args,
194  const DtReaderWriter::SearchPaths& searchPaths = SearchPaths(),
195  const DtVariableBindingsList& variableBindings = nullVariableReference());
196  virtual DtlObjPtr getData(DtlObjPtr args,
197  const DtReaderWriter::SearchPaths& searchPaths = SearchPaths(),
198  const DtVariableBindingsList& variableBindings = nullVariableReference());
199 
203  virtual const char* readerWriterType() const;
204 
206  virtual bool isValidProperty(const DtPropertyInterface*) const;
207 
209  virtual DtPropertyInterface* createProperty(DtlObjPtr args, DtReaderWriterRegistry* parentRegistry);
210 
213  virtual char* encode(char*) const;
214 
217  virtual const char* decode(const char*);
218 
222  virtual void getSize(int& size) const;
223 
225  static DtReaderWriterPropertyFactory* propertyFactory();
226  static void cleanupPropertyFactory();
227 
229  virtual void copyVariables(const DtRwVariableBindings& other);
230 
231  virtual bool isReadonly() const;
232 
234  virtual int hlaAlignment() const;
235 
238  virtual int requiredPadding(const char* buf, const DtPropertyInterface* field) const;
239 
241  virtual const char* propertyType() const;
242 
244  virtual int count() const;
245 
249  virtual const DtReaderWriter* findPropertyRw(const DtString& propName) const;
250  virtual DtReaderWriter* findPropertyRw(const DtString& propName);
252 
253  virtual DtString stringRep(const DtString& root = "") const;
254 
266  virtual bool merge(const DtPropertyInterface& target, MergeFlags, const DtMergePath& path = DtMergePath(),
267  const std::set<DtString>& ignore = std::set<DtString>());
268 
273  virtual DtRwProperties createFromPercentages(const DtRwProperties& percentages, const DtRwProperties& baseValues,
274  const DtString& base = "Base-");
275 
278  virtual bool findRootAndVariable(const DtString& varName, DtReaderWriter*& root, DtReaderWriter*& variable) const;
279 
282  virtual DtReaderWriter* readerWriter();
283  virtual const DtReaderWriter* readerWriter() const;
285 
288  virtual DtPropertyInterface* property();
289  virtual const DtPropertyInterface* property() const;
291 
293  virtual DtSymbolString propertyName() const { return name(); };
294 
296  virtual void setPropertyName(const DtString& propertyName) { setName(propertyName); };
297 
300  virtual bool isUpdateNeeded(DtTime t) const;
301 
303  virtual bool hasReceivedUpdateSince(DtTime t) const;
304 
308  virtual DtTime updateClockTime() const;
309 
312  virtual bool isPublished() const;
313  virtual void setIsPublished(bool isPub);
315 
319  virtual unsigned disRecordType() const;
320  virtual void setDisRecordType(unsigned recType);
322 
324  virtual void clearVariables();
325 
327  virtual void reset();
328 
331  virtual void removeVariable(DtReaderWriter*);
332  virtual void removeVariable(const DtReaderWriter*);
334 
336  virtual void invalidateCache();
337 
339  virtual void invalidateCacheForProperty(const DtString& propName);
340 
341  static const DtRwProperties& emptyProperties();
342 
345 
347  static bool rollUpInteger(const DtReaderWriter* source, DtReaderWriter* destination, const DtMergePath& path);
348 
350  static bool rollUpReal(const DtReaderWriter* source, DtReaderWriter* destination, const DtMergePath& path);
351 
353  static bool rollUpString(const DtReaderWriter* source, DtReaderWriter* destination, const DtMergePath& path);
354 
356  static bool rollUpBoolean(const DtReaderWriter* source, DtReaderWriter* destination, const DtMergePath& path);
358 
359  virtual bool setWritePrototypeHeader(bool);
360  virtual bool writePrototypeHeader() const;
361 
363  virtual void cloneAndAddProperty(const DtReaderWriter& rw);
364 
367  virtual void setKeepPublishingSettings(bool keep);
368  virtual bool keepPublishingSettings() const;
369 
370 protected:
372  virtual void filterIgnoredProperties(DtReaderWriter* rw, const std::set<DtString>& ignore);
373 
375  virtual void getInterface(DtPropertyInterface* pFace, DtlObjPtr args,
376  const DtReaderWriter::SearchPaths& searchPaths = SearchPaths(),
377  const DtVariableBindingsList& variableBindings = nullVariableReference());
378 
379  virtual void writeSelf(std::string& fp, int indentLevel, bool writeUnspecified, const DtFilename& path);
380  virtual void writeData(std::string& fp, int indentLevel, bool writeUnspecified, const DtFilename& path);
381 
382  virtual void putData(std::string&, int indentLevel = 0);
383 
384  virtual int hlaAlignment(const DtPropertyInterface* field) const;
385 
387  virtual void getSize(const DtPropertyInterface*, int& size) const;
388 
389  virtual char* encode(const DtPropertyInterface*, char* buf) const;
390  virtual const char* decode(DtPropertyInterface* iFace, const char* buf);
391 
393  virtual void unrecognizedItem(const DtEnvironmentSP env, const DtEnvValueSP root,
394  const DtReaderWriter::SearchPaths& searchPaths, const DtVariableBindingsList& varBindings);
395 
397  virtual bool traverseAndModifyPercentage(DtRwProperties& results, const DtRwProperties& baseValues,
398  const DtReaderWriter* percentage, const DtString& base) const;
399 
400  virtual void writePrototypeHeader(std::string& fp, const DtReaderWriter* rw, int indentLevel) const;
401 
403  virtual void writePropertyData(DtReaderWriter* rw, std::string& fp, int indentLevel, bool writeUnspecified, const DtFilename& path);
404 
407  virtual void getSortedProperties(const DtRwVariableBindings& varBindings, std::vector<const DtReaderWriter*>& propertyList) const;
408  virtual void getSortedProperties(DtRwVariableBindings& varBindings, std::vector<DtReaderWriter*>& propertyList);
410 
413  virtual bool isDebugEnabled() const;
414  virtual void setDebugEnabled(bool en);
416 
417 protected:
419 
420  mutable std::multimap<DtString, DtReaderWriter*> myRwPropertyCache;
421  mutable tbb::spin_mutex* myCacheMutex;
422 
424 
428 
431  mutable int mySizeAtLastCheck;
432 
433  unsigned myDisRecordType;
434 
436 
438 
440 
442 
445 };
446 
447 template <typename KeyType>
449 {
450  DtWarn << "Could not convert key, \"" << property()->propertyName()
451  << "\", to the specified type." << std::endl;
452 
453  return KeyType();
454 }
455 
456 template <>
457 inline int DtPropertiesIterator::key<int>() const
458 {
459  bool ok = false;
460  DtString keyStr(property()->propertyName().string());
461  int result = keyStr.toInt(&ok);
462 
463  if (!ok)
464  {
465  DtWarn << "Could not convert key, \"" << property()->propertyName()
466  << "\", to an int." << std::endl;
467  }
468 
469  return result;
470 }
471 
472 template <>
473 inline double DtPropertiesIterator::key<double>() const
474 {
475  bool ok = false;
476  DtString keyStr(property()->propertyName().string());
477  int result = keyStr.toDouble(&ok);
478 
479  if (!ok)
480  {
481  DtWarn << "Could not convert key, \"" << property()->propertyName()
482  << "\", to an double." << std::endl;
483  }
484 
485  return result;
486 }
487 
488 template <>
489 inline DtString DtPropertiesIterator::key<DtString>() const
490 {
491  return property()->propertyName().string();
492 }
493 
494 template <>
495 inline std::string DtPropertiesIterator::key<std::string>() const
496 {
497  return property()->propertyName().string();
498 }
499 
500 template <typename KeyType>
502 {
503  DtWarn << "Could not convert key, \"" << property()->propertyName()
504  << "\", to the specified type." << std::endl;
505 }
506 
507 template <>
508 inline int DtPropertiesConstIterator::key<int>() const
509 {
510  bool ok = false;
511  DtString keyStr(property()->propertyName().string());
512  int result = keyStr.toInt(&ok);
513 
514  if (!ok)
515  {
516  DtWarn << "Could not convert key, \"" << property()->propertyName()
517  << "\", to an int." << std::endl;
518  }
519 
520  return result;
521 }
522 
523 template <>
524 inline double DtPropertiesConstIterator::key<double>() const
525 {
526  bool ok = false;
527  DtString keyStr(property()->propertyName().string());
528  int result = keyStr.toDouble(&ok);
529 
530  if (!ok)
531  {
532  DtWarn << "Could not convert key, \"" << property()->propertyName()
533  << "\", to an double." << std::endl;
534  }
535 
536  return result;
537 }
538 
539 template <>
540 inline DtString DtPropertiesConstIterator::key<DtString>() const
541 {
542  return property()->propertyName().string();
543 }
544 
545 template <>
546 inline std::string DtPropertiesConstIterator::key<std::string>() const
547 {
548  return property()->propertyName().string();
549 }
virtual DtTime updateClockTime() const =0
Returns the current time on the update clock. Can be used to pass into a future call to hasReceivedUp...
DtString myPreviousParentPropFullName
Definition: rwProperties.h:444
virtual void setName(const DtString &)
Set the name of the object. Uses the myName variable. Only set if you understand that this could have...
tbb::spin_mutex * myCacheMutex
Definition: rwProperties.h:421
int mySizeAtLastCheck
Stores the number of items in the last at the last time it was discovered the size changed...
Definition: rwProperties.h:431
#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
This class allows one to collect and compare strings using an index number instead of having to do st...
Definition: symbolString.h:27
DtPropertiesConstIterator const_iterator
Definition: rwProperties.h:135
virtual DtString stringRep(const DtString &root="") const =0
virtual void unrecognizedItem(const DtEnvironmentSP env, const DtEnvValueSP root, const SearchPaths &searchPaths, const DtVariableBindingsList &varBindings)
Called when the xml reader tries to parse an unknown reader/writer item. Default is a no-op...
virtual void copy(const DtPropertyInterface &rhs)=0
Copies the given property into the current one as long as the types are the same. The details of how ...
const DtPropertyInterface * property() const
virtual void setKeepPublishingSettings(bool keep)=0
Specifies whether the publishing settings for this property should be retained when it is updated fro...
DtRwVariableBindings & operator=(const DtRwVariableBindings &orig)
std::vector< DtReaderWriterRegistryData * >::iterator myRegIter
Definition: rwProperties.h:64
virtual const char * decode(const char *)=0
Decodes the property from the specified buffer. Assumes buffer is the start of the property and prece...
DtClock myClock
Definition: rwProperties.h:423
virtual void setIsPublished(bool isPub)=0
Whether this property should be published.
DT_DLL_readerWriter DtBoost::shared_ptr< DtEnvironment > DtEnvironmentSP
Definition: readerWriter.h:30
virtual DtSymbolString propertyName() const
The name of this property.
Definition: rwProperties.h:293
bool myIsPublished
Definition: rwProperties.h:435
voidpf void uLong size
Definition: ioapi.h:39
virtual void setDebugEnabled(bool en)=0
Enables debug output. Generally this should be left off.
DT_DLL_terrainCS bool operator==(const DtDegMinSec &lhs, const DtDegMinSec &rhs)
Definition: readerWriter.h:85
virtual void removeVariable(DtReaderWriter *)
bool myWritePrototypeHeader
Definition: rwProperties.h:437
virtual bool isDebugEnabled() const =0
Enables debug output. Generally this should be left off.
Definition: readerWriterRegistry.h:39
std::multimap< DtString, DtReaderWriter * > myRwPropertyCache
Definition: rwProperties.h:420
DtPropertiesIterator iterator
Definition: rwProperties.h:134
bool myKeepPublishingSettingsOnCopy
Definition: rwProperties.h:441
virtual bool removeProperty(const DtString &propertyName)
Definition: propertyInterface.h:238
DtTime myLastTimeSizeChanged
Stores the last time at which it was discovered that the size of the list changed.
Definition: rwProperties.h:427
voidpf void * buf
Definition: ioapi.h:39
virtual int hlaAlignment() const =0
Returns alignment necessary to encode this item in HLA.
Iterator for traversing DtRwProperties or its subclasses.
Definition: rwProperties.h:69
virtual DtlObjPtr getData(DtlObjPtr args, const DtReaderWriter::SearchPaths &searchPaths, const DtVariableBindingsList &variableBindings)=0
Override to allow a variable to be assigned to a property of derived type.
Interface class used to define minimal interface for a property. The DtPropertyInterface class provid...
Definition: propertyInterface.h:48
virtual char * encode(char *) const =0
Encodes the property into the supplied buffer. Does not align the property. Buffer must already be al...
ReaderWriter object that maintains a list of reader-writer variable bindings. It keeps a list of name...
Definition: rwVariableBindings.h:27
static DtReaderWriterPropertyFactory * thePropertyFactory
Definition: rwProperties.h:418
bool myDebugEnabled
Definition: rwProperties.h:439
virtual bool addProperty(DtPropertyInterface *property)
Adds an existing property to the properties container. The container will take ownership of the given...
Definition: propertyInterface.h:216
virtual void clearVariables()
Removes and deletes all variable items.
unsigned myDisRecordType
Definition: rwProperties.h:433
virtual void getSelf(DtlObjPtr args, const std::vector< DtFilename > &searchPaths=std::vector< DtFilename >(), const DtVariableBindingsList &variableBindings=nullVariableReference())
Reads in items, using the factory to read the correct types.
virtual void copyVariables(const DtRwVariableBindings &other)
Copies all variable items from another bindings list and adds them to the local one.
virtual bool merge(const DtPropertyInterface &target, MergeFlags, const DtMergePath &path=DtMergePath(), const std::set< DtString > &ignore=std::set< DtString >())=0
Takes the contents of the supplied properties and merges with the following rules if replace is false...
const DtRwProperties * myProperties
Definition: rwProperties.h:108
Specialized type of reader/writer factory that supports properties.
Definition: readerWriterFactory.h:187
std::list< const DtRwVariableBindings * > DtVariableBindingsList
Definition: readerWriterRegistry.h:29
DtRwProperties * myProperties
Definition: rwProperties.h:63
bool isReadonly() const
Definition: readerWriter.h:214
const DtReaderWriter * findPropertyRw(const DtReaderWriter &properties, const DtString &propertyName)
Contains utility functions to make it easier to find and extract data from a set of extended properti...
std::vector< DtFilename > SearchPaths
Definition: readerWriter.h:92
KeyType key() const
Definition: rwProperties.h:448
int getSize() const
Returns the network size of this item in bytes. This does not include any upfront padding for alignme...
std::vector< DtMergePathStruct > DtMergePath
Definition: readerWriterFactory.h:181
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...
virtual DtPropertyInterface * property()
Returns a PropertyInterface pointer of the ReaderWriter. Returns 0 by default, must by overridden by ...
virtual bool hasReceivedUpdateSince(DtTime t) const =0
Returns true if an update was received remotely since the specified time.
const char * source
Definition: lz4.h:442
virtual DtReaderWriter * readerWriter()=0
Returns a ReaderWriter pointer of the property. If property is not a ReaderWriter, this should be overridden to return 0.
virtual bool isPublished() const =0
Whether this property should be published.
static const DtVariableBindingsList & nullVariableReference()
virtual void setDisRecordType(unsigned recType)=0
If this property is published, which DIS record type should it use. Default is 0, which indicates tha...
DtPropertyInterface * property()
Defines the DtPropertyInterface class, the interface for all property classes.
virtual unsigned disRecordType() const =0
If this property is published, which DIS record type should it use. Default is 0, which indicates tha...
virtual void putData(std::string &fp, int indentLevel=0)
Deriving class overrides these to get/put class specific data.
KeyType key() const
Definition: rwProperties.h:501
virtual DtSymbolString propertyName() const =0
The name of this property.
std::vector< DtReaderWriterRegistryData * >::const_iterator myRegIter
Definition: rwProperties.h:109
DtPropertyInterface * myPreviousParentProp
Definition: rwProperties.h:443
Definition: rwProperties.h:25
virtual const DtPropertyInterface * findPropertyInterface(const DtString &propertyName) const
Definition: propertyInterface.h:117
A list of properties. A DtPropertyInterface object that is a specialized version of DtRwVariableBindi...
Definition: rwProperties.h:126
virtual void writeSelf(std::string &fp, int indentLevel=0, bool writeUnspecified=false, const DtFilename &path=DtFilename::nullFilename())
Writes out registry data, but includes the type strings when writing.
DT_DLL_terrainCS bool operator!=(const DtDegMinSec &lhs, const DtDegMinSec &rhs)
virtual const char * propertyType() const =0
Typically returns reader/writer type.
virtual bool isUpdateNeeded(DtTime t) const =0
Returns true if the value has been updated since the specified time and needs to be sent on the netwo...
virtual DtSymbolString name() const
Accessor for name of this readable/writable object.
virtual void setPropertyName(const DtString &propertyName)
Sets name of this property. Should generally only be called when initially created.
Definition: rwProperties.h:296
virtual bool keepPublishingSettings() const =0
virtual void reset()=0
Override to clear out variable value.
MergeFlags
Determines how two lists of properties will be merged by the merge function.
Definition: propertyInterface.h:53

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)