hla: Timestamp support down to the DataElements.

This commit is contained in:
Mathias Froehlich
2012-03-02 21:36:08 +01:00
parent e4e3760b3d
commit a07ca86207
9 changed files with 196 additions and 30 deletions
+38 -1
View File
@@ -99,6 +99,7 @@ HLAArrayDataElement::HLAArrayDataElement(const HLAArrayDataType* dataType) :
HLAArrayDataElement::~HLAArrayDataElement() HLAArrayDataElement::~HLAArrayDataElement()
{ {
clearStamp();
} }
bool bool
@@ -171,7 +172,11 @@ HLAArrayDataElement::setElement(unsigned index, HLADataElement* value)
for (unsigned j = oldSize; j < index; ++j) for (unsigned j = oldSize; j < index; ++j)
_elementVector[j] = newElement(j); _elementVector[j] = newElement(j);
} }
if (_elementVector[index].valid())
_elementVector[index]->clearStamp();
_elementVector[index] = value; _elementVector[index] = value;
if (value)
value->attachStamp(*this);
} }
void void
@@ -186,12 +191,27 @@ HLAArrayDataElement::getDataElementFactory()
return _dataElementFactory.get(); return _dataElementFactory.get();
} }
void
HLAArrayDataElement::_setStamp(Stamp* stamp)
{
HLAAbstractArrayDataElement::_setStamp(stamp);
for (ElementVector::iterator i = _elementVector.begin(); i != _elementVector.end(); ++i) {
if (!i->valid())
continue;
(*i)->attachStamp(*this);
}
}
HLADataElement* HLADataElement*
HLAArrayDataElement::newElement(unsigned index) HLAArrayDataElement::newElement(unsigned index)
{ {
if (!_dataElementFactory.valid()) if (!_dataElementFactory.valid())
return 0; return 0;
return _dataElementFactory->createElement(*this, index); HLADataElement* dataElement = _dataElementFactory->createElement(*this, index);
if (!dataElement)
return 0;
dataElement->attachStamp(*this);
return dataElement;
} }
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
@@ -203,6 +223,7 @@ HLAVariantArrayDataElement::HLAVariantArrayDataElement() :
HLAVariantArrayDataElement::~HLAVariantArrayDataElement() HLAVariantArrayDataElement::~HLAVariantArrayDataElement()
{ {
clearStamp();
} }
bool bool
@@ -292,7 +313,11 @@ HLAVariantArrayDataElement::setElement(unsigned index, HLAVariantRecordDataEleme
for (unsigned j = oldSize; j < index; ++j) for (unsigned j = oldSize; j < index; ++j)
_elementVector[j] = newElement(); _elementVector[j] = newElement();
} }
if (_elementVector[index].valid())
_elementVector[index]->clearStamp();
_elementVector[index] = value; _elementVector[index] = value;
if (value)
value->attachStamp(*this);
} }
void void
@@ -307,6 +332,17 @@ HLAVariantArrayDataElement::getAlternativeDataElementFactory()
return _alternativeDataElementFactory.get(); return _alternativeDataElementFactory.get();
} }
void
HLAVariantArrayDataElement::_setStamp(Stamp* stamp)
{
HLAAbstractArrayDataElement::_setStamp(stamp);
for (ElementVector::iterator i = _elementVector.begin(); i != _elementVector.end(); ++i) {
if (!i->valid())
continue;
(*i)->attachStamp(*this);
}
}
HLAVariantRecordDataElement* HLAVariantRecordDataElement*
HLAVariantArrayDataElement::newElement() HLAVariantArrayDataElement::newElement()
{ {
@@ -321,6 +357,7 @@ HLAVariantArrayDataElement::newElement()
return 0; return 0;
HLAVariantRecordDataElement* variantRecordDataElement = new HLAVariantRecordDataElement(variantRecordDataType); HLAVariantRecordDataElement* variantRecordDataElement = new HLAVariantRecordDataElement(variantRecordDataType);
variantRecordDataElement->setDataElementFactory(_alternativeDataElementFactory.get()); variantRecordDataElement->setDataElementFactory(_alternativeDataElementFactory.get());
variantRecordDataElement->attachStamp(*this);
return variantRecordDataElement; return variantRecordDataElement;
} }
+6
View File
@@ -78,6 +78,9 @@ public:
void setDataElementFactory(DataElementFactory* dataElementFactory); void setDataElementFactory(DataElementFactory* dataElementFactory);
DataElementFactory* getDataElementFactory(); DataElementFactory* getDataElementFactory();
protected:
virtual void _setStamp(Stamp* stamp);
private: private:
HLADataElement* newElement(unsigned index); HLADataElement* newElement(unsigned index);
@@ -112,6 +115,9 @@ public:
void setAlternativeDataElementFactory(AlternativeDataElementFactory* alternativeDataElementFactory); void setAlternativeDataElementFactory(AlternativeDataElementFactory* alternativeDataElementFactory);
AlternativeDataElementFactory* getAlternativeDataElementFactory(); AlternativeDataElementFactory* getAlternativeDataElementFactory();
protected:
virtual void _setStamp(Stamp* stamp);
private: private:
HLAVariantRecordDataElement* newElement(); HLAVariantRecordDataElement* newElement();
+51
View File
@@ -131,6 +131,51 @@ HLADataElement::~HLADataElement()
{ {
} }
void
HLADataElement::setTimeStamp(const SGTimeStamp& timeStamp)
{
if (!_stamp.valid())
return;
_stamp->setTimeStamp(timeStamp);
}
void
HLADataElement::setTimeStampValid(bool timeStampValid)
{
if (!_stamp.valid())
return;
_stamp->setTimeStampValid(timeStampValid);
}
double
HLADataElement::getTimeDifference(const SGTimeStamp& timeStamp) const
{
if (!_stamp.valid())
return 0;
if (!_stamp->getTimeStampValid())
return 0;
return (timeStamp - _stamp->getTimeStamp()).toSecs();
}
void
HLADataElement::createStamp()
{
_setStamp(new Stamp);
setDirty(true);
}
void
HLADataElement::attachStamp(HLADataElement& dataElement)
{
_setStamp(dataElement._getStamp());
}
void
HLADataElement::clearStamp()
{
_setStamp(0);
}
void void
HLADataElement::accept(HLADataElementVisitor& visitor) HLADataElement::accept(HLADataElementVisitor& visitor)
{ {
@@ -198,4 +243,10 @@ HLADataElement::toStringPathPair(const std::string& s)
return StringPathPair(attribute, path); return StringPathPair(attribute, path);
} }
void
HLADataElement::_setStamp(HLADataElement::Stamp* stamp)
{
_stamp = stamp;
}
} }
+57 -27
View File
@@ -46,34 +46,30 @@ public:
virtual const HLADataType* getDataType() const = 0; virtual const HLADataType* getDataType() const = 0;
virtual bool setDataType(const HLADataType* dataType) = 0; virtual bool setDataType(const HLADataType* dataType) = 0;
// Container for the timestamp the originating attribute was last updated for /// Returns the time stamp if this data element.
// class TimeStamp : public SGReferenced { /// Do not access this getter if the getTimeStampValid() method returns false.
// public: const SGTimeStamp& getTimeStamp() const
// const SGTimeStamp& getTimeStamp() const { return _stamp->getTimeStamp(); }
// { return _timeStamp; } void setTimeStamp(const SGTimeStamp& timeStamp);
// void setTimeStamp(const SGTimeStamp& timeStamp)
// { _timeStamp = timeStamp; }
// private:
// SGTimeStamp _timeStamp;
// };
// const TimeStamp* getTimeStamp() const bool getTimeStampValid() const
// { return _timeStamp.get(); } { if (!_stamp.valid()) return false; return _stamp->getTimeStampValid(); }
// void setTimeStamp(const TimeStamp* timeStamp) void setTimeStampValid(bool timeStampValid);
// { _timeStamp = timeStamp; }
// struct ChangeCount : public SGReferenced { /// Convenience function that gives the time difference in seconds to a given timestamp
// ChangeCount() : _value(0) {} /// This function returns 0 if the timestamp is not valid.
// unsigned _value; double getTimeDifference(const SGTimeStamp& timeStamp) const;
// };
// SGSharedPtr<ChangeCount> _changeCount; /// Dirty tracking of the attribute/parameter that this data element belongs to
// unsigned getChangeCount() const bool getDirty() const
// { { if (!_stamp.valid()) return true; return _stamp->getDirty(); }
// // If we don't have return allways the same void setDirty(bool dirty)
// if (!_changeCount.valid()) { if (!_stamp.valid()) return; _stamp->setDirty(dirty); }
// return 0;
// return _changeCount->_value; /// Stamp handling
// } void createStamp();
void attachStamp(HLADataElement& dataElement);
void clearStamp();
/// HLADataElements could be identified by path /// HLADataElements could be identified by path
/// These paths are composed of structure field names and array indices in the /// These paths are composed of structure field names and array indices in the
@@ -163,8 +159,42 @@ public:
static Path toPath(const std::string& s) static Path toPath(const std::string& s)
{ return toStringPathPair(s).second; } { return toStringPathPair(s).second; }
protected:
// Container for the timestamp the originating attribute was last updated for
class Stamp : public SGReferenced {
public:
Stamp() : _timeStampValid(false), _dirty(true)
{ }
const SGTimeStamp& getTimeStamp() const
{ return _timeStamp; }
void setTimeStamp(const SGTimeStamp& timeStamp)
{ _timeStamp = timeStamp; }
bool getTimeStampValid() const
{ return _timeStampValid; }
void setTimeStampValid(bool timeStampValid)
{ _timeStampValid = timeStampValid; }
bool getDirty() const
{ return _dirty; }
void setDirty(bool dirty)
{ _dirty = dirty; }
private:
SGTimeStamp _timeStamp;
bool _timeStampValid;
bool _dirty;
};
/// get the stamp
Stamp* _getStamp() const
{ return _stamp.get(); }
/// Set the stamp
virtual void _setStamp(Stamp* stamp);
private: private:
// SGSharedPtr<const TimeStamp> _timeStamp; SGSharedPtr<Stamp> _stamp;
}; };
class HLADataElementProvider { class HLADataElementProvider {
+16
View File
@@ -120,6 +120,7 @@ HLAFixedRecordDataElement::HLAFixedRecordDataElement(const HLAFixedRecordDataTyp
HLAFixedRecordDataElement::~HLAFixedRecordDataElement() HLAFixedRecordDataElement::~HLAFixedRecordDataElement()
{ {
clearStamp();
} }
bool bool
@@ -181,7 +182,11 @@ HLAFixedRecordDataElement::setField(unsigned index, HLADataElement* value)
{ {
if (getNumFields() <= index) if (getNumFields() <= index)
return; return;
if (_fieldVector[index].valid())
_fieldVector[index]->clearStamp();
_fieldVector[index] = value; _fieldVector[index] = value;
if (value)
value->attachStamp(*this);
} }
void void
@@ -190,4 +195,15 @@ HLAFixedRecordDataElement::setField(const std::string& name, HLADataElement* val
setField(getFieldNumber(name), value); setField(getFieldNumber(name), value);
} }
void
HLAFixedRecordDataElement::_setStamp(Stamp* stamp)
{
HLAAbstractFixedRecordDataElement::_setStamp(stamp);
for (FieldVector::iterator i = _fieldVector.begin(); i != _fieldVector.end(); ++i) {
if (!i->valid())
continue;
(*i)->attachStamp(*this);
}
}
} }
@@ -70,6 +70,9 @@ public:
void setField(unsigned index, HLADataElement* value); void setField(unsigned index, HLADataElement* value);
void setField(const std::string& name, HLADataElement* value); void setField(const std::string& name, HLADataElement* value);
protected:
virtual void _setStamp(Stamp* stamp);
private: private:
typedef std::vector<SGSharedPtr<HLADataElement> > FieldVector; typedef std::vector<SGSharedPtr<HLADataElement> > FieldVector;
FieldVector _fieldVector; FieldVector _fieldVector;
+7 -1
View File
@@ -116,7 +116,11 @@ HLAObjectInstance::setAttributeDataElement(unsigned index, const SGSharedPtr<HLA
if (numAttributes <= index) if (numAttributes <= index)
return; return;
_attributeVector.resize(numAttributes); _attributeVector.resize(numAttributes);
if (_attributeVector[index]._dataElement.valid())
_attributeVector[index]._dataElement->clearStamp();
_attributeVector[index]._dataElement = dataElement; _attributeVector[index]._dataElement = dataElement;
if (_attributeVector[index]._dataElement.valid())
_attributeVector[index]._dataElement->createStamp();
if (getAttributeOwned(index)) if (getAttributeOwned(index))
encodeAttributeValue(index); encodeAttributeValue(index);
} }
@@ -533,6 +537,7 @@ HLAObjectInstance::reflectAttributeValue(unsigned index, const RTIData& tag)
HLADataElement* dataElement = getAttributeDataElement(index); HLADataElement* dataElement = getAttributeDataElement(index);
if (!dataElement) if (!dataElement)
return; return;
dataElement->setTimeStampValid(false);
_rtiObjectInstance->decodeAttributeData(index, *dataElement); _rtiObjectInstance->decodeAttributeData(index, *dataElement);
} }
@@ -542,7 +547,8 @@ HLAObjectInstance::reflectAttributeValue(unsigned index, const SGTimeStamp& time
HLADataElement* dataElement = getAttributeDataElement(index); HLADataElement* dataElement = getAttributeDataElement(index);
if (!dataElement) if (!dataElement)
return; return;
// dataElement->setTimeStamp(timeStamp); dataElement->setTimeStamp(timeStamp);
dataElement->setTimeStampValid(true);
_rtiObjectInstance->decodeAttributeData(index, *dataElement); _rtiObjectInstance->decodeAttributeData(index, *dataElement);
} }
+15 -1
View File
@@ -113,6 +113,7 @@ HLAVariantRecordDataElement::HLAVariantRecordDataElement(const HLAVariantRecordD
HLAVariantRecordDataElement::~HLAVariantRecordDataElement() HLAVariantRecordDataElement::~HLAVariantRecordDataElement()
{ {
clearStamp();
} }
bool bool
@@ -158,12 +159,25 @@ HLAVariantRecordDataElement::getDataElementFactory()
return _dataElementFactory; return _dataElementFactory;
} }
void
HLAVariantRecordDataElement::_setStamp(Stamp* stamp)
{
HLAAbstractVariantRecordDataElement::_setStamp(stamp);
if (!_dataElement.valid())
return;
_dataElement->attachStamp(*this);
}
HLADataElement* HLADataElement*
HLAVariantRecordDataElement::newElement(unsigned index) HLAVariantRecordDataElement::newElement(unsigned index)
{ {
if (!_dataElementFactory.valid()) if (!_dataElementFactory.valid())
return 0; return 0;
return _dataElementFactory->createElement(*this, index); HLADataElement* dataElement = _dataElementFactory->createElement(*this, index);
if (!dataElement)
return 0;
dataElement->attachStamp(*this);
return dataElement;
} }
} }
@@ -71,6 +71,9 @@ public:
void setDataElementFactory(DataElementFactory* dataElementFactory); void setDataElementFactory(DataElementFactory* dataElementFactory);
DataElementFactory* getDataElementFactory(); DataElementFactory* getDataElementFactory();
protected:
virtual void _setStamp(Stamp* stamp);
private: private:
HLADataElement* newElement(unsigned index); HLADataElement* newElement(unsigned index);