]> git.mxchange.org Git - simgear.git/blobdiff - simgear/hla/HLAObjectClass.hxx
hla: Use raw pointers for HLAFederate::_insert methods.
[simgear.git] / simgear / hla / HLAObjectClass.hxx
index b0db5ad1f9b40b776040ac16e899f28d5ff1a68d..d80e4f8d5988d9527e39dde7be1f85471f2bbd7b 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2009 - 2010  Mathias Froehlich - Mathias.Froehlich@web.de
+// Copyright (C) 2009 - 2012  Mathias Froehlich - Mathias.Froehlich@web.de
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Library General Public
 #ifndef HLAObjectClass_hxx
 #define HLAObjectClass_hxx
 
-#include <set>
 #include <string>
 #include <vector>
 
 #include "HLADataType.hxx"
 #include "HLAObjectInstance.hxx"
+#include "HLATypes.hxx"
 
 namespace simgear {
 
@@ -32,30 +32,56 @@ class HLAFederate;
 
 class HLAObjectClass : public SGWeakReferenced {
 public:
-    HLAObjectClass(const std::string& name, HLAFederate& federate);
+    HLAObjectClass(const std::string& name, HLAFederate* federate);
     virtual ~HLAObjectClass();
 
-    const std::string& getName() const
-    { return _name; }
+    /// Return the name of this object class
+    const std::string& getName() const;
 
+    /// return the federate this class belongs to
+    const SGWeakPtr<HLAFederate>& getFederate() const;
+
+    /// Return the number of attributes in this object class
     unsigned getNumAttributes() const;
+
+    /// Adds a new attribute to this object class, return the index
+    unsigned addAttribute(const std::string& name);
+
+    /// Return the attribute index for the attribute with the given name
     unsigned getAttributeIndex(const std::string& name) const;
+    /// Return the attribute name for the attribute with the given index
     std::string getAttributeName(unsigned index) const;
 
+    /// Return the data type of the attribute with the given index
     const HLADataType* getAttributeDataType(unsigned index) const;
-    void setAttributeDataType(unsigned index, const HLADataType*);
+    /// Sets the data type of the attribute with the given index to dataType
+    void setAttributeDataType(unsigned index, const HLADataType* dataType);
 
+    /// Return the update type of the attribute with the given index
     HLAUpdateType getAttributeUpdateType(unsigned index) const;
+    /// Sets the update type of the attribute with the given index to updateType
     void setAttributeUpdateType(unsigned index, HLAUpdateType updateType);
 
-    HLADataElement::IndexPathPair getIndexPathPair(const HLADataElement::AttributePathPair&) const;
+    /// Return the subscription type of the attribute with the given index
+    HLASubscriptionType getAttributeSubscriptionType(unsigned index) const;
+    /// Sets the subscription type of the attribute with the given index to subscriptionType
+    void setAttributeSubscriptionType(unsigned index, HLASubscriptionType subscriptionType);
+
+    /// Return the publication type of the attribute with the given index
+    HLAPublicationType getAttributePublicationType(unsigned index) const;
+    /// Sets the publication type of the attribute with the given index to publicationType
+    void setAttributePublicationType(unsigned index, HLAPublicationType publicationType);
+
+    /// Return the index, path pair for the given string path pair
+    HLADataElement::IndexPathPair getIndexPathPair(const HLADataElement::StringPathPair&) const;
+    /// Return the index, path pair for the given string path
     HLADataElement::IndexPathPair getIndexPathPair(const std::string& path) const;
 
-    bool subscribe(const std::set<unsigned>& indexSet, bool active);
-    bool unsubscribe();
+    virtual bool subscribe();
+    virtual bool unsubscribe();
 
-    bool publish(const std::set<unsigned>& indexSet);
-    bool unpublish();
+    virtual bool publish();
+    virtual bool unpublish();
 
     // Object instance creation and destruction
     class InstanceCallback : public SGReferenced {
@@ -74,6 +100,16 @@ public:
     const SGSharedPtr<InstanceCallback>& getInstanceCallback() const
     { return _instanceCallback; }
 
+    virtual void discoverInstance(HLAObjectInstance& objectInstance, const RTIData& tag);
+    virtual void removeInstance(HLAObjectInstance& objectInstance, const RTIData& tag);
+    virtual void registerInstance(HLAObjectInstance& objectInstance);
+    virtual void deleteInstance(HLAObjectInstance& objectInstance);
+
+    // Is called by the default registration callback if installed
+    // Should register the already known object instances of this class.
+    virtual void startRegistration() const;
+    virtual void stopRegistration() const;
+
     // Handles startRegistrationForObjectClass and stopRegistrationForObjectClass events
     class RegistrationCallback : public SGReferenced {
     public:
@@ -87,43 +123,63 @@ public:
     const SGSharedPtr<RegistrationCallback>& getRegistrationCallback() const
     { return _registrationCallback; }
 
-    // Is called by the default registration callback if installed
-    void startRegistration() const;
-    void stopRegistration() const;
+    /// Create a new instance of this class.
+    virtual HLAObjectInstance* createObjectInstance(const std::string& name);
 
-protected:
-    virtual HLAObjectInstance* createObjectInstance(RTIObjectInstance* rtiObjectInstance);
+    virtual void createAttributeDataElements(HLAObjectInstance& objectInstance);
+    virtual HLADataElement* createAttributeDataElement(HLAObjectInstance& objectInstance, unsigned index);
 
 private:
+    HLAObjectClass(const HLAObjectClass&);
+    HLAObjectClass& operator=(const HLAObjectClass&);
+
+    void _setRTIObjectClass(RTIObjectClass* objectClass);
+    void _resolveAttributeIndex(const std::string& name, unsigned index);
+    void _clearRTIObjectClass();
+
     // The internal entry points from the RTILObjectClass callback functions
-    void discoverInstance(RTIObjectInstance* objectInstance, const RTIData& tag);
-    void removeInstance(HLAObjectInstance& objectInstance, const RTIData& tag);
-    void registerInstance(HLAObjectInstance& objectInstance);
-    void deleteInstance(HLAObjectInstance& objectInstance);
-
-    void discoverInstanceCallback(HLAObjectInstance& objectInstance, const RTIData& tag) const;
-    void removeInstanceCallback(HLAObjectInstance& objectInstance, const RTIData& tag) const;
-    void registerInstanceCallback(HLAObjectInstance& objectInstance) const;
-    void deleteInstanceCallback(HLAObjectInstance& objectInstance) const;
-
-    void startRegistrationCallback();
-    void stopRegistrationCallback();
+    void _discoverInstance(RTIObjectInstance* objectInstance, const RTIData& tag);
+    void _removeInstance(HLAObjectInstance& objectInstance, const RTIData& tag);
+    void _registerInstance(HLAObjectInstance* objectInstance);
+    void _deleteInstance(HLAObjectInstance& objectInstance);
+
+    void _startRegistration();
+    void _stopRegistration();
+
     friend class HLAObjectInstance;
     friend class RTIObjectClass;
 
-    // The object class name
+    struct Attribute {
+        Attribute() : _subscriptionType(HLAUnsubscribed), _publicationType(HLAUnpublished), _updateType(HLAUndefinedUpdate) {}
+        Attribute(const std::string& name) : _name(name), _subscriptionType(HLAUnsubscribed), _publicationType(HLAUnpublished), _updateType(HLAUndefinedUpdate) {}
+        std::string _name;
+        SGSharedPtr<const HLADataType> _dataType;
+        HLASubscriptionType _subscriptionType;
+        HLAPublicationType _publicationType;
+        HLAUpdateType _updateType;
+    };
+    typedef std::vector<Attribute> AttributeVector;
+    typedef std::map<std::string,unsigned> NameIndexMap;
+
+    /// The parent federate.
+    SGWeakPtr<HLAFederate> _federate;
+
+    /// The object class name
     std::string _name;
 
-    // The underlying rti dispatcher class
+    /// The underlying rti dispatcher class
     SGSharedPtr<RTIObjectClass> _rtiObjectClass;
 
+    /// The attribute data
+    AttributeVector _attributeVector;
+    /// The mapping from attribute names to attribute indices
+    NameIndexMap _nameIndexMap;
+
     // Callback classes
     SGSharedPtr<InstanceCallback> _instanceCallback;
     SGSharedPtr<RegistrationCallback> _registrationCallback;
 
-    // The set of active objects
-    typedef std::set<SGSharedPtr<HLAObjectInstance> > ObjectInstanceSet;
-    ObjectInstanceSet _objectInstanceSet;
+    friend class HLAFederate;
 };
 
 } // namespace simgear