]> git.mxchange.org Git - simgear.git/blobdiff - simgear/props/props_io.cxx
Frederic Bouvier:
[simgear.git] / simgear / props / props_io.cxx
index 92781ea6e3b5a8bfcf80affa4f4b4f5a36893689..0aba26edbf4e0782109322afe34e98b4ae7bbf10 100644 (file)
@@ -117,9 +117,9 @@ checkFlag (const char * flag, bool defaultState = true)
 {
   if (flag == 0)
     return defaultState;
-  else if (flag == "y")
+  else if (!strcmp(flag, "y"))
     return true;
-  else if (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 (name != "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;
@@ -322,6 +322,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 +483,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,6 +580,8 @@ 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");