Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
tsoc
openmm
Commits
0c7dc959
Commit
0c7dc959
authored
Jun 13, 2014
by
peastman
Browse files
XmlSerializer generates XML directly rather than going through TinyXml
parent
fa11f993
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
18 deletions
+25
-18
serialization/include/openmm/serialization/XmlSerializer.h
serialization/include/openmm/serialization/XmlSerializer.h
+2
-2
serialization/src/XmlSerializer.cpp
serialization/src/XmlSerializer.cpp
+23
-16
No files found.
serialization/include/openmm/serialization/XmlSerializer.h
View file @
0c7dc959
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* 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 *
* Authors: Peter Eastman *
* Contributors: *
* Contributors: *
* *
* *
...
@@ -79,7 +79,7 @@ public:
...
@@ -79,7 +79,7 @@ public:
private:
private:
static
void
serialize
(
const
SerializationNode
&
node
,
std
::
ostream
&
stream
);
static
void
serialize
(
const
SerializationNode
&
node
,
std
::
ostream
&
stream
);
static
void
*
deserializeStream
(
std
::
istream
&
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
);
static
void
decodeNode
(
SerializationNode
&
node
,
const
TiXmlElement
&
element
);
};
};
...
...
serialization/src/XmlSerializer.cpp
View file @
0c7dc959
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* 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 *
* Authors: Peter Eastman *
* Contributors: *
* Contributors: *
* *
* *
...
@@ -36,25 +36,32 @@ using namespace OpenMM;
...
@@ -36,25 +36,32 @@ using namespace OpenMM;
using
namespace
std
;
using
namespace
std
;
void
XmlSerializer
::
serialize
(
const
SerializationNode
&
node
,
std
::
ostream
&
stream
)
{
void
XmlSerializer
::
serialize
(
const
SerializationNode
&
node
,
std
::
ostream
&
stream
)
{
TiXmlDocument
doc
;
stream
<<
"<?xml version=
\"
1.0
\"
?>
\n
"
;
TiXmlDeclaration
*
decl
=
new
TiXmlDeclaration
(
"1.0"
,
""
,
""
);
encodeNode
(
node
,
stream
,
0
);
doc
.
LinkEndChild
(
decl
);
doc
.
LinkEndChild
(
encodeNode
(
node
));
TiXmlPrinter
printer
;
printer
.
SetIndent
(
"
\t
"
);
doc
.
Accept
(
&
printer
);
stream
<<
printer
.
Str
();
}
}
TiXmlElement
*
XmlSerializer
::
encodeNode
(
const
SerializationNode
&
node
)
{
void
XmlSerializer
::
encodeNode
(
const
SerializationNode
&
node
,
std
::
ostream
&
stream
,
int
depth
)
{
TiXmlElement
*
element
=
new
TiXmlElement
(
node
.
getName
());
for
(
int
i
=
0
;
i
<
depth
;
i
++
)
stream
<<
'\t'
;
stream
<<
'<'
<<
node
.
getName
();
const
map
<
string
,
string
>&
properties
=
node
.
getProperties
();
const
map
<
string
,
string
>&
properties
=
node
.
getProperties
();
for
(
map
<
string
,
string
>::
const_iterator
iter
=
properties
.
begin
();
iter
!=
properties
.
end
();
++
iter
)
for
(
map
<
string
,
string
>::
const_iterator
iter
=
properties
.
begin
();
iter
!=
properties
.
end
();
++
iter
)
{
element
->
SetAttribute
(
iter
->
first
.
c_str
(),
iter
->
second
.
c_str
());
string
name
,
value
;
TiXmlBase
::
EncodeString
(
iter
->
first
,
&
name
);
TiXmlBase
::
EncodeString
(
iter
->
second
,
&
value
);
stream
<<
' '
<<
name
<<
"=
\"
"
<<
value
<<
'\"'
;
}
const
vector
<
SerializationNode
>&
children
=
node
.
getChildren
();
const
vector
<
SerializationNode
>&
children
=
node
.
getChildren
();
if
(
children
.
size
()
==
0
)
stream
<<
"/>
\n
"
;
else
{
stream
<<
">
\n
"
;
for
(
int
i
=
0
;
i
<
(
int
)
children
.
size
();
i
++
)
for
(
int
i
=
0
;
i
<
(
int
)
children
.
size
();
i
++
)
element
->
LinkEndChild
(
encodeNode
(
children
[
i
]));
encodeNode
(
children
[
i
],
stream
,
depth
+
1
);
return
element
;
for
(
int
i
=
0
;
i
<
depth
;
i
++
)
stream
<<
'\t'
;
stream
<<
"</"
<<
node
.
getName
()
<<
">
\n
"
;
}
}
}
void
*
XmlSerializer
::
deserializeStream
(
std
::
istream
&
stream
)
{
void
*
XmlSerializer
::
deserializeStream
(
std
::
istream
&
stream
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment