|
bool | IsInput () |
| Method for checking if we are inputting or outputting. Can be used from your serializable class. More...
|
|
template<class C > |
Serialization & | operator<< (C &serializable) |
| Operator for outputting a serializable class into the defined filename or std::iostream. More...
|
|
template<class C > |
Serialization & | operator>> (C &serializable) |
| Operator for reading a serializable class from the defined filename or std::iostream. More...
|
|
| Serialization (std::string _filename) |
| Constructor for serializing to/from specified filename. More...
|
|
| Serialization (std::basic_iostream< char > &_stream) |
| Constructor for serializing any iostream (e.g. std::stringstream) More...
|
|
| Serialization (std::basic_istream< char > &_stream) |
| Constructor for serializing any istream (e.g. std::cin) More...
|
|
| Serialization (std::basic_ostream< char > &_stream) |
| Constructor for serializing any ostream (e.g. std::cout) More...
|
|
bool | Serialize (int &data, const std::string &name) |
| Method for serializing 'int' data element. Used from your serializable class. More...
|
|
bool | Serialize (unsigned short &data, const std::string &name) |
| Method for serializing 'int' data element. Used from your serializable class. More...
|
|
bool | Serialize (unsigned long &data, const std::string &name) |
| Method for serializing 'int' data element. Used from your serializable class. More...
|
|
bool | Serialize (double &data, const std::string &name) |
| Method for serializing 'double' data element. Used from your serializable class. More...
|
|
bool | Serialize (std::string &data, const std::string &name) |
| Method for serializing 'std::string' data element. Used from your serializable class. More...
|
|
bool | Serialize (CvMat &data, const std::string &name) |
| Method for serializing 'CvMat' data element. Used from your serializable class. More...
|
|
template<class C > |
bool | SerializeClass (C &serializable) |
| Method for serializing a serializable class. Used by operators << and >> . More...
|
|
| ~Serialization () |
| Destructor. More...
|
|
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"; };
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):
std::stringstream ss;
std::cout<<ss.str()<<std::endl;
See the constructor Serialization::Serialization documentation for further use examples.
Definition at line 352 of file Util.h.
alvar::Serialization::Serialization |
( |
std::string |
_filename | ) |
|
Constructor for serializing to/from specified filename.
Note that this is not identical to:
ofstream ofs("test1.xml");
ifstream ifs("test1.xml");
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.