class HLAObjectInstance : public SGWeakReferenced {
public:
- HLAObjectInstance(HLAObjectClass* objectClass);
+ HLAObjectInstance(HLAObjectClass* objectClass = 0);
virtual ~HLAObjectInstance();
/// Return the name of this object instance
- const std::string& getName() const
- { return _name; }
+ const std::string& getName() const;
+
+ /// return the federate this instance belongs to
+ const SGWeakPtr<HLAFederate>& getFederate() const;
/// Return the object class of this instance.
/// Should always return a valid object class.
- const SGSharedPtr<HLAObjectClass>& getObjectClass() const
- { return _objectClass; }
+ const SGSharedPtr<HLAObjectClass>& getObjectClass() const;
/// Return the number of attributes
unsigned getNumAttributes() const;
/// Return the attribute name for the attribute with the given index
std::string getAttributeName(unsigned index) const;
- /// Return true if the attribute with the given index is owned by this federate
+ /// Return true if the attribute with the given index is owned by
+ /// this federate
bool getAttributeOwned(unsigned index) const;
/// Return the data type of the attribute with the given index
HLADataElement* getAttributeDataElement(unsigned index);
const HLADataElement* getAttributeDataElement(unsigned index) const;
- /// Write the raw attribute data value into data, works only of the object is backed up with an rti object instance
+ /// Write the raw attribute data value into data, works only of the object
+ /// is backed up with an rti object instance
bool getAttributeData(unsigned index, RTIData& data) const;
/// Sets the data element of the attribute with the given index to dataElement
void setAttributeDataElement(unsigned index, const SGSharedPtr<HLADataElement>& dataElement);
- /// Sets the data element of the attribute with the given index to the content of pathElementMap
- void setAttribute(unsigned index, const HLAPathElementMap& pathElementMap);
- void setAttributes(const HLAAttributePathElementMap& attributePathElementMap);
+ /// Retrieve the data element index for the given path.
+ bool getDataElementIndex(HLADataElementIndex& index, const std::string& path) const;
+ HLADataElementIndex getDataElementIndex(const std::string& path) const;
+
+ /// Return the data element of the attribute with the given index
+ HLADataElement* getAttributeDataElement(const HLADataElementIndex& index);
+ const HLADataElement* getAttributeDataElement(const HLADataElementIndex& index) const;
+ /// Set the data element of the attribute with the given index
+ void setAttributeDataElement(const HLADataElementIndex& index, const SGSharedPtr<HLADataElement>& dataElement);
+
+ /// Return the data element of the attribute with the given path.
+ /// The method is only for convenience as parsing the path is expensive.
+ /// Precompute the index and use the index instead if you use this method more often.
+ HLADataElement* getAttributeDataElement(const std::string& path);
+ const HLADataElement* getAttributeDataElement(const std::string& path) const;
+ /// Set the data element of the attribute with the given path
+ /// The method is only for convenience as parsing the path is expensive.
+ /// Precompute the index and use the index instead if you use this method more often.
+ void setAttributeDataElement(const std::string& path, const SGSharedPtr<HLADataElement>& dataElement);
+
+ /// Gets called on discovering this object instance.
+ virtual void discoverInstance(const RTIData& tag);
+ /// Gets called on remove this object instance.
+ virtual void removeInstance(const RTIData& tag);
+
+ /// Call this to register the object instance at the rti and assign the object class to it.
void registerInstance();
- void deleteInstance(const RTIData& tag);
+ virtual void registerInstance(HLAObjectClass* objectClass);
+ /// Call this to delete the object instance from the rti.
+ virtual void deleteInstance(const RTIData& tag);
+
+ /// Is called when the instance is either registered or discovered.
+ /// It creates data elements for each element that is not yet set and that has a data type attached.
+ /// the default calls back into the object class createAttributeDataElements method.
+ virtual void createAttributeDataElements();
+ /// Create and set the data element with index. Called somewhere in the above callchain.
+ void createAndSetAttributeDataElement(unsigned index);
+ /// Create an individual data element, the default calls back into the object class
+ /// createAttributeDataElement method.
+ virtual HLADataElement* createAttributeDataElement(unsigned index);
// Push the current values into the RTI
virtual void updateAttributeValues(const RTIData& tag);
const SGSharedPtr<ReflectCallback>& getReflectCallback() const
{ return _reflectCallback; }
- // deprecated.
- class AttributeCallback : public SGReferenced {
- public:
- virtual ~AttributeCallback() {}
- virtual void updateAttributeValues(HLAObjectInstance& objectInstance, const RTIData& tag)
- { }
- virtual void reflectAttributeValues(HLAObjectInstance& objectInstance,
- const RTIIndexDataPairList& dataPairList, const RTIData& tag)
- { }
- virtual void reflectAttributeValues(HLAObjectInstance& objectInstance, const RTIIndexDataPairList& dataPairList,
- const SGTimeStamp& timeStamp, const RTIData& tag)
- { reflectAttributeValues(objectInstance, dataPairList, tag); }
- };
-
- void setAttributeCallback(const SGSharedPtr<AttributeCallback>& attributeCallback)
- { _attributeCallback = attributeCallback; }
- const SGSharedPtr<AttributeCallback>& getAttributeCallback() const
- { return _attributeCallback; }
-
private:
void _setRTIObjectInstance(RTIObjectInstance* rtiObjectInstance);
void _clearRTIObjectInstance();
void _reflectAttributeValues(const HLAIndexList& indexList, const RTIData& tag);
void _reflectAttributeValues(const HLAIndexList& indexList, const SGTimeStamp& timeStamp, const RTIData& tag);
- class DataElementFactoryVisitor;
-
struct Attribute {
Attribute() : _enabledUpdate(false), _unconditionalUpdate(false) {}
SGSharedPtr<HLADataElement> _dataElement;
- // SGSharedPtr<HLADataElement::TimeStamp> _timeStamp;
bool _enabledUpdate;
bool _unconditionalUpdate;
// HLAIndexList::iterator _unconditionalUpdateAttributeIndexListIterator;
// Callback classes
SGSharedPtr<UpdateCallback> _updateCallback;
SGSharedPtr<ReflectCallback> _reflectCallback;
- SGSharedPtr<AttributeCallback> _attributeCallback;
friend class HLAFederate;
friend class HLAObjectClass;