#include "sg_path.hxx"
#include "props.hxx"
+#include "props_io.hxx"
#include STL_IOSTREAM
#if !defined(SG_HAVE_NATIVE_SGI_COMPILERS)
public:
PropsVisitor (SGPropertyNode * root, const string &base)
- : _root(root), _level(0), _base(base), _exception(0) {}
+ : _root(root), _level(0), _base(base), _hasException(false) {}
- virtual ~PropsVisitor () { delete _exception; }
+ virtual ~PropsVisitor () {}
void startXML ();
void endXML ();
void data (const char * s, int length);
void warning (const char * message, int line, int column);
- bool hasException () const { return (_exception != 0); }
- const sg_io_exception * getException () const { return _exception; }
+ bool hasException () const { return _hasException; }
+ sg_io_exception &getException () { return _exception; }
+ void setException (const sg_io_exception &exception) {
+ _exception = exception;
+ _hasException = true;
+ }
private:
int _level;
vector<State> _state_stack;
string _base;
- sg_io_exception * _exception;
+ sg_io_exception _exception;
+ bool _hasException;
};
void
attval = atts.getValue("archive");
if (checkFlag(attval, false))
mode |= SGPropertyNode::ARCHIVE;
+ attval = atts.getValue("trace-read");
+ if (checkFlag(attval, false))
+ mode |= SGPropertyNode::TRACE_READ;
+ attval = atts.getValue("trace-write");
+ if (checkFlag(attval, false))
+ mode |= SGPropertyNode::TRACE_WRITE;
// Check for an alias.
attval = atts.getValue("alias");
path.append(attval);
try {
readProperties(path.str(), node);
- } catch (const sg_io_exception &t) {
- cerr << "Caught exception\n";
- _exception = t.clone();
+ } catch (sg_io_exception &e) {
+ setException(e);
}
}
} else if (st.type == "double") {
ret = st.node->setDoubleValue(strtod(_data.c_str(), 0));
} else if (st.type == "string") {
- ret = st.node->setStringValue(_data);
+ ret = st.node->setStringValue(_data.c_str());
} else if (st.type == "unspecified") {
- ret = st.node->setUnspecifiedValue(_data);
+ ret = st.node->setUnspecifiedValue(_data.c_str());
} else {
string message = "Unrecognized data type '";
message += st.type;
PropsVisitor visitor(start_node, base);
readXML(input, visitor, base);
if (visitor.hasException())
- throw *(visitor.getException());
+ throw visitor.getException();
}
PropsVisitor visitor(start_node, file);
readXML(file, visitor);
if (visitor.hasException())
- throw *(visitor.getException());
+ throw visitor.getException();
}
return "double";
case SGPropertyNode::STRING:
return "string";
+ case SGPropertyNode::ALIAS:
+ case SGPropertyNode::NONE:
+ return "unspecified";
}
// keep the compiler from squawking
static bool
-writeNode (ostream &output, const SGPropertyNode * node, int indent)
+writeNode (ostream &output, const SGPropertyNode * node,
+ bool write_all, int indent)
{
// Don't write the node or any of
// its descendants unless it is
// allowed to be archived.
- if (!isArchivable(node))
+ if (!write_all && !isArchivable(node))
return true; // Everything's OK, but we won't write.
- const string &name = node->getName();
- int index = node->getIndex();
+ const string name = node->getName();
int nChildren = node->nChildren();
// If there is a literal value,
// write it first.
- if (node->hasValue() && node->getAttribute(SGPropertyNode::ARCHIVE)) {
+ if (node->hasValue() && (write_all || node->getAttribute(SGPropertyNode::ARCHIVE))) {
doIndent(output, indent);
output << '<' << name;
writeAtts(output, node);
}
}
- // If there are children, write them
- // next.
+ // If there are children, write them next.
if (nChildren > 0 || node->isAlias()) {
doIndent(output, indent);
output << '<' << name;
writeAtts(output, node);
output << '>' << endl;
for (int i = 0; i < nChildren; i++)
- writeNode(output, node->getChild(i), indent + INDENT_STEP);
+ writeNode(output, node->getChild(i), write_all, indent + INDENT_STEP);
doIndent(output, indent);
output << "</" << name << '>' << endl;
}
void
-writeProperties (ostream &output, const SGPropertyNode * start_node)
+writeProperties (ostream &output, const SGPropertyNode * start_node,
+ bool write_all)
{
int nChildren = start_node->nChildren();
output << "<PropertyList>" << endl;
for (int i = 0; i < nChildren; i++) {
- writeNode(output, start_node->getChild(i), INDENT_STEP);
+ writeNode(output, start_node->getChild(i), write_all, INDENT_STEP);
}
output << "</PropertyList>" << endl;
void
-writeProperties (const string &file, const SGPropertyNode * start_node)
+writeProperties (const string &file, const SGPropertyNode * start_node,
+ bool write_all)
{
ofstream output(file.c_str());
if (output.good()) {
- writeProperties(output, start_node);
+ writeProperties(output, start_node, write_all);
} else {
throw sg_io_exception("Cannot open file", sg_location(file));
}