| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // | ||
| 2 | // Copyright (c) 2017-2024 CNRS INRIA | ||
| 3 | // This file was borrowed from the Pinocchio library: | ||
| 4 | // https://github.com/stack-of-tasks/pinocchio | ||
| 5 | // | ||
| 6 | |||
| 7 | #ifndef COAL_PYTHON_SERIALIZABLE_H | ||
| 8 | #define COAL_PYTHON_SERIALIZABLE_H | ||
| 9 | |||
| 10 | #include <boost/python.hpp> | ||
| 11 | |||
| 12 | #include "coal/serialization/archive.h" | ||
| 13 | #include "coal/serialization/serializer.h" | ||
| 14 | |||
| 15 | namespace coal { | ||
| 16 | namespace python { | ||
| 17 | |||
| 18 | using Serializer = ::coal::serialization::Serializer; | ||
| 19 | |||
| 20 | namespace bp = boost::python; | ||
| 21 | |||
| 22 | template <typename Derived> | ||
| 23 | struct SerializableVisitor | ||
| 24 | : public bp::def_visitor<SerializableVisitor<Derived>> { | ||
| 25 | template <class PyClass> | ||
| 26 | 205 | void visit(PyClass& cl) const { | |
| 27 |
2/4✓ Branch 1 taken 105 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 105 times.
✗ Branch 5 not taken.
|
205 | cl.def("saveToText", &Serializer::saveToText<Derived>, bp::arg("filename"), |
| 28 | "Saves *this inside a text file.") | ||
| 29 |
1/2✓ Branch 1 taken 105 times.
✗ Branch 2 not taken.
|
205 | .def("loadFromText", &Serializer::loadFromText<Derived>, |
| 30 |
1/2✓ Branch 1 taken 105 times.
✗ Branch 2 not taken.
|
410 | bp::arg("filename"), "Loads *this from a text file.") |
| 31 | |||
| 32 |
1/2✓ Branch 1 taken 105 times.
✗ Branch 2 not taken.
|
205 | .def("saveToString", &Serializer::saveToString<Derived>, |
| 33 |
1/2✓ Branch 1 taken 105 times.
✗ Branch 2 not taken.
|
410 | bp::arg("self"), "Parses the current object to a string.") |
| 34 |
2/4✓ Branch 1 taken 105 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 105 times.
✗ Branch 5 not taken.
|
410 | .def("loadFromString", &Serializer::loadFromString<Derived>, |
| 35 | bp::args("self", "string"), | ||
| 36 | "Parses from the input string the content of the current object.") | ||
| 37 | |||
| 38 |
2/4✓ Branch 1 taken 105 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 105 times.
✗ Branch 5 not taken.
|
410 | .def("saveToXML", &Serializer::saveToXML<Derived>, |
| 39 | bp::args("filename", "tag_name"), "Saves *this inside a XML file.") | ||
| 40 |
2/4✓ Branch 1 taken 105 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 105 times.
✗ Branch 5 not taken.
|
410 | .def("loadFromXML", &Serializer::loadFromXML<Derived>, |
| 41 | bp::args("self", "filename", "tag_name"), | ||
| 42 | "Loads *this from a XML file.") | ||
| 43 | |||
| 44 |
2/4✓ Branch 1 taken 105 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 105 times.
✗ Branch 5 not taken.
|
410 | .def("saveToBinary", &Serializer::saveToBinary<Derived>, |
| 45 | bp::args("self", "filename"), "Saves *this inside a binary file.") | ||
| 46 |
2/4✓ Branch 1 taken 105 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 105 times.
✗ Branch 5 not taken.
|
410 | .def("loadFromBinary", &Serializer::loadFromBinary<Derived>, |
| 47 | bp::args("self", "filename"), "Loads *this from a binary file.") | ||
| 48 | |||
| 49 |
2/4✓ Branch 1 taken 105 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 105 times.
✗ Branch 5 not taken.
|
410 | .def("saveToBuffer", &Serializer::saveToBuffer<Derived>, |
| 50 | bp::args("self", "buffer"), "Saves *this inside a binary buffer.") | ||
| 51 |
2/4✓ Branch 1 taken 105 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 105 times.
✗ Branch 5 not taken.
|
205 | .def("loadFromBuffer", &Serializer::loadFromBuffer<Derived>, |
| 52 | bp::args("self", "buffer"), "Loads *this from a binary buffer."); | ||
| 53 | 205 | } | |
| 54 | }; | ||
| 55 | } // namespace python | ||
| 56 | } // namespace coal | ||
| 57 | |||
| 58 | #endif // ifndef COAL_PYTHON_SERIALIZABLE_H | ||
| 59 |