Tweaks from David Megginson.
This commit is contained in:
@@ -28,7 +28,7 @@ libsgmisc_a_SOURCES = \
|
||||
|
||||
noinst_PROGRAMS = props_test
|
||||
|
||||
props_test_SOURCES = props_test.cxx
|
||||
props_test_SOURCES = props_test.cxx props_test.hxx
|
||||
props_test_LDADD = libsgmisc.a ../xml/libsgxml.a ../debug/libsgdebug.a
|
||||
|
||||
INCLUDES += -I$(top_srcdir) $(ZLIB_INCL)
|
||||
|
||||
@@ -473,6 +473,7 @@ bool readProperties (istream &input, SGPropertyNode * start_node);
|
||||
bool readProperties (const string &file, SGPropertyNode * start_node);
|
||||
bool writeProperties (ostream &output, const SGPropertyNode * start_node);
|
||||
bool writeProperties (const string &file, const SGPropertyNode * start_node);
|
||||
bool copyProperties (const SGPropertyNode *in, SGPropertyNode *out);
|
||||
|
||||
|
||||
#endif // __PROPS_HXX
|
||||
|
||||
@@ -329,3 +329,61 @@ writeProperties (const string &file, const SGPropertyNode * start_node)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copy one property list to another.
|
||||
*/
|
||||
bool
|
||||
copyProperties (const SGPropertyNode *in, SGPropertyNode *out)
|
||||
{
|
||||
bool retval = true;
|
||||
|
||||
// First, copy the actual value,
|
||||
// if any.
|
||||
if (in->hasValue()) {
|
||||
switch (in->getType()) {
|
||||
case SGValue::BOOL:
|
||||
if (!out->setBoolValue(in->getBoolValue()))
|
||||
retval = false;
|
||||
break;
|
||||
case SGValue::INT:
|
||||
if (!out->setIntValue(in->getIntValue()))
|
||||
retval = false;
|
||||
break;
|
||||
case SGValue::FLOAT:
|
||||
if (!out->setFloatValue(in->getFloatValue()))
|
||||
retval = false;
|
||||
break;
|
||||
case SGValue::DOUBLE:
|
||||
if (!out->setDoubleValue(in->getDoubleValue()))
|
||||
retval = false;
|
||||
break;
|
||||
case SGValue::STRING:
|
||||
if (!out->setStringValue(in->getStringValue()))
|
||||
retval = false;
|
||||
break;
|
||||
case SGValue::UNKNOWN:
|
||||
if (!out->setUnknownValue(in->getStringValue()))
|
||||
retval = false;
|
||||
break;
|
||||
default:
|
||||
throw string("Unknown SGValue type"); // FIXME!!!
|
||||
}
|
||||
}
|
||||
|
||||
// Next, copy the children.
|
||||
int nChildren = in->nChildren();
|
||||
for (int i = 0; i < nChildren; i++) {
|
||||
const SGPropertyNode * in_child = in->getChild(i);
|
||||
SGPropertyNode * out_child = out->getChild(in_child->getName(),
|
||||
in_child->getIndex(),
|
||||
true);
|
||||
if (!copyProperties(in_child, out_child))
|
||||
retval = false;
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
// end of props_io.cxx
|
||||
|
||||
Reference in New Issue
Block a user