Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members  

xdr_cxx.h

00001 // $Id: xdr_cxx.h,v 1.6 2003/01/16 03:21:00 peterson Exp $
00002 
00003 // The Next Great Finite Element Library.
00004 // Copyright (C) 2002  Benjamin S. Kirk, John W. Peterson
00005   
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License, or (at your option) any later version.
00010   
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015   
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 
00020 
00021 
00022 #ifndef __xdr_cxx_h__
00023 #define __xdr_cxx_h__
00024 
00025 // Local includes
00026 #include "mesh_common.h"
00027 
00028 // C++ includes
00029 #ifdef HAVE_RPC_RPC_H
00030 #  include <rpc/rpc.h>
00031 #endif
00032 
00033 #include <fstream>
00034 #include <iomanip>
00035 #include <vector>
00036 #include <string>
00037 #ifdef USE_COMPLEX_NUMBERS
00038 # include <complex>
00039 #endif
00040 
00041 #define xdr_MAX_STRING_LENGTH 256
00042 
00043 #ifndef SINGLE_PRECISION
00044 #define xdr_REAL xdr_double
00045 #else
00046 #define xdr_REAL xdr_float
00047 #endif
00048 
00049 
00050 
00051 //--------------------------------------------------------------
00052 // Xdr class definition
00053 
00062 class Xdr
00063 {
00064   
00065 public:
00066 
00070   enum XdrMODE {UNKNOWN = -1, ENCODE=0, DECODE, WRITE, READ};
00071 
00076   Xdr (const std::string& name="", const XdrMODE m=UNKNOWN);
00077 
00081   ~Xdr ();
00082 
00086   void open (const std::string& name);
00087 
00091   void close();
00092 
00097   bool is_open() const;
00098 
00103   bool reading() const { return ((mode == DECODE) || (mode == READ)); };
00104 
00109   bool writing() const { return ((mode == ENCODE) || (mode == WRITE)); };
00110 
00115   XdrMODE access_mode() const { return mode; };
00116 
00117   // Data access methods
00118 
00122   void data(int& a, const char* comment="");
00123 
00127   Xdr& operator << (int& a) { assert (writing()); data(a); return *this; };
00128 
00132   Xdr& operator >> (int& a) { assert (reading()); data(a); return *this; };
00133   
00137   void data(unsigned int& a, const char* comment="");
00138 
00142   Xdr& operator << (unsigned int& a) { assert (writing()); data(a); return *this; };
00143 
00147   Xdr& operator >> (unsigned int& a) { assert (reading()); data(a); return *this; };
00148 
00152   void data(short int& a, const char* comment="");
00153 
00157   Xdr& operator << (short int& a) { assert (writing()); data(a); return *this; };
00158 
00162   Xdr& operator >> (short int& a) { assert (reading()); data(a); return *this; };
00163 
00167   void data(unsigned short int& a, const char* comment="");
00168 
00172   Xdr& operator << (unsigned short int& a) { assert (writing()); data(a); return *this; };
00173 
00177   Xdr& operator >> (unsigned short int& a) { assert (reading()); data(a); return *this; };
00178 
00182   void data(float& a, const char* comment="");
00183 
00187   Xdr& operator << (float& a) { assert (writing()); data(a); return *this; };
00188 
00192   Xdr& operator >> (float& a) { assert (reading()); data(a); return *this; };
00193 
00197   void data(double& a, const char* comment="");
00198 
00202   Xdr& operator << (double& a) { assert (writing()); data(a); return *this; };
00203 
00207   Xdr& operator >> (double& a) { assert (reading()); data(a); return *this; };
00208 
00209 
00210 #ifdef USE_COMPLEX_NUMBERS
00211 
00215   void data(std::complex<float>& a, const char* comment="");
00216 
00220   Xdr& operator << (std::complex<float>& a) { assert (writing()); data(a); return *this; };
00221 
00225   Xdr& operator >> (std::complex<float>& a) { assert (reading()); data(a); return *this; };
00226 
00230   void data(std::complex<double>& a, const char* comment="");
00231 
00235   Xdr& operator << (std::complex<double>& a) { assert (writing()); data(a); return *this; };
00236 
00240   Xdr& operator >> (std::complex<double>& a) { assert (reading()); data(a); return *this; };
00241 
00242 
00243 #endif
00244 
00248   void data(std::vector<int>& v, const char* comment="");
00249 
00253   Xdr& operator << (std::vector<int>& v) { assert (writing()); data(v); return *this; };
00254 
00258   Xdr& operator >> (std::vector<int>& v) { assert (reading()); data(v); return *this; };
00259 
00263   void data(std::vector<unsigned int>& v, const char* comment="");
00264 
00268   Xdr& operator << (std::vector<unsigned int>& v) { assert (writing()); data(v); return *this; };
00269 
00273   Xdr& operator >> (std::vector<unsigned int>& v) { assert (reading()); data(v); return *this; };
00274 
00278   void data(std::vector<short int>& v, const char* comment="");
00279 
00283   Xdr& operator << (std::vector<short int>& v) { assert (writing()); data(v); return *this; };
00284 
00288   Xdr& operator >> (std::vector<short int>& v) { assert (reading()); data(v); return *this; };
00289 
00293   void data(std::vector<unsigned short int>& v, const char* comment="");
00294 
00298   Xdr& operator << (std::vector<unsigned short int>& v) { assert (writing()); data(v); return *this; };
00299 
00303   Xdr& operator >> (std::vector<unsigned short int>& v) { assert (reading()); data(v); return *this; };
00304 
00308   void data(std::vector<float>& v, const char* comment="");
00309 
00313   Xdr& operator << (std::vector<float>& v) { assert (writing()); data(v); return *this; };
00314 
00318   Xdr& operator >> (std::vector<float>& v) { assert (reading()); data(v); return *this; };
00319 
00323   void data(std::vector<double>& v, const char* comment="");
00324 
00328   Xdr& operator << (std::vector<double>& v) { assert (writing()); data(v); return *this; };
00329 
00333   Xdr& operator >> (std::vector<double>& v) { assert (reading()); data(v); return *this; };
00334 
00335 
00336 #ifdef USE_COMPLEX_NUMBERS
00337 
00341   void data(std::vector< std::complex<float> >& v, const char* comment="");
00342 
00346   Xdr& operator << (std::vector< std::complex<float> >& v) { assert (writing()); data(v); return *this; };
00347 
00351   Xdr& operator >> (std::vector< std::complex<float> >& v) { assert (reading()); data(v); return *this; };
00352 
00356   void data(std::vector< std::complex<double> >& v, const char* comment="");
00357 
00361   Xdr& operator << (std::vector< std::complex<double> >& v) { assert (writing()); data(v); return *this; };
00362 
00366   Xdr& operator >> (std::vector< std::complex<double> >& v) { assert (reading()); data(v); return *this; };
00367 
00368 #endif
00369 
00370 
00374   void data(std::string& s, const char* comment="");
00375 
00379   Xdr& operator << (std::string& v) { assert (writing()); data(v); return *this; };
00380 
00384   Xdr& operator >> (std::string& v) { assert (reading()); data(v); return *this; };
00385 
00386 
00387 private:
00388 
00392   const XdrMODE mode;
00393 
00394 #ifdef HAVE_RPC_RPC_H
00395   
00402   XDR* xdrs;
00403   
00404 #endif
00405 
00409   FILE* fp;
00410 
00414   std::ofstream out;
00415 
00419   std::ifstream in;
00420 
00424   const int comm_len;
00425   char comm[xdr_MAX_STRING_LENGTH];  
00426 };
00427 
00428 
00429 
00430 #endif

Generated on Wed Jan 22 09:02:38 2003 for libMesh by doxygen1.2.14 written by Dimitri van Heesch,  1997-2002