<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <title>ucommon: ucommon/persist.h Source File</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <link href="navtree.css" rel="stylesheet" type="text/css"/> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="navtree.js"></script> <script type="text/javascript" src="resize.js"></script> <script type="text/javascript"> $(document).ready(initResizable); </script> <link href="doxygen.css" rel="stylesheet" type="text/css"/> </head> <body> <!-- Generated by Doxygen 1.7.3 --> <div id="top"> <div id="titlearea"> <table cellspacing="0" cellpadding="0"> <tbody> <tr style="height: 56px;"> <td style="padding-left: 0.5em;"> <div id="projectname">ucommon</div> </td> </tr> </tbody> </table> </div> <div id="navrow1" class="tabs"> <ul class="tablist"> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="annotated.html"><span>Data Structures</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> <li><a href="examples.html"><span>Examples</span></a></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>Globals</span></a></li> </ul> </div> </div> <div id="side-nav" class="ui-resizable side-nav-resizable"> <div id="nav-tree"> <div id="nav-tree-contents"> </div> </div> <div id="splitbar" style="-moz-user-select:none;" class="ui-resizable-handle"> </div> </div> <script type="text/javascript"> initNavTree('a00192.html',''); </script> <div id="doc-content"> <div class="header"> <div class="headertitle"> <h1>ucommon/persist.h</h1> </div> </div> <div class="contents"> <a href="a00192.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// Copyright (C) 2006-2010 David Sugar, Tycho Softworks.</span> <a name="l00002"></a>00002 <span class="comment">//</span> <a name="l00003"></a>00003 <span class="comment">// This file is part of GNU uCommon C++.</span> <a name="l00004"></a>00004 <span class="comment">//</span> <a name="l00005"></a>00005 <span class="comment">// GNU uCommon C++ is free software: you can redistribute it and/or modify</span> <a name="l00006"></a>00006 <span class="comment">// it under the terms of the GNU Lesser General Public License as published</span> <a name="l00007"></a>00007 <span class="comment">// by the Free Software Foundation, either version 3 of the License, or</span> <a name="l00008"></a>00008 <span class="comment">// (at your option) any later version.</span> <a name="l00009"></a>00009 <span class="comment">//</span> <a name="l00010"></a>00010 <span class="comment">// GNU uCommon C++ is distributed in the hope that it will be useful,</span> <a name="l00011"></a>00011 <span class="comment">// but WITHOUT ANY WARRANTY; without even the implied warranty of</span> <a name="l00012"></a>00012 <span class="comment">// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span> <a name="l00013"></a>00013 <span class="comment">// GNU Lesser General Public License for more details.</span> <a name="l00014"></a>00014 <span class="comment">//</span> <a name="l00015"></a>00015 <span class="comment">// You should have received a copy of the GNU Lesser General Public License</span> <a name="l00016"></a>00016 <span class="comment">// along with GNU uCommon C++. If not, see <http://www.gnu.org/licenses/>.</span> <a name="l00017"></a>00017 <a name="l00023"></a>00023 <span class="preprocessor">#if defined(OLD_STDCPP) || defined(NEW_STDCPP)</span> <a name="l00024"></a>00024 <span class="preprocessor"></span><span class="preprocessor">#if !defined(_MSC_VER) || _MSC_VER >= 1400</span> <a name="l00025"></a>00025 <span class="preprocessor"></span><span class="preprocessor">#ifndef _UCOMMON_PERSIST_H_</span> <a name="l00026"></a>00026 <span class="preprocessor"></span><span class="preprocessor">#define _UCOMMON_PERSIST_H_</span> <a name="l00027"></a>00027 <span class="preprocessor"></span> <a name="l00028"></a>00028 <span class="preprocessor">#ifndef _UCOMMON_PLATFORM_H_</span> <a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#include <ucommon/platform.h></span> <a name="l00030"></a>00030 <span class="preprocessor">#endif</span> <a name="l00031"></a>00031 <span class="preprocessor"></span> <a name="l00032"></a>00032 <span class="preprocessor">#include <iostream></span> <a name="l00033"></a>00033 <span class="preprocessor">#include <string></span> <a name="l00034"></a>00034 <span class="preprocessor">#include <vector></span> <a name="l00035"></a>00035 <span class="preprocessor">#include <deque></span> <a name="l00036"></a>00036 <span class="preprocessor">#include <map></span> <a name="l00037"></a>00037 <a name="l00038"></a>00038 NAMESPACE_UCOMMON <a name="l00039"></a>00039 <span class="preprocessor">#define NS_PREFIX ucc::</span> <a name="l00040"></a>00040 <span class="preprocessor"></span> <a name="l00041"></a>00041 <span class="comment">// This typedef allows us to declare NewPersistObjectFunction now</span> <a name="l00042"></a>00042 <span class="keyword">typedef</span> <span class="keyword">class </span><a class="code" href="a00106.html" title="PersistObject.">PersistObject</a>* (*NewPersistObjectFunction) (void); <a name="l00043"></a>00043 <a name="l00044"></a>00044 <span class="keyword">class </span>__EXPORT PersistException <a name="l00045"></a>00045 { <a name="l00046"></a>00046 <span class="keyword">public</span>: <a name="l00047"></a>00047 PersistException(<span class="keyword">const</span> std::string& reason); <a name="l00048"></a>00048 <span class="keyword">const</span> std::string& getString() <span class="keyword">const</span>; <a name="l00049"></a>00049 <a name="l00050"></a>00050 <span class="keyword">virtual</span> ~PersistException() throw(); <a name="l00051"></a>00051 <a name="l00052"></a>00052 protected: <a name="l00053"></a>00053 std::<span class="keywordtype">string</span> _what; <a name="l00054"></a>00054 }; <a name="l00055"></a>00055 <a name="l00064"></a><a class="code" href="a00166.html">00064</a> class __EXPORT <a class="code" href="a00166.html" title="Type manager for persistence engine.">TypeManager</a> <a name="l00065"></a>00065 { <a name="l00066"></a>00066 <span class="keyword">public</span>: <a name="l00071"></a><a class="code" href="a00167.html">00071</a> <span class="keyword">class </span><a class="code" href="a00167.html" title="This manages a registration to the typemanager - attempting to remove problems with the optimizers...">registration</a> <a name="l00072"></a>00072 { <a name="l00073"></a>00073 <span class="keyword">public</span>: <a name="l00074"></a>00074 <a class="code" href="a00167.html" title="This manages a registration to the typemanager - attempting to remove problems with the optimizers...">registration</a>(<span class="keyword">const</span> <span class="keywordtype">char</span>* name, NewPersistObjectFunction func); <a name="l00075"></a>00075 <span class="keyword">virtual</span> ~<a class="code" href="a00167.html" title="This manages a registration to the typemanager - attempting to remove problems with the optimizers...">registration</a>(); <a name="l00076"></a>00076 <span class="keyword">private</span>: <a name="l00077"></a>00077 std::string myName; <a name="l00078"></a>00078 }; <a name="l00079"></a>00079 <a name="l00083"></a>00083 <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="a00187.html#acb69ad5389c3840d5c5a88bd56912459" title="Add a linked object onto a stack of linked objects.">add</a>(<span class="keyword">const</span> <span class="keywordtype">char</span>* name, NewPersistObjectFunction construction); <a name="l00084"></a>00084 <a name="l00088"></a>00088 <span class="keyword">static</span> <span class="keywordtype">void</span> <span class="keyword">remove</span>(<span class="keyword">const</span> <span class="keywordtype">char</span>* name); <a name="l00089"></a>00089 <a name="l00095"></a>00095 <span class="keyword">static</span> <a class="code" href="a00106.html" title="PersistObject.">PersistObject</a>* createInstanceOf(<span class="keyword">const</span> <span class="keywordtype">char</span>* name); <a name="l00096"></a>00096 <a name="l00097"></a>00097 <span class="keyword">typedef</span> std::map<std::string,NewPersistObjectFunction> StringFunctionMap; <a name="l00098"></a>00098 }; <a name="l00099"></a>00099 <a name="l00100"></a>00100 <span class="comment">/*</span> <a name="l00101"></a>00101 <span class="comment"> * The following defines are used to declare and define the relevant code</span> <a name="l00102"></a>00102 <span class="comment"> * to allow a class to use the Persistence::Engine code.</span> <a name="l00103"></a>00103 <span class="comment"> */</span> <a name="l00104"></a>00104 <a name="l00105"></a>00105 <span class="preprocessor">#define DECLARE_PERSISTENCE(ClassType) \</span> <a name="l00106"></a>00106 <span class="preprocessor"> public: \</span> <a name="l00107"></a>00107 <span class="preprocessor"> friend NS_PREFIX PersistEngine& operator>>( NS_PREFIX PersistEngine& ar, ClassType *&ob); \</span> <a name="l00108"></a>00108 <span class="preprocessor"> friend NS_PREFIX PersistEngine& operator<<( NS_PREFIX PersistEngine& ar, ClassType const &ob); \</span> <a name="l00109"></a>00109 <span class="preprocessor"> friend NS_PREFIX PersistObject *createNew##ClassType(); \</span> <a name="l00110"></a>00110 <span class="preprocessor"> virtual const char* getPersistenceID() const; \</span> <a name="l00111"></a>00111 <span class="preprocessor"> static NS_PREFIX TypeManager::Registration registrationFor##ClassType;</span> <a name="l00112"></a>00112 <span class="preprocessor"></span> <a name="l00113"></a>00113 <span class="preprocessor">#define IMPLEMENT_PERSISTENCE(ClassType, FullyQualifiedName) \</span> <a name="l00114"></a>00114 <span class="preprocessor"> NS_PREFIX PersistObject *createNew##ClassType() { return new ClassType; } \</span> <a name="l00115"></a>00115 <span class="preprocessor"> const char* ClassType::getPersistenceID() const {return FullyQualifiedName;} \</span> <a name="l00116"></a>00116 <span class="preprocessor"> NS_PREFIX PersistEngine& operator>>(NS_PREFIX PersistEngine& ar, ClassType &ob) \</span> <a name="l00117"></a>00117 <span class="preprocessor"> { ar >> (NS_PREFIX PersistObject &) ob; return ar; } \</span> <a name="l00118"></a>00118 <span class="preprocessor"> NS_PREFIX PersistEngine& operator>>(NS_PREFIX PersistEngine& ar, ClassType *&ob) \</span> <a name="l00119"></a>00119 <span class="preprocessor"> { ar >> (NS_PREFIX PersistObject *&) ob; return ar; } \</span> <a name="l00120"></a>00120 <span class="preprocessor"> NS_PREFIX PersistEngine& operator<<(NS_PREFIX PersistEngine& ar, ClassType const &ob) \</span> <a name="l00121"></a>00121 <span class="preprocessor"> { ar << (NS_PREFIX PersistObject const *)&ob; return ar; } \</span> <a name="l00122"></a>00122 <span class="preprocessor"> NS_PREFIX TypeManager::Registration \</span> <a name="l00123"></a>00123 <span class="preprocessor"> ClassType::registrationFor##ClassType(FullyQualifiedName, \</span> <a name="l00124"></a>00124 <span class="preprocessor"> createNew##ClassType);</span> <a name="l00125"></a>00125 <span class="preprocessor"></span> <a name="l00126"></a>00126 <span class="keyword">class </span><a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>; <a name="l00127"></a>00127 <a name="l00147"></a><a class="code" href="a00106.html">00147</a> <span class="keyword">class </span>__EXPORT <a class="code" href="a00106.html" title="PersistObject.">PersistObject</a> <a name="l00148"></a>00148 { <a name="l00149"></a>00149 <span class="keyword">public</span>: <a name="l00155"></a>00155 <a class="code" href="a00106.html" title="PersistObject.">PersistObject</a>(); <a name="l00156"></a>00156 <a name="l00160"></a>00160 <span class="keyword">virtual</span> ~<a class="code" href="a00106.html" title="PersistObject.">PersistObject</a>(); <a name="l00161"></a>00161 <a name="l00165"></a>00165 <span class="keyword">virtual</span> <span class="keyword">const</span> <span class="keywordtype">char</span>* getPersistenceID() <span class="keyword">const</span>; <a name="l00166"></a>00166 <a name="l00172"></a>00172 <span class="keyword">virtual</span> <span class="keywordtype">bool</span> write(<a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& archive) <span class="keyword">const</span>; <a name="l00173"></a>00173 <a name="l00179"></a>00179 <span class="keyword">virtual</span> <span class="keywordtype">bool</span> read(<a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& archive); <a name="l00180"></a>00180 }; <a name="l00181"></a>00181 <a name="l00190"></a><a class="code" href="a00105.html">00190</a> <span class="keyword">class </span>__EXPORT <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a> <a name="l00191"></a>00191 { <a name="l00192"></a>00192 <span class="keyword">public</span>: <a name="l00196"></a><a class="code" href="a00105.html#a36f88957bf7f7105d4eed1d0af52132d">00196</a> <span class="keyword">enum</span> <a class="code" href="a00105.html#a36f88957bf7f7105d4eed1d0af52132d" title="These are the modes the Persistence::Engine can work in.">EngineMode</a> { <a name="l00197"></a>00197 modeRead, <a name="l00198"></a>00198 modeWrite <a name="l00199"></a>00199 }; <a name="l00200"></a>00200 <a name="l00206"></a>00206 <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>(std::iostream& stream, EngineMode mode) <span class="keywordflow">throw</span>(PersistException); <a name="l00207"></a>00207 <a name="l00208"></a>00208 <span class="keyword">virtual</span> ~<a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>(); <a name="l00209"></a>00209 <a name="l00210"></a>00210 <span class="comment">// Write operations</span> <a name="l00211"></a>00211 <a name="l00215"></a><a class="code" href="a00105.html#a7828aecc7f2895f4226aeb98110d42de">00215</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> write(<span class="keyword">const</span> <a class="code" href="a00106.html" title="PersistObject.">PersistObject</a> &<span class="keywordtype">object</span>) <span class="keywordflow">throw</span>(PersistException) <a name="l00216"></a>00216 {<a class="code" href="a00105.html#a7828aecc7f2895f4226aeb98110d42de" title="writes a PersistObject from a reference.">write</a>(&<span class="keywordtype">object</span>); }; <a name="l00217"></a>00217 <a name="l00221"></a>00221 <span class="keywordtype">void</span> write(<span class="keyword">const</span> <a class="code" href="a00106.html" title="PersistObject.">PersistObject</a> *<span class="keywordtype">object</span>) <span class="keywordflow">throw</span>(PersistException); <a name="l00222"></a>00222 <a name="l00223"></a>00223 <span class="comment">// writes supported primitive types</span> <a name="l00224"></a>00224 <span class="comment">// shortcut, to make the following more readable</span> <a name="l00225"></a>00225 <span class="preprocessor">#define CCXX_ENGINEWRITE_REF(valref) writeBinary((const uint8_t*)&valref,sizeof(valref))</span> <a name="l00226"></a>00226 <span class="preprocessor"></span> <span class="keyword">inline</span> <span class="keywordtype">void</span> write(int8_t i) <span class="keywordflow">throw</span>(PersistException) { CCXX_ENGINEWRITE_REF(i); } <a name="l00227"></a>00227 <span class="keyword">inline</span> <span class="keywordtype">void</span> write(uint8_t i) <span class="keywordflow">throw</span>(PersistException) { CCXX_ENGINEWRITE_REF(i); } <a name="l00228"></a>00228 <span class="keyword">inline</span> <span class="keywordtype">void</span> write(int16_t i) <span class="keywordflow">throw</span>(PersistException) { CCXX_ENGINEWRITE_REF(i); } <a name="l00229"></a>00229 <span class="keyword">inline</span> <span class="keywordtype">void</span> write(uint16_t i) <span class="keywordflow">throw</span>(PersistException) { CCXX_ENGINEWRITE_REF(i); } <a name="l00230"></a>00230 <span class="keyword">inline</span> <span class="keywordtype">void</span> write(int32_t i) <span class="keywordflow">throw</span>(PersistException) { CCXX_ENGINEWRITE_REF(i); } <a name="l00231"></a>00231 <span class="keyword">inline</span> <span class="keywordtype">void</span> write(uint32_t i) <span class="keywordflow">throw</span>(PersistException) { CCXX_ENGINEWRITE_REF(i); } <a name="l00232"></a>00232 <span class="keyword">inline</span> <span class="keywordtype">void</span> write(<span class="keywordtype">float</span> i) <span class="keywordflow">throw</span>(PersistException) { CCXX_ENGINEWRITE_REF(i); } <a name="l00233"></a>00233 <span class="keyword">inline</span> <span class="keywordtype">void</span> write(<span class="keywordtype">double</span> i) <span class="keywordflow">throw</span>(PersistException) { CCXX_ENGINEWRITE_REF(i); } <a name="l00234"></a>00234 <span class="keyword">inline</span> <span class="keywordtype">void</span> write(<span class="keywordtype">bool</span> i) <span class="keywordflow">throw</span>(PersistException) { CCXX_ENGINEWRITE_REF(i); } <a name="l00235"></a>00235 <span class="preprocessor">#undef CCXX_ENGINEWRITE_REF</span> <a name="l00236"></a>00236 <span class="preprocessor"></span> <a name="l00237"></a>00237 <span class="keywordtype">void</span> write(<span class="keyword">const</span> std::string& str) <span class="keywordflow">throw</span>(PersistException); <a name="l00238"></a>00238 <a name="l00239"></a>00239 <span class="comment">// Every write operation boils down to one or more of these</span> <a name="l00240"></a>00240 <span class="keywordtype">void</span> writeBinary(<span class="keyword">const</span> uint8_t* data, <span class="keyword">const</span> uint32_t size) <span class="keywordflow">throw</span>(PersistException); <a name="l00241"></a>00241 <a name="l00242"></a>00242 <span class="comment">// Read Operations</span> <a name="l00243"></a>00243 <a name="l00247"></a>00247 <span class="keywordtype">void</span> read(<a class="code" href="a00106.html" title="PersistObject.">PersistObject</a> &<span class="keywordtype">object</span>) <span class="keywordflow">throw</span>(PersistException); <a name="l00248"></a>00248 <a name="l00252"></a>00252 <span class="keywordtype">void</span> read(<a class="code" href="a00106.html" title="PersistObject.">PersistObject</a> *&<span class="keywordtype">object</span>) <span class="keywordflow">throw</span>(PersistException); <a name="l00253"></a>00253 <a name="l00254"></a>00254 <span class="comment">// reads supported primitive types</span> <a name="l00255"></a>00255 <span class="comment">// shortcut, to make the following more readable</span> <a name="l00256"></a>00256 <span class="preprocessor">#define CCXX_ENGINEREAD_REF(valref) readBinary((uint8_t*)&valref,sizeof(valref))</span> <a name="l00257"></a>00257 <span class="preprocessor"></span> <span class="keyword">inline</span> <span class="keywordtype">void</span> read(int8_t& i) <span class="keywordflow">throw</span>(PersistException) { CCXX_ENGINEREAD_REF(i); } <a name="l00258"></a>00258 <span class="keyword">inline</span> <span class="keywordtype">void</span> read(uint8_t& i) <span class="keywordflow">throw</span>(PersistException) { CCXX_ENGINEREAD_REF(i); } <a name="l00259"></a>00259 <span class="keyword">inline</span> <span class="keywordtype">void</span> read(int16_t& i) <span class="keywordflow">throw</span>(PersistException) { CCXX_ENGINEREAD_REF(i); } <a name="l00260"></a>00260 <span class="keyword">inline</span> <span class="keywordtype">void</span> read(uint16_t& i) <span class="keywordflow">throw</span>(PersistException) { CCXX_ENGINEREAD_REF(i); } <a name="l00261"></a>00261 <span class="keyword">inline</span> <span class="keywordtype">void</span> read(int32_t& i) <span class="keywordflow">throw</span>(PersistException) { CCXX_ENGINEREAD_REF(i); } <a name="l00262"></a>00262 <span class="keyword">inline</span> <span class="keywordtype">void</span> read(uint32_t& i) <span class="keywordflow">throw</span>(PersistException) { CCXX_ENGINEREAD_REF(i); } <a name="l00263"></a>00263 <span class="keyword">inline</span> <span class="keywordtype">void</span> read(<span class="keywordtype">float</span>& i) <span class="keywordflow">throw</span>(PersistException) { CCXX_ENGINEREAD_REF(i); } <a name="l00264"></a>00264 <span class="keyword">inline</span> <span class="keywordtype">void</span> read(<span class="keywordtype">double</span>& i) <span class="keywordflow">throw</span>(PersistException) { CCXX_ENGINEREAD_REF(i); } <a name="l00265"></a>00265 <span class="keyword">inline</span> <span class="keywordtype">void</span> read(<span class="keywordtype">bool</span> &i) <span class="keywordflow">throw</span>(PersistException) { CCXX_ENGINEREAD_REF(i); } <a name="l00266"></a>00266 <span class="preprocessor">#undef CCXX_ENGINEREAD_REF</span> <a name="l00267"></a>00267 <span class="preprocessor"></span> <a name="l00268"></a>00268 <span class="keywordtype">void</span> read(std::string& str) <span class="keywordflow">throw</span>(PersistException); <a name="l00269"></a>00269 <a name="l00270"></a>00270 <span class="comment">// Every read operation boiled down to one or more of these</span> <a name="l00271"></a>00271 <span class="keywordtype">void</span> readBinary(uint8_t* data, uint32_t size) <span class="keywordflow">throw</span>(PersistException); <a name="l00272"></a>00272 <a name="l00273"></a>00273 <span class="keyword">private</span>: <a name="l00278"></a>00278 <span class="keywordtype">void</span> readObject(<a class="code" href="a00106.html" title="PersistObject.">PersistObject</a>* <span class="keywordtype">object</span>) <span class="keywordflow">throw</span>(PersistException); <a name="l00279"></a>00279 <a name="l00283"></a>00283 <span class="keyword">const</span> std::string readClass() throw(PersistException); <a name="l00284"></a>00284 <a name="l00285"></a>00285 <a name="l00289"></a>00289 std::iostream& myUnderlyingStream; <a name="l00290"></a>00290 <a name="l00294"></a>00294 EngineMode myOperationalMode; <a name="l00295"></a>00295 <a name="l00299"></a>00299 typedef std::vector<<a class="code" href="a00106.html" title="PersistObject.">PersistObject</a>*> ArchiveVector; <a name="l00300"></a>00300 typedef std::map<<a class="code" href="a00106.html" title="PersistObject.">PersistObject</a> const*, int32_t> ArchiveMap; <a name="l00301"></a>00301 typedef std::vector<std::<span class="keywordtype">string</span>> ClassVector; <a name="l00302"></a>00302 typedef std::map<std::<span class="keywordtype">string</span>, int32_t> ClassMap; <a name="l00303"></a>00303 <a name="l00304"></a>00304 ArchiveVector myArchiveVector; <a name="l00305"></a>00305 ArchiveMap myArchiveMap; <a name="l00306"></a>00306 ClassVector myClassVector; <a name="l00307"></a>00307 ClassMap myClassMap; <a name="l00308"></a>00308 }; <a name="l00309"></a>00309 <a name="l00310"></a>00310 <span class="preprocessor">#define CCXX_RE(ar,ob) ar.read(ob); return ar</span> <a name="l00311"></a>00311 <span class="preprocessor"></span><span class="preprocessor">#define CCXX_WE(ar,ob) ar.write(ob); return ar</span> <a name="l00312"></a>00312 <span class="preprocessor"></span> <a name="l00313"></a>00313 <span class="comment">// Standard >> and << stream operators for PersistObject</span> <a name="l00315"></a><a class="code" href="a00105.html#a8eab0795c1b902f5f32ba5b710127865">00315</a> <span class="comment"></span><span class="keyword">inline</span> <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& operator >>( <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& ar, <a class="code" href="a00106.html" title="PersistObject.">PersistObject</a> &ob) <span class="keywordflow">throw</span>(PersistException) {CCXX_RE(ar,ob);} <a name="l00317"></a><a class="code" href="a00105.html#a973e61ab243ea5f7e7b1233bf305b69c">00317</a> <span class="keyword">inline</span> <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& operator >>( <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& ar, <a class="code" href="a00106.html" title="PersistObject.">PersistObject</a> *&ob) <span class="keywordflow">throw</span>(PersistException) {CCXX_RE(ar,ob);} <a name="l00319"></a><a class="code" href="a00105.html#afba84e3fdb2f3beccc82199eddee184f">00319</a> <span class="keyword">inline</span> <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& operator <<( <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& ar, <a class="code" href="a00106.html" title="PersistObject.">PersistObject</a> <span class="keyword">const</span> &ob) <span class="keywordflow">throw</span>(PersistException) {CCXX_WE(ar,ob);} <a name="l00321"></a><a class="code" href="a00105.html#a080db3c17b91319bd47d63cb6a4708ee">00321</a> <span class="keyword">inline</span> <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& operator <<( <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& ar, <a class="code" href="a00106.html" title="PersistObject.">PersistObject</a> <span class="keyword">const</span> *ob) <span class="keywordflow">throw</span>(PersistException) {CCXX_WE(ar,ob);} <a name="l00322"></a>00322 <a name="l00324"></a><a class="code" href="a00105.html#a656076b14bde68e55fce1dfaef299490">00324</a> <span class="keyword">inline</span> <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& operator >>( <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& ar, int8_t& ob) <span class="keywordflow">throw</span>(PersistException) {CCXX_RE(ar,ob);} <a name="l00326"></a><a class="code" href="a00105.html#a174ce456a138787b9b88669ba0fccdae">00326</a> <span class="keyword">inline</span> <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& operator <<( <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& ar, int8_t ob) <span class="keywordflow">throw</span>(PersistException) {CCXX_WE(ar,ob);} <a name="l00327"></a>00327 <a name="l00329"></a><a class="code" href="a00105.html#a2413005bf76c5dc13a32bad1275f34be">00329</a> <span class="keyword">inline</span> <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& operator >>( <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& ar, uint8_t& ob) <span class="keywordflow">throw</span>(PersistException) {CCXX_RE(ar,ob);} <a name="l00331"></a><a class="code" href="a00105.html#a34d0240c8b75f11d5080a64bfeb72ee4">00331</a> <span class="keyword">inline</span> <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& operator <<( <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& ar, uint8_t ob) <span class="keywordflow">throw</span>(PersistException) {CCXX_WE(ar,ob);} <a name="l00332"></a>00332 <a name="l00334"></a><a class="code" href="a00105.html#af4cf1edfee3f461d9fea2e6a02836015">00334</a> <span class="keyword">inline</span> <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& operator >>( <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& ar, int16_t& ob) <span class="keywordflow">throw</span>(PersistException) {CCXX_RE(ar,ob);} <a name="l00336"></a><a class="code" href="a00105.html#a605487a6322ca08e6e60838333a42185">00336</a> <span class="keyword">inline</span> <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& operator <<( <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& ar, int16_t ob) <span class="keywordflow">throw</span>(PersistException) {CCXX_WE(ar,ob);} <a name="l00337"></a>00337 <a name="l00339"></a><a class="code" href="a00105.html#ac01040027ef66bd667cd96b88ee9e723">00339</a> <span class="keyword">inline</span> <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& operator >>( <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& ar, uint16_t& ob) <span class="keywordflow">throw</span>(PersistException) {CCXX_RE(ar,ob);} <a name="l00341"></a><a class="code" href="a00105.html#a61385c7be33326b689272fc1da42d35e">00341</a> <span class="keyword">inline</span> <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& operator <<( <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& ar, uint16_t ob) <span class="keywordflow">throw</span>(PersistException) {CCXX_WE(ar,ob);} <a name="l00342"></a>00342 <a name="l00344"></a><a class="code" href="a00105.html#af379588f9dec57fcb2c390c28eec4fc7">00344</a> <span class="keyword">inline</span> <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& operator >>( <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& ar, int32_t& ob) <span class="keywordflow">throw</span>(PersistException) {CCXX_RE(ar,ob);} <a name="l00346"></a><a class="code" href="a00105.html#ace11b7bcbb91b68d19f1d79b3ebdeb47">00346</a> <span class="keyword">inline</span> <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& operator <<( <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& ar, int32_t ob) <span class="keywordflow">throw</span>(PersistException) {CCXX_WE(ar,ob);} <a name="l00347"></a>00347 <a name="l00349"></a><a class="code" href="a00105.html#add4ecc625e6884f30231e08e747b019c">00349</a> <span class="keyword">inline</span> <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& operator >>( <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& ar, uint32_t& ob) <span class="keywordflow">throw</span>(PersistException) {CCXX_RE(ar,ob);} <a name="l00351"></a><a class="code" href="a00105.html#ab106be082e70769703be383e25f7102c">00351</a> <span class="keyword">inline</span> <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& operator <<( <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& ar, uint32_t ob) <span class="keywordflow">throw</span>(PersistException) {CCXX_WE(ar,ob);} <a name="l00352"></a>00352 <a name="l00354"></a><a class="code" href="a00105.html#aec94544fe56c15ec269d91d3331fd62c">00354</a> <span class="keyword">inline</span> <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& operator >>( <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& ar, <span class="keywordtype">float</span>& ob) <span class="keywordflow">throw</span>(PersistException) {CCXX_RE(ar,ob);} <a name="l00356"></a><a class="code" href="a00105.html#a43f3013cd0d0bc0abf372906620ae13f">00356</a> <span class="keyword">inline</span> <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& operator <<( <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& ar, <span class="keywordtype">float</span> ob) <span class="keywordflow">throw</span>(PersistException) {CCXX_WE(ar,ob);} <a name="l00357"></a>00357 <a name="l00359"></a><a class="code" href="a00105.html#ab49ca0b9d2813563cd95abd2ea986f6c">00359</a> <span class="keyword">inline</span> <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& operator >>( <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& ar, <span class="keywordtype">double</span>& ob) <span class="keywordflow">throw</span>(PersistException) {CCXX_RE(ar,ob);} <a name="l00361"></a><a class="code" href="a00105.html#a3886b0fa8c305ca54944bf902575f8d6">00361</a> <span class="keyword">inline</span> <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& operator <<( <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& ar, <span class="keywordtype">double</span> ob) <span class="keywordflow">throw</span>(PersistException) {CCXX_WE(ar,ob);} <a name="l00362"></a>00362 <a name="l00364"></a><a class="code" href="a00105.html#a5a13710f8cc57d37d4e42846f04e72eb">00364</a> <span class="keyword">inline</span> <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& operator >>( <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& ar, std::string& ob) <span class="keywordflow">throw</span>(PersistException) {CCXX_RE(ar,ob);} <a name="l00366"></a><a class="code" href="a00105.html#a1581120820161b08a709c9da96c8973e">00366</a> <span class="keyword">inline</span> <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& operator <<( <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& ar, std::string ob) <span class="keywordflow">throw</span>(PersistException) {CCXX_WE(ar,ob);} <a name="l00367"></a>00367 <a name="l00369"></a><a class="code" href="a00105.html#aedf1afeb0fc6acc4aec5190957db8ff3">00369</a> <span class="keyword">inline</span> <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& operator >>( <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& ar, <span class="keywordtype">bool</span>& ob) <span class="keywordflow">throw</span>(PersistException) {CCXX_RE(ar,ob);} <a name="l00371"></a><a class="code" href="a00105.html#a68c12e354a97b9673060ca72ca26d838">00371</a> <span class="keyword">inline</span> <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& operator <<( <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& ar, <span class="keywordtype">bool</span> ob) <span class="keywordflow">throw</span>(PersistException) {CCXX_WE(ar,ob);} <a name="l00372"></a>00372 <a name="l00373"></a>00373 <span class="preprocessor">#undef CCXX_RE</span> <a name="l00374"></a>00374 <span class="preprocessor"></span><span class="preprocessor">#undef CCXX_WE</span> <a name="l00375"></a>00375 <span class="preprocessor"></span> <a name="l00385"></a>00385 <span class="keyword">template</span><<span class="keyword">class</span> T> <a name="l00386"></a><a class="code" href="a00105.html#a39d0dadeae3c0178c8f303e6ed60e090">00386</a> <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& operator <<( PersistEngine& ar, typename std::vector<T> <span class="keyword">const</span>& ob) <span class="keywordflow">throw</span>(PersistException) <a name="l00387"></a>00387 { <a name="l00388"></a>00388 ar << (uint32_t)ob.size(); <a name="l00389"></a>00389 <span class="keywordflow">for</span>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i=0; i < ob.size(); ++i) <a name="l00390"></a>00390 ar << ob[i]; <a name="l00391"></a>00391 <span class="keywordflow">return</span> ar; <a name="l00392"></a>00392 } <a name="l00393"></a>00393 <a name="l00399"></a>00399 <span class="keyword">template</span><<span class="keyword">class</span> T> <a name="l00400"></a><a class="code" href="a00105.html#ade59cae8c29052145d0d1bf7be08e0f4">00400</a> <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& operator >>( <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& ar, <span class="keyword">typename</span> std::vector<T>& ob) <span class="keywordflow">throw</span>(PersistException) <a name="l00401"></a>00401 { <a name="l00402"></a>00402 ob.clear(); <a name="l00403"></a>00403 uint32_t siz; <a name="l00404"></a>00404 ar >> siz; <a name="l00405"></a>00405 ob.resize(siz); <a name="l00406"></a>00406 <span class="keywordflow">for</span>(uint32_t i=0; i < siz; ++i) <a name="l00407"></a>00407 ar >> ob[i]; <a name="l00408"></a>00408 <span class="keywordflow">return</span> ar; <a name="l00409"></a>00409 } <a name="l00410"></a>00410 <a name="l00416"></a>00416 <span class="keyword">template</span><<span class="keyword">class</span> T> <a name="l00417"></a><a class="code" href="a00105.html#a75201fa6097b9ca48f63613c11b69c51">00417</a> <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& operator <<( PersistEngine& ar, typename std::deque<T> <span class="keyword">const</span>& ob) <span class="keywordflow">throw</span>(PersistException) <a name="l00418"></a>00418 { <a name="l00419"></a>00419 ar << (uint32_t)ob.size(); <a name="l00420"></a>00420 <span class="keywordflow">for</span>(<span class="keyword">typename</span> std::deque<T>::const_iterator it=ob.begin(); it != ob.end(); ++it) <a name="l00421"></a>00421 ar << *it; <a name="l00422"></a>00422 <span class="keywordflow">return</span> ar; <a name="l00423"></a>00423 } <a name="l00424"></a>00424 <a name="l00430"></a>00430 <span class="keyword">template</span><<span class="keyword">class</span> T> <a name="l00431"></a><a class="code" href="a00105.html#a98d1c3d071b030122d3e9d81ffd4363f">00431</a> <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& operator >>( <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& ar, <span class="keyword">typename</span> std::deque<T>& ob) <span class="keywordflow">throw</span>(PersistException) <a name="l00432"></a>00432 { <a name="l00433"></a>00433 ob.clear(); <a name="l00434"></a>00434 uint32_t siz; <a name="l00435"></a>00435 ar >> siz; <a name="l00436"></a>00436 <span class="comment">//ob.resize(siz);</span> <a name="l00437"></a>00437 <span class="keywordflow">for</span>(uint32_t i=0; i < siz; ++i) { <a name="l00438"></a>00438 T node; <a name="l00439"></a>00439 ar >> node; <a name="l00440"></a>00440 ob.push_back(node); <a name="l00441"></a>00441 <span class="comment">//ar >> ob[i];</span> <a name="l00442"></a>00442 } <a name="l00443"></a>00443 <span class="keywordflow">return</span> ar; <a name="l00444"></a>00444 } <a name="l00445"></a>00445 <a name="l00451"></a>00451 <span class="keyword">template</span><<span class="keyword">class</span> Key, <span class="keyword">class</span> Value> <a name="l00452"></a><a class="code" href="a00105.html#aa5e40aaa194a47e1ef0e3862fe715e38">00452</a> <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& operator <<( PersistEngine& ar, typename std::map<Key,Value> <span class="keyword">const</span> & ob) <span class="keywordflow">throw</span>(PersistException) <a name="l00453"></a>00453 { <a name="l00454"></a>00454 ar << (uint32_t)ob.size(); <a name="l00455"></a>00455 <span class="keywordflow">for</span>(<span class="keyword">typename</span> std::map<Key,Value>::const_iterator it = ob.begin();it != ob.end();++it) <a name="l00456"></a>00456 ar << it->first << it->second; <a name="l00457"></a>00457 <span class="keywordflow">return</span> ar; <a name="l00458"></a>00458 } <a name="l00459"></a>00459 <a name="l00465"></a>00465 <span class="keyword">template</span><<span class="keyword">class</span> Key, <span class="keyword">class</span> Value> <a name="l00466"></a><a class="code" href="a00105.html#a7a2cc17a9d49d5853af8a3b4282d5894">00466</a> <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& operator >>( <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& ar, <span class="keyword">typename</span> std::map<Key,Value>& ob) <span class="keywordflow">throw</span>(PersistException) <a name="l00467"></a>00467 { <a name="l00468"></a>00468 ob.clear(); <a name="l00469"></a>00469 uint32_t siz; <a name="l00470"></a>00470 ar >> siz; <a name="l00471"></a>00471 <span class="keywordflow">for</span>(uint32_t i=0; i < siz; ++i) { <a name="l00472"></a>00472 Key a; <a name="l00473"></a>00473 ar >> a; <a name="l00474"></a>00474 ar >> ob[a]; <a name="l00475"></a>00475 } <a name="l00476"></a>00476 <span class="keywordflow">return</span> ar; <a name="l00477"></a>00477 } <a name="l00478"></a>00478 <a name="l00483"></a>00483 <span class="keyword">template</span><<span class="keyword">class</span> x, <span class="keyword">class</span> y> <a name="l00484"></a><a class="code" href="a00105.html#aafe13391274a155c9afc1257cc707f6b">00484</a> <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& operator <<( PersistEngine& ar, std::pair<x,y> &ob) <span class="keywordflow">throw</span>(PersistException) <a name="l00485"></a>00485 { <a name="l00486"></a>00486 ar << ob.first << ob.second; <a name="l00487"></a>00487 <span class="keywordflow">return</span> ar; <a name="l00488"></a>00488 } <a name="l00489"></a>00489 <a name="l00494"></a>00494 <span class="keyword">template</span><<span class="keyword">class</span> x, <span class="keyword">class</span> y> <a name="l00495"></a><a class="code" href="a00105.html#abd4ca742d9ad58a5081393e2708dde73">00495</a> <a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& operator >>(<a class="code" href="a00105.html" title="Stream serialization of persistent classes.">PersistEngine</a>& ar, std::pair<x, y> &ob) <span class="keywordflow">throw</span>(PersistException) <a name="l00496"></a>00496 { <a name="l00497"></a>00497 ar >> ob.first >> ob.second; <a name="l00498"></a>00498 <span class="keywordflow">return</span> ar; <a name="l00499"></a>00499 } <a name="l00500"></a>00500 <a name="l00501"></a>00501 END_NAMESPACE <a name="l00502"></a>00502 <a name="l00503"></a>00503 <span class="preprocessor">#endif</span> <a name="l00504"></a>00504 <span class="preprocessor"></span><span class="preprocessor">#endif</span> <a name="l00505"></a>00505 <span class="preprocessor"></span><span class="preprocessor">#endif</span> </pre></div></div> </div> <div id="nav-path" class="navpath"> <ul> <li class="navelem"><a class="el" href="a00192.html">persist.h</a> </li> <li class="footer">Generated on Wed Apr 13 2011 22:39:47 for ucommon by  <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.3 </li> </ul> </div> </body> </html>