+
+
+void
+writeProperties (const string &file, const SGPropertyNode * start_node)
+{
+ ofstream output(file.c_str());
+ if (output.good()) {
+ writeProperties(output, start_node);
+ } else {
+ throw sg_io_exception("Cannot open file", sg_location(file));
+ }
+}
+
+
+\f
+////////////////////////////////////////////////////////////////////////
+// Copy properties from one tree to another.
+////////////////////////////////////////////////////////////////////////
+
+
+/**
+ * Copy one property tree to another.
+ *
+ * @param in The source property tree.
+ * @param out The destination property tree.
+ * @return true if all properties were copied, false if some failed
+ * (for example, if the property's value is tied read-only).
+ */
+bool
+copyProperties (const SGPropertyNode *in, SGPropertyNode *out)
+{
+ bool retval = true;
+
+ // First, copy the actual value,
+ // if any.
+ if (in->hasValue()) {
+ switch (in->getType()) {
+ case SGPropertyNode::BOOL:
+ if (!out->setBoolValue(in->getBoolValue()))
+ retval = false;
+ break;
+ case SGPropertyNode::INT:
+ if (!out->setIntValue(in->getIntValue()))
+ retval = false;
+ break;
+ case SGPropertyNode::LONG:
+ if (!out->setLongValue(in->getLongValue()))
+ retval = false;
+ break;
+ case SGPropertyNode::FLOAT:
+ if (!out->setFloatValue(in->getFloatValue()))
+ retval = false;
+ break;
+ case SGPropertyNode::DOUBLE:
+ if (!out->setDoubleValue(in->getDoubleValue()))
+ retval = false;
+ break;
+ case SGPropertyNode::STRING:
+ if (!out->setStringValue(in->getStringValue()))
+ retval = false;
+ break;
+ case SGPropertyNode::UNSPECIFIED:
+ if (!out->setUnspecifiedValue(in->getStringValue()))
+ retval = false;
+ break;
+ default:
+ string message = "Unknown internal SGPropertyNode type";
+ message += in->getType();
+ throw sg_error(message, "SimGear Property Reader");
+ }
+ }
+
+ // 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