<commit_before>// Copyright (C) 2009 - 2010  <NAME> - <EMAIL>
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
//

#ifndef RTIObjectInstance_hxx
#define RTIObjectInstance_hxx

#include <list>
#include <map>
#include <string>
#include <vector>
#include "simgear/debug/logstream.hxx"
#include "simgear/structure/SGReferenced.hxx"
#include "simgear/structure/SGWeakPtr.hxx"
#include "simgear/timing/timestamp.hxx"
#include "RTIData.hxx"
#include "RTIObjectClass.hxx"
#include "HLADataElement.hxx"

class SGTimeStamp;

namespace simgear {

class RTIObjectClass;
class HLAObjectInstance;

class RTIObjectInstance : public SGReferenced {
public:
    RTIObjectInstance(HLAObjectInstance* hlaObjectInstance);
    virtual ~RTIObjectInstance();

    virtual const RTIObjectClass* getObjectClass() const = 0;

    virtual std::string getName() const = 0;

    unsigned getNumAttributes() const;
    unsigned getAttributeIndex(const std::string& name) const;
    std::string getAttributeName(unsigned index) const;

    virtual void deleteObjectInstance(const RTIData& tag) = 0;
    virtual void deleteObjectInstance(const SGTimeStamp& timeStamp, const RTIData& tag) = 0;
    virtual void localDeleteObjectInstance() = 0;

    virtual void requestObjectAttributeValueUpdate() = 0;

    virtual void updateAttributeValues(const RTIData& tag) = 0;
    virtual void updateAttributeValues(const SGTimeStamp& timeStamp, const RTIData& tag) = 0;

    void removeInstance(const RTIData& tag);
    // Call this if you want to roll up the queued timestamed updates
    // and reflect that into the attached data elements.
    void reflectQueuedAttributeValues(const SGTimeStamp& timeStamp)
    {
        // replay all updates up to the given timestamp
        UpdateListMap::iterator last = _updateListMap.upper_bound(timeStamp);
        for (UpdateListMap::iterator i = _updateListMap.begin(); i != last; ++i) {
            for (UpdateList::iterator j = i->second.begin(); j != i->second.end(); ++j) {
                // FIXME have a variant that takes the timestamp?
                reflectAttributeValues(j->_indexDataPairList, j->_tag);
            }
            putUpdateToPool(i->second);
        }
    }
    void reflectAttributeValues(const RTIIndexDataPairList& dataPairList, const RTIData& tag);
    void reflectAttributeValues(const RTIIndexDataPairList& dataPairList, const SGTimeStamp& timeStamp, const RTIData& tag);
    void reflectAttributeValue(unsigned i, const RTIData& data)
    {
        if (_attributeData.size() <= i)
            return;
        HLADataElement* dataElement = _attributeData[i]._dataElement.get();
        if (!dataElement)
            return;
        HLADecodeStream stream(data);
        dataElement->decode(stream);
    }

    const HLADataType* getAttributeDataType(unsigned i) const
    {
        return getObjectClass()->getAttributeDataType(i);
    }
    HLAUpdateType getAttributeUpdateType(unsigned i) const
    {
        return getObjectClass()->getAttributeUpdateType(i);
    }
    bool getAttributeSubscribed(unsigned i) const
    {
        return getObjectClass()->getAttributeSubscribed(i);
    }
    bool getAttributePublished(unsigned i) const
    {
        return getObjectClass()->getAttributePublished(i);
    }

    HLADataElement* getDataElement(unsigned i)
    {
        if (_attributeData.size() <= i)
            return 0;
        return _attributeData[i]._dataElement.get();
    }
    const HLADataElement* getDataElement(unsigned i) const
    {
        if (_attributeData.size() <= i)
            return 0;
        return _attributeData[i]._dataElement.get();
    }
    void setDataElement(unsigned i, HLADataElement* dataElement)
    {
        if (_attributeData.size() <= i)
            return;
        _attributeData[i]._dataElement = dataElement;
    }

    void updateAttributesFromClass(bool owned)
    {
        // FIXME: rethink that!!!
        unsigned numAttributes = getNumAttributes();
        unsigned i = 0;
        for (; i < _attributeData.size(); ++i) {
            if (getAttributePublished(i)) {
            } else {
                _attributeData[i].setUpdateEnabled(false);
                _attributeData[i].setOwned(false);
            }
        }
        _attributeData.resize(numAttributes);
        for (; i < numAttributes; ++i) {
            if (getAttributePublished(i)) {
                _attributeData[i].setUpdateEnabled(true);
                _attributeData[i].setOwned(owned);
            } else {
                _attributeData[i].setUpdateEnabled(false);
                _attributeData[i].setOwned(false);
            }
        }
    }

    void setAttributeForceUpdate(unsigned i)
    {
        if (_attributeData.size() <= i)
            return;
        _attributeData[i].setForceUpdate(true);
    }
    void setAttributeInScope(unsigned i, bool inScope)
    {
        if (_attributeData.size() <= i)
            return;
        _attributeData[i].setInScope(inScope);
    }
    void setAttributeUpdateEnabled(unsigned i, bool enabled)
    {
        if (_attributeData.size() <= i)
            return;
        _attributeData[i].setUpdateEnabled(enabled);
    }
    void setAttributeUpdated(unsigned i)
    {
        if (_attributeData.size() <= i)
            return;<commit_msg>hla: Initially request update for subscribed unowned attributes.<commit_after>// Copyright (C) 2009 - 2010  <NAME> - <EMAIL>.de
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
//

#ifndef RTIObjectInstance_hxx
#define RTIObjectInstance_hxx

#include <list>
#include <map>
#include <string>
#include <vector>
#include "simgear/debug/logstream.hxx"
#include "simgear/structure/SGReferenced.hxx"
#include "simgear/structure/SGWeakPtr.hxx"
#include "simgear/timing/timestamp.hxx"
#include "RTIData.hxx"
#include "RTIObjectClass.hxx"
#include "HLADataElement.hxx"

class SGTimeStamp;

namespace simgear {

class RTIObjectClass;
class HLAObjectInstance;

class RTIObjectInstance : public SGReferenced {
public:
    RTIObjectInstance(HLAObjectInstance* hlaObjectInstance);
    virtual ~RTIObjectInstance();

    virtual const RTIObjectClass* getObjectClass() const = 0;

    virtual std::string getName() const = 0;

    unsigned getNumAttributes() const;
    unsigned getAttributeIndex(const std::string& name) const;
    std::string getAttributeName(unsigned index) const;

    virtual void deleteObjectInstance(const RTIData& tag) = 0;
    virtual void deleteObjectInstance(const SGTimeStamp& timeStamp, const RTIData& tag) = 0;
    virtual void localDeleteObjectInstance() = 0;

    virtual void requestObjectAttributeValueUpdate() = 0;

    virtual void updateAttributeValues(const RTIData& tag) = 0;
    virtual void updateAttributeValues(const SGTimeStamp& timeStamp, const RTIData& tag) = 0;

    void removeInstance(const RTIData& tag);
    // Call this if you want to roll up the queued timestamed updates
    // and reflect that into the attached data elements.
    void reflectQueuedAttributeValues(const SGTimeStamp& timeStamp)
    {
        // replay all updates up to the given timestamp
        UpdateListMap::iterator last = _updateListMap.upper_bound(timeStamp);
        for (UpdateListMap::iterator i = _updateListMap.begin(); i != last; ++i) {
            for (UpdateList::iterator j = i->second.begin(); j != i->second.end(); ++j) {
                // FIXME have a variant that takes the timestamp?
                reflectAttributeValues(j->_indexDataPairList, j->_tag);
            }
            putUpdateToPool(i->second);
        }
    }
    void reflectAttributeValues(const RTIIndexDataPairList& dataPairList, const RTIData& tag);
    void reflectAttributeValues(const RTIIndexDataPairList& dataPairList, const SGTimeStamp& timeStamp, const RTIData& tag);
    void reflectAttributeValue(unsigned i, const RTIData& data)
    {
        if (_attributeData.size() <= i)
            return;
        HLADataElement* dataElement = _attributeData[i]._dataElement.get();
        if (!dataElement)
            return;
        HLADecodeStream stream(data);
        dataElement->decode(stream);
    }

    const HLADataType* getAttributeDataType(unsigned i) const
    {
        return getObjectClass()->getAttributeDataType(i);
    }
    HLAUpdateType getAttributeUpdateType(unsigned i) const
    {
        return getObjectClass()->getAttributeUpdateType(i);
    }
    bool getAttributeSubscribed(unsigned i) const
    {
        return getObjectClass()->getAttributeSubscribed(i);
    }
    bool getAttributePublished(unsigned i) const
    {
        return getObjectClass()->getAttributePublished(i);
    }

    HLADataElement* getDataElement(unsigned i)
    {
        if (_attributeData.size() <= i)
            return 0;
        return _attributeData[i]._dataElement.get();
    }
    const HLADataElement* getDataElement(unsigned i) const
    {
        if (_attributeData.size() <= i)
            return 0;
        return _attributeData[i]._dataElement.get();
    }
    void setDataElement(unsigned i, HLADataElement* dataElement)
    {
        if (_attributeData.size() <= i)
            return;
        _attributeData[i]._dataElement = dataElement;
    }

    void updateAttributesFromClass(bool owned)
    {
        // FIXME: rethink that!!!
        unsigned numAttributes = getNumAttributes();
        unsigned i = 0;
        for (; i < _attributeData.size(); ++i) {
            if (getAttributePublished(i)) {
            } else {
                _attributeData[i].setUpdateEnabled(false);
                _attributeData[i].setOwned(false);
                if (getAttributeSubscribed(i))
                    _attributeData[i].setRequestUpdate(true);
            }
        }
        _attributeData.resize(numAttributes);
        for (; i < numAttributes; ++i) {
            if (getAttributePublished(i)) {
                _attributeData[i].setUpdateEnabled(true);
                _attributeData[i].setOwned(owned);
                if (!owned && getAttributeSubscribed(i))
                    _attributeData[i].setRequestUpdate(true);
            } else {
                _attributeData[i].setUpdateEnabled(false);
                _attributeData[i].setOwned(false);
                if (getAttributeSubscribed(i))
                    _attributeData[i].setRequestUpdate(true);
            }
        }
    }

    void setAttributeForceUpdate(unsigned i)
    {
        if (_attributeData.size() <= i)
            return;
        _attributeData[i].setForceUpdate(true);
    }
    void setAttributeInScope(unsigned i, bool inScope)
    {
        if (_attributeData.size() <= i)
            return;
        _attributeData[i].setInScope(inScope);
    }
    void setAttributeUpdateEnabled(unsigned i, bool enabled)
    {
        if (_attributeData.size() <= i)
            return;
        _attributeData[i].setUpdateEnabled(enabled);
    }
    void setAttributeUpdated(unsigned i)
    {
        if (_attributeData.size() <= i)
            return;
{'fraction_non_alphanumeric': 0.09701310327988931, 'fraction_numerical': 0.005045983559860015, 'mean_word_length': 2.8568738229755177, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7537215', 'n_tokens_mistral': 3485, 'n_tokens_neox': 3370, 'n_words': 920}