From 22b41d892a26c58c9f56d60dd1cc71c2a2dd7f17 Mon Sep 17 00:00:00 2001 From: curt Date: Fri, 19 Jan 2001 21:56:02 +0000 Subject: [PATCH] Tweaks from David Megginson. --- simgear/misc/Makefile.am | 2 +- simgear/misc/props.hxx | 1 + simgear/misc/props_io.cxx | 58 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/simgear/misc/Makefile.am b/simgear/misc/Makefile.am index 9623cc64..8e91feb7 100644 --- a/simgear/misc/Makefile.am +++ b/simgear/misc/Makefile.am @@ -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) diff --git a/simgear/misc/props.hxx b/simgear/misc/props.hxx index f8d00738..a4579732 100644 --- a/simgear/misc/props.hxx +++ b/simgear/misc/props.hxx @@ -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 diff --git a/simgear/misc/props_io.cxx b/simgear/misc/props_io.cxx index 2a0196b7..aac7735b 100644 --- a/simgear/misc/props_io.cxx +++ b/simgear/misc/props_io.cxx @@ -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 -- 2.39.5