"src/vscode:/vscode.git/clone" did not exist on "0757c45b1e361bbc703a5e1e212ec16f8ed0d339"
Commit e60bf3c2 authored by peastman's avatar peastman
Browse files

Merge pull request #484 from peastman/xml

XmlSerializer generates XML directly rather than going through TinyXml
parents a1b2641c 0c7dc959
......@@ -9,7 +9,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2010 Stanford University and the Authors. *
* Portions copyright (c) 2010-2014 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
......@@ -79,7 +79,7 @@ public:
private:
static void serialize(const SerializationNode& node, std::ostream& stream);
static void* deserializeStream(std::istream& stream);
static TiXmlElement* encodeNode(const SerializationNode& node);
static void encodeNode(const SerializationNode& node, std::ostream& stream, int depth);
static void decodeNode(SerializationNode& node, const TiXmlElement& element);
};
......
......@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2010 Stanford University and the Authors. *
* Portions copyright (c) 2010-2014 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
......@@ -36,25 +36,32 @@ using namespace OpenMM;
using namespace std;
void XmlSerializer::serialize(const SerializationNode& node, std::ostream& stream) {
TiXmlDocument doc;
TiXmlDeclaration* decl = new TiXmlDeclaration( "1.0", "", "" );
doc.LinkEndChild(decl);
doc.LinkEndChild(encodeNode(node));
TiXmlPrinter printer;
printer.SetIndent("\t");
doc.Accept(&printer);
stream << printer.Str();
stream << "<?xml version=\"1.0\" ?>\n";
encodeNode(node, stream, 0);
}
TiXmlElement* XmlSerializer::encodeNode(const SerializationNode& node) {
TiXmlElement* element = new TiXmlElement(node.getName());
void XmlSerializer::encodeNode(const SerializationNode& node, std::ostream& stream, int depth) {
for (int i = 0; i < depth; i++)
stream << '\t';
stream << '<' << node.getName();
const map<string, string>& properties = node.getProperties();
for (map<string, string>::const_iterator iter = properties.begin(); iter != properties.end(); ++iter)
element->SetAttribute(iter->first.c_str(), iter->second.c_str());
for (map<string, string>::const_iterator iter = properties.begin(); iter != properties.end(); ++iter) {
string name, value;
TiXmlBase::EncodeString(iter->first, &name);
TiXmlBase::EncodeString(iter->second, &value);
stream << ' ' << name << "=\"" << value << '\"';
}
const vector<SerializationNode>& children = node.getChildren();
if (children.size() == 0)
stream << "/>\n";
else {
stream << ">\n";
for (int i = 0; i < (int) children.size(); i++)
element->LinkEndChild(encodeNode(children[i]));
return element;
encodeNode(children[i], stream, depth+1);
for (int i = 0; i < depth; i++)
stream << '\t';
stream << "</" << node.getName() << ">\n";
}
}
void* XmlSerializer::deserializeStream(std::istream& stream) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment