1 #ifndef OPENMM_XML_SERIALIZER_H_
2 #define OPENMM_XML_SERIALIZER_H_
35 #include "openmm/serialization/SerializationNode.h"
36 #include "openmm/serialization/SerializationProxy.h"
37 #include "openmm/OpenMMException.h"
38 #include "openmm/internal/windowsExport.h"
59 static void serialize(
const T*
object,
const std::string& rootName, std::ostream& stream) {
60 const SerializationProxy& proxy = SerializationProxy::getProxy(
typeid(*
object));
61 SerializationNode node;
62 node.setName(rootName);
63 proxy.serialize(
object, node);
64 if (node.hasProperty(
"type"))
65 throw OpenMMException(proxy.getTypeName()+
" created node with reserved property 'type'");
66 node.setStringProperty(
"type", proxy.getTypeName());
67 serialize(node, stream);
77 return reinterpret_cast<T*
>(deserializeStream(stream));
80 static void serialize(
const SerializationNode& node, std::ostream& stream);
81 static void* deserializeStream(std::istream& stream);
82 static void encodeNode(
const SerializationNode& node, std::ostream& stream,
int depth);
83 static void decodeNode(SerializationNode& node,
const TiXmlElement& element);
static void serialize(const T *object, const std::string &rootName, std::ostream &stream)
Serialize an object as XML.
Definition: XmlSerializer.h:59
XmlSerializer is used for serializing objects as XML, and for reconstructing them again...
Definition: XmlSerializer.h:49
This class is used for all exceptions thrown by OpenMM.
Definition: OpenMMException.h:44
static T * deserialize(std::istream &stream)
Reconstruct an object that has been serialized as XML.
Definition: XmlSerializer.h:76