Public Member Functions |
bool | IsInput () |
| Method for checking if we are inputting or outputting. Can be used from your serializable class.
|
template<class C > |
Serialization & | operator<< (C &serializable) |
| Operator for outputting a serializable class into the defined filename or std::iostream.
|
template<class C > |
Serialization & | operator>> (C &serializable) |
| Operator for reading a serializable class from the defined filename or std::iostream.
|
| Serialization (std::string _filename) |
| Constructor for serializing to/from specified filename.
|
| Serialization (std::basic_iostream< char > &_stream) |
| Constructor for serializing any iostream (e.g. std::stringstream)
|
| Serialization (std::basic_istream< char > &_stream) |
| Constructor for serializing any istream (e.g. std::cin)
|
| Serialization (std::basic_ostream< char > &_stream) |
| Constructor for serializing any ostream (e.g. std::cout)
|
bool | Serialize (int &data, const std::string &name) |
| Method for serializing 'int' data element. Used from your serializable class.
|
bool | Serialize (unsigned short &data, const std::string &name) |
| Method for serializing 'int' data element. Used from your serializable class.
|
bool | Serialize (unsigned long &data, const std::string &name) |
| Method for serializing 'int' data element. Used from your serializable class.
|
bool | Serialize (double &data, const std::string &name) |
| Method for serializing 'double' data element. Used from your serializable class.
|
bool | Serialize (std::string &data, const std::string &name) |
| Method for serializing 'std::string' data element. Used from your serializable class.
|
bool | Serialize (CvMat &data, const std::string &name) |
| Method for serializing 'CvMat' data element. Used from your serializable class.
|
template<class C > |
bool | SerializeClass (C &serializable) |
| Method for serializing a serializable class. Used by operators << and >> .
|
| ~Serialization () |
| Destructor.
|
Protected Member Functions |
bool | Ascend () |
bool | Descend (const char *id) |
bool | Input () |
bool | Output () |
Protected Attributes |
std::string | filename |
void * | formatter_handle |
bool | input |
std::ios * | stream |
Class for serializing class content to/from file or std::iostream.
The class is mainly meant to serialize classes that implement two required methods SerializeId and Serialize . For example alvar::Camera implements the following to make it serializable:
const char *SerializeId { return "camera"; };
bool Serialize(Serialization *ser) {
if (!ser->Serialize(calib_x_res, "width")) return false;
if (!ser->Serialize(calib_y_res, "height")) return false;
if (!ser->Serialize(calib_K, "intrinsic_matrix")) return false;
if (!ser->Serialize(calib_D, "distortion")) return false;
return true;
}
In your classes Serialize -method you can use the overloaded Serialize method of the Serialization class to serialize data or data arrays. In addition you can use SerializeClass to serialize inner serializable classes.
After the class is serializable i.e. it implements the above two methods you can serialize it as follows (some examples):
See the constructor Serialization::Serialization documentation for further use examples.
Definition at line 351 of file Util.h.
Constructor for serializing to/from specified filename.
Note that this is not identical to:
There are differences with these approaches. When using the constructor with 'filename', we use the tinyxml Save and Load methods, while with iostream we use tinyxml operators for << and >> . The prior approach uses properly indented xml-files with XML declaration <?...?>. In the latter approach the indentations and the XML declaration are left out. The XML declaration <?...?> is left out because for some reason tinyxml doesn't parse it correctly when using operator>> .
Definition at line 422 of file Util.cpp.