pinocchio  3.3.1
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
serializable.hpp
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:
30  void loadFromText(const std::string & filename)
31  {
32  pinocchio::serialization::loadFromText(derived(), filename);
33  }
34 
36  void saveToText(const std::string & filename) const
37  {
38  pinocchio::serialization::saveToText(derived(), filename);
39  }
40 
42  void loadFromStringStream(std::istringstream & is)
43  {
44  pinocchio::serialization::loadFromStringStream(derived(), is);
45  }
46 
48  void saveToStringStream(std::stringstream & ss) const
49  {
50  pinocchio::serialization::saveToStringStream(derived(), ss);
51  }
52 
54  void loadFromString(const std::string & str)
55  {
56  pinocchio::serialization::loadFromString(derived(), str);
57  }
58 
60  std::string saveToString() const
61  {
62  return pinocchio::serialization::saveToString(derived());
63  }
64 
66  void loadFromXML(const std::string & filename, const std::string & tag_name)
67  {
68  pinocchio::serialization::loadFromXML(derived(), filename, tag_name);
69  }
70 
72  void saveToXML(const std::string & filename, const std::string & tag_name) const
73  {
74  pinocchio::serialization::saveToXML(derived(), filename, tag_name);
75  }
76 
78  void loadFromBinary(const std::string & filename)
79  {
80  pinocchio::serialization::loadFromBinary(derived(), filename);
81  }
82 
84  void saveToBinary(const std::string & filename) const
85  {
86  pinocchio::serialization::saveToBinary(derived(), filename);
87  }
88 
90  void loadFromBinary(boost::asio::streambuf & container)
91  {
92  pinocchio::serialization::loadFromBinary(derived(), container);
93  }
94 
96  void saveToBinary(boost::asio::streambuf & container) const
97  {
98  pinocchio::serialization::saveToBinary(derived(), container);
99  }
100 
102  void loadFromBinary(StaticBuffer & container)
103  {
104  pinocchio::serialization::loadFromBinary(derived(), container);
105  }
106 
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__
Main pinocchio namespace.
Definition: treeview.dox:11
void saveToXML(const std::string &filename, const std::string &tag_name) const
Saves a Derived object as an XML file.
void loadFromXML(const std::string &filename, const std::string &tag_name)
Loads a Derived object from an XML file.
void saveToStringStream(std::stringstream &ss) const
Saves a Derived object to a string stream.
void loadFromBinary(const std::string &filename)
Loads a Derived object from an binary file.
void loadFromText(const std::string &filename)
Loads a Derived object from a text file.
void loadFromBinary(boost::asio::streambuf &container)
Loads a Derived object from a binary container.
void saveToBinary(boost::asio::streambuf &container) const
Saves a Derived object as a binary container.
void saveToBinary(StaticBuffer &container) const
Saves a Derived object as a static binary container.
std::string saveToString() const
Saves a Derived object to a string.
void loadFromBinary(StaticBuffer &container)
Loads a Derived object from a static binary container.
void loadFromStringStream(std::istringstream &is)
Loads a Derived object from a stream string.
void loadFromString(const std::string &str)
Loads a Derived object from a string.
void saveToText(const std::string &filename) const
Saves a Derived object as a text file.
void saveToBinary(const std::string &filename) const
Saves a Derived object as an binary file.
Static buffer with pre-allocated memory.