Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
loco-3d
Multicontact-api
Commits
3bb60a04
Commit
3bb60a04
authored
Mar 29, 2020
by
Pierre Fernbach
Browse files
[Python] factorize pickle code for all classes
parent
e7b67d10
Changes
2
Hide whitespace changes
Inline
Side-by-side
include/multicontact-api/bindings/python/scenario/contact-sequence.hpp
View file @
3bb60a04
...
...
@@ -229,8 +229,7 @@ struct ContactSequencePythonVisitor : public bp::def_visitor<ContactSequencePyth
"if t equal to the last phase timeFinal, this index is returned."
)
.
def
(
bp
::
self
==
bp
::
self
)
.
def
(
bp
::
self
!=
bp
::
self
)
.
def
(
"copy"
,
&
copy
,
"Returns a copy of *this."
)
.
def_pickle
(
cs_pickle_suite
());
.
def
(
"copy"
,
&
copy
,
"Returns a copy of *this."
);
}
static
void
expose
(
const
std
::
string
&
class_name
)
{
...
...
@@ -262,24 +261,6 @@ struct ContactSequencePythonVisitor : public bp::def_visitor<ContactSequencePyth
return
toPythonList
<
std
::
string
>
(
self
.
getAllEffectorsInContact
());
}
struct
cs_pickle_suite
:
bp
::
pickle_suite
{
static
bp
::
object
getstate
(
const
CS
&
cs
)
{
std
::
ostringstream
os
;
boost
::
archive
::
text_oarchive
oa
(
os
);
oa
<<
cs
;
return
bp
::
str
(
os
.
str
());
}
static
void
setstate
(
CS
&
cs
,
bp
::
object
entries
)
{
bp
::
str
s
=
bp
::
extract
<
bp
::
str
>
(
entries
)();
std
::
string
st
=
bp
::
extract
<
std
::
string
>
(
s
)();
std
::
istringstream
is
(
st
);
boost
::
archive
::
text_iarchive
ia
(
is
);
ia
>>
cs
;
}
};
};
}
// namespace python
}
// namespace multicontact_api
...
...
include/multicontact-api/bindings/python/serialization/archive.hpp
View file @
3bb60a04
...
...
@@ -11,6 +11,26 @@ namespace python {
namespace
bp
=
boost
::
python
;
template
<
typename
Derived
>
struct
cs_pickle_suite
:
bp
::
pickle_suite
{
static
bp
::
object
getstate
(
const
Derived
&
cs
)
{
std
::
ostringstream
os
;
boost
::
archive
::
text_oarchive
oa
(
os
);
oa
<<
cs
;
return
bp
::
str
(
os
.
str
());
}
static
void
setstate
(
Derived
&
cs
,
bp
::
object
entries
)
{
bp
::
str
s
=
bp
::
extract
<
bp
::
str
>
(
entries
)();
std
::
string
st
=
bp
::
extract
<
std
::
string
>
(
s
)();
std
::
istringstream
is
(
st
);
boost
::
archive
::
text_iarchive
ia
(
is
);
ia
>>
cs
;
}
};
template
<
typename
Derived
>
struct
SerializableVisitor
:
public
boost
::
python
::
def_visitor
<
SerializableVisitor
<
Derived
>
>
{
template
<
class
PyClass
>
...
...
@@ -20,7 +40,8 @@ struct SerializableVisitor : public boost::python::def_visitor<SerializableVisit
.
def
(
"saveAsXML"
,
&
Derived
::
saveAsXML
,
bp
::
args
(
"filename"
,
"tag_name"
),
"Saves *this inside a XML file."
)
.
def
(
"loadFromXML"
,
&
Derived
::
loadFromXML
,
bp
::
args
(
"filename"
,
"tag_name"
),
"Loads *this from a XML file."
)
.
def
(
"saveAsBinary"
,
&
Derived
::
saveAsBinary
,
bp
::
args
(
"filename"
),
"Saves *this inside a binary file."
)
.
def
(
"loadFromBinary"
,
&
Derived
::
loadFromBinary
,
bp
::
args
(
"filename"
),
"Loads *this from a binary file."
);
.
def
(
"loadFromBinary"
,
&
Derived
::
loadFromBinary
,
bp
::
args
(
"filename"
),
"Loads *this from a binary file."
)
.
def_pickle
(
cs_pickle_suite
<
Derived
>
());
}
};
}
// namespace python
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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