}
HLAObjectInstance::HLAObjectInstance(HLAObjectClass* objectClass) :
- _federate(objectClass->_federate),
_objectClass(objectClass)
{
+ if (objectClass)
+ _federate = objectClass->_federate;
}
HLAObjectInstance::~HLAObjectInstance()
unsigned
HLAObjectInstance::getNumAttributes() const
{
+ if (!_objectClass.valid())
+ return 0;
return _objectClass->getNumAttributes();
}
unsigned
HLAObjectInstance::getAttributeIndex(const std::string& name) const
{
+ if (!_objectClass.valid())
+ return ~0u;
return _objectClass->getAttributeIndex(name);
}
std::string
HLAObjectInstance::getAttributeName(unsigned index) const
{
+ if (!_objectClass.valid())
+ return std::string();
return _objectClass->getAttributeName(index);
}
const HLADataType*
HLAObjectInstance::getAttributeDataType(unsigned index) const
{
+ if (!_objectClass.valid())
+ return 0;
return _objectClass->getAttributeDataType(index);
}
void
HLAObjectInstance::registerInstance()
+{
+ registerInstance(_objectClass.get());
+}
+
+void
+HLAObjectInstance::registerInstance(HLAObjectClass* objectClass)
{
if (_rtiObjectInstance.valid()) {
SG_LOG(SG_IO, SG_ALERT, "Trying to register object " << getName() << " already known to the RTI!");
return;
}
- if (!_objectClass.valid()) {
+ if (!objectClass) {
SG_LOG(SG_IO, SG_ALERT, "Could not register object with unknown object class!");
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
if (!_objectClass->_rtiObjectClass.valid())
return;
void
HLAObjectInstance::_setRTIObjectInstance(RTIObjectInstance* rtiObjectInstance)
{
+ if (!_objectClass.valid())
+ return;
+
_rtiObjectInstance = rtiObjectInstance;
_rtiObjectInstance->setObjectInstance(this);
_name = _rtiObjectInstance->getName();
unsigned numAttributes = getNumAttributes();
_attributeVector.resize(numAttributes);
for (unsigned i = 0; i < numAttributes; ++i) {
- HLAUpdateType updateType = getObjectClass()->getAttributeUpdateType(i);
+ HLAUpdateType updateType = _objectClass->getAttributeUpdateType(i);
if (getAttributeOwned(i) && updateType != HLAUndefinedUpdate) {
_attributeVector[i]._enabledUpdate = true;
_attributeVector[i]._unconditionalUpdate = (updateType == HLAPeriodicUpdate);
// This makes sense with any new object. Even if we registered one, there might be unpublished attributes.
HLAIndexList indexList;
for (unsigned i = 0; i < numAttributes; ++i) {
- HLAUpdateType updateType = getObjectClass()->getAttributeUpdateType(i);
+ HLAUpdateType updateType = _objectClass->getAttributeUpdateType(i);
if (getAttributeOwned(i))
continue;
if (updateType == HLAUndefinedUpdate)