xdr_cxx.h
Go to the documentation of this file.00001 // The libMesh Finite Element Library. 00002 // Copyright (C) 2002-2012 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner 00003 00004 // This library is free software; you can redistribute it and/or 00005 // modify it under the terms of the GNU Lesser General Public 00006 // License as published by the Free Software Foundation; either 00007 // version 2.1 of the License, or (at your option) any later version. 00008 00009 // This library is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // Lesser General Public License for more details. 00013 00014 // You should have received a copy of the GNU Lesser General Public 00015 // License along with this library; if not, write to the Free Software 00016 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 00018 00019 00020 #ifndef LIBMESH_XDR_CXX_H 00021 #define LIBMESH_XDR_CXX_H 00022 00023 // Local includes 00024 #include "libmesh/libmesh_common.h" 00025 #include "libmesh/libmesh.h" 00026 #include "libmesh/enum_xdr_mode.h" 00027 #include "libmesh/auto_ptr.h" 00028 00029 // C++ includes 00030 #ifdef LIBMESH_HAVE_XDR 00031 # include <rpc/rpc.h> 00032 #endif 00033 00034 #include <iosfwd> 00035 #include <vector> 00036 #include <string> 00037 #ifdef LIBMESH_USE_COMPLEX_NUMBERS 00038 # include <complex> 00039 #endif 00040 00041 const unsigned int xdr_MAX_STRING_LENGTH=256; 00042 00043 #ifndef LIBMESH_DEFAULT_SINGLE_PRECISION 00044 #define xdr_REAL xdr_double 00045 #else 00046 #define xdr_REAL xdr_float 00047 #endif 00048 00049 namespace libMesh 00050 { 00051 00052 00053 00054 //-------------------------------------------------------------- 00055 // Xdr class definition 00056 00065 class Xdr 00066 { 00067 00068 public: 00069 00074 Xdr (const std::string& name="", const libMeshEnums::XdrMODE m=UNKNOWN); 00075 00079 ~Xdr (); 00080 00084 void open (const std::string& name); 00085 00089 void close(); 00090 00095 bool is_open() const; 00096 00101 bool reading() const { return ((mode == DECODE) || (mode == READ)); } 00102 00107 bool writing() const { return ((mode == ENCODE) || (mode == WRITE)); } 00108 00113 XdrMODE access_mode () const { return mode; } 00114 00115 // Data access methods 00116 00120 template <typename T> 00121 void data(T& a, const char* comment=""); 00122 00126 template <typename T> 00127 Xdr& operator << (T& a) { libmesh_assert (writing()); data(a); return *this; } 00128 00132 template <typename T> 00133 Xdr& operator >> (T& a) { libmesh_assert (reading()); data(a); return *this; } 00134 00138 template <typename T> 00139 void data_stream (T *val, const unsigned int len, const unsigned int line_break=libMesh::invalid_uint); 00140 00144 void comment (std::string &); 00145 00149 void set_version(int ver) { version_number = ver; } 00150 00154 int version() const { return version_number; } 00155 00156 private: 00157 00161 template <typename T> 00162 void do_read(T& a); 00163 00164 template <typename T> 00165 void do_read(std::complex<T>& a); 00166 00167 template <typename T> 00168 void do_read(std::vector<T>& a); 00169 00170 template <typename T> 00171 void do_read(std::vector<std::complex<T> >& a); 00172 00176 template <typename T> 00177 void do_write(T& a); 00178 00179 template <typename T> 00180 void do_write(std::complex<T>& a); 00181 00182 template <typename T> 00183 void do_write(std::vector<T>& a); 00184 00185 template <typename T> 00186 void do_write(std::vector<std::complex<T> >& a); 00187 00191 const XdrMODE mode; 00192 00196 std::string file_name; 00197 00198 #ifdef LIBMESH_HAVE_XDR 00199 00206 XDR* xdrs; 00207 00211 FILE* fp; 00212 00213 #endif 00214 00218 AutoPtr<std::istream> in; 00219 00223 AutoPtr<std::ostream> out; 00224 00228 const int comm_len; 00229 char comm[xdr_MAX_STRING_LENGTH]; 00230 00234 bool gzipped_file, bzipped_file, xzipped_file; 00235 00239 int version_number; 00240 }; 00241 00242 00243 } // namespace libMesh 00244 00245 00246 #endif // LIBMESH_XDR_CXX_H
Site Created By: libMesh Developers
Last modified: February 05 2013 19:54:49 UTC
Hosted By: