hla: Enalble creating object instances without object class.
This enables creating HLAObjectInstance instances without valid initial object class pointer. This is useful for local implemented object instances.
This commit is contained in:
parent
2f0a6fdb67
commit
c62c778c88
@ -47,9 +47,10 @@ HLAObjectInstance::ReflectCallback::~ReflectCallback()
|
|||||||
}
|
}
|
||||||
|
|
||||||
HLAObjectInstance::HLAObjectInstance(HLAObjectClass* objectClass) :
|
HLAObjectInstance::HLAObjectInstance(HLAObjectClass* objectClass) :
|
||||||
_federate(objectClass->_federate),
|
|
||||||
_objectClass(objectClass)
|
_objectClass(objectClass)
|
||||||
{
|
{
|
||||||
|
if (objectClass)
|
||||||
|
_federate = objectClass->_federate;
|
||||||
}
|
}
|
||||||
|
|
||||||
HLAObjectInstance::~HLAObjectInstance()
|
HLAObjectInstance::~HLAObjectInstance()
|
||||||
@ -78,18 +79,24 @@ HLAObjectInstance::getObjectClass() const
|
|||||||
unsigned
|
unsigned
|
||||||
HLAObjectInstance::getNumAttributes() const
|
HLAObjectInstance::getNumAttributes() const
|
||||||
{
|
{
|
||||||
|
if (!_objectClass.valid())
|
||||||
|
return 0;
|
||||||
return _objectClass->getNumAttributes();
|
return _objectClass->getNumAttributes();
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned
|
unsigned
|
||||||
HLAObjectInstance::getAttributeIndex(const std::string& name) const
|
HLAObjectInstance::getAttributeIndex(const std::string& name) const
|
||||||
{
|
{
|
||||||
|
if (!_objectClass.valid())
|
||||||
|
return ~0u;
|
||||||
return _objectClass->getAttributeIndex(name);
|
return _objectClass->getAttributeIndex(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
HLAObjectInstance::getAttributeName(unsigned index) const
|
HLAObjectInstance::getAttributeName(unsigned index) const
|
||||||
{
|
{
|
||||||
|
if (!_objectClass.valid())
|
||||||
|
return std::string();
|
||||||
return _objectClass->getAttributeName(index);
|
return _objectClass->getAttributeName(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,6 +111,8 @@ HLAObjectInstance::getAttributeOwned(unsigned index) const
|
|||||||
const HLADataType*
|
const HLADataType*
|
||||||
HLAObjectInstance::getAttributeDataType(unsigned index) const
|
HLAObjectInstance::getAttributeDataType(unsigned index) const
|
||||||
{
|
{
|
||||||
|
if (!_objectClass.valid())
|
||||||
|
return 0;
|
||||||
return _objectClass->getAttributeDataType(index);
|
return _objectClass->getAttributeDataType(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -435,15 +444,27 @@ HLAObjectInstance::setAttributes(const HLAAttributePathElementMap& attributePath
|
|||||||
|
|
||||||
void
|
void
|
||||||
HLAObjectInstance::registerInstance()
|
HLAObjectInstance::registerInstance()
|
||||||
|
{
|
||||||
|
registerInstance(_objectClass.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
HLAObjectInstance::registerInstance(HLAObjectClass* objectClass)
|
||||||
{
|
{
|
||||||
if (_rtiObjectInstance.valid()) {
|
if (_rtiObjectInstance.valid()) {
|
||||||
SG_LOG(SG_IO, SG_ALERT, "Trying to register object " << getName() << " already known to the RTI!");
|
SG_LOG(SG_IO, SG_ALERT, "Trying to register object " << getName() << " already known to the RTI!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!_objectClass.valid()) {
|
if (!objectClass) {
|
||||||
SG_LOG(SG_IO, SG_ALERT, "Could not register object with unknown object class!");
|
SG_LOG(SG_IO, SG_ALERT, "Could not register object with unknown object class!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (_objectClass.valid() && objectClass != _objectClass.get()) {
|
||||||
|
SG_LOG(SG_IO, SG_ALERT, "Could not change object class while registering!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_objectClass = objectClass;
|
||||||
|
_federate = _objectClass->_federate;
|
||||||
// This error must have been flagged before
|
// This error must have been flagged before
|
||||||
if (!_objectClass->_rtiObjectClass.valid())
|
if (!_objectClass->_rtiObjectClass.valid())
|
||||||
return;
|
return;
|
||||||
@ -582,6 +603,9 @@ HLAObjectInstance::reflectAttributeValue(unsigned index, const SGTimeStamp& time
|
|||||||
void
|
void
|
||||||
HLAObjectInstance::_setRTIObjectInstance(RTIObjectInstance* rtiObjectInstance)
|
HLAObjectInstance::_setRTIObjectInstance(RTIObjectInstance* rtiObjectInstance)
|
||||||
{
|
{
|
||||||
|
if (!_objectClass.valid())
|
||||||
|
return;
|
||||||
|
|
||||||
_rtiObjectInstance = rtiObjectInstance;
|
_rtiObjectInstance = rtiObjectInstance;
|
||||||
_rtiObjectInstance->setObjectInstance(this);
|
_rtiObjectInstance->setObjectInstance(this);
|
||||||
_name = _rtiObjectInstance->getName();
|
_name = _rtiObjectInstance->getName();
|
||||||
@ -589,7 +613,7 @@ HLAObjectInstance::_setRTIObjectInstance(RTIObjectInstance* rtiObjectInstance)
|
|||||||
unsigned numAttributes = getNumAttributes();
|
unsigned numAttributes = getNumAttributes();
|
||||||
_attributeVector.resize(numAttributes);
|
_attributeVector.resize(numAttributes);
|
||||||
for (unsigned i = 0; i < numAttributes; ++i) {
|
for (unsigned i = 0; i < numAttributes; ++i) {
|
||||||
HLAUpdateType updateType = getObjectClass()->getAttributeUpdateType(i);
|
HLAUpdateType updateType = _objectClass->getAttributeUpdateType(i);
|
||||||
if (getAttributeOwned(i) && updateType != HLAUndefinedUpdate) {
|
if (getAttributeOwned(i) && updateType != HLAUndefinedUpdate) {
|
||||||
_attributeVector[i]._enabledUpdate = true;
|
_attributeVector[i]._enabledUpdate = true;
|
||||||
_attributeVector[i]._unconditionalUpdate = (updateType == HLAPeriodicUpdate);
|
_attributeVector[i]._unconditionalUpdate = (updateType == HLAPeriodicUpdate);
|
||||||
@ -604,7 +628,7 @@ HLAObjectInstance::_setRTIObjectInstance(RTIObjectInstance* rtiObjectInstance)
|
|||||||
// This makes sense with any new object. Even if we registered one, there might be unpublished attributes.
|
// This makes sense with any new object. Even if we registered one, there might be unpublished attributes.
|
||||||
HLAIndexList indexList;
|
HLAIndexList indexList;
|
||||||
for (unsigned i = 0; i < numAttributes; ++i) {
|
for (unsigned i = 0; i < numAttributes; ++i) {
|
||||||
HLAUpdateType updateType = getObjectClass()->getAttributeUpdateType(i);
|
HLAUpdateType updateType = _objectClass->getAttributeUpdateType(i);
|
||||||
if (getAttributeOwned(i))
|
if (getAttributeOwned(i))
|
||||||
continue;
|
continue;
|
||||||
if (updateType == HLAUndefinedUpdate)
|
if (updateType == HLAUndefinedUpdate)
|
||||||
|
@ -35,7 +35,7 @@ class HLAObjectClass;
|
|||||||
|
|
||||||
class HLAObjectInstance : public SGWeakReferenced {
|
class HLAObjectInstance : public SGWeakReferenced {
|
||||||
public:
|
public:
|
||||||
HLAObjectInstance(HLAObjectClass* objectClass);
|
HLAObjectInstance(HLAObjectClass* objectClass = 0);
|
||||||
virtual ~HLAObjectInstance();
|
virtual ~HLAObjectInstance();
|
||||||
|
|
||||||
/// Return the name of this object instance
|
/// Return the name of this object instance
|
||||||
@ -78,6 +78,7 @@ public:
|
|||||||
void setAttributes(const HLAAttributePathElementMap& attributePathElementMap);
|
void setAttributes(const HLAAttributePathElementMap& attributePathElementMap);
|
||||||
|
|
||||||
void registerInstance();
|
void registerInstance();
|
||||||
|
void registerInstance(HLAObjectClass* objectClass);
|
||||||
void deleteInstance(const RTIData& tag);
|
void deleteInstance(const RTIData& tag);
|
||||||
|
|
||||||
// Push the current values into the RTI
|
// Push the current values into the RTI
|
||||||
|
Loading…
Reference in New Issue
Block a user