Directory: | ./ |
---|---|
File: | python/serializable.hh |
Date: | 2025-04-01 09:23:31 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 14 | 14 | 100.0% |
Branches: | 19 | 38 | 50.0% |
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 | 195 | void visit(PyClass& cl) const { | |
27 |
1/2✓ Branch 2 taken 100 times.
✗ Branch 3 not taken.
|
195 | cl.def("saveToText", &Serializer::saveToText<Derived>, bp::arg("filename"), |
28 | "Saves *this inside a text file.") | ||
29 |
1/2✓ Branch 1 taken 100 times.
✗ Branch 2 not taken.
|
195 | .def("loadFromText", &Serializer::loadFromText<Derived>, |
30 |
1/2✓ Branch 1 taken 100 times.
✗ Branch 2 not taken.
|
390 | bp::arg("filename"), "Loads *this from a text file.") |
31 | |||
32 |
1/2✓ Branch 1 taken 100 times.
✗ Branch 2 not taken.
|
195 | .def("saveToString", &Serializer::saveToString<Derived>, |
33 |
1/2✓ Branch 1 taken 100 times.
✗ Branch 2 not taken.
|
390 | bp::arg("self"), "Parses the current object to a string.") |
34 |
2/4✓ Branch 1 taken 100 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 100 times.
✗ Branch 5 not taken.
|
390 | .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 100 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 100 times.
✗ Branch 5 not taken.
|
390 | .def("saveToXML", &Serializer::saveToXML<Derived>, |
39 | bp::args("filename", "tag_name"), "Saves *this inside a XML file.") | ||
40 |
2/4✓ Branch 1 taken 100 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 100 times.
✗ Branch 5 not taken.
|
390 | .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 100 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 100 times.
✗ Branch 5 not taken.
|
390 | .def("saveToBinary", &Serializer::saveToBinary<Derived>, |
45 | bp::args("self", "filename"), "Saves *this inside a binary file.") | ||
46 |
2/4✓ Branch 1 taken 100 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 100 times.
✗ Branch 5 not taken.
|
390 | .def("loadFromBinary", &Serializer::loadFromBinary<Derived>, |
47 | bp::args("self", "filename"), "Loads *this from a binary file.") | ||
48 | |||
49 |
2/4✓ Branch 1 taken 100 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 100 times.
✗ Branch 5 not taken.
|
390 | .def("saveToBuffer", &Serializer::saveToBuffer<Derived>, |
50 | bp::args("self", "buffer"), "Saves *this inside a binary buffer.") | ||
51 |
2/4✓ Branch 1 taken 100 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 100 times.
✗ Branch 5 not taken.
|
195 | .def("loadFromBuffer", &Serializer::loadFromBuffer<Derived>, |
52 | bp::args("self", "buffer"), "Loads *this from a binary buffer."); | ||
53 | 195 | } | |
54 | }; | ||
55 | } // namespace python | ||
56 | } // namespace coal | ||
57 | |||
58 | #endif // ifndef COAL_PYTHON_SERIALIZABLE_H | ||
59 |