VR-Forces 5.0.2 Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Types | Public Member Functions
DtPropertyInterface Class Referenceabstract

Interface class used to define minimal interface for a property. The DtPropertyInterface class provides the basic interface to a VR-Forces state or parameter property. Properties fall into one of three categories:

  1. Basic data types. These include types like integers, reals, bools, and strings.
  2. Structures. Structures are lists of related, but distinct properties of different types.
  3. Lists and Maps. Contains a variable number of properties of the same type. Structures, lists, and maps can be based on any other property data types.

Each sim object has a list of both state properties (which are dynamic) and parameters properties (which are static). All properties are defined in the state-data and parameter-data sections of the OPE file used by the sim object. The VR-Forces Users Guide has more general information on properties.

The state and parameter properties are maintained by the DtVrfObjectStateRepository of the object. These lists of state properties and parameter properties are implemented as DtRwProperties, which is itself a subclass of DtPropertyInterface. Therefore you can find any property of an object using the same API as you would to find a property or field that is a subcomponent of another property (as in a structure).

The DtPropertyInterface has a number of functions to help you find and access state and parameter properties. These are documented with some example code as well. The DtRwPropertiesStructure, DtRwPropertiesList, and DtRwPropertiesMap classes have further functions that will help you access their constituent fields and elements.

Inheritance diagram for DtPropertyInterface:
Inheritance graph
[legend]

Public Types

enum  MergeFlags {
  Replace = 0x00000001, MinimalSimilarityCheck = 0x00000002, RollUp = 0x00000004, AddMissing = 0x00000008,
  KeepIsPublished = 0x00000010
}
 

Public Member Functions

virtual ~DtPropertyInterface ()
 
virtual void copy (const DtPropertyInterface &rhs)=0
 
virtual const charpropertyType () const =0
 
virtual DtSymbolString propertyName () const =0
 
virtual void setPropertyName (const DtString &propertyName)=0
 
virtual DtString stringRep (const DtString &root="") const =0
 
virtual bool isSimilarProperty (const DtPropertyInterface *rhs, bool strict=true) const
 
virtual bool merge (const DtPropertyInterface &target, MergeFlags, const DtMergePath &path=DtMergePath(), const std::set< DtString > &ignore=std::set< DtString >())=0
 
virtual DtlObjPtr getData (DtlObjPtr args, const DtReaderWriter::SearchPaths &searchPaths, const DtVariableBindingsList &variableBindings)=0
 
virtual bool isPublishedArg (DtlObjPtr arg, unsigned &disVarRecType) const
 
virtual void reset ()=0
 
Getting and setting the property value

Returns the value of this property. If the value cannot be converted to the specified type, the boost::optional will have a value of false. If it can be, the boost::optional will have a value of true and can then be dereferenced to get the value itself. Example:

int val;
boost::optional<int> propVal = property->propertyValue<int>();
if (propVal)
{
val = *propVal;
}
template<typename ValueType >
boost::optional< ValueType > propertyValue () const
 
template<typename ValueType >
bool setPropertyValue (ValueType val)
 
Generic property lookup functions

These functions return the DtPropertyInterface for the named property, assuming it is found within this property. This will only work if this property is composed of other properties (i.e. a structure or an overall DtRwProperties). If this property cannot be found, a null pointer is returned. Example:

DtPropertyInterface* property =
obj->vrfState()->stateProperties().findPropertyInterface("My-Property-Name");
if (property)
{
// Property was found.
}

Additionally, if you want to find the a field within a structure, you can use the '.' character to indicate this relationship. So the code to find a field with the name "Field1" in the property "My-Structure" would look like this:

obj->vrfState()->stateProperties().findPropertyInterface("My-Structure.Field1");
virtual const DtPropertyInterfacefindPropertyInterface (const DtString &propertyName) const
 
virtual DtPropertyInterfacefindPropertyInterface (const DtString &propertyName)
 
Specific property type lookup functions

These functions return the specific property type for the named property, assuming it is found within this property and matches this type. This will only work if this property is composed of other properties (i.e. a structure or an overall DtRwProperties). If this property cannot be found or is of the wrong type, a null pointer is returned. Example:

obj->vrfState()->stateProperties().findProperty<DtRwPropertiesStructure>("My-Property-Name");
if (property)
{
// Property was found and it was of the expected type.
}

Additionally, if you want to find the a field within a structure, you can use the '.' character to indicate this relationship. So the code to find a field with the name "Field1" in the property "My-Structure" would look like this: DtRwPropertyInt* field = obj->vrfState()->stateProperties().findProperty<DtRwPropertyInt>("My-Structure.Field1");

template<typename SpecificPropType >
const SpecificPropType * findProperty (const DtString &propertyName) const
 
template<typename SpecificPropType >
SpecificPropType * findProperty (const DtString &propertyName)
 
Convenience functions for finding and getting/setting property value

This is a convenience function that combines the functionality of findProperty and propertyValue to immediately return the value of the property with the given name, assuming it can be found within this property and its value can be converted to the specified type. If not, the boost::optional will be false. Example:

int val;
boost::optional<int> propVal =
obj->vrfState()->stateProperties().findPropertyValue<int>("My-Property-Name");
if (propVal)
{
val = *propVal;
}

Additionally, if you want to find the value of a field within a structure, you can use the '.' character to indicate this relationship. So the code to find the value of a field with the name "Field1" in the property "My-Structure" would look like this:

boost::optional<int> fieldVal =
obj->vrfState()->stateProperties().findPropertyValue("My-Structure.Field1");
template<typename ValueType >
boost::optional< ValueType > findPropertyValue (const DtString &propertyName) const
 
template<typename ValueType >
bool findAndSetPropertyValue (const DtString &propertyName, ValueType val)
 
Property addition functions

These functions can be used to add new properties to a properties container. This can be used to add new fields to a DtRwPropertiesStructure or a new property to a DtRwProperties. If this property is not of supported properties container type these functions will fail.

Adds an existing property to the properties container. The container will take ownership of the given property. Returns false if this operation was not possible.

DtRwPropertyInt* newProp = new DtRwPropertyInt("Num Soldiers", 4);
obj->vrfState()->stateProperties().addProperty(newProp);
virtual bool addProperty (DtPropertyInterface *property)
 
template<typename SpecificPropType >
SpecificPropType * addNewProperty (const DtString &propertyName)
 
Property removal functions

These functions can be used to removed properties from a properties container. This can be used to remove fields from a DtRwPropertiesStructure or an existing property from a DtRwProperties. If this property is not of supported properties container type this function will fail. Returns true if successful.

virtual bool removeProperty (const DtString &propertyName)
 
virtual bool removeProperty (const DtPropertyInterface *property)
 
Network encoding and decoding

Encodes the property into the supplied buffer. Does not align the property. Buffer must already be aligned correctly based on the hlaAlignment() value of this property.

virtual charencode (char *) const =0
 
virtual const chardecode (const char *)=0
 
virtual void getSize (int &size) const =0
 
int getSize () const
 
virtual int hlaAlignment () const =0
 
virtual DtReaderWriterreaderWriter ()=0
 
virtual const DtReaderWriterreaderWriter () const =0
 
virtual bool isPublished () const =0
 
virtual void setIsPublished (bool isPub)=0
 
virtual unsigned disRecordType () const =0
 
virtual void setDisRecordType (unsigned recType)=0
 
virtual bool isDebugEnabled () const =0
 
virtual void setDebugEnabled (bool en)=0
 

Member Enumeration Documentation

Determines how two lists of properties will be merged by the merge function.

Enumerator
Replace 
MinimalSimilarityCheck 
RollUp 
AddMissing 
KeepIsPublished 

Constructor & Destructor Documentation

virtual DtPropertyInterface::~DtPropertyInterface ( )
virtual

Member Function Documentation

template<typename ValueType >
boost::optional<ValueType> DtPropertyInterface::propertyValue ( ) const

Sets the value of this property. If the value cannot be converted from the specified type, the operation will fail and false will be returned. Otherwise returns true. Example:

bool success = property->setPropertyValue<DtString>("new value");
template<typename ValueType >
bool DtPropertyInterface::setPropertyValue ( ValueType  val)

Sets the value of this property. If the value cannot be converted from the specified type, the operation will fail and false will be returned. Otherwise returns true. Example:

bool success = property->setPropertyValue<DtString>("new value");
virtual const DtPropertyInterface* DtPropertyInterface::findPropertyInterface ( const DtString propertyName) const
inlinevirtual

Reimplemented in DtRwProperties.

virtual DtPropertyInterface* DtPropertyInterface::findPropertyInterface ( const DtString propertyName)
inlinevirtual

Reimplemented in DtRwProperties.

template<typename SpecificPropType >
const SpecificPropType* DtPropertyInterface::findProperty ( const DtString propertyName) const
template<typename SpecificPropType >
SpecificPropType* DtPropertyInterface::findProperty ( const DtString propertyName)
template<typename ValueType >
boost::optional<ValueType> DtPropertyInterface::findPropertyValue ( const DtString propertyName) const

This is a convenience function that combines the functionality of findProperty and setPropertyValue to immediately set the value of the property with the given name, assuming it can be found within this property and its value can be converted from the specified type. If successful, returns true, otherwise returns false. Example:

bool success = obj->vrfState()->stateProperties().findAndSetPropertyValue<int>(
"My-Property-Name", 4);

Additionally, if you want to find and set the value of a field within a structure, you can use the '.' character to indicate this relationship. So the code to find and set the value of a field with the name "Field1" in the property "My-Structure" would look like this:

bool success = obj->vrfState()->stateProperties().findAndSetPropertyValue<double>(
"My-Structure.Field1", 123.45);
template<typename ValueType >
bool DtPropertyInterface::findAndSetPropertyValue ( const DtString propertyName,
ValueType  val 
)

This is a convenience function that combines the functionality of findProperty and setPropertyValue to immediately set the value of the property with the given name, assuming it can be found within this property and its value can be converted from the specified type. If successful, returns true, otherwise returns false. Example:

bool success = obj->vrfState()->stateProperties().findAndSetPropertyValue<int>(
"My-Property-Name", 4);

Additionally, if you want to find and set the value of a field within a structure, you can use the '.' character to indicate this relationship. So the code to find and set the value of a field with the name "Field1" in the property "My-Structure" would look like this:

bool success = obj->vrfState()->stateProperties().findAndSetPropertyValue<double>(
"My-Structure.Field1", 123.45);
virtual bool DtPropertyInterface::addProperty ( DtPropertyInterface property)
inlinevirtual

Adds a new property of the specified type and returns pointer to the new item. Returns a null pointer if a property with that name already existed.

DtRwPropertyInt* newProp =
obj->vrfState()->stateProperties().addProperty<DtRwPropertyInt>("Num Soldiers");

Reimplemented in DtRwProperties.

template<typename SpecificPropType >
SpecificPropType* DtPropertyInterface::addNewProperty ( const DtString propertyName)

Adds a new property of the specified type and returns pointer to the new item. Returns a null pointer if a property with that name already existed.

DtRwPropertyInt* newProp =
obj->vrfState()->stateProperties().addProperty<DtRwPropertyInt>("Num Soldiers");
virtual bool DtPropertyInterface::removeProperty ( const DtString propertyName)
inlinevirtual

Reimplemented in DtRwProperties.

virtual bool DtPropertyInterface::removeProperty ( const DtPropertyInterface property)
inlinevirtual

Reimplemented in DtRwProperties.

virtual void DtPropertyInterface::copy ( const DtPropertyInterface rhs)
pure virtual
virtual char* DtPropertyInterface::encode ( char ) const
pure virtual
virtual const char* DtPropertyInterface::decode ( const char )
pure virtual
virtual void DtPropertyInterface::getSize ( int size) const
pure virtual
int DtPropertyInterface::getSize ( ) const

Returns the network size of this item in bytes. This does not include any upfront padding for alignment.

virtual int DtPropertyInterface::hlaAlignment ( ) const
pure virtual
virtual const char* DtPropertyInterface::propertyType ( ) const
pure virtual
virtual DtSymbolString DtPropertyInterface::propertyName ( ) const
pure virtual
virtual void DtPropertyInterface::setPropertyName ( const DtString propertyName)
pure virtual
virtual DtString DtPropertyInterface::stringRep ( const DtString root = "") const
pure virtual
virtual DtReaderWriter* DtPropertyInterface::readerWriter ( )
pure virtual
virtual const DtReaderWriter* DtPropertyInterface::readerWriter ( ) const
pure virtual
virtual bool DtPropertyInterface::isSimilarProperty ( const DtPropertyInterface rhs,
bool  strict = true 
) const
virtual

Returns true if the readerWriterType is the same. Subclasses can do extra checking. If strict is true, some property types will do extra checking and fail if the types do not exactly match. If false, these types will do a basic check, which can be useful when the the types are similar enough to perform a merge.

Reimplemented in DtRwPropertyReal64, DtRwPropertyReal32, DtRwPropertyReal, DtRwPropertyInt32, DtRwPropertyInt16, DtRwPropertyInt8, DtRwPropertyInt, DtRwPropertiesMap, DtRwPropertiesStructure, DtRwPropertiesList, and DtRwPropertiesFixedArray.

virtual bool DtPropertyInterface::merge ( const DtPropertyInterface target,
MergeFlags  ,
const DtMergePath path = DtMergePath(),
const std::set< DtString > &  ignore = std::set< DtString >() 
)
pure virtual

Takes the contents of the supplied properties and merges with the following rules if replace is false: 1) If the same named property of the same type (and prototype and key) exists regardless of what the contents are in this property, it is replaced with the contents of the target 2) If a property in the target does not exist in source, it is not merged in 3) All other items are kept in the source.

If replace is true, any matching items are replaced by their target. This will add/remove properties

This is a non-recursive function. It only looks at top level property items. Returns true if merge was successful

Implemented in DtRwProperties, DtRwProperty< _RwType >, DtRwProperty< DtRwString >, DtRwProperty< DtRwInt >, DtRwProperty< DtRwInt8 >, DtRwProperty< DtRwInt16 >, DtRwProperty< DtRwReal >, DtRwProperty< DtRwVector >, DtRwProperty< DtRwReal64 >, DtRwProperty< DtRwBoolean >, DtRwProperty< DtRwOffsetVector >, DtRwProperty< DtRwInt32 >, and DtRwProperty< DtRwReal32 >.

virtual DtlObjPtr DtPropertyInterface::getData ( DtlObjPtr  args,
const DtReaderWriter::SearchPaths searchPaths,
const DtVariableBindingsList variableBindings 
)
pure virtual
virtual bool DtPropertyInterface::isPublishedArg ( DtlObjPtr  arg,
unsigned disVarRecType 
) const
virtual

Tests whether the argument specified indicates this property should be published. If a specific DIS variable record type is indicated, this is returned in disVarRecType.

virtual bool DtPropertyInterface::isPublished ( ) const
pure virtual
virtual void DtPropertyInterface::setIsPublished ( bool  isPub)
pure virtual
virtual unsigned DtPropertyInterface::disRecordType ( ) const
pure virtual
virtual void DtPropertyInterface::setDisRecordType ( unsigned  recType)
pure virtual
virtual void DtPropertyInterface::reset ( )
pure virtual
virtual bool DtPropertyInterface::isDebugEnabled ( ) const
pure virtual
virtual void DtPropertyInterface::setDebugEnabled ( bool  en)
pure virtual

The documentation for this class was generated from the following file:

Document ID: Generated on Sun Dec 4 20:22:03 EST 2022 from SVN revision 249613
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)