]> git.mxchange.org Git - simgear.git/blobdiff - simgear/props/props_io.cxx
Modified Files:
[simgear.git] / simgear / props / props_io.cxx
index f79fa9b1ed216216e2f48f902dc540136d23d713..187f566060fb2f18fae8740a7f8abebcb8325952 100644 (file)
@@ -1,3 +1,12 @@
+/**
+ * \file props_io.cxx
+ * Started Fall 2000 by David Megginson, david@megginson.com
+ * This code is released into the Public Domain.
+ *
+ * See props.html for documentation [replace with URL when available].
+ *
+ * $Id$
+ */
 
 #ifdef HAVE_CONFIG_H
 #  include <simgear_config.h>
@@ -220,6 +229,21 @@ PropsVisitor::startElement (const char * name, const XMLAttributes &atts)
       } catch (sg_io_exception &e) {
        setException(e);
       }
+
+      const char *omit = atts.getValue("omit-node");
+      if (omit && !strcmp(omit, "y")) {
+        int nChildren = node->nChildren();
+        for (int i = 0; i < nChildren; i++) {
+          SGPropertyNode *src = node->getChild(i);
+          const char *name = src->getName();
+          int index = st.counters[name];
+          st.counters[name]++;
+          SGPropertyNode *dst = st.node->getChild(name, index, true);
+          copyProperties(src, dst);
+        }
+        st.node->removeChild(node->getName(), node->getIndex(), false);
+        node = st.node;
+      }
     }
 
     const char *type = atts.getValue("type");
@@ -255,6 +279,8 @@ PropsVisitor::endElement (const char * name)
       ret = st.node->setStringValue(_data.c_str());
     } else if (st.type == "unspecified") {
       ret = st.node->setUnspecifiedValue(_data.c_str());
+    } else if (_level == 1) {
+      ret = true;              // empty <PropertyList>
     } else {
       string message = "Unrecognized data type '";
       message += st.type;
@@ -423,11 +449,11 @@ doIndent (ostream &output, int indent)
 
 
 static void
-writeAtts (ostream &output, const SGPropertyNode * node)
+writeAtts (ostream &output, const SGPropertyNode * node, bool forceindex)
 {
   int index = node->getIndex();
 
-  if (index != 0)
+  if (index != 0 || forceindex)
     output << " n=\"" << index << '"';
 
 #if 0
@@ -475,13 +501,14 @@ writeNode (ostream &output, const SGPropertyNode * node,
 
   const string name = node->getName();
   int nChildren = node->nChildren();
+  bool node_has_value = false;
 
                                // If there is a literal value,
                                // write it first.
   if (node->hasValue() && (write_all || node->getAttribute(archive_flag))) {
     doIndent(output, indent);
     output << '<' << name;
-    writeAtts(output, node);
+    writeAtts(output, node, nChildren != 0);
     if (node->isAlias() && node->getAliasTarget() != 0) {
       output << " alias=\"" << node->getAliasTarget()->getPath()
             << "\"/>" << endl;
@@ -492,13 +519,14 @@ writeNode (ostream &output, const SGPropertyNode * node,
       writeData(output, node->getStringValue());
       output << "</" << name << '>' << endl;
     }
+    node_has_value = true;
   }
 
                                // If there are children, write them next.
   if (nChildren > 0) {
     doIndent(output, indent);
     output << '<' << name;
-    writeAtts(output, node);
+    writeAtts(output, node, node_has_value);
     output << '>' << endl;
     for (int i = 0; i < nChildren; i++)
       writeNode(output, node->getChild(i), write_all, indent + INDENT_STEP, archive_flag);
@@ -531,6 +559,9 @@ void
 writeProperties (const string &file, const SGPropertyNode * start_node,
                  bool write_all, SGPropertyNode::Attribute archive_flag)
 {
+  SGPath path(file.c_str());
+  path.create_dir(0777);
+
   ofstream output(file.c_str());
   if (output.good()) {
     writeProperties(output, start_node, write_all, archive_flag);