]> git.mxchange.org Git - simgear.git/commitdiff
Modified Files:
authorfrohlich <frohlich>
Wed, 26 Dec 2007 19:03:21 +0000 (19:03 +0000)
committerfrohlich <frohlich>
Wed, 26 Dec 2007 19:03:21 +0000 (19:03 +0000)
simgear/props/props.hxx: Add a bunch of convinience functions.

simgear/props/props.hxx

index 41361c9862e392ff4ba7c0ce4a6b69e22e16a216..ce58e00ce2e3adc8ea1d0b4ca1a1efa4cd9b2e9b 100644 (file)
@@ -628,6 +628,14 @@ public:
     return (getChild(name, index) != 0);
   }
 
+  /**
+   * Test whether a named child exists.
+   */
+  bool hasChild (const std::string& name, int index = 0) const
+  {
+    return (getChild(name, index) != 0);
+  }
+
 
   /**
    * Get a child node by name and index.
@@ -635,18 +643,36 @@ public:
   SGPropertyNode * getChild (const char * name, int index = 0,
                             bool create = false);
 
+  /**
+   * Get a child node by name and index.
+   */
+  SGPropertyNode * getChild (const std::string& name, int index = 0,
+                            bool create = false)
+  { return getChild(name.c_str(), index, create); }
+
 
   /**
    * Get a const child node by name and index.
    */
   const SGPropertyNode * getChild (const char * name, int index = 0) const;
 
+  /**
+   * Get a const child node by name and index.
+   */
+  const SGPropertyNode * getChild (const std::string& name, int index = 0) const
+  { return getChild(name.c_str(), index); }
+
 
   /**
    * Get a vector of all children with the specified name.
    */
   vector<SGPropertyNode_ptr> getChildren (const char * name) const;
 
+  /**
+   * Get a vector of all children with the specified name.
+   */
+  vector<SGPropertyNode_ptr> getChildren (const std::string& name) const
+  { return getChildren(name.c_str()); }
 
   /**
    * Remove child by position.
@@ -660,6 +686,13 @@ public:
   SGPropertyNode_ptr removeChild (const char * name, int index = 0,
                                   bool keep = true);
 
+  /**
+   * Remove a child node
+   */
+  SGPropertyNode_ptr removeChild (const std::string& name, int index = 0,
+                                  bool keep = true)
+  { return removeChild(name.c_str(), index, keep); }
+
   /**
    * Remove all children with the specified name.
    */
@@ -667,6 +700,13 @@ public:
                                              bool keep = true);
 
 
+  /**
+   * Remove all children with the specified name.
+   */
+  vector<SGPropertyNode_ptr> removeChildren (const std::string& name,
+                                             bool keep = true)
+  { return removeChildren(name.c_str(), keep); }
+
   //
   // Alias support.
   //
@@ -683,6 +723,12 @@ public:
    */
   bool alias (const char * path);
 
+  /**
+   * Alias this node's leaf value to another's by relative path.
+   */
+  bool alias (const std::string& path)
+  { return alias(path.c_str()); }
+
 
   /**
    * Remove any alias for this node.
@@ -736,6 +782,11 @@ public:
    */
   SGPropertyNode * getNode (const char * relative_path, bool create = false);
 
+  /**
+   * Get a pointer to another node by relative path.
+   */
+  SGPropertyNode * getNode (const std::string& relative_path, bool create = false)
+  { return getNode(relative_path.c_str(), create); }
 
   /**
    * Get a pointer to another node by relative path.
@@ -750,12 +801,31 @@ public:
   SGPropertyNode * getNode (const char * relative_path, int index,
                            bool create = false);
 
+  /**
+   * Get a pointer to another node by relative path.
+   *
+   * This method leaves the index off the last member of the path,
+   * so that the user can specify it separately (and save some
+   * string building).  For example, getNode("/bar[1]/foo", 3) is
+   * exactly equivalent to getNode("bar[1]/foo[3]").  The index
+   * provided overrides any given in the path itself for the last
+   * component.
+   */
+  SGPropertyNode * getNode (const std::string& relative_path, int index,
+                           bool create = false)
+  { return getNode(relative_path.c_str(), index, create); }
 
   /**
    * Get a const pointer to another node by relative path.
    */
   const SGPropertyNode * getNode (const char * relative_path) const;
 
+  /**
+   * Get a const pointer to another node by relative path.
+   */
+  const SGPropertyNode * getNode (const std::string& relative_path) const
+  { return getNode(relative_path.c_str()); }
+
 
   /**
    * Get a const pointer to another node by relative path.
@@ -766,6 +836,15 @@ public:
   const SGPropertyNode * getNode (const char * relative_path,
                                  int index) const;
 
+  /**
+   * Get a const pointer to another node by relative path.
+   *
+   * This method leaves the index off the last member of the path,
+   * so that the user can specify it separate.
+   */
+  const SGPropertyNode * getNode (const std::string& relative_path,
+                                 int index) const
+  { return getNode(relative_path.c_str(), index); }
 
   //
   // Access Mode.
@@ -880,6 +959,12 @@ public:
    */
   bool setStringValue (const char * value);
 
+  /**
+   * Set a string value for this node.
+   */
+  bool setStringValue (const std::string& value)
+  { return setStringValue(value.c_str()); }
+
 
   /**
    * Set a value of unspecified type for this node.
@@ -951,12 +1036,22 @@ public:
    */
   Type getType (const char * relative_path) const;
 
+  /**
+   * Get another node's type.
+   */
+  Type getType (const std::string& relative_path) const
+  { return getType(relative_path.c_str()); }
 
   /**
    * Test whether another node has a leaf value.
    */
   bool hasValue (const char * relative_path) const;
 
+  /**
+   * Test whether another node has a leaf value.
+   */
+  bool hasValue (const std::string& relative_path) const
+  { return hasValue(relative_path.c_str()); }
 
   /**
    * Get another node's value as a bool.
@@ -964,6 +1059,12 @@ public:
   bool getBoolValue (const char * relative_path,
                     bool defaultValue = false) const;
 
+  /**
+   * Get another node's value as a bool.
+   */
+  bool getBoolValue (const std::string& relative_path,
+                    bool defaultValue = false) const
+  { return getBoolValue(relative_path.c_str(), defaultValue); }
 
   /**
    * Get another node's value as an int.
@@ -971,6 +1072,13 @@ public:
   int getIntValue (const char * relative_path,
                   int defaultValue = 0) const;
 
+  /**
+   * Get another node's value as an int.
+   */
+  int getIntValue (const std::string& relative_path,
+                   int defaultValue = 0) const
+  { return getIntValue(relative_path.c_str(), defaultValue); }
+
 
   /**
    * Get another node's value as a long int.
@@ -978,20 +1086,39 @@ public:
   long getLongValue (const char * relative_path,
                     long defaultValue = 0L) const;
 
+  /**
+   * Get another node's value as a long int.
+   */
+  long getLongValue (const std::string& relative_path,
+                    long defaultValue = 0L) const
+  { return getLongValue(relative_path.c_str(), defaultValue); }
 
   /**
    * Get another node's value as a float.
    */
   float getFloatValue (const char * relative_path,
-                      float defaultValue = 0.0) const;
+                      float defaultValue = 0.0f) const;
+
+  /**
+   * Get another node's value as a float.
+   */
+  float getFloatValue (const std::string& relative_path,
+                      float defaultValue = 0.0f) const
+  { return getFloatValue(relative_path.c_str(), defaultValue); }
 
 
   /**
    * Get another node's value as a double.
    */
   double getDoubleValue (const char * relative_path,
-                        double defaultValue = 0.0L) const;
+                        double defaultValue = 0.0) const;
 
+  /**
+   * Get another node's value as a double.
+   */
+  double getDoubleValue (const std::string& relative_path,
+                        double defaultValue = 0.0) const
+  { return getDoubleValue(relative_path.c_str(), defaultValue); }
 
   /**
    * Get another node's value as a string.
@@ -1000,41 +1127,85 @@ public:
                               const char * defaultValue = "") const;
 
 
+  /**
+   * Get another node's value as a string.
+   */
+  const char * getStringValue (const std::string& relative_path,
+                              const char * defaultValue = "") const
+  { return getStringValue(relative_path.c_str(), defaultValue); }
+
+
   /**
    * Set another node's value as a bool.
    */
   bool setBoolValue (const char * relative_path, bool value);
 
+  /**
+   * Set another node's value as a bool.
+   */
+  bool setBoolValue (const std::string& relative_path, bool value)
+  { return setBoolValue(relative_path.c_str(), value); }
+
 
   /**
    * Set another node's value as an int.
    */
   bool setIntValue (const char * relative_path, int value);
 
+  /**
+   * Set another node's value as an int.
+   */
+  bool setIntValue (const std::string& relative_path, int value)
+  { return setIntValue(relative_path.c_str(), value); }
+
 
   /**
    * Set another node's value as a long int.
    */
   bool setLongValue (const char * relative_path, long value);
 
+  /**
+   * Set another node's value as a long int.
+   */
+  bool setLongValue (const std::string& relative_path, long value)
+  { return setLongValue(relative_path.c_str(), value); }
+
 
   /**
    * Set another node's value as a float.
    */
   bool setFloatValue (const char * relative_path, float value);
 
+  /**
+   * Set another node's value as a float.
+   */
+  bool setFloatValue (const std::string& relative_path, float value)
+  { return setFloatValue(relative_path.c_str(), value); }
+
 
   /**
    * Set another node's value as a double.
    */
   bool setDoubleValue (const char * relative_path, double value);
 
+  /**
+   * Set another node's value as a double.
+   */
+  bool setDoubleValue (const std::string& relative_path, double value)
+  { return setDoubleValue(relative_path.c_str(), value); }
+
 
   /**
    * Set another node's value as a string.
    */
   bool setStringValue (const char * relative_path, const char * value);
 
+  /**
+   * Set another node's value as a string.
+   */
+  bool setStringValue (const std::string& relative_path, const char * value)
+  { return setStringValue(relative_path.c_str(), value); }
+
 
   /**
    * Set another node's value with no specified type.
@@ -1047,6 +1218,11 @@ public:
    */
   bool isTied (const char * relative_path) const;
 
+  /**
+   * Test whether another node is bound to an external data source.
+   */
+  bool isTied (const std::string& relative_path) const
+  { return isTied(relative_path.c_str()); }
 
   /**
    * Bind another node to an external bool source.
@@ -1054,6 +1230,13 @@ public:
   bool tie (const char * relative_path, const SGRawValue<bool> &rawValue,
            bool useDefault = true);
 
+  /**
+   * Bind another node to an external bool source.
+   */
+  bool tie (const std::string& relative_path, const SGRawValue<bool> &rawValue,
+           bool useDefault = true)
+  { return tie(relative_path.c_str(), rawValue, useDefault); }
+
 
   /**
    * Bind another node to an external int source.
@@ -1061,6 +1244,13 @@ public:
   bool tie (const char * relative_path, const SGRawValue<int> &rawValue,
            bool useDefault = true);
 
+  /**
+   * Bind another node to an external int source.
+   */
+  bool tie (const std::string& relative_path, const SGRawValue<int> &rawValue,
+           bool useDefault = true)
+  { return tie(relative_path.c_str(), rawValue, useDefault); }
+
 
   /**
    * Bind another node to an external long int source.
@@ -1068,6 +1258,13 @@ public:
   bool tie (const char * relative_path, const SGRawValue<long> &rawValue,
            bool useDefault = true);
 
+  /**
+   * Bind another node to an external long int source.
+   */
+  bool tie (const std::string& relative_path, const SGRawValue<long> &rawValue,
+           bool useDefault = true)
+  { return tie(relative_path.c_str(), rawValue, useDefault); }
+
 
   /**
    * Bind another node to an external float source.
@@ -1075,6 +1272,13 @@ public:
   bool tie (const char * relative_path, const SGRawValue<float> &rawValue,
            bool useDefault = true);
 
+  /**
+   * Bind another node to an external float source.
+   */
+  bool tie (const std::string& relative_path, const SGRawValue<float> &rawValue,
+           bool useDefault = true)
+  { return tie(relative_path.c_str(), rawValue, useDefault); }
+
 
   /**
    * Bind another node to an external double source.
@@ -1082,6 +1286,13 @@ public:
   bool tie (const char * relative_path, const SGRawValue<double> &rawValue,
            bool useDefault = true);
 
+  /**
+   * Bind another node to an external double source.
+   */
+  bool tie (const std::string& relative_path, const SGRawValue<double> &rawValue,
+           bool useDefault = true)
+  { return tie(relative_path.c_str(), rawValue, useDefault); }
+
 
   /**
    * Bind another node to an external string source.
@@ -1089,12 +1300,25 @@ public:
   bool tie (const char * relative_path, const SGRawValue<const char *> &rawValue,
            bool useDefault = true);
 
+  /**
+   * Bind another node to an external string source.
+   */
+  bool tie (const std::string& relative_path, const SGRawValue<const char*> &rawValue,
+           bool useDefault = true)
+  { return tie(relative_path.c_str(), rawValue, useDefault); }
+
 
   /**
    * Unbind another node from any external data source.
    */
   bool untie (const char * relative_path);
 
+  /**
+   * Unbind another node from any external data source.
+   */
+  bool untie (const std::string& relative_path)
+  { return untie(relative_path.c_str()); }
+
 
   /**
    * Add a change listener to the property. If "initial" is set call the