]> git.mxchange.org Git - simgear.git/blobdiff - simgear/misc/props_io.cxx
Patch from Cameron Moore:
[simgear.git] / simgear / misc / props_io.cxx
index 160539ae73b41309c9f6d1fe88b9bdeada65976c..45f8829665f7d5f85b69d122066e0b5800dba413 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "sg_path.hxx"
 #include "props.hxx"
+#include "props_io.hxx"
 
 #include STL_IOSTREAM
 #if !defined(SG_HAVE_NATIVE_SGI_COMPILERS)
@@ -234,9 +235,9 @@ PropsVisitor::endElement (const char * name)
     } else if (st.type == "double") {
       ret = st.node->setDoubleValue(strtod(_data.c_str(), 0));
     } else if (st.type == "string") {
-      ret = st.node->setStringValue(_data);
+      ret = st.node->setStringValue(_data.c_str());
     } else if (st.type == "unspecified") {
-      ret = st.node->setUnspecifiedValue(_data);
+      ret = st.node->setUnspecifiedValue(_data.c_str());
     } else {
       string message = "Unrecognized data type '";
       message += st.type;
@@ -343,6 +344,9 @@ getTypeName (SGPropertyNode::Type type)
     return "double";
   case SGPropertyNode::STRING:
     return "string";
+  case SGPropertyNode::ALIAS:
+  case SGPropertyNode::NONE:
+    return "unspecified";
   }
 
   // keep the compiler from squawking
@@ -425,21 +429,21 @@ isArchivable (const SGPropertyNode * node)
 
 
 static bool
-writeNode (ostream &output, const SGPropertyNode * node, int indent)
+writeNode (ostream &output, const SGPropertyNode * node,
+          bool write_all, int indent)
 {
                                // Don't write the node or any of
                                // its descendants unless it is
                                // allowed to be archived.
-  if (!isArchivable(node))
+  if (!write_all && !isArchivable(node))
     return true;               // Everything's OK, but we won't write.
 
-  const string &name = node->getName();
-  int index = node->getIndex();
+  const string name = node->getName();
   int nChildren = node->nChildren();
 
                                // If there is a literal value,
                                // write it first.
-  if (node->hasValue() && node->getAttribute(SGPropertyNode::ARCHIVE)) {
+  if (node->hasValue() && (write_all || node->getAttribute(SGPropertyNode::ARCHIVE))) {
     doIndent(output, indent);
     output << '<' << name;
     writeAtts(output, node);
@@ -455,15 +459,14 @@ writeNode (ostream &output, const SGPropertyNode * node, int indent)
     }
   }
 
-                               // If there are children, write them
-                               // next.
+                               // If there are children, write them next.
   if (nChildren > 0 || node->isAlias()) {
     doIndent(output, indent);
     output << '<' << name;
     writeAtts(output, node);
     output << '>' << endl;
     for (int i = 0; i < nChildren; i++)
-      writeNode(output, node->getChild(i), indent + INDENT_STEP);
+      writeNode(output, node->getChild(i), write_all, indent + INDENT_STEP);
     doIndent(output, indent);
     output << "</" << name << '>' << endl;
   }
@@ -473,7 +476,8 @@ writeNode (ostream &output, const SGPropertyNode * node, int indent)
 
 
 void
-writeProperties (ostream &output, const SGPropertyNode * start_node)
+writeProperties (ostream &output, const SGPropertyNode * start_node,
+                bool write_all)
 {
   int nChildren = start_node->nChildren();
 
@@ -481,7 +485,7 @@ writeProperties (ostream &output, const SGPropertyNode * start_node)
   output << "<PropertyList>" << endl;
 
   for (int i = 0; i < nChildren; i++) {
-    writeNode(output, start_node->getChild(i), INDENT_STEP);
+    writeNode(output, start_node->getChild(i), write_all, INDENT_STEP);
   }
 
   output << "</PropertyList>" << endl;
@@ -489,11 +493,12 @@ writeProperties (ostream &output, const SGPropertyNode * start_node)
 
 
 void
-writeProperties (const string &file, const SGPropertyNode * start_node)
+writeProperties (const string &file, const SGPropertyNode * start_node,
+                bool write_all)
 {
   ofstream output(file.c_str());
   if (output.good()) {
-    writeProperties(output, start_node);
+    writeProperties(output, start_node, write_all);
   } else {
     throw sg_io_exception("Cannot open file", sg_location(file));
   }