<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> <title>CSerializable.h Source File</title> <link href="doxygen.css" rel="stylesheet" type="text/css"> <link href="tabs.css" rel="stylesheet" type="text/css"> </head><body> <div align="left"><a href="http://www.mrpt.org/">Main MRPT website</a> > <b>C++ reference</b> </div> <div align="right"> <a href="index.html"><img border="0" src="mrpt_logo.png" alt="MRPT logo"></a> </div> <!-- Generated by Doxygen 1.7.5 --> <script type="text/javascript"> var searchBox = new SearchBox("searchBox", "search",false,'Search'); </script> <div id="navrow1" class="tabs"> <ul class="tablist"> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="pages.html"><span>Related Pages</span></a></li> <li><a href="modules.html"><span>Modules</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="annotated.html"><span>Classes</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> <li> <div id="MSearchBox" class="MSearchBoxInactive"> <div class="left"> <form id="FSearchBox" action="search.php" method="get"> <img id="MSearchSelect" src="search/mag.png" alt=""/> <input type="text" id="MSearchField" name="query" value="Search" size="20" accesskey="S" onfocus="searchBox.OnSearchFieldFocus(true)" onblur="searchBox.OnSearchFieldFocus(false)"/> </form> </div><div class="right"></div> </div> </li> </ul> </div> <div id="navrow2" class="tabs2"> <ul class="tablist"> <li><a href="files.html"><span>File List</span></a></li> <li><a href="globals.html"><span>File Members</span></a></li> </ul> </div> <div class="header"> <div class="headertitle"> <div class="title">CSerializable.h</div> </div> </div> <div class="contents"> <a href="_c_serializable_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* +---------------------------------------------------------------------------+</span> <a name="l00002"></a>00002 <span class="comment"> | The Mobile Robot Programming Toolkit (MRPT) C++ library |</span> <a name="l00003"></a>00003 <span class="comment"> | |</span> <a name="l00004"></a>00004 <span class="comment"> | http://www.mrpt.org/ |</span> <a name="l00005"></a>00005 <span class="comment"> | |</span> <a name="l00006"></a>00006 <span class="comment"> | Copyright (C) 2005-2011 University of Malaga |</span> <a name="l00007"></a>00007 <span class="comment"> | |</span> <a name="l00008"></a>00008 <span class="comment"> | This software was written by the Machine Perception and Intelligent |</span> <a name="l00009"></a>00009 <span class="comment"> | Robotics Lab, University of Malaga (Spain). |</span> <a name="l00010"></a>00010 <span class="comment"> | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> |</span> <a name="l00011"></a>00011 <span class="comment"> | |</span> <a name="l00012"></a>00012 <span class="comment"> | This file is part of the MRPT project. |</span> <a name="l00013"></a>00013 <span class="comment"> | |</span> <a name="l00014"></a>00014 <span class="comment"> | MRPT is free software: you can redistribute it and/or modify |</span> <a name="l00015"></a>00015 <span class="comment"> | it under the terms of the GNU General Public License as published by |</span> <a name="l00016"></a>00016 <span class="comment"> | the Free Software Foundation, either version 3 of the License, or |</span> <a name="l00017"></a>00017 <span class="comment"> | (at your option) any later version. |</span> <a name="l00018"></a>00018 <span class="comment"> | |</span> <a name="l00019"></a>00019 <span class="comment"> | MRPT is distributed in the hope that it will be useful, |</span> <a name="l00020"></a>00020 <span class="comment"> | but WITHOUT ANY WARRANTY; without even the implied warranty of |</span> <a name="l00021"></a>00021 <span class="comment"> | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |</span> <a name="l00022"></a>00022 <span class="comment"> | GNU General Public License for more details. |</span> <a name="l00023"></a>00023 <span class="comment"> | |</span> <a name="l00024"></a>00024 <span class="comment"> | You should have received a copy of the GNU General Public License |</span> <a name="l00025"></a>00025 <span class="comment"> | along with MRPT. If not, see <http://www.gnu.org/licenses/>. |</span> <a name="l00026"></a>00026 <span class="comment"> | |</span> <a name="l00027"></a>00027 <span class="comment"> +---------------------------------------------------------------------------+ */</span> <a name="l00028"></a>00028 <span class="preprocessor">#ifndef CSERIALIZABLE_H</span> <a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#define CSERIALIZABLE_H</span> <a name="l00030"></a>00030 <span class="preprocessor"></span> <a name="l00031"></a>00031 <span class="preprocessor">#include <<a class="code" href="_c_object_8h.html">mrpt/utils/CObject.h</a>></span> <a name="l00032"></a>00032 <span class="preprocessor">#include <<a class="code" href="_c_stream_8h.html">mrpt/utils/CStream.h</a>></span> <a name="l00033"></a>00033 <span class="preprocessor">#include <<a class="code" href="safe__pointers_8h.html">mrpt/utils/safe_pointers.h</a>></span> <a name="l00034"></a>00034 <a name="l00035"></a>00035 <span class="preprocessor">#include <set></span> <a name="l00036"></a>00036 <span class="preprocessor">#include <list></span> <a name="l00037"></a>00037 <a name="l00038"></a>00038 <span class="keyword">namespace </span>mrpt <a name="l00039"></a>00039 {<span class="comment"></span> <a name="l00040"></a>00040 <span class="comment"> /** Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.</span> <a name="l00041"></a>00041 <span class="comment"> * \ingroup mrpt_base_grp</span> <a name="l00042"></a>00042 <span class="comment"> */</span> <a name="l00043"></a>00043 <span class="keyword">namespace </span>utils <a name="l00044"></a>00044 { <a name="l00045"></a><a class="code" href="structmrpt_1_1utils_1_1_c_serializable_ptr.html#a5dd5b25ef6cf4ee98707066d8981dc9a">00045</a> <a class="code" href="_c_object_8h.html#aa64e4575978b49af0f2d47b1fdf5ad75" title="This declaration must be inserted in all CObject classes definition, before the class declaration...">DEFINE_MRPT_OBJECT_PRE</a>( <a class="code" href="classmrpt_1_1utils_1_1_c_serializable.html" title="The virtual base class which provides a unified interface for all persistent objects in MRPT...">CSerializable</a> ) <a name="l00046"></a>00046 <a name="l00047"></a>00047 <span class="comment">/** The virtual base class which provides a unified interface for all persistent objects in MRPT.</span> <a name="l00048"></a>00048 <span class="comment"> * Many important properties of this class are inherited from mrpt::utils::CObject. See that class for more details.</span> <a name="l00049"></a>00049 <span class="comment"> * Refer to the tutorial about <a href="http://www.mrpt.org/Serialization" >serialization</a> in the wiki.</span> <a name="l00050"></a>00050 <span class="comment"> * \sa CStream</span> <a name="l00051"></a>00051 <span class="comment"> * \ingroup mrpt_base_grp</span> <a name="l00052"></a>00052 <span class="comment"> */</span> <a name="l00053"></a>00053 class <a class="code" href="base_2include_2mrpt_2base_2link__pragmas_8h.html#a6045fa0129b1a3d6c8bf895470e66574">BASE_IMPEXP</a> <a class="code" href="classmrpt_1_1utils_1_1_c_serializable.html" title="The virtual base class which provides a unified interface for all persistent objects in MRPT...">CSerializable</a> : public mrpt::utils::<a class="code" href="classmrpt_1_1utils_1_1_c_object.html" title="The virtual base class of all MRPT classes with a unified RTTI system.">CObject</a> <a name="l00054"></a>00054 { <a name="l00055"></a>00055 <span class="comment">// This must be added to any CObject derived class:</span> <a name="l00056"></a><a class="code" href="classmrpt_1_1utils_1_1_c_serializable.html#a6fec28a53e20dfc1c4d046c26f9f7b48">00056</a> <a class="code" href="_c_object_8h.html#a80d5b68d3ba12ec5f640ce53651b121b" title="This declaration must be inserted in virtual CSerializable classes definition:">DEFINE_VIRTUAL_MRPT_OBJECT</a>( <a class="code" href="classmrpt_1_1utils_1_1_c_serializable.html" title="The virtual base class which provides a unified interface for all persistent objects in MRPT...">CSerializable</a> ) <a name="l00057"></a>00057 <a name="l00058"></a><a class="code" href="classmrpt_1_1utils_1_1_c_serializable.html#a51c9d8a08d564387db423282c8d09226">00058</a> virtual ~<a class="code" href="classmrpt_1_1utils_1_1_c_serializable.html" title="The virtual base class which provides a unified interface for all persistent objects in MRPT...">CSerializable</a>() { } <a name="l00059"></a>00059 <a name="l00060"></a>00060 <span class="keyword">protected</span>:<span class="comment"></span> <a name="l00061"></a>00061 <span class="comment"> /** Introduces a pure virtual method responsible for writing to a CStream.</span> <a name="l00062"></a>00062 <span class="comment"> * This can not be used directly be users, instead use "stream << object;"</span> <a name="l00063"></a>00063 <span class="comment"> * for writing it to a stream.</span> <a name="l00064"></a>00064 <span class="comment"> * \param out The output binary stream where object must be dumped.</span> <a name="l00065"></a>00065 <span class="comment"> * \param getVersion If NULL, the object must be dumped. If not, only the</span> <a name="l00066"></a>00066 <span class="comment"> * version of the object dump must be returned in this pointer. This enables</span> <a name="l00067"></a>00067 <span class="comment"> * the versioning of objects dumping and backward compatibility with previously</span> <a name="l00068"></a>00068 <span class="comment"> * stored data.</span> <a name="l00069"></a>00069 <span class="comment"> * \exception std::exception On any error, see CStream::WriteBuffer</span> <a name="l00070"></a>00070 <span class="comment"> * \sa CStream</span> <a name="l00071"></a>00071 <span class="comment"> */</span> <a name="l00072"></a>00072 <span class="keyword">virtual</span> <span class="keywordtype">void</span> writeToStream(<a class="code" href="classmrpt_1_1utils_1_1_c_stream.html" title="This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...">mrpt::utils::CStream</a> &out, <span class="keywordtype">int</span> *getVersion) <span class="keyword">const</span> = 0; <a name="l00073"></a>00073 <span class="comment"></span> <a name="l00074"></a>00074 <span class="comment"> /** Introduces a pure virtual method responsible for loading from a CStream</span> <a name="l00075"></a>00075 <span class="comment"> * This can not be used directly be users, instead use "stream >> object;"</span> <a name="l00076"></a>00076 <span class="comment"> * for reading it from a stream or "stream >> object_ptr;" if the class is</span> <a name="l00077"></a>00077 <span class="comment"> * unknown apriori.</span> <a name="l00078"></a>00078 <span class="comment"> * \param in The input binary stream where the object data must read from.</span> <a name="l00079"></a>00079 <span class="comment"> * \param version The version of the object stored in the stream: use this version</span> <a name="l00080"></a>00080 <span class="comment"> * number in your code to know how to read the incoming data.</span> <a name="l00081"></a>00081 <span class="comment"> * \exception std::exception On any error, see CStream::ReadBuffer</span> <a name="l00082"></a>00082 <span class="comment"> * \sa CStream</span> <a name="l00083"></a>00083 <span class="comment"> */</span> <a name="l00084"></a>00084 <span class="keyword">virtual</span> <span class="keywordtype">void</span> readFromStream(<a class="code" href="classmrpt_1_1utils_1_1_c_stream.html" title="This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...">mrpt::utils::CStream</a> &in, <span class="keywordtype">int</span> version) = 0; <a name="l00085"></a>00085 }; <span class="comment">// End of class def.</span> <a name="l00086"></a>00086 <a name="l00087"></a>00087 <span class="comment"></span> <a name="l00088"></a>00088 <span class="comment"> /** @name Non-streaming serialization functions</span> <a name="l00089"></a>00089 <span class="comment"> @{ */</span> <a name="l00090"></a>00090 <span class="comment"></span> <a name="l00091"></a>00091 <span class="comment"> /** Used to pass MRPT objects into a CORBA-like object (strings). See doc about "Integration with BABEL".</span> <a name="l00092"></a>00092 <span class="comment"> * \param o The object to be serialized.</span> <a name="l00093"></a>00093 <span class="comment"> * \return The string containing the binay version of object.</span> <a name="l00094"></a>00094 <span class="comment"> * \sa StringToObject, <a href="http://www.mrpt.org/Integration_with_BABEL" >Integration with BABEL</a></span> <a name="l00095"></a>00095 <span class="comment"> */</span> <a name="l00096"></a>00096 std::string <a class="code" href="base_2include_2mrpt_2base_2link__pragmas_8h.html#a6045fa0129b1a3d6c8bf895470e66574">BASE_IMPEXP</a> <a class="code" href="namespacemrpt_1_1utils.html#a06ed9b2f48694d76491290d425bcc5b8" title="Used to pass MRPT objects into a CORBA-like object (strings).">ObjectToString</a>(<span class="keyword">const</span> <a class="code" href="namespacemrpt_1_1utils.html#a9f31abb393bf84af21fecce4c4070b40">CSerializable</a> *o); <a name="l00097"></a>00097 <span class="comment"></span> <a name="l00098"></a>00098 <span class="comment"> /** Used to pass CORBA-like objects (strings) into a MRPT object.</span> <a name="l00099"></a>00099 <span class="comment"> * \param str An string generated with ObjectToString</span> <a name="l00100"></a>00100 <span class="comment"> * \param obj A currently empty pointer, where a pointer to the newly created object will be stored.</span> <a name="l00101"></a>00101 <span class="comment"> * \exception None On any internal exception, this function returns NULL.</span> <a name="l00102"></a>00102 <span class="comment"> * \sa ObjectToString, <a href="http://www.mrpt.org/Integration_with_BABEL" >Integration with BABEL</a></span> <a name="l00103"></a>00103 <span class="comment"> */</span> <a name="l00104"></a>00104 <span class="keywordtype">void</span> <a class="code" href="base_2include_2mrpt_2base_2link__pragmas_8h.html#a6045fa0129b1a3d6c8bf895470e66574">BASE_IMPEXP</a> <a class="code" href="namespacemrpt_1_1utils.html#aff5bcfca78de7fe76619e012be514536" title="Used to pass CORBA-like objects (strings) into a MRPT object.">StringToObject</a>(<span class="keyword">const</span> <a class="code" href="classstd_1_1string.html" title="STL class.">std::string</a> &str, <a class="code" href="namespacemrpt_1_1utils.html#a8bda39888b98f509c0d97bf5eebac3c3">CSerializablePtr</a> &obj); <a name="l00105"></a>00105 <span class="comment"></span> <a name="l00106"></a>00106 <span class="comment"> /** Converts (serializes) an MRPT object into an array of bytes.</span> <a name="l00107"></a>00107 <span class="comment"> * \param o The object to be serialized.</span> <a name="l00108"></a>00108 <span class="comment"> * \param out_vector The vector which at return will contain the data. Size will be set automatically.</span> <a name="l00109"></a>00109 <span class="comment"> * \sa OctetVectorToObject, ObjectToString</span> <a name="l00110"></a>00110 <span class="comment"> */</span> <a name="l00111"></a>00111 <span class="keywordtype">void</span> <a class="code" href="base_2include_2mrpt_2base_2link__pragmas_8h.html#a6045fa0129b1a3d6c8bf895470e66574">BASE_IMPEXP</a> <a class="code" href="namespacemrpt_1_1utils.html#a16c964ccdd95e205756d4c9423d327a1" title="Converts (serializes) an MRPT object into an array of bytes.">ObjectToOctetVector</a>(<span class="keyword">const</span> <a class="code" href="namespacemrpt_1_1utils.html#a9f31abb393bf84af21fecce4c4070b40">CSerializable</a> *o, <a class="code" href="classstd_1_1vector.html" title="STL class.">vector_byte</a> & out_vector); <a name="l00112"></a>00112 <span class="comment"></span> <a name="l00113"></a>00113 <span class="comment"> /** Converts back (de-serializes) a sequence of binary data into a MRPT object, without prior information about the object's class.</span> <a name="l00114"></a>00114 <span class="comment"> * \param in_data The serialized input data representing the object.</span> <a name="l00115"></a>00115 <span class="comment"> * \param obj The newly created object will be stored in this smart pointer.</span> <a name="l00116"></a>00116 <span class="comment"> * \exception None On any internal exception, this function returns a NULL pointer.</span> <a name="l00117"></a>00117 <span class="comment"> * \sa ObjectToOctetVector, StringToObject</span> <a name="l00118"></a>00118 <span class="comment"> */</span> <a name="l00119"></a>00119 <span class="keywordtype">void</span> <a class="code" href="base_2include_2mrpt_2base_2link__pragmas_8h.html#a6045fa0129b1a3d6c8bf895470e66574">BASE_IMPEXP</a> <a class="code" href="namespacemrpt_1_1utils.html#ab4df6fdf9180e0b0d68796d04bb491ea" title="Converts back (de-serializes) a sequence of binary data into a MRPT object, without prior information...">OctetVectorToObject</a>(<span class="keyword">const</span> <a class="code" href="classstd_1_1vector.html" title="STL class.">vector_byte</a> & in_data, <a class="code" href="namespacemrpt_1_1utils.html#a8bda39888b98f509c0d97bf5eebac3c3">CSerializablePtr</a> &obj); <a name="l00120"></a>00120 <span class="comment"></span> <a name="l00121"></a>00121 <span class="comment"> /** Converts (serializes) an MRPT object into an array of bytes within a std::string, without codifying to avoid NULL characters.</span> <a name="l00122"></a>00122 <span class="comment"> * This is therefore more efficient than ObjectToString</span> <a name="l00123"></a>00123 <span class="comment"> * \param o The object to be serialized.</span> <a name="l00124"></a>00124 <span class="comment"> * \param out_vector The string which at return will contain the data. Size will be set automatically.</span> <a name="l00125"></a>00125 <span class="comment"> * \sa RawStringToObject, ObjectToOctetVector</span> <a name="l00126"></a>00126 <span class="comment"> */</span> <a name="l00127"></a>00127 <span class="keywordtype">void</span> <a class="code" href="base_2include_2mrpt_2base_2link__pragmas_8h.html#a6045fa0129b1a3d6c8bf895470e66574">BASE_IMPEXP</a> <a class="code" href="namespacemrpt_1_1utils.html#aeae09d5d3a2adbfed024fdbe32ffda21" title="Converts (serializes) an MRPT object into an array of bytes within a std::string, without codifying t...">ObjectToRawString</a>(<span class="keyword">const</span> <a class="code" href="namespacemrpt_1_1utils.html#a9f31abb393bf84af21fecce4c4070b40">CSerializable</a> *o, <a class="code" href="classstd_1_1string.html" title="STL class.">std::string</a> & out_str); <a name="l00128"></a>00128 <span class="comment"></span> <a name="l00129"></a>00129 <span class="comment"> /** Converts back (de-serializes) a sequence of binary data within a std::string into a MRPT object, without prior information about the object's class.</span> <a name="l00130"></a>00130 <span class="comment"> * \param in_data The serialized input data representing the object.</span> <a name="l00131"></a>00131 <span class="comment"> * \param obj The newly created object will be stored in this smart pointer.</span> <a name="l00132"></a>00132 <span class="comment"> * \exception None On any internal exception, this function returns a NULL pointer.</span> <a name="l00133"></a>00133 <span class="comment"> * \sa ObjectToRawString</span> <a name="l00134"></a>00134 <span class="comment"> */</span> <a name="l00135"></a>00135 <span class="keywordtype">void</span> <a class="code" href="base_2include_2mrpt_2base_2link__pragmas_8h.html#a6045fa0129b1a3d6c8bf895470e66574">BASE_IMPEXP</a> <a class="code" href="namespacemrpt_1_1utils.html#a42ebda9258713a4a9bada754001c4d8b" title="Converts back (de-serializes) a sequence of binary data within a std::string into a MRPT object...">RawStringToObject</a>(<span class="keyword">const</span> <a class="code" href="classstd_1_1string.html" title="STL class.">std::string</a> & in_str, <a class="code" href="namespacemrpt_1_1utils.html#a8bda39888b98f509c0d97bf5eebac3c3">CSerializablePtr</a> &obj); <a name="l00136"></a>00136 <span class="comment"></span> <a name="l00137"></a>00137 <span class="comment"> /** @} */</span> <a name="l00138"></a>00138 <a name="l00139"></a>00139 <a name="l00140"></a>00140 <span class="comment"></span> <a name="l00141"></a>00141 <span class="comment"> /** @name Conversion of type to string at compile time</span> <a name="l00142"></a>00142 <span class="comment"> * IMPORTANT: See also the implementation of Serialization for STL containers in mrpt/utils/stl_extensions.h</span> <a name="l00143"></a>00143 <span class="comment"> @{ */</span> <a name="l00144"></a>00144 <span class="comment"></span> <a name="l00145"></a>00145 <span class="comment"> /** A template to obtain the type of its argument as a string at compile time.</span> <a name="l00146"></a>00146 <span class="comment"> * It works with all classes derived from CSerializable, plus many specializations for the plain data types (bool, double, uint8_t, etc...)</span> <a name="l00147"></a>00147 <span class="comment"> * For example:</span> <a name="l00148"></a>00148 <span class="comment"> * \code</span> <a name="l00149"></a>00149 <span class="comment"> * cout << TTypeName<double>::get() << endl; // "double"</span> <a name="l00150"></a>00150 <span class="comment"> * cout << TTypeName<CPose2D>::get() << endl; // "CPose2D"</span> <a name="l00151"></a>00151 <span class="comment"> * cout << TTypeName<mrpt::slam::COccupancyGridMap2D>::get() << endl; // "COccupancyGridMap2D"</span> <a name="l00152"></a>00152 <span class="comment"> * \endcode</span> <a name="l00153"></a>00153 <span class="comment"> *</span> <a name="l00154"></a>00154 <span class="comment"> * Users can extend this for custom structs/classes with the macro DECLARE_CUSTOM_TTYPENAME:</span> <a name="l00155"></a>00155 <span class="comment"> * \code</span> <a name="l00156"></a>00156 <span class="comment"> * class MyClass { ... };</span> <a name="l00157"></a>00157 <span class="comment"> * DECLARE_CUSTOM_TTYPENAME(MyClass)</span> <a name="l00158"></a>00158 <span class="comment"> * cout << TTypeName<MyClass>::get() << endl; // "MyClass"</span> <a name="l00159"></a>00159 <span class="comment"> * \endcode</span> <a name="l00160"></a>00160 <span class="comment"> *</span> <a name="l00161"></a>00161 <span class="comment"> * The following types are NOT ALLOWED since they have platform-dependant sizes:</span> <a name="l00162"></a>00162 <span class="comment"> * - int, unsigned int</span> <a name="l00163"></a>00163 <span class="comment"> * - long, unsigned long</span> <a name="l00164"></a>00164 <span class="comment"> * - short, unsigned short</span> <a name="l00165"></a>00165 <span class="comment"> * - size_t</span> <a name="l00166"></a>00166 <span class="comment"> *</span> <a name="l00167"></a>00167 <span class="comment"> */</span> <a name="l00168"></a>00168 <span class="keyword">template</span><<span class="keyword">typename</span> T> <a name="l00169"></a>00169 <span class="keyword">struct </span>TTypeName <a name="l00170"></a>00170 { <a name="l00171"></a><a class="code" href="structmrpt_1_1utils_1_1_t_type_name.html#a1528b7a1ef2ebab41ca230e5d49f1a6d">00171</a> <span class="keyword">static</span> std<a class="code" href="classstd_1_1string.html" title="STL class.">::string</a> <span class="keyword">get</span>() { <a name="l00172"></a>00172 <span class="keywordflow">return</span> <a class="code" href="classstd_1_1string.html" title="STL class.">std::string</a>( T::classinfo->className ); <a name="l00173"></a>00173 } <a name="l00174"></a>00174 }; <a name="l00175"></a>00175 <span class="comment"></span> <a name="l00176"></a>00176 <span class="comment"> /** Identical to MRPT_DECLARE_TTYPENAME but intended for user code.</span> <a name="l00177"></a>00177 <span class="comment"> * MUST be placed at the GLOBAL namespace.</span> <a name="l00178"></a>00178 <span class="comment"> */</span> <a name="l00179"></a><a class="code" href="_c_serializable_8h.html#aac77500ae43a282574851009d7399d81">00179</a> <span class="preprocessor"> #define DECLARE_CUSTOM_TTYPENAME(_TYPE) \</span> <a name="l00180"></a>00180 <span class="preprocessor"> namespace mrpt { namespace utils { MRPT_DECLARE_TTYPENAME(_TYPE) } }</span> <a name="l00181"></a>00181 <span class="preprocessor"></span> <a name="l00182"></a><a class="code" href="_c_serializable_8h.html#a3d50ead2a44af4340ef8e3a88b78df10">00182</a> <span class="preprocessor"> #define MRPT_DECLARE_TTYPENAME(_TYPE) \</span> <a name="l00183"></a>00183 <span class="preprocessor"> template<> struct TTypeName <_TYPE > { \</span> <a name="l00184"></a>00184 <span class="preprocessor"> static std::string get() { return std::string(#_TYPE); } };</span> <a name="l00185"></a>00185 <span class="preprocessor"></span> <a name="l00186"></a><a class="code" href="_c_serializable_8h.html#a81695246461c7c04018786a6b6e75b6d">00186</a> <span class="preprocessor"> #define MRPT_DECLARE_TTYPENAME_PTR(_TYPE) \</span> <a name="l00187"></a>00187 <span class="preprocessor"> template<> struct TTypeName <_TYPE##Ptr> { \</span> <a name="l00188"></a>00188 <span class="preprocessor"> static std::string get() { return TTypeName<_TYPE>::get(); } };</span> <a name="l00189"></a>00189 <span class="preprocessor"></span> <a name="l00190"></a>00190 <a class="code" href="_c_serializable_8h.html#a3d50ead2a44af4340ef8e3a88b78df10">MRPT_DECLARE_TTYPENAME</a>(<span class="keywordtype">bool</span>) <a name="l00191"></a>00191 <a class="code" href="_c_serializable_8h.html#a3d50ead2a44af4340ef8e3a88b78df10">MRPT_DECLARE_TTYPENAME</a>(<span class="keywordtype">double</span>) <a name="l00192"></a>00192 <a class="code" href="_c_serializable_8h.html#a3d50ead2a44af4340ef8e3a88b78df10">MRPT_DECLARE_TTYPENAME</a>(<span class="keywordtype">float</span>) <a name="l00193"></a>00193 <a class="code" href="_c_serializable_8h.html#a3d50ead2a44af4340ef8e3a88b78df10">MRPT_DECLARE_TTYPENAME</a>(uint64_t) <a name="l00194"></a>00194 <a class="code" href="_c_serializable_8h.html#a3d50ead2a44af4340ef8e3a88b78df10">MRPT_DECLARE_TTYPENAME</a>(int64_t) <a name="l00195"></a>00195 <a class="code" href="_c_serializable_8h.html#a3d50ead2a44af4340ef8e3a88b78df10">MRPT_DECLARE_TTYPENAME</a>(uint32_t) <a name="l00196"></a>00196 <a class="code" href="_c_serializable_8h.html#a3d50ead2a44af4340ef8e3a88b78df10">MRPT_DECLARE_TTYPENAME</a>(int32_t) <a name="l00197"></a>00197 <a class="code" href="_c_serializable_8h.html#a3d50ead2a44af4340ef8e3a88b78df10">MRPT_DECLARE_TTYPENAME</a>(uint16_t) <a name="l00198"></a>00198 <a class="code" href="_c_serializable_8h.html#a3d50ead2a44af4340ef8e3a88b78df10">MRPT_DECLARE_TTYPENAME</a>(int16_t) <a name="l00199"></a>00199 <a class="code" href="_c_serializable_8h.html#a3d50ead2a44af4340ef8e3a88b78df10">MRPT_DECLARE_TTYPENAME</a>(uint8_t) <a name="l00200"></a>00200 <a class="code" href="_c_serializable_8h.html#a3d50ead2a44af4340ef8e3a88b78df10">MRPT_DECLARE_TTYPENAME</a>(int8_t) <a name="l00201"></a>00201 <a name="l00202"></a>00202 <a class="code" href="_c_serializable_8h.html#a3d50ead2a44af4340ef8e3a88b78df10">MRPT_DECLARE_TTYPENAME</a>(std::<span class="keywordtype">string</span>) <a name="l00203"></a>00203 <a name="l00204"></a>00204 <a name="l00205"></a><a class="code" href="_c_serializable_8h.html#a988f455c4e9dbf9c78f58adc75627fdc">00205</a> <span class="preprocessor">#define MRPT_DECLARE_TTYPENAME_CONTAINER(_CONTAINER) \</span> <a name="l00206"></a>00206 <span class="preprocessor"> template< typename V > \</span> <a name="l00207"></a>00207 <span class="preprocessor"> struct TTypeName <_CONTAINER<V> > { \</span> <a name="l00208"></a>00208 <span class="preprocessor"> static std::string get() { \</span> <a name="l00209"></a>00209 <span class="preprocessor"> return std::string( #_CONTAINER )+std::string("<")+std::string( TTypeName<V>::get() ) + std::string(">"); \</span> <a name="l00210"></a>00210 <span class="preprocessor"> } \</span> <a name="l00211"></a>00211 <span class="preprocessor"> };</span> <a name="l00212"></a>00212 <span class="preprocessor"></span> <a name="l00213"></a>00213 <a class="code" href="_c_serializable_8h.html#a988f455c4e9dbf9c78f58adc75627fdc">MRPT_DECLARE_TTYPENAME_CONTAINER</a>( <a class="code" href="classstd_1_1vector.html" title="STL class.">std::vector</a> ) <a name="l00214"></a>00214 <a class="code" href="_c_serializable_8h.html#a988f455c4e9dbf9c78f58adc75627fdc">MRPT_DECLARE_TTYPENAME_CONTAINER</a>( std::deque ) <a name="l00215"></a>00215 <a class="code" href="_c_serializable_8h.html#a988f455c4e9dbf9c78f58adc75627fdc">MRPT_DECLARE_TTYPENAME_CONTAINER</a>( std::list ) <a name="l00216"></a>00216 <a class="code" href="_c_serializable_8h.html#a988f455c4e9dbf9c78f58adc75627fdc">MRPT_DECLARE_TTYPENAME_CONTAINER</a>( std::set ) <a name="l00217"></a>00217 <a name="l00218"></a>00218 <span class="comment">// These ones act as a "translation" between vector_XXX types and their base classes:</span> <a name="l00219"></a><a class="code" href="_c_serializable_8h.html#a31a2cb66ebc61fff6cd6d5e3d9465c19">00219</a> <span class="preprocessor">#define MRPT_DECLARE_TTYPENAME_MAP_FOR_VECTOR(_CONT) \</span> <a name="l00220"></a>00220 <span class="preprocessor"> template<> struct TTypeName <_CONT> : TTypeName<std::vector<_CONT::Scalar> > { };</span> <a name="l00221"></a>00221 <span class="preprocessor"></span> <a name="l00222"></a>00222 <a class="code" href="_c_serializable_8h.html#a31a2cb66ebc61fff6cd6d5e3d9465c19">MRPT_DECLARE_TTYPENAME_MAP_FOR_VECTOR</a>(<a class="code" href="namespacemrpt.html#aa271572e3985202e030758bfd54a02e1">vector_float</a>) <a name="l00223"></a>00223 <a class="code" href="_c_serializable_8h.html#a31a2cb66ebc61fff6cd6d5e3d9465c19">MRPT_DECLARE_TTYPENAME_MAP_FOR_VECTOR</a>(<a class="code" href="namespacemrpt.html#a4a6aab2c98368ca6b554c04f8fe84cfb">vector_double</a>) <a name="l00224"></a>00224 <a name="l00225"></a>00225 <span class="comment">// These ones are not needed since typedef's of "std::vector<>" are automatically supported</span> <a name="l00226"></a>00226 <span class="comment">//MRPT_DECLARE_TTYPENAME_MAP_FOR_STDVECTOR(vector_signed_byte )</span> <a name="l00227"></a>00227 <span class="comment">//MRPT_DECLARE_TTYPENAME_MAP_FOR_STDVECTOR(vector_signed_word)</span> <a name="l00228"></a>00228 <span class="comment">//MRPT_DECLARE_TTYPENAME_MAP_FOR_STDVECTOR(vector_int)</span> <a name="l00229"></a>00229 <span class="comment">//MRPT_DECLARE_TTYPENAME_MAP_FOR_STDVECTOR(vector_long)</span> <a name="l00230"></a>00230 <span class="comment">//MRPT_DECLARE_TTYPENAME_MAP_FOR_STDVECTOR(vector_byte)</span> <a name="l00231"></a>00231 <span class="comment">//MRPT_DECLARE_TTYPENAME_MAP_FOR_STDVECTOR(vector_word)</span> <a name="l00232"></a>00232 <span class="comment">//MRPT_DECLARE_TTYPENAME_MAP_FOR_STDVECTOR(vector_uint)</span> <a name="l00233"></a>00233 <span class="comment">//#if MRPT_WORD_SIZE!=32 // If it's 32 bit, size_t <=> uint32_t</span> <a name="l00234"></a>00234 <span class="comment">//MRPT_DECLARE_TTYPENAME_MAP_FOR_STDVECTOR(vector_size_t)</span> <a name="l00235"></a>00235 <span class="comment">//#endif</span> <a name="l00236"></a>00236 <a name="l00237"></a>00237 <a name="l00238"></a><a class="code" href="_c_serializable_8h.html#aea6791b84a5804fa07c5a6923409b446">00238</a> <span class="preprocessor">#define MRPT_DECLARE_TTYPENAME_CONTAINER_ASSOC(_CONTAINER) \</span> <a name="l00239"></a>00239 <span class="preprocessor"> template< typename K, typename V > \</span> <a name="l00240"></a>00240 <span class="preprocessor"> struct TTypeName <_CONTAINER<K,V> > { \</span> <a name="l00241"></a>00241 <span class="preprocessor"> static std::string get() { \</span> <a name="l00242"></a>00242 <span class="preprocessor"> return std::string( #_CONTAINER )+std::string("<")+std::string( TTypeName<K>::get() )+ std::string(",")+std::string( TTypeName<V>::get() )+std::string(">"); \</span> <a name="l00243"></a>00243 <span class="preprocessor"> } \</span> <a name="l00244"></a>00244 <span class="preprocessor"> };</span> <a name="l00245"></a>00245 <span class="preprocessor"></span> <a name="l00246"></a>00246 <a class="code" href="_c_serializable_8h.html#aea6791b84a5804fa07c5a6923409b446">MRPT_DECLARE_TTYPENAME_CONTAINER_ASSOC</a>( <a class="code" href="classstd_1_1map.html" title="STL class.">std::map</a> ) <a name="l00247"></a>00247 <a class="code" href="_c_serializable_8h.html#aea6791b84a5804fa07c5a6923409b446">MRPT_DECLARE_TTYPENAME_CONTAINER_ASSOC</a>( std::multimap ) <a name="l00248"></a>00248 <a name="l00249"></a>00249 <a name="l00250"></a>00250 template< typename T1, typename T2 > <a name="l00251"></a>00251 struct TTypeName <std::pair<T1,T2> > { <a name="l00252"></a><a class="code" href="structmrpt_1_1utils_1_1_t_type_name_3_01std_1_1pair_3_01_t1_00_01_t2_01_4_01_4.html#a11a30b6e508f4016add1f23bb74f9760">00252</a> <span class="keyword">static</span> std<a class="code" href="classstd_1_1string.html" title="STL class.">::string</a> <span class="keyword">get</span>() { <a name="l00253"></a>00253 <span class="keywordflow">return</span> <a class="code" href="classstd_1_1string.html" title="STL class.">std::string</a>(<span class="stringliteral">"std::pair<"</span>)+<a class="code" href="classstd_1_1string.html" title="STL class.">std::string</a>( <a class="code" href="structmrpt_1_1utils_1_1_t_type_name.html" title="A template to obtain the type of its argument as a string at compile time.">TTypeName<T1>::get</a>() )+ <a class="code" href="classstd_1_1string.html" title="STL class.">std::string</a>(<span class="stringliteral">","</span>)+<a class="code" href="classstd_1_1string.html" title="STL class.">std::string</a>( <a class="code" href="structmrpt_1_1utils_1_1_t_type_name.html" title="A template to obtain the type of its argument as a string at compile time.">TTypeName<T2>::get</a>() )+<a class="code" href="classstd_1_1string.html" title="STL class.">std::string</a>(<span class="stringliteral">">"</span>); <a name="l00254"></a>00254 } <a name="l00255"></a>00255 }; <a name="l00256"></a>00256 <span class="comment"></span> <a name="l00257"></a>00257 <span class="comment"> /** @} */</span> <a name="l00258"></a>00258 <a name="l00259"></a>00259 <span class="comment"></span> <a name="l00260"></a>00260 <span class="comment"> /** This declaration must be inserted in all CSerializable classes definition, within the class declaration.</span> <a name="l00261"></a>00261 <span class="comment"> */</span> <a name="l00262"></a><a class="code" href="_c_serializable_8h.html#a72ab55bf7ae009c89b75715cfa21e84d">00262</a> <span class="preprocessor"> #define DEFINE_SERIALIZABLE(class_name) \</span> <a name="l00263"></a>00263 <span class="preprocessor"> DEFINE_MRPT_OBJECT(class_name) \</span> <a name="l00264"></a>00264 <span class="preprocessor"> protected: \</span> <a name="l00265"></a>00265 <span class="preprocessor"></span><span class="comment"> /*! @name CSerializable virtual methods */</span> \ <a name="l00266"></a>00266 <span class="comment"> /*! @{ */</span> \ <a name="l00267"></a>00267 void writeToStream(mrpt::utils::CStream &out, int *getVersion) const;\ <a name="l00268"></a>00268 void readFromStream(mrpt::utils::CStream &in, int version); \ <a name="l00269"></a>00269 <span class="comment"> /*! @} */</span> <a name="l00270"></a>00270 <span class="comment"></span> <a name="l00271"></a>00271 <span class="comment"> /** This declaration must be inserted in all CSerializable classes definition, before the class declaration.</span> <a name="l00272"></a>00272 <span class="comment"> */</span> <a name="l00273"></a><a class="code" href="_c_serializable_8h.html#a4f65adffe92332a1a157f834338b1d49">00273</a> <span class="preprocessor"> #define DEFINE_SERIALIZABLE_PRE_CUSTOM_LINKAGE(class_name,_LINKAGE_) \</span> <a name="l00274"></a>00274 <span class="preprocessor"> DEFINE_MRPT_OBJECT_PRE_CUSTOM_BASE_LINKAGE2(class_name, CSerializable, _LINKAGE_ class_name) \</span> <a name="l00275"></a>00275 <span class="preprocessor"> _LINKAGE_ ::mrpt::utils::CStream& operator>>(mrpt::utils::CStream& in, class_name##Ptr &pObj);</span> <a name="l00276"></a>00276 <span class="preprocessor"></span> <a name="l00277"></a>00277 <span class="comment"></span> <a name="l00278"></a>00278 <span class="comment"> /** This declaration must be inserted in all CSerializable classes definition, before the class declaration.</span> <a name="l00279"></a>00279 <span class="comment"> */</span> <a name="l00280"></a><a class="code" href="_c_serializable_8h.html#a5155da97198db5986e6369e2fe7a3539">00280</a> <span class="preprocessor"> #define DEFINE_SERIALIZABLE_PRE(class_name) \</span> <a name="l00281"></a>00281 <span class="preprocessor"> DEFINE_MRPT_OBJECT_PRE_CUSTOM_BASE_LINKAGE2(class_name, CSerializable, BASE_IMPEXP class_name) \</span> <a name="l00282"></a>00282 <span class="preprocessor"> BASE_IMPEXP ::mrpt::utils::CStream& operator>>(mrpt::utils::CStream& in, class_name##Ptr &pObj);</span> <a name="l00283"></a>00283 <span class="preprocessor"></span><span class="comment"></span> <a name="l00284"></a>00284 <span class="comment"> /** This declaration must be inserted in all CSerializable classes definition, before the class declaration.</span> <a name="l00285"></a>00285 <span class="comment"> */</span> <a name="l00286"></a><a class="code" href="_c_serializable_8h.html#a9ef523d787f6cb837a0585b790882588">00286</a> <span class="preprocessor"> #define DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_ ) \</span> <a name="l00287"></a>00287 <span class="preprocessor"> DEFINE_MRPT_OBJECT_PRE_CUSTOM_BASE_LINKAGE2(class_name, base_name, _LINKAGE_ class_name) \</span> <a name="l00288"></a>00288 <span class="preprocessor"> _LINKAGE_ ::mrpt::utils::CStream& operator>>(mrpt::utils::CStream& in, class_name##Ptr &pObj);</span> <a name="l00289"></a>00289 <span class="preprocessor"></span> <a name="l00290"></a>00290 <span class="comment"></span> <a name="l00291"></a>00291 <span class="comment"> /** This declaration must be inserted in all CSerializable classes definition, before the class declaration.</span> <a name="l00292"></a>00292 <span class="comment"> */</span> <a name="l00293"></a><a class="code" href="_c_serializable_8h.html#ab89b7a3de0a1baf5a5af4454add7d0f8">00293</a> <span class="preprocessor"> #define DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE(class_name, base_name) \</span> <a name="l00294"></a>00294 <span class="preprocessor"> DEFINE_MRPT_OBJECT_PRE_CUSTOM_BASE_LINKAGE(class_name, base_name, BASE_IMPEXP ) \</span> <a name="l00295"></a>00295 <span class="preprocessor"> BASE_IMPEXP ::mrpt::utils::CStream& operator>>(mrpt::utils::CStream& in, class_name##Ptr &pObj);</span> <a name="l00296"></a>00296 <span class="preprocessor"></span><span class="comment"></span> <a name="l00297"></a>00297 <span class="comment"> /** This must be inserted in all CSerializable classes implementation files:</span> <a name="l00298"></a>00298 <span class="comment"> */</span> <a name="l00299"></a><a class="code" href="_c_serializable_8h.html#a5720fe2c7372e6b325004e7bdc5dd692">00299</a> <span class="preprocessor"> #define IMPLEMENTS_SERIALIZABLE(class_name, base,NameSpace) \</span> <a name="l00300"></a>00300 <span class="preprocessor"> IMPLEMENTS_MRPT_OBJECT(class_name, base,NameSpace) \</span> <a name="l00301"></a>00301 <span class="preprocessor"> mrpt::utils::CStream& NameSpace::operator>>(mrpt::utils::CStream& in, NameSpace::class_name##Ptr &pObj) \</span> <a name="l00302"></a>00302 <span class="preprocessor"> { pObj = NameSpace::class_name##Ptr( in.ReadObject() ); return in; }</span> <a name="l00303"></a>00303 <span class="preprocessor"></span><span class="comment"></span> <a name="l00304"></a>00304 <span class="comment"> /** This declaration must be inserted in virtual CSerializable classes definition:</span> <a name="l00305"></a>00305 <span class="comment"> */</span> <a name="l00306"></a><a class="code" href="_c_serializable_8h.html#a5876f72cf51bfb66a82bf81cc493febc">00306</a> <span class="preprocessor"> #define DEFINE_VIRTUAL_SERIALIZABLE(class_name) \</span> <a name="l00307"></a>00307 <span class="preprocessor"> DEFINE_VIRTUAL_MRPT_OBJECT(class_name)</span> <a name="l00308"></a>00308 <span class="preprocessor"></span><span class="comment"></span> <a name="l00309"></a>00309 <span class="comment"> /** This must be inserted as implementation of some required members for</span> <a name="l00310"></a>00310 <span class="comment"> * virtual CSerializable classes:</span> <a name="l00311"></a>00311 <span class="comment"> */</span> <a name="l00312"></a><a class="code" href="_c_serializable_8h.html#a9dcb53a0dc06be1b78b78046f7e9757a">00312</a> <span class="preprocessor"> #define IMPLEMENTS_VIRTUAL_SERIALIZABLE(class_name, base_class_name,NameSpace) \</span> <a name="l00313"></a>00313 <span class="preprocessor"> IMPLEMENTS_VIRTUAL_MRPT_OBJECT(class_name, base_class_name,NameSpace) \</span> <a name="l00314"></a>00314 <span class="preprocessor"> mrpt::utils::CStream& NameSpace::operator>>(mrpt::utils::CStream& in, class_name##Ptr &pObj) \</span> <a name="l00315"></a>00315 <span class="preprocessor"> { pObj = class_name##Ptr( in.ReadObject() ); return in; }</span> <a name="l00316"></a>00316 <span class="preprocessor"></span> <a name="l00317"></a>00317 <a name="l00318"></a>00318 } <span class="comment">// End of namespace</span> <a name="l00319"></a>00319 } <span class="comment">// End of namespace</span> <a name="l00320"></a>00320 <a name="l00321"></a>00321 <span class="preprocessor">#endif</span> </pre></div></div> </div> <br><hr><br> <table border="0" width="100%"> <tr> <td> Page generated by <a href="http://www.doxygen.org" target="_blank">Doxygen 1.7.5</a> for MRPT 0.9.5 SVN: at Sun Sep 25 17:20:18 UTC 2011</td><td></td> <td width="100"> </td> <td width="150"> </td></tr> </table> </body></html>