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
88313407
Commit
88313407
authored
Mar 06, 2017
by
peastman
Browse files
Use C++11 style loops
parent
d314e695
Changes
25
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
46 additions
and
65 deletions
+46
-65
serialization/src/SerializationNode.cpp
serialization/src/SerializationNode.cpp
+6
-6
serialization/src/StateProxy.cpp
serialization/src/StateProxy.cpp
+8
-23
serialization/src/SystemProxy.cpp
serialization/src/SystemProxy.cpp
+3
-6
serialization/src/TabulatedFunctionProxies.cpp
serialization/src/TabulatedFunctionProxies.cpp
+24
-24
serialization/src/XmlSerializer.cpp
serialization/src/XmlSerializer.cpp
+5
-6
No files found.
serialization/src/SerializationNode.cpp
View file @
88313407
...
...
@@ -56,16 +56,16 @@ vector<SerializationNode>& SerializationNode::getChildren() {
}
const
SerializationNode
&
SerializationNode
::
getChildNode
(
const
std
::
string
&
name
)
const
{
for
(
int
i
=
0
;
i
<
(
int
)
children
.
size
();
i
++
)
if
(
child
ren
[
i
]
.
name
==
name
)
return
child
ren
[
i
]
;
for
(
auto
&
child
:
children
)
if
(
child
.
name
==
name
)
return
child
;
throw
OpenMMException
(
"Unknown child '"
+
name
+
"' for node '"
+
getName
()
+
"'"
);
}
SerializationNode
&
SerializationNode
::
getChildNode
(
const
std
::
string
&
name
)
{
for
(
int
i
=
0
;
i
<
(
int
)
children
.
size
();
i
++
)
if
(
child
ren
[
i
]
.
name
==
name
)
return
child
ren
[
i
]
;
for
(
auto
&
child
:
children
)
if
(
child
.
name
==
name
)
return
child
;
throw
OpenMMException
(
"Unknown child '"
+
name
+
"' for node '"
+
getName
()
+
"'"
);
}
...
...
serialization/src/StateProxy.cpp
View file @
88313407
...
...
@@ -56,11 +56,8 @@ void StateProxy::serialize(const void* object, SerializationNode& node) const {
if
((
s
.
getDataTypes
()
&
State
::
Parameters
)
!=
0
)
{
s
.
getParameters
();
SerializationNode
&
parametersNode
=
node
.
createChildNode
(
"Parameters"
);
map
<
string
,
double
>
stateParams
=
s
.
getParameters
();
map
<
string
,
double
>::
const_iterator
it
;
for
(
it
=
stateParams
.
begin
();
it
!=
stateParams
.
end
();
it
++
)
{
parametersNode
.
setDoubleProperty
(
it
->
first
,
it
->
second
);
}
for
(
auto
&
param
:
s
.
getParameters
())
parametersNode
.
setDoubleProperty
(
param
.
first
,
param
.
second
);
}
if
((
s
.
getDataTypes
()
&
State
::
Energy
)
!=
0
)
{
s
.
getPotentialEnergy
();
...
...
@@ -108,17 +105,11 @@ void* StateProxy::deserialize(const SerializationNode& node) const {
int
types
=
0
;
vector
<
int
>
arraySizes
;
State
::
StateBuilder
builder
(
outTime
);
const
vector
<
SerializationNode
>&
children
=
node
.
getChildren
();
for
(
int
j
=
0
;
j
<
(
int
)
children
.
size
();
j
++
)
{
const
SerializationNode
&
child
=
children
[
j
];
for
(
auto
&
child
:
node
.
getChildren
())
{
if
(
child
.
getName
()
==
"Parameters"
)
{
map
<
string
,
double
>
outStateParams
;
// inStateParams is really a <string,double> pair, where string is the name and double is the value
// but we want to avoid casting a string to a double and instead use the built in routines,
map
<
string
,
string
>
inStateParams
=
child
.
getProperties
();
for
(
map
<
string
,
string
>::
const_iterator
pit
=
inStateParams
.
begin
();
pit
!=
inStateParams
.
end
();
pit
++
)
{
outStateParams
[
pit
->
first
]
=
child
.
getDoubleProperty
(
pit
->
first
);
}
for
(
auto
&
param
:
child
.
getProperties
())
outStateParams
[
param
.
first
]
=
child
.
getDoubleProperty
(
param
.
first
);
builder
.
setParameters
(
outStateParams
);
}
else
if
(
child
.
getName
()
==
"Energies"
)
{
...
...
@@ -128,28 +119,22 @@ void* StateProxy::deserialize(const SerializationNode& node) const {
}
else
if
(
child
.
getName
()
==
"Positions"
)
{
vector
<
Vec3
>
outPositions
;
for
(
int
i
=
0
;
i
<
(
int
)
child
.
getChildren
().
size
();
i
++
)
{
const
SerializationNode
&
particle
=
child
.
getChildren
()[
i
];
for
(
auto
&
particle
:
child
.
getChildren
())
outPositions
.
push_back
(
Vec3
(
particle
.
getDoubleProperty
(
"x"
),
particle
.
getDoubleProperty
(
"y"
),
particle
.
getDoubleProperty
(
"z"
)));
}
builder
.
setPositions
(
outPositions
);
arraySizes
.
push_back
(
outPositions
.
size
());
}
else
if
(
child
.
getName
()
==
"Velocities"
)
{
vector
<
Vec3
>
outVelocities
;
for
(
int
i
=
0
;
i
<
(
int
)
child
.
getChildren
().
size
();
i
++
)
{
const
SerializationNode
&
particle
=
child
.
getChildren
()[
i
];
for
(
auto
&
particle
:
child
.
getChildren
())
outVelocities
.
push_back
(
Vec3
(
particle
.
getDoubleProperty
(
"x"
),
particle
.
getDoubleProperty
(
"y"
),
particle
.
getDoubleProperty
(
"z"
)));
}
builder
.
setVelocities
(
outVelocities
);
arraySizes
.
push_back
(
outVelocities
.
size
());
}
else
if
(
child
.
getName
()
==
"Forces"
)
{
vector
<
Vec3
>
outForces
;
for
(
int
i
=
0
;
i
<
(
int
)
child
.
getChildren
().
size
();
i
++
)
{
const
SerializationNode
&
particle
=
child
.
getChildren
()[
i
];
for
(
auto
&
particle
:
child
.
getChildren
())
outForces
.
push_back
(
Vec3
(
particle
.
getDoubleProperty
(
"x"
),
particle
.
getDoubleProperty
(
"y"
),
particle
.
getDoubleProperty
(
"z"
)));
}
builder
.
setForces
(
outForces
);
arraySizes
.
push_back
(
outForces
.
size
());
}
...
...
serialization/src/SystemProxy.cpp
View file @
88313407
...
...
@@ -129,14 +129,11 @@ void* SystemProxy::deserialize(const SerializationNode& node) const {
}
}
const
SerializationNode
&
constraints
=
node
.
getChildNode
(
"Constraints"
);
for
(
int
i
=
0
;
i
<
(
int
)
constraints
.
getChildren
().
size
();
i
++
)
{
const
SerializationNode
&
constraint
=
constraints
.
getChildren
()[
i
];
for
(
auto
&
constraint
:
constraints
.
getChildren
())
system
->
addConstraint
(
constraint
.
getIntProperty
(
"p1"
),
constraint
.
getIntProperty
(
"p2"
),
constraint
.
getDoubleProperty
(
"d"
));
}
const
SerializationNode
&
forces
=
node
.
getChildNode
(
"Forces"
);
for
(
int
i
=
0
;
i
<
(
int
)
forces
.
getChildren
().
size
();
i
++
)
{
system
->
addForce
(
forces
.
getChildren
()[
i
].
decodeObject
<
Force
>
());
}
for
(
auto
&
force
:
forces
.
getChildren
())
system
->
addForce
(
force
.
decodeObject
<
Force
>
());
}
catch
(...)
{
delete
system
;
...
...
serialization/src/TabulatedFunctionProxies.cpp
View file @
88313407
...
...
@@ -49,8 +49,8 @@ void Continuous1DFunctionProxy::serialize(const void* object, SerializationNode&
node
.
setDoubleProperty
(
"min"
,
min
);
node
.
setDoubleProperty
(
"max"
,
max
);
SerializationNode
&
valuesNode
=
node
.
createChildNode
(
"Values"
);
for
(
int
j
=
0
;
j
<
(
int
)
values
.
size
();
j
++
)
valuesNode
.
createChildNode
(
"Value"
).
setDoubleProperty
(
"v"
,
v
alues
[
j
]
);
for
(
auto
v
:
values
)
valuesNode
.
createChildNode
(
"Value"
).
setDoubleProperty
(
"v"
,
v
);
}
void
*
Continuous1DFunctionProxy
::
deserialize
(
const
SerializationNode
&
node
)
const
{
...
...
@@ -58,8 +58,8 @@ void* Continuous1DFunctionProxy::deserialize(const SerializationNode& node) cons
throw
OpenMMException
(
"Unsupported version number"
);
const
SerializationNode
&
valuesNode
=
node
.
getChildNode
(
"Values"
);
vector
<
double
>
values
;
for
(
int
j
=
0
;
j
<
(
int
)
valuesNode
.
getChildren
()
.
size
();
j
++
)
values
.
push_back
(
valuesNode
.
getChildren
()[
j
]
.
getDoubleProperty
(
"v"
));
for
(
auto
&
child
:
valuesNode
.
getChildren
())
values
.
push_back
(
child
.
getDoubleProperty
(
"v"
));
return
new
Continuous1DFunction
(
values
,
node
.
getDoubleProperty
(
"min"
),
node
.
getDoubleProperty
(
"max"
));
}
...
...
@@ -80,8 +80,8 @@ void Continuous2DFunctionProxy::serialize(const void* object, SerializationNode&
node
.
setDoubleProperty
(
"ymin"
,
ymin
);
node
.
setDoubleProperty
(
"ymax"
,
ymax
);
SerializationNode
&
valuesNode
=
node
.
createChildNode
(
"Values"
);
for
(
int
j
=
0
;
j
<
(
int
)
values
.
size
();
j
++
)
valuesNode
.
createChildNode
(
"Value"
).
setDoubleProperty
(
"v"
,
v
alues
[
j
]
);
for
(
auto
v
:
values
)
valuesNode
.
createChildNode
(
"Value"
).
setDoubleProperty
(
"v"
,
v
);
}
void
*
Continuous2DFunctionProxy
::
deserialize
(
const
SerializationNode
&
node
)
const
{
...
...
@@ -89,8 +89,8 @@ void* Continuous2DFunctionProxy::deserialize(const SerializationNode& node) cons
throw
OpenMMException
(
"Unsupported version number"
);
const
SerializationNode
&
valuesNode
=
node
.
getChildNode
(
"Values"
);
vector
<
double
>
values
;
for
(
int
j
=
0
;
j
<
(
int
)
valuesNode
.
getChildren
()
.
size
();
j
++
)
values
.
push_back
(
valuesNode
.
getChildren
()[
j
]
.
getDoubleProperty
(
"v"
));
for
(
auto
&
child
:
valuesNode
.
getChildren
())
values
.
push_back
(
child
.
getDoubleProperty
(
"v"
));
return
new
Continuous2DFunction
(
node
.
getIntProperty
(
"xsize"
),
node
.
getIntProperty
(
"ysize"
),
values
,
node
.
getDoubleProperty
(
"xmin"
),
node
.
getDoubleProperty
(
"xmax"
),
node
.
getDoubleProperty
(
"ymin"
),
node
.
getDoubleProperty
(
"ymax"
));
}
...
...
@@ -115,8 +115,8 @@ void Continuous3DFunctionProxy::serialize(const void* object, SerializationNode&
node
.
setDoubleProperty
(
"zmin"
,
zmin
);
node
.
setDoubleProperty
(
"zmax"
,
zmax
);
SerializationNode
&
valuesNode
=
node
.
createChildNode
(
"Values"
);
for
(
int
j
=
0
;
j
<
(
int
)
values
.
size
();
j
++
)
valuesNode
.
createChildNode
(
"Value"
).
setDoubleProperty
(
"v"
,
v
alues
[
j
]
);
for
(
auto
v
:
values
)
valuesNode
.
createChildNode
(
"Value"
).
setDoubleProperty
(
"v"
,
v
);
}
void
*
Continuous3DFunctionProxy
::
deserialize
(
const
SerializationNode
&
node
)
const
{
...
...
@@ -124,8 +124,8 @@ void* Continuous3DFunctionProxy::deserialize(const SerializationNode& node) cons
throw
OpenMMException
(
"Unsupported version number"
);
const
SerializationNode
&
valuesNode
=
node
.
getChildNode
(
"Values"
);
vector
<
double
>
values
;
for
(
int
j
=
0
;
j
<
(
int
)
valuesNode
.
getChildren
()
.
size
();
j
++
)
values
.
push_back
(
valuesNode
.
getChildren
()[
j
]
.
getDoubleProperty
(
"v"
));
for
(
auto
&
child
:
valuesNode
.
getChildren
())
values
.
push_back
(
child
.
getDoubleProperty
(
"v"
));
return
new
Continuous3DFunction
(
node
.
getIntProperty
(
"xsize"
),
node
.
getIntProperty
(
"ysize"
),
node
.
getIntProperty
(
"zsize"
),
values
,
node
.
getDoubleProperty
(
"xmin"
),
node
.
getDoubleProperty
(
"xmax"
),
node
.
getDoubleProperty
(
"ymin"
),
node
.
getDoubleProperty
(
"ymax"
),
node
.
getDoubleProperty
(
"zmin"
),
node
.
getDoubleProperty
(
"zmax"
));
...
...
@@ -140,8 +140,8 @@ void Discrete1DFunctionProxy::serialize(const void* object, SerializationNode& n
vector
<
double
>
values
;
function
.
getFunctionParameters
(
values
);
SerializationNode
&
valuesNode
=
node
.
createChildNode
(
"Values"
);
for
(
int
j
=
0
;
j
<
(
int
)
values
.
size
();
j
++
)
valuesNode
.
createChildNode
(
"Value"
).
setDoubleProperty
(
"v"
,
v
alues
[
j
]
);
for
(
auto
v
:
values
)
valuesNode
.
createChildNode
(
"Value"
).
setDoubleProperty
(
"v"
,
v
);
}
void
*
Discrete1DFunctionProxy
::
deserialize
(
const
SerializationNode
&
node
)
const
{
...
...
@@ -149,8 +149,8 @@ void* Discrete1DFunctionProxy::deserialize(const SerializationNode& node) const
throw
OpenMMException
(
"Unsupported version number"
);
const
SerializationNode
&
valuesNode
=
node
.
getChildNode
(
"Values"
);
vector
<
double
>
values
;
for
(
int
j
=
0
;
j
<
(
int
)
valuesNode
.
getChildren
()
.
size
();
j
++
)
values
.
push_back
(
valuesNode
.
getChildren
()[
j
]
.
getDoubleProperty
(
"v"
));
for
(
auto
&
child
:
valuesNode
.
getChildren
())
values
.
push_back
(
child
.
getDoubleProperty
(
"v"
));
return
new
Discrete1DFunction
(
values
);
}
...
...
@@ -166,8 +166,8 @@ void Discrete2DFunctionProxy::serialize(const void* object, SerializationNode& n
node
.
setDoubleProperty
(
"xsize"
,
xsize
);
node
.
setDoubleProperty
(
"ysize"
,
ysize
);
SerializationNode
&
valuesNode
=
node
.
createChildNode
(
"Values"
);
for
(
int
j
=
0
;
j
<
(
int
)
values
.
size
();
j
++
)
valuesNode
.
createChildNode
(
"Value"
).
setDoubleProperty
(
"v"
,
v
alues
[
j
]
);
for
(
auto
v
:
values
)
valuesNode
.
createChildNode
(
"Value"
).
setDoubleProperty
(
"v"
,
v
);
}
void
*
Discrete2DFunctionProxy
::
deserialize
(
const
SerializationNode
&
node
)
const
{
...
...
@@ -175,8 +175,8 @@ void* Discrete2DFunctionProxy::deserialize(const SerializationNode& node) const
throw
OpenMMException
(
"Unsupported version number"
);
const
SerializationNode
&
valuesNode
=
node
.
getChildNode
(
"Values"
);
vector
<
double
>
values
;
for
(
int
j
=
0
;
j
<
(
int
)
valuesNode
.
getChildren
()
.
size
();
j
++
)
values
.
push_back
(
valuesNode
.
getChildren
()[
j
]
.
getDoubleProperty
(
"v"
));
for
(
auto
&
child
:
valuesNode
.
getChildren
())
values
.
push_back
(
child
.
getDoubleProperty
(
"v"
));
return
new
Discrete2DFunction
(
node
.
getIntProperty
(
"xsize"
),
node
.
getIntProperty
(
"ysize"
),
values
);
}
...
...
@@ -193,8 +193,8 @@ void Discrete3DFunctionProxy::serialize(const void* object, SerializationNode& n
node
.
setDoubleProperty
(
"ysize"
,
ysize
);
node
.
setDoubleProperty
(
"zsize"
,
zsize
);
SerializationNode
&
valuesNode
=
node
.
createChildNode
(
"Values"
);
for
(
int
j
=
0
;
j
<
(
int
)
values
.
size
();
j
++
)
valuesNode
.
createChildNode
(
"Value"
).
setDoubleProperty
(
"v"
,
v
alues
[
j
]
);
for
(
auto
v
:
values
)
valuesNode
.
createChildNode
(
"Value"
).
setDoubleProperty
(
"v"
,
v
);
}
void
*
Discrete3DFunctionProxy
::
deserialize
(
const
SerializationNode
&
node
)
const
{
...
...
@@ -202,7 +202,7 @@ void* Discrete3DFunctionProxy::deserialize(const SerializationNode& node) const
throw
OpenMMException
(
"Unsupported version number"
);
const
SerializationNode
&
valuesNode
=
node
.
getChildNode
(
"Values"
);
vector
<
double
>
values
;
for
(
int
j
=
0
;
j
<
(
int
)
valuesNode
.
getChildren
()
.
size
();
j
++
)
values
.
push_back
(
valuesNode
.
getChildren
()[
j
]
.
getDoubleProperty
(
"v"
));
for
(
auto
&
child
:
valuesNode
.
getChildren
())
values
.
push_back
(
child
.
getDoubleProperty
(
"v"
));
return
new
Discrete3DFunction
(
node
.
getIntProperty
(
"xsize"
),
node
.
getIntProperty
(
"ysize"
),
node
.
getIntProperty
(
"zsize"
),
values
);
}
serialization/src/XmlSerializer.cpp
View file @
88313407
...
...
@@ -115,11 +115,10 @@ void XmlSerializer::encodeNode(const SerializationNode& node, std::ostream& stre
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
)
{
for
(
auto
&
prop
:
node
.
getProperties
())
{
string
name
,
value
;
encodeString
(
iter
->
first
,
&
name
);
encodeString
(
iter
->
second
,
&
value
);
encodeString
(
prop
.
first
,
&
name
);
encodeString
(
prop
.
second
,
&
value
);
stream
<<
' '
<<
name
<<
"=
\"
"
<<
value
<<
'\"'
;
}
const
vector
<
SerializationNode
>&
children
=
node
.
getChildren
();
...
...
@@ -127,8 +126,8 @@ void XmlSerializer::encodeNode(const SerializationNode& node, std::ostream& stre
stream
<<
"/>
\n
"
;
else
{
stream
<<
">
\n
"
;
for
(
int
i
=
0
;
i
<
(
int
)
children
.
size
();
i
++
)
encodeNode
(
child
ren
[
i
]
,
stream
,
depth
+
1
);
for
(
auto
&
child
:
children
)
encodeNode
(
child
,
stream
,
depth
+
1
);
for
(
int
i
=
0
;
i
<
depth
;
i
++
)
stream
<<
'\t'
;
stream
<<
"</"
<<
node
.
getName
()
<<
">
\n
"
;
...
...
Prev
1
2
Next
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