Line |
Branch |
Exec |
Source |
1 |
|
|
// |
2 |
|
|
// Copyright (c) 2017-2021 CNRS INRIA |
3 |
|
|
// |
4 |
|
|
|
5 |
|
|
#ifndef __pinocchio_serialization_serializable_hpp__ |
6 |
|
|
#define __pinocchio_serialization_serializable_hpp__ |
7 |
|
|
|
8 |
|
|
#include "pinocchio/serialization/archive.hpp" |
9 |
|
|
|
10 |
|
|
namespace pinocchio |
11 |
|
|
{ |
12 |
|
|
namespace serialization |
13 |
|
|
{ |
14 |
|
|
|
15 |
|
|
template<class Derived> |
16 |
|
|
struct Serializable |
17 |
|
|
{ |
18 |
|
|
private: |
19 |
|
✗ |
Derived & derived() |
20 |
|
|
{ |
21 |
|
✗ |
return *static_cast<Derived *>(this); |
22 |
|
|
} |
23 |
|
✗ |
const Derived & derived() const |
24 |
|
|
{ |
25 |
|
✗ |
return *static_cast<const Derived *>(this); |
26 |
|
|
} |
27 |
|
|
|
28 |
|
|
public: |
29 |
|
|
/// \brief Loads a Derived object from a text file. |
30 |
|
✗ |
void loadFromText(const std::string & filename) |
31 |
|
|
{ |
32 |
|
✗ |
pinocchio::serialization::loadFromText(derived(), filename); |
33 |
|
|
} |
34 |
|
|
|
35 |
|
|
/// \brief Saves a Derived object as a text file. |
36 |
|
✗ |
void saveToText(const std::string & filename) const |
37 |
|
|
{ |
38 |
|
✗ |
pinocchio::serialization::saveToText(derived(), filename); |
39 |
|
|
} |
40 |
|
|
|
41 |
|
|
/// \brief Loads a Derived object from a stream string. |
42 |
|
|
void loadFromStringStream(std::istringstream & is) |
43 |
|
|
{ |
44 |
|
|
pinocchio::serialization::loadFromStringStream(derived(), is); |
45 |
|
|
} |
46 |
|
|
|
47 |
|
|
/// \brief Saves a Derived object to a string stream. |
48 |
|
|
void saveToStringStream(std::stringstream & ss) const |
49 |
|
|
{ |
50 |
|
|
pinocchio::serialization::saveToStringStream(derived(), ss); |
51 |
|
|
} |
52 |
|
|
|
53 |
|
|
/// \brief Loads a Derived object from a string. |
54 |
|
✗ |
void loadFromString(const std::string & str) |
55 |
|
|
{ |
56 |
|
✗ |
pinocchio::serialization::loadFromString(derived(), str); |
57 |
|
|
} |
58 |
|
|
|
59 |
|
|
/// \brief Saves a Derived object to a string. |
60 |
|
✗ |
std::string saveToString() const |
61 |
|
|
{ |
62 |
|
✗ |
return pinocchio::serialization::saveToString(derived()); |
63 |
|
|
} |
64 |
|
|
|
65 |
|
|
/// \brief Loads a Derived object from an XML file. |
66 |
|
✗ |
void loadFromXML(const std::string & filename, const std::string & tag_name) |
67 |
|
|
{ |
68 |
|
✗ |
pinocchio::serialization::loadFromXML(derived(), filename, tag_name); |
69 |
|
|
} |
70 |
|
|
|
71 |
|
|
/// \brief Saves a Derived object as an XML file. |
72 |
|
✗ |
void saveToXML(const std::string & filename, const std::string & tag_name) const |
73 |
|
|
{ |
74 |
|
✗ |
pinocchio::serialization::saveToXML(derived(), filename, tag_name); |
75 |
|
|
} |
76 |
|
|
|
77 |
|
|
/// \brief Loads a Derived object from an binary file. |
78 |
|
✗ |
void loadFromBinary(const std::string & filename) |
79 |
|
|
{ |
80 |
|
✗ |
pinocchio::serialization::loadFromBinary(derived(), filename); |
81 |
|
|
} |
82 |
|
|
|
83 |
|
|
/// \brief Saves a Derived object as an binary file. |
84 |
|
✗ |
void saveToBinary(const std::string & filename) const |
85 |
|
|
{ |
86 |
|
✗ |
pinocchio::serialization::saveToBinary(derived(), filename); |
87 |
|
|
} |
88 |
|
|
|
89 |
|
|
/// \brief Loads a Derived object from a binary container. |
90 |
|
✗ |
void loadFromBinary(boost::asio::streambuf & container) |
91 |
|
|
{ |
92 |
|
✗ |
pinocchio::serialization::loadFromBinary(derived(), container); |
93 |
|
|
} |
94 |
|
|
|
95 |
|
|
/// \brief Saves a Derived object as a binary container. |
96 |
|
✗ |
void saveToBinary(boost::asio::streambuf & container) const |
97 |
|
|
{ |
98 |
|
✗ |
pinocchio::serialization::saveToBinary(derived(), container); |
99 |
|
|
} |
100 |
|
|
|
101 |
|
|
/// \brief Loads a Derived object from a static binary container. |
102 |
|
✗ |
void loadFromBinary(StaticBuffer & container) |
103 |
|
|
{ |
104 |
|
✗ |
pinocchio::serialization::loadFromBinary(derived(), container); |
105 |
|
|
} |
106 |
|
|
|
107 |
|
|
/// \brief Saves a Derived object as a static binary container. |
108 |
|
✗ |
void saveToBinary(StaticBuffer & container) const |
109 |
|
|
{ |
110 |
|
✗ |
pinocchio::serialization::saveToBinary(derived(), container); |
111 |
|
|
} |
112 |
|
|
}; |
113 |
|
|
|
114 |
|
|
} // namespace serialization |
115 |
|
|
} // namespace pinocchio |
116 |
|
|
|
117 |
|
|
#endif // ifndef __pinocchio_serialization_serializable_hpp__ |
118 |
|
|
|