From: mfranz Date: Sun, 6 May 2007 17:33:15 +0000 (+0000) Subject: - fix bug where a property tree saved with writeProperties() and read back X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=414f1c27e4e1e937675ae8ffbf0fffbb2cb3304a;p=simgear.git - fix bug where a property tree saved with writeProperties() and read back in with readProperties() would not look the same, because element indices of '0' were even dropped when a node has a "secret" value *and* children - introduce "omit-node" modifier attribute for the "include" attribute. This inserts the given file in place of the including node, while the node is dropped. This is desirable for multiple includes (which can't be done by multiply using the "include" attribute, as this isn't valid XML spec syntax) --- diff --git a/simgear/props/props_io.cxx b/simgear/props/props_io.cxx index 1b6e0f44..b89f1d46 100644 --- a/simgear/props/props_io.cxx +++ b/simgear/props/props_io.cxx @@ -229,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"); @@ -432,11 +447,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 @@ -484,13 +499,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; @@ -501,13 +517,14 @@ writeNode (ostream &output, const SGPropertyNode * node, writeData(output, node->getStringValue()); output << "' << 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);