Melchior FRANZ:

fgLoadFlight() loads a property file ("fgfs.sav") to a new property tree,
and then copies that over to the main tree. copyProperties() didn't know
how to handle type SGPropertyNode::ALIAS and hence threw an exception that
made fgfs abort.

The attached patch adds support for ALIAS to copyProperties(): aliased
nodes are created in the target tree if necessary, and then linked like in
the source tree. It seemed useful to add an optional argument to
props.[ch]xx/getType() that would indeed return the property type "ALIAS"
for aliased nodes, and not the type of the node that it refers to. The patch
also fixes a bug in writeNode() that caused extra lines after alias entries.

If there's resistance to the change to getType() (David?) I can easily use
isAlias(). This just makes copyProperties() a tad uglier, but I can live with
it. It's useful for scanning a tree, though, if an alias node can be treated
exactly like all other nodes, without automatic redirection.
This commit is contained in:
ehofman 2004-12-19 10:19:14 +00:00
parent 7b24e94c66
commit 37ac409586
3 changed files with 14 additions and 5 deletions

View File

@ -969,9 +969,9 @@ SGPropertyNode::getPath (bool simplify) const
}
SGPropertyNode::Type
SGPropertyNode::getType () const
SGPropertyNode::getType (bool deref_alias) const
{
if (_type == ALIAS)
if (_type == ALIAS && deref_alias)
return _value.alias->getType();
else
return _type;

View File

@ -850,8 +850,10 @@ public:
/**
* Get the type of leaf value, if any, for this node.
* When applied to an ALIAS node, deref_alias decides if the type
* of the referred node is to be returned (default), or ALIAS.
*/
Type getType () const;
Type getType (bool deref_alias = true) const;
/**

View File

@ -368,6 +368,7 @@ getTypeName (SGPropertyNode::Type type)
case SGPropertyNode::STRING:
return "string";
case SGPropertyNode::ALIAS:
return "alias";
case SGPropertyNode::NONE:
return "unspecified";
}
@ -483,7 +484,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);
@ -550,7 +551,7 @@ copyProperties (const SGPropertyNode *in, SGPropertyNode *out)
// First, copy the actual value,
// if any.
if (in->hasValue()) {
switch (in->getType()) {
switch (in->getType(false)) {
case SGPropertyNode::BOOL:
if (!out->setBoolValue(in->getBoolValue()))
retval = false;
@ -579,6 +580,12 @@ copyProperties (const SGPropertyNode *in, SGPropertyNode *out)
if (!out->setUnspecifiedValue(in->getStringValue()))
retval = false;
break;
case SGPropertyNode::ALIAS: {
const char *path = in->getAliasTarget()->getPath();
SGPropertyNode *node = out->getRootNode()->getNode(path, true);
out->alias(node);
break;
}
default:
string message = "Unknown internal SGPropertyNode type";
message += in->getType();