<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <title>MPQC: stateout.h Source File</title> <link href="tabs.css" rel="stylesheet" type="text/css"> <link href="doxygen.css" rel="stylesheet" type="text/css"> </head><body> <!-- Generated by Doxygen 1.5.9 --> <div class="navigation" id="top"> <div class="tabs"> <ul> <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="annotated.html"><span>Classes</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> </ul> </div> <div class="tabs"> <ul> <li><a href="files.html"><span>File List</span></a></li> </ul> </div> <h1>stateout.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">//</span> <a name="l00002"></a>00002 <span class="comment">// stateout.h</span> <a name="l00003"></a>00003 <span class="comment">//</span> <a name="l00004"></a>00004 <span class="comment">// Copyright (C) 1998 Limit Point Systems, Inc.</span> <a name="l00005"></a>00005 <span class="comment">//</span> <a name="l00006"></a>00006 <span class="comment">// Author: Curtis Janssen <cljanss@limitpt.com></span> <a name="l00007"></a>00007 <span class="comment">// Maintainer: LPS</span> <a name="l00008"></a>00008 <span class="comment">//</span> <a name="l00009"></a>00009 <span class="comment">// This file is part of the SC Toolkit.</span> <a name="l00010"></a>00010 <span class="comment">//</span> <a name="l00011"></a>00011 <span class="comment">// The SC Toolkit is free software; you can redistribute it and/or modify</span> <a name="l00012"></a>00012 <span class="comment">// it under the terms of the GNU Library General Public License as published by</span> <a name="l00013"></a>00013 <span class="comment">// the Free Software Foundation; either version 2, or (at your option)</span> <a name="l00014"></a>00014 <span class="comment">// any later version.</span> <a name="l00015"></a>00015 <span class="comment">//</span> <a name="l00016"></a>00016 <span class="comment">// The SC Toolkit is distributed in the hope that it will be useful,</span> <a name="l00017"></a>00017 <span class="comment">// but WITHOUT ANY WARRANTY; without even the implied warranty of</span> <a name="l00018"></a>00018 <span class="comment">// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span> <a name="l00019"></a>00019 <span class="comment">// GNU Library General Public License for more details.</span> <a name="l00020"></a>00020 <span class="comment">//</span> <a name="l00021"></a>00021 <span class="comment">// You should have received a copy of the GNU Library General Public License</span> <a name="l00022"></a>00022 <span class="comment">// along with the SC Toolkit; see the file COPYING.LIB. If not, write to</span> <a name="l00023"></a>00023 <span class="comment">// the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.</span> <a name="l00024"></a>00024 <span class="comment">//</span> <a name="l00025"></a>00025 <span class="comment">// The U.S. Government is granted a limited license as per AL 91-7.</span> <a name="l00026"></a>00026 <span class="comment">//</span> <a name="l00027"></a>00027 <a name="l00028"></a>00028 <span class="preprocessor">#ifndef _util_state_stateout_h</span> <a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#define _util_state_stateout_h</span> <a name="l00030"></a>00030 <span class="preprocessor"></span> <a name="l00031"></a>00031 <span class="preprocessor">#ifdef __GNUC__</span> <a name="l00032"></a>00032 <span class="preprocessor"></span><span class="preprocessor">#pragma interface</span> <a name="l00033"></a>00033 <span class="preprocessor"></span><span class="preprocessor">#endif</span> <a name="l00034"></a>00034 <span class="preprocessor"></span> <a name="l00035"></a>00035 <span class="preprocessor">#include <string></span> <a name="l00036"></a>00036 <span class="preprocessor">#include <vector></span> <a name="l00037"></a>00037 <span class="preprocessor">#include <map></span> <a name="l00038"></a>00038 <a name="l00039"></a>00039 <span class="preprocessor">#include <util/class/class.h></span> <a name="l00040"></a>00040 <span class="preprocessor">#include <util/state/state.h></span> <a name="l00041"></a>00041 <a name="l00042"></a>00042 <span class="keyword">namespace </span>sc { <a name="l00043"></a>00043 <a name="l00044"></a>00044 <span class="keyword">class </span>StateOutData { <a name="l00045"></a>00045 <span class="keyword">public</span>: <a name="l00046"></a>00046 <span class="keywordtype">int</span> num; <a name="l00047"></a>00047 <span class="keywordtype">int</span> size; <a name="l00048"></a>00048 <span class="keywordtype">int</span> type; <a name="l00049"></a>00049 <span class="keywordtype">int</span> offset; <a name="l00050"></a>00050 <a name="l00051"></a>00051 StateOutData(): num(0), size(0), type(0), offset(0) {} <a name="l00052"></a>00052 }; <a name="l00053"></a>00053 <a name="l00061"></a><a class="code" href="classsc_1_1StateOut.html">00061</a> <span class="keyword">class </span><a class="code" href="classsc_1_1StateOut.html" title="Serializes objects that derive from SavableState.">StateOut</a>: <span class="keyword">public</span> <a class="code" href="classsc_1_1DescribedClass.html" title="Classes which need runtime information about themselves and their relationship to...">DescribedClass</a> { <a name="l00062"></a>00062 <span class="keyword">friend</span> <span class="keyword">class </span><a class="code" href="classsc_1_1SavableState.html" title="Base class for objects that can save/restore state.">SavableState</a>; <a name="l00063"></a>00063 <span class="keyword">friend</span> <span class="keyword">class </span><a class="code" href="classsc_1_1TranslateDataOut.html" title="Convert data to other formats.">TranslateDataOut</a>; <a name="l00064"></a>00064 <span class="keyword">private</span>: <a name="l00065"></a>00065 <span class="comment">// do not allow copy constructor or assignment</span> <a name="l00066"></a>00066 <a class="code" href="classsc_1_1StateOut.html" title="Serializes objects that derive from SavableState.">StateOut</a>(<span class="keyword">const</span> <a class="code" href="classsc_1_1StateOut.html" title="Serializes objects that derive from SavableState.">StateOut</a>&); <a name="l00067"></a>00067 <span class="keywordtype">void</span> operator=(<span class="keyword">const</span> <a class="code" href="classsc_1_1StateOut.html" title="Serializes objects that derive from SavableState.">StateOut</a>&); <a name="l00068"></a>00068 <span class="keywordtype">int</span> have_cd_; <a name="l00069"></a>00069 <span class="keyword">protected</span>: <a name="l00070"></a>00070 <span class="keywordtype">int</span> dir_loc_loc_; <a name="l00071"></a>00071 <a class="code" href="classsc_1_1TranslateDataOut.html" title="Convert data to other formats.">TranslateDataOut</a> *translate_; <a name="l00072"></a>00072 <span class="keywordtype">int</span> copy_references_; <a name="l00073"></a>00073 <span class="keywordtype">int</span> next_object_number_; <a name="l00074"></a>00074 std::map<Ref<SavableState>,StateOutData> ps_; <a name="l00075"></a>00075 std::map<ClassDescP,int> classidmap_; <a name="l00076"></a>00076 <span class="keywordtype">int</span> nextclassid_; <a name="l00077"></a>00077 <span class="keywordtype">int</span> node_to_node_; <a name="l00078"></a>00078 <span class="keyword">virtual</span> <span class="keywordtype">int</span> put_array_void(<span class="keyword">const</span> <span class="keywordtype">void</span>*,<span class="keywordtype">int</span>); <a name="l00079"></a>00079 <span class="keyword">virtual</span> <span class="keywordtype">int</span> putparents(<span class="keyword">const</span> <a class="code" href="classsc_1_1ClassDesc.html" title="This class is used to contain information about classes.">ClassDesc</a>*); <a name="l00080"></a>00080 <a name="l00081"></a>00081 <span class="keywordtype">void</span> put_directory(); <a name="l00082"></a>00082 <a name="l00083"></a>00083 <span class="comment">// The following members are called by friend SavableState</span> <a name="l00084"></a>00084 <a name="l00085"></a>00085 <span class="keywordtype">void</span> have_classdesc() { have_cd_ = 1; } <a name="l00086"></a>00086 <span class="keywordtype">int</span> need_classdesc() { <span class="keywordtype">int</span> tmp = have_cd_; have_cd_ = 0; <span class="keywordflow">return</span> !tmp; } <a name="l00087"></a>00087 <a name="l00092"></a>00092 <span class="keyword">virtual</span> <span class="keywordtype">int</span> <a class="code" href="classsc_1_1StateOut.html#f39b5e2067f12dbcafd6bdf3ff054635" title="This will prepare StateOut to output a pointer to data.">putobject</a>(<span class="keyword">const</span> <a class="code" href="classsc_1_1Ref.html">Ref<SavableState></a> &); <a name="l00093"></a>00093 <a name="l00095"></a>00095 <span class="keyword">virtual</span> <span class="keywordtype">int</span> <a class="code" href="classsc_1_1StateOut.html#c8d021ee9372bcfe7fbefc81619dd8e0" title="Write out information about the given ClassDesc.">put</a>(<span class="keyword">const</span> <a class="code" href="classsc_1_1ClassDesc.html" title="This class is used to contain information about classes.">ClassDesc</a>*); <a name="l00096"></a>00096 <span class="keyword">public</span>: <a name="l00097"></a>00097 <a class="code" href="classsc_1_1StateOut.html" title="Serializes objects that derive from SavableState.">StateOut</a>(); <a name="l00098"></a>00098 <span class="keyword">virtual</span> ~<a class="code" href="classsc_1_1StateOut.html" title="Serializes objects that derive from SavableState.">StateOut</a>(); <a name="l00099"></a>00099 <a name="l00101"></a>00101 <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classsc_1_1StateOut.html#ae7189c3581f8536a46346b9d1a8f077" title="Write out header information.">put_header</a>(); <a name="l00102"></a>00102 <a name="l00105"></a>00105 <span class="keyword">virtual</span> <span class="keywordtype">int</span> <a class="code" href="classsc_1_1StateOut.html#5d6a62cef6fd5d76a9c1e7c12db4aeb2" title="This is like put except the length of the char array is determined by interpreting...">putstring</a>(<span class="keyword">const</span> <span class="keywordtype">char</span>*); <a name="l00106"></a>00106 <a name="l00108"></a>00108 <span class="keyword">virtual</span> <span class="keywordtype">int</span> <a class="code" href="classsc_1_1StateOut.html#c8d021ee9372bcfe7fbefc81619dd8e0" title="Write out information about the given ClassDesc.">put</a>(<span class="keyword">const</span> std::string &); <a name="l00109"></a>00109 <a name="l00111"></a>00111 <span class="keyword">virtual</span> <span class="keywordtype">int</span> <a class="code" href="classsc_1_1StateOut.html#c8d021ee9372bcfe7fbefc81619dd8e0" title="Write out information about the given ClassDesc.">put</a>(<span class="keywordtype">char</span> r); <a name="l00112"></a>00112 <span class="keyword">virtual</span> <span class="keywordtype">int</span> <a class="code" href="classsc_1_1StateOut.html#c8d021ee9372bcfe7fbefc81619dd8e0" title="Write out information about the given ClassDesc.">put</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> r); <a name="l00113"></a>00113 <span class="keyword">virtual</span> <span class="keywordtype">int</span> <a class="code" href="classsc_1_1StateOut.html#c8d021ee9372bcfe7fbefc81619dd8e0" title="Write out information about the given ClassDesc.">put</a>(<span class="keywordtype">int</span> r); <a name="l00114"></a>00114 <span class="keyword">virtual</span> <span class="keywordtype">int</span> <a class="code" href="classsc_1_1StateOut.html#c8d021ee9372bcfe7fbefc81619dd8e0" title="Write out information about the given ClassDesc.">put</a>(<span class="keywordtype">bool</span> r); <a name="l00115"></a>00115 <span class="keyword">virtual</span> <span class="keywordtype">int</span> <a class="code" href="classsc_1_1StateOut.html#c8d021ee9372bcfe7fbefc81619dd8e0" title="Write out information about the given ClassDesc.">put</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> r); <a name="l00116"></a>00116 <span class="keyword">virtual</span> <span class="keywordtype">int</span> <a class="code" href="classsc_1_1StateOut.html#c8d021ee9372bcfe7fbefc81619dd8e0" title="Write out information about the given ClassDesc.">put</a>(<span class="keywordtype">float</span> r); <a name="l00117"></a>00117 <span class="keyword">virtual</span> <span class="keywordtype">int</span> <a class="code" href="classsc_1_1StateOut.html#c8d021ee9372bcfe7fbefc81619dd8e0" title="Write out information about the given ClassDesc.">put</a>(<span class="keywordtype">double</span> r); <a name="l00120"></a>00120 <span class="keyword">virtual</span> <span class="keywordtype">int</span> <a class="code" href="classsc_1_1StateOut.html#c8d021ee9372bcfe7fbefc81619dd8e0" title="Write out information about the given ClassDesc.">put</a>(<span class="keyword">const</span> <span class="keywordtype">char</span>*,<span class="keywordtype">int</span>); <a name="l00121"></a>00121 <span class="keyword">virtual</span> <span class="keywordtype">int</span> <a class="code" href="classsc_1_1StateOut.html#c8d021ee9372bcfe7fbefc81619dd8e0" title="Write out information about the given ClassDesc.">put</a>(<span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>*,<span class="keywordtype">int</span>); <a name="l00122"></a>00122 <span class="keyword">virtual</span> <span class="keywordtype">int</span> <a class="code" href="classsc_1_1StateOut.html#c8d021ee9372bcfe7fbefc81619dd8e0" title="Write out information about the given ClassDesc.">put</a>(<span class="keyword">const</span> <span class="keywordtype">int</span>*,<span class="keywordtype">int</span>); <a name="l00123"></a>00123 <span class="keyword">virtual</span> <span class="keywordtype">int</span> <a class="code" href="classsc_1_1StateOut.html#c8d021ee9372bcfe7fbefc81619dd8e0" title="Write out information about the given ClassDesc.">put</a>(<span class="keyword">const</span> <span class="keywordtype">float</span>*,<span class="keywordtype">int</span>); <a name="l00124"></a>00124 <span class="keyword">virtual</span> <span class="keywordtype">int</span> <a class="code" href="classsc_1_1StateOut.html#c8d021ee9372bcfe7fbefc81619dd8e0" title="Write out information about the given ClassDesc.">put</a>(<span class="keyword">const</span> <span class="keywordtype">double</span>*,<span class="keywordtype">int</span>); <a name="l00127"></a>00127 <span class="keyword">virtual</span> <span class="keywordtype">int</span> <a class="code" href="classsc_1_1StateOut.html#350b1462bd0375a27249b36dab9c0e93" title="Put arrays of data.">put_array_char</a>(<span class="keyword">const</span> <span class="keywordtype">char</span>*p,<span class="keywordtype">int</span> size); <a name="l00128"></a>00128 <span class="keyword">virtual</span> <span class="keywordtype">int</span> put_array_uint(<span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>*p,<span class="keywordtype">int</span> size); <a name="l00129"></a>00129 <span class="keyword">virtual</span> <span class="keywordtype">int</span> put_array_int(<span class="keyword">const</span> <span class="keywordtype">int</span>*p,<span class="keywordtype">int</span> size); <a name="l00130"></a>00130 <span class="keyword">virtual</span> <span class="keywordtype">int</span> put_array_float(<span class="keyword">const</span> <span class="keywordtype">float</span>*p,<span class="keywordtype">int</span> size); <a name="l00131"></a>00131 <span class="keyword">virtual</span> <span class="keywordtype">int</span> put_array_double(<span class="keyword">const</span> <span class="keywordtype">double</span>*p,<span class="keywordtype">int</span> size); <a name="l00132"></a>00132 <a name="l00134"></a>00134 <span class="keyword">template</span> <<span class="keyword">class</span> T> <a name="l00135"></a><a class="code" href="classsc_1_1StateOut.html#d838206f15161c509ef4b9ec3b44fb6b">00135</a> <span class="keywordtype">int</span> <a class="code" href="classsc_1_1StateOut.html#d838206f15161c509ef4b9ec3b44fb6b" title="Write an STL vector of data.">put</a>(<span class="keyword">typename</span> std::vector<T> &v) { <a name="l00136"></a>00136 <span class="keywordtype">int</span> l = v.size(); <a name="l00137"></a>00137 <span class="keywordtype">int</span> r = <a class="code" href="classsc_1_1StateOut.html#c8d021ee9372bcfe7fbefc81619dd8e0" title="Write out information about the given ClassDesc.">put</a>(l); <a name="l00138"></a>00138 <span class="keywordflow">if</span> (l) { <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=0; i<l; i++) r += <a class="code" href="classsc_1_1StateOut.html#c8d021ee9372bcfe7fbefc81619dd8e0" title="Write out information about the given ClassDesc.">put</a>(v[i]); } <a name="l00139"></a>00139 <span class="keywordflow">return</span> r; <a name="l00140"></a>00140 } <a name="l00141"></a>00141 <a name="l00145"></a>00145 <span class="keywordtype">void</span> <a class="code" href="classsc_1_1StateOut.html#bde7f4d7ab20c6d6a11e9b7698f46034" title="Don&#39;t keep track of pointers to objects.">forget_references</a>(); <a name="l00150"></a>00150 <span class="keywordtype">void</span> <a class="code" href="classsc_1_1StateOut.html#0738a805531667e6aec4d61fe2088d99" title="If a reference to an object that has already been written is encountered, copy it...">copy_references</a>(); <a name="l00151"></a>00151 <a name="l00153"></a>00153 <span class="keyword">virtual</span> <span class="keywordtype">int</span> <a class="code" href="classsc_1_1StateOut.html#bdd9125db6df177eef2b06ade39b463c" title="Returns true if this object uses a directory.">use_directory</a>(); <a name="l00154"></a>00154 <a name="l00156"></a>00156 <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classsc_1_1StateOut.html#0b561c95818fbd2f5094661f2fafe170" title="Flush out any remaining data.">flush</a>(); <a name="l00157"></a>00157 <a name="l00162"></a><a class="code" href="classsc_1_1StateOut.html#11e3bd77eb2ae738a5d026658f21913d">00162</a> <span class="keywordtype">int</span> <a class="code" href="classsc_1_1StateOut.html#11e3bd77eb2ae738a5d026658f21913d" title="True if this is a node to node save/restore.">node_to_node</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> node_to_node_; } <a name="l00163"></a>00163 <a name="l00166"></a>00166 <span class="keyword">virtual</span> <span class="keywordtype">int</span> <a class="code" href="classsc_1_1StateOut.html#4ab8319018ac939e50b926d905682277" title="Returns the current position in the file.">tell</a>(); <a name="l00169"></a>00169 <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classsc_1_1StateOut.html#fb97930b80ca2b021deea3de828fe8ea" title="Set the current position in the file.">seek</a>(<span class="keywordtype">int</span> loc); <a name="l00172"></a>00172 <span class="keyword">virtual</span> <span class="keywordtype">int</span> <a class="code" href="classsc_1_1StateOut.html#c26beeda97950b0d1f6dd05c8e782226" title="Return non-zero if tell and seek do anything sensible.">seekable</a>(); <a name="l00173"></a>00173 }; <a name="l00174"></a>00174 <a name="l00175"></a>00175 } <a name="l00176"></a>00176 <a name="l00177"></a>00177 <span class="preprocessor">#endif</span> <a name="l00178"></a>00178 <span class="preprocessor"></span> <a name="l00179"></a>00179 <span class="comment">// Local Variables:</span> <a name="l00180"></a>00180 <span class="comment">// mode: c++</span> <a name="l00181"></a>00181 <span class="comment">// c-file-style: "CLJ"</span> <a name="l00182"></a>00182 <span class="comment">// End:</span> </pre></div></div> <hr> <address> <small> Generated at Wed Oct 14 14:12:11 2009 for <a href="http://www.mpqc.org">MPQC</a> 2.3.1 using the documentation package <a href="http://www.doxygen.org">Doxygen</a> 1.5.9. </small> </address> </body> </html>