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 |
|
|
|
20 |
|
|
Derived & derived() { return *static_cast<Derived*>(this); } |
21 |
|
|
const Derived & derived() const { return *static_cast<const Derived*>(this); } |
22 |
|
|
|
23 |
|
|
public: |
24 |
|
|
|
25 |
|
|
/// \brief Loads a Derived object from a text file. |
26 |
|
|
void loadFromText(const std::string & filename) |
27 |
|
|
{ |
28 |
|
|
pinocchio::serialization::loadFromText(derived(),filename); |
29 |
|
|
} |
30 |
|
|
|
31 |
|
|
/// \brief Saves a Derived object as a text file. |
32 |
|
|
void saveToText(const std::string & filename) const |
33 |
|
|
{ |
34 |
|
|
pinocchio::serialization::saveToText(derived(),filename); |
35 |
|
|
} |
36 |
|
|
|
37 |
|
|
/// \brief Loads a Derived object from a stream string. |
38 |
|
|
void loadFromStringStream(std::istringstream & is) |
39 |
|
|
{ |
40 |
|
|
pinocchio::serialization::loadFromStringStream(derived(),is); |
41 |
|
|
} |
42 |
|
|
|
43 |
|
|
/// \brief Saves a Derived object to a string stream. |
44 |
|
|
void saveToStringStream(std::stringstream & ss) const |
45 |
|
|
{ |
46 |
|
|
pinocchio::serialization::saveToStringStream(derived(),ss); |
47 |
|
|
} |
48 |
|
|
|
49 |
|
|
/// \brief Loads a Derived object from a string. |
50 |
|
|
void loadFromString(const std::string & str) |
51 |
|
|
{ |
52 |
|
|
pinocchio::serialization::loadFromString(derived(),str); |
53 |
|
|
} |
54 |
|
|
|
55 |
|
|
/// \brief Saves a Derived object to a string. |
56 |
|
|
std::string saveToString() const |
57 |
|
|
{ |
58 |
|
|
return pinocchio::serialization::saveToString(derived()); |
59 |
|
|
} |
60 |
|
|
|
61 |
|
|
/// \brief Loads a Derived object from an XML file. |
62 |
|
|
void loadFromXML(const std::string & filename, |
63 |
|
|
const std::string & tag_name) |
64 |
|
|
{ |
65 |
|
|
pinocchio::serialization::loadFromXML(derived(),filename,tag_name); |
66 |
|
|
} |
67 |
|
|
|
68 |
|
|
/// \brief Saves a Derived object as an XML file. |
69 |
|
|
void saveToXML(const std::string & filename, |
70 |
|
|
const std::string & tag_name) const |
71 |
|
|
{ |
72 |
|
|
pinocchio::serialization::saveToXML(derived(),filename,tag_name); |
73 |
|
|
} |
74 |
|
|
|
75 |
|
|
/// \brief Loads a Derived object from an binary file. |
76 |
|
|
void loadFromBinary(const std::string & filename) |
77 |
|
|
{ |
78 |
|
|
pinocchio::serialization::loadFromBinary(derived(),filename); |
79 |
|
|
} |
80 |
|
|
|
81 |
|
|
/// \brief Saves a Derived object as an binary file. |
82 |
|
|
void saveToBinary(const std::string & filename) const |
83 |
|
|
{ |
84 |
|
|
pinocchio::serialization::saveToBinary(derived(),filename); |
85 |
|
|
} |
86 |
|
|
|
87 |
|
|
/// \brief Loads a Derived object from a binary container. |
88 |
|
|
void loadFromBinary(boost::asio::streambuf & container) |
89 |
|
|
{ |
90 |
|
|
pinocchio::serialization::loadFromBinary(derived(),container); |
91 |
|
|
} |
92 |
|
|
|
93 |
|
|
/// \brief Saves a Derived object as a binary container. |
94 |
|
|
void saveToBinary(boost::asio::streambuf & container) const |
95 |
|
|
{ |
96 |
|
|
pinocchio::serialization::saveToBinary(derived(),container); |
97 |
|
|
} |
98 |
|
|
|
99 |
|
|
/// \brief Loads a Derived object from a static binary container. |
100 |
|
|
void loadFromBinary(StaticBuffer & container) |
101 |
|
|
{ |
102 |
|
|
pinocchio::serialization::loadFromBinary(derived(),container); |
103 |
|
|
} |
104 |
|
|
|
105 |
|
|
/// \brief Saves a Derived object as a static binary container. |
106 |
|
|
void saveToBinary(StaticBuffer & container) const |
107 |
|
|
{ |
108 |
|
|
pinocchio::serialization::saveToBinary(derived(),container); |
109 |
|
|
} |
110 |
|
|
|
111 |
|
|
}; |
112 |
|
|
|
113 |
|
|
} |
114 |
|
|
} // namespace pinocchio |
115 |
|
|
|
116 |
|
|
#endif // ifndef __pinocchio_serialization_serializable_hpp__ |
117 |
|
|
|