- changed default value of "archive" attribute from "y" to "n"

- modified to write out non-archivable parents if they have an
  archivable descendant (i.e. archive="n" no longer kills a whole
  subbranch); this makes sense now that archive defaults to "n".
- don't save the flags -- let the program handle them itself
- produce slightly less verbose output; omit n="0" in elements
This commit is contained in:
curt
2001-07-12 21:09:12 +00:00
parent 007a1e4659
commit f1a79e6b9f
+36 -13
View File
@@ -30,7 +30,7 @@ SG_USING_STD(string);
SG_USING_STD(vector); SG_USING_STD(vector);
SG_USING_STD(map); SG_USING_STD(map);
#define DEFAULT_MODE (SGPropertyNode::READ|SGPropertyNode::WRITE|SGPropertyNode::ARCHIVE) #define DEFAULT_MODE (SGPropertyNode::READ|SGPropertyNode::WRITE)
@@ -108,18 +108,20 @@ PropsVisitor::endXML ()
/** /**
* Check a yes/no flag that defaults to 'yes'. * Check a yes/no flag, with default.
*/ */
static bool static bool
checkFlag (const char * flag) checkFlag (const char * flag, bool defaultState = true)
{ {
if (flag == 0 || string(flag) == "y") if (flag == 0)
return defaultState;
else if (string(flag) == "y")
return true; return true;
else if (string(flag) == "n") else if (string(flag) == "n")
return false; return false;
else { else {
SG_LOG(SG_INPUT, SG_ALERT, "Unrecognized flag value '" << flag SG_LOG(SG_INPUT, SG_ALERT, "Unrecognized flag value '" << flag
<< "', assuming 'y'"); << "', assuming yes");
return true; return true;
} }
} }
@@ -161,13 +163,13 @@ PropsVisitor::startElement (const char * name, const XMLAttributes &atts)
int mode = 0; int mode = 0;
attval = atts.getValue("read"); attval = atts.getValue("read");
if (checkFlag(attval)) if (checkFlag(attval, true))
mode |= SGPropertyNode::READ; mode |= SGPropertyNode::READ;
attval = atts.getValue("write"); attval = atts.getValue("write");
if (checkFlag(attval)) if (checkFlag(attval, true))
mode |= SGPropertyNode::WRITE; mode |= SGPropertyNode::WRITE;
attval = atts.getValue("archive"); attval = atts.getValue("archive");
if (checkFlag(attval)) if (checkFlag(attval, false))
mode |= SGPropertyNode::ARCHIVE; mode |= SGPropertyNode::ARCHIVE;
// Check for an alias. // Check for an alias.
@@ -382,27 +384,48 @@ writeAtts (ostream &output, const SGPropertyNode * node)
int index = node->getIndex(); int index = node->getIndex();
if (index != 0) if (index != 0)
output << " n = \"" << index << '"'; output << " n=\"" << index << '"';
#if 0
if (!node->getAttribute(SGPropertyNode::READ)) if (!node->getAttribute(SGPropertyNode::READ))
output << " read=\"n\""; output << " read=\"n\"";
if (!node->getAttribute(SGPropertyNode::WRITE)) if (!node->getAttribute(SGPropertyNode::WRITE))
output << " write=\"n\""; output << " write=\"n\"";
if (!node->getAttribute(SGPropertyNode::ARCHIVE)) if (node->getAttribute(SGPropertyNode::ARCHIVE))
output << " archive=\"n\""; output << " archive=\"y\"";
#endif
} }
/**
* Test whether a node is archivable or has archivable descendants.
*/
static bool
isArchivable (const SGPropertyNode * node)
{
// FIXME: it's inefficient to do this all the time
if (node->getAttribute(SGPropertyNode::ARCHIVE))
return true;
else {
int nChildren = node->nChildren();
for (int i = 0; i < nChildren; i++)
if (isArchivable(node->getChild(i)))
return true;
}
return false;
}
static bool static bool
writeNode (ostream &output, const SGPropertyNode * node, int indent) writeNode (ostream &output, const SGPropertyNode * node, int indent)
{ {
// Don't write the node or any of // Don't write the node or any of
// its descendants unless it is // its descendants unless it is
// allowed to be archived. // allowed to be archived.
if (!node->getAttribute(SGPropertyNode::ARCHIVE)) if (!isArchivable(node))
return true; // Everything's OK, but we won't write. return true; // Everything's OK, but we won't write.
const string &name = node->getName(); const string &name = node->getName();
@@ -411,7 +434,7 @@ writeNode (ostream &output, const SGPropertyNode * node, int indent)
// If there is a literal value, // If there is a literal value,
// write it first. // write it first.
if (node->hasValue()) { if (node->hasValue() && node->getAttribute(SGPropertyNode::ARCHIVE)) {
doIndent(output, indent); doIndent(output, indent);
output << '<' << name; output << '<' << name;
writeAtts(output, node); writeAtts(output, node);