]> git.mxchange.org Git - simgear.git/blobdiff - simgear/props/props.hxx
whoops, sorry (Yes, it *was* tested, but then I made another "trivial"
[simgear.git] / simgear / props / props.hxx
index 9ce7df4bf52524d315366884ae72b97b292da427..7c38fcb14b755851029eb115da0551cc733d448c 100644 (file)
@@ -41,6 +41,9 @@ SG_USING_STD(ostream);
 
 #endif
 
+#include <simgear/structure/SGReferenced.hxx>
+#include <simgear/structure/SGSharedPtr.hxx>
+
 
 #ifdef NONE
 #pragma warn A sloppy coder has defined NONE as a macro!
@@ -452,70 +455,8 @@ private:
  * 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;
-};
-
+typedef SGSharedPtr<SGPropertyNode> SGPropertyNode_ptr;
+typedef SGSharedPtr<const SGPropertyNode> SGConstPropertyNode_ptr;
 
 \f
 /**
@@ -546,7 +487,7 @@ private:
 /**
  * A node in a property tree.
  */
-class SGPropertyNode
+class SGPropertyNode : public SGReferenced
 {
 public:
 
@@ -585,7 +526,8 @@ public:
     ARCHIVE = 4,
     REMOVED = 8,
     TRACE_READ = 16,
-    TRACE_WRITE = 32
+    TRACE_WRITE = 32,
+    USERARCHIVE = 64
   };
 
 
@@ -628,7 +570,7 @@ public:
   /**
    * Get the node's simple (XML) name.
    */
-  const char * getName () const { return _name; }
+  const char * getName () const { return _name.c_str(); }
 
 
   /**
@@ -706,12 +648,24 @@ public:
   vector<SGPropertyNode_ptr> getChildren (const char * name) const;
 
 
+  /**
+   * Remove child by position.
+   */
+  SGPropertyNode_ptr removeChild (int pos, bool keep = true);
+
+
   /**
    * Remove a child node
    */
   SGPropertyNode_ptr removeChild (const char * name, int index = 0,
                                   bool keep = true);
 
+  /**
+   * Remove all children with the specified name.
+   */
+  vector<SGPropertyNode_ptr> removeChildren (const char * name,
+                                             bool keep = true);
+
 
   //
   // Alias support.
@@ -1143,9 +1097,11 @@ public:
 
 
   /**
-   * Add a change listener to the property.
+   * Add a change listener to the property. If "initial" is set call the
+   * listener initially.
    */
-  void addChangeListener (SGPropertyChangeListener * listener);
+  void addChangeListener (SGPropertyChangeListener * listener,
+                          bool initial = false);
 
 
   /**
@@ -1227,35 +1183,22 @@ 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;
 
-  char * _name;
-  mutable char * _display_name;
   int _index;
+  string _name;
+  mutable string _display_name;
+  /// To avoid cyclic reference counting loops this shall not be a reference
+  /// counted pointer
   SGPropertyNode * _parent;
   vector<SGPropertyNode_ptr> _children;
   vector<SGPropertyNode_ptr> _removedChildren;
-  mutable char * _path;
+  mutable string _path;
+  mutable string _buffer;
   hash_table * _path_cache;
   Type _type;
   bool _tied;
   int _attr;
-  int _count;
 
                                // The right kind of pointer...
   union {
@@ -1293,14 +1236,14 @@ private:
     class entry {
     public:
       entry ();
-      virtual ~entry ();
-      virtual const char * get_key () { return _key; }
-      virtual void set_key (const char * key);
-      virtual SGPropertyNode * get_value () { return _value; }
-      virtual void set_value (SGPropertyNode * value);
+      ~entry ();
+      const char * get_key () { return _key.c_str(); }
+      void set_key (const char * key);
+      SGPropertyNode * get_value () { return _value; }
+      void set_value (SGPropertyNode * value);
     private:
-      char * _key;
-      SGPropertyNode * _value;
+      string _key;
+      SGSharedPtr<SGPropertyNode>  _value;
     };
 
 
@@ -1310,9 +1253,9 @@ private:
     class bucket {
     public:
       bucket ();
-      virtual ~bucket ();
-      virtual entry * get_entry (const char * key, bool create = false);
-      virtual void erase(const char * key);
+      ~bucket ();
+      entry * get_entry (const char * key, bool create = false);
+      void erase(const char * key);
     private:
       int _length;
       entry ** _entries;
@@ -1321,10 +1264,10 @@ private:
     friend class bucket;
 
     hash_table ();
-    virtual ~hash_table ();
-    virtual SGPropertyNode * get (const char * key);
-    virtual void put (const char * key, SGPropertyNode * value);
-    virtual void erase(const char * key);
+    ~hash_table ();
+    SGPropertyNode * get (const char * key);
+    void put (const char * key, SGPropertyNode * value);
+    void erase(const char * key);
 
   private:
     unsigned int hashcode (const char * key);