]> git.mxchange.org Git - simgear.git/blobdiff - simgear/props/props_io.cxx
Harald JOHNSEN:
[simgear.git] / simgear / props / props_io.cxx
index e808e0b63bdb9bf7196151f3a1fcbfab86f455c5..a4fe5a16e4b62c54f17440dec2b8877a1ddf66ac 100644 (file)
@@ -117,9 +117,9 @@ checkFlag (const char * flag, bool defaultState = true)
 {
   if (flag == 0)
     return defaultState;
-  else if (string(flag) == "y")
+  else if (!strcmp(flag, "y"))
     return true;
-  else if (string(flag) == "n")
+  else if (!strcmp(flag, "n"))
     return false;
   else {
     string message = "Unrecognized flag value '";
@@ -133,11 +133,10 @@ checkFlag (const char * flag, bool defaultState = true)
 void
 PropsVisitor::startElement (const char * name, const XMLAttributes &atts)
 {
-  State &st = state();
   const char * attval;
 
   if (_level == 0) {
-    if (string(name) != (string)"PropertyList") {
+    if (strcmp(name, "PropertyList")) {
       string message = "Root element name is ";
       message += name;
       message += "; expected PropertyList";
@@ -160,6 +159,7 @@ PropsVisitor::startElement (const char * name, const XMLAttributes &atts)
   }
 
   else {
+    State &st = state();
                                // Get the index.
     attval = atts.getValue("n");
     int index = 0;
@@ -214,7 +214,10 @@ PropsVisitor::startElement (const char * name, const XMLAttributes &atts)
       }
     }
 
-    push_state(node, atts.getValue("type"), mode);
+    const char *type = atts.getValue("type");
+    if (type)
+      node->clearValue();
+    push_state(node, type, mode);
   }
 }
 
@@ -322,6 +325,23 @@ readProperties (const string &file, SGPropertyNode * start_node)
 }
 
 
+/**
+ * Read properties from an in-memory buffer.
+ *
+ * @param buf A character buffer containing the xml data.
+ * @param size The size/length of the buffer in bytes
+ * @param start_node The root node for reading properties.
+ * @return true if the read succeeded, false otherwise.
+ */
+void readProperties (const char *buf, const int size,
+                     SGPropertyNode * start_node)
+{
+  PropsVisitor visitor(start_node, "");
+  readXML(buf, size, visitor);
+  if (visitor.hasException())
+    throw visitor.getException();
+}
+
 \f
 ////////////////////////////////////////////////////////////////////////
 // Property list writer.
@@ -466,7 +486,7 @@ writeNode (ostream &output, const SGPropertyNode * node,
   }
 
                                // If there are children, write them next.
-  if (nChildren > 0 || node->isAlias()) {
+  if (nChildren > 0) {
     doIndent(output, indent);
     output << '<' << name;
     writeAtts(output, node);
@@ -563,12 +583,17 @@ copyProperties (const SGPropertyNode *in, SGPropertyNode *out)
        retval = false;
       break;
     default:
+      if (in->isAlias())
+       break;
       string message = "Unknown internal SGPropertyNode type";
       message += in->getType();
       throw sg_error(message, "SimGear Property Reader");
     }
   }
 
+                               // copy the attributes.
+  out->setAttributes( in->getAttributes() );
+
                                // Next, copy the children.
   int nChildren = in->nChildren();
   for (int i = 0; i < nChildren; i++) {