]> git.mxchange.org Git - simgear.git/blobdiff - simgear/misc/props.hxx
MSVC++ bug work-around from Frederic Bouvier.
[simgear.git] / simgear / misc / props.hxx
index 6a0032f69560c3d620a746a974b067ad747d8a05..b4a429974c5b5ea485a10d4ed47b2f474949ccb9 100644 (file)
@@ -449,6 +449,100 @@ private:
   setter_t _setter;
 };
 
+\f
+/**
+ * The smart pointer that manage reference counting
+ */
+class SGPropertyNode;
+class SGPropertyNode_ptr
+{
+public:
+
+  /**
+   * Default constructor
+   */
+  SGPropertyNode_ptr();
+
+  /**
+   * Copy constructor
+   */
+  SGPropertyNode_ptr( const SGPropertyNode_ptr &r );
+
+  /**
+   * Constructor from a pointer to a node
+   */
+  SGPropertyNode_ptr( SGPropertyNode *p );
+
+  /**
+   * Destructor
+   */
+  ~SGPropertyNode_ptr();
+
+  /**
+   * Assignement operator
+   */
+  SGPropertyNode_ptr &operator=( const SGPropertyNode_ptr &r );
+
+  /**
+   * Pointer access operator
+   */
+  SGPropertyNode *operator->();
+
+  /**
+   * Pointer access operator (const)
+   */
+  const SGPropertyNode *operator->() const;
+
+  /**
+   * Conversion to SGPropertyNode * operator
+   */
+  operator SGPropertyNode *();
+
+  /**
+   * Conversion to const SGPropertyNode * operator
+   */
+  operator const SGPropertyNode *() const;
+
+  /**
+   * Return the pointer.
+   */
+  SGPropertyNode * ptr () { return _ptr; }
+
+  /**
+   * Validity test
+   */
+  bool valid() const;
+
+private:
+
+  SGPropertyNode *_ptr;
+};
+
+
+\f
+/**
+ * The property change listener interface.
+ *
+ * <p>Any class that needs to listen for property changes must implement
+ * this interface.</p>
+ */
+class SGPropertyChangeListener
+{
+public:
+  virtual ~SGPropertyChangeListener ();
+  virtual void valueChanged (SGPropertyNode * node);
+  virtual void childAdded (SGPropertyNode * parent, SGPropertyNode * child);
+  virtual void childRemoved (SGPropertyNode * parent, SGPropertyNode * child);
+
+protected:
+  friend class SGPropertyNode;
+  virtual void register_property (SGPropertyNode * node);
+  virtual void unregister_property (SGPropertyNode * node);
+
+private:
+  vector<SGPropertyNode *> _properties;
+};
+
 
 \f
 /**
@@ -491,11 +585,19 @@ public:
     READ = 1,
     WRITE = 2,
     ARCHIVE = 4,
-    TRACE_READ = 8,
-    TRACE_WRITE = 16
+    REMOVED = 8,
+    TRACE_READ = 16,
+    TRACE_WRITE = 32
   };
 
 
+  /**
+   * Last used attribute
+   * Update as needed when enum Attribute is changed
+   */
+  static const int LAST_USED_ATTRIBUTE;
+
+
   /**
    * Default constructor.
    */
@@ -588,13 +690,14 @@ public:
   /**
    * Get a vector of all children with the specified name.
    */
-  vector<SGPropertyNode *> getChildren (const char * name);
+  vector<SGPropertyNode_ptr> getChildren (const char * name) const;
 
 
   /**
-   * Get a vector all all children (const) with the specified name.
+   * Remove a child node
    */
-  vector<const SGPropertyNode *> getChildren (const char * name) const;
+  SGPropertyNode_ptr removeChild (const char * name, int index = 0,
+                                  bool keep = true);
 
 
   //
@@ -1026,8 +1129,41 @@ public:
   bool untie (const char * relative_path);
 
 
+  /**
+   * Add a change listener to the property.
+   */
+  void addChangeListener (SGPropertyChangeListener * listener);
+
+
+  /**
+   * Remove a change listener from the property.
+   */
+  void removeChangeListener (SGPropertyChangeListener * listener);
+
+
+  /**
+   * Fire a value change event to all listeners.
+   */
+  void fireValueChanged ();
+
+
+  /**
+   * Fire a child-added event to all listeners.
+   */
+  void fireChildAdded (SGPropertyNode * child);
+
+
+  /**
+   * Fire a child-removed event to all listeners.
+   */
+  void fireChildRemoved (SGPropertyNode * child);
+
+
 protected:
 
+  void fireValueChanged (SGPropertyNode * node);
+  void fireChildAdded (SGPropertyNode * parent, SGPropertyNode * child);
+  void fireChildRemoved (SGPropertyNode * parent, SGPropertyNode * child);
 
   /**
    * Protected constructor for making new nodes on demand.
@@ -1077,6 +1213,20 @@ private:
    */
   void trace_write () const;
 
+
+  /**
+   * Increment reference counter
+   */
+  void incrementRef();
+
+  /**
+   * Decrement reference counter
+   */
+  int decrementRef();
+
+  friend class SGPropertyNode_ptr;
+
+
   mutable char _buffer[MAX_STRING_LEN+1];
 
   class hash_table;
@@ -1084,11 +1234,13 @@ private:
   char * _name;
   int _index;
   SGPropertyNode * _parent;
-  vector<SGPropertyNode *> _children;
+  vector<SGPropertyNode_ptr> _children;
+  vector<SGPropertyNode_ptr> _removedChildren;
   hash_table * _path_cache;
   Type _type;
   bool _tied;
   int _attr;
+  int _count;
 
                                // The right kind of pointer...
   union {
@@ -1110,6 +1262,8 @@ private:
     char * string_val;
   } _local_val;
 
+  vector <SGPropertyChangeListener *> * _listeners;
+
 
 \f
   /**