xdr_cxx.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2014 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 #ifndef LIBMESH_XDR_CXX_H
21 #define LIBMESH_XDR_CXX_H
22 
23 // Local includes
24 #include "libmesh/libmesh_common.h"
25 #include "libmesh/libmesh.h"
26 #include "libmesh/enum_xdr_mode.h"
27 #include "libmesh/auto_ptr.h"
28 
29 // C++ includes
30 #ifdef LIBMESH_HAVE_XDR
31 # ifdef LIBMESH_HAVE_RPC_RPC_H
32 # include <rpc/rpc.h>
33 # elif LIBMESH_HAVE_RPC_XDR_H
34 # include <rpc/xdr.h>
35 # endif
36 #endif
37 
38 #include <cstdio> // FILE
39 #include <iosfwd>
40 #include <vector>
41 #include <string>
42 #ifdef LIBMESH_USE_COMPLEX_NUMBERS
43 # include <complex>
44 #endif
45 
46 const unsigned int xdr_MAX_STRING_LENGTH=256;
47 
48 #ifndef LIBMESH_DEFAULT_SINGLE_PRECISION
49 #define xdr_REAL xdr_double
50 #else
51 #define xdr_REAL xdr_float
52 #endif
53 
54 namespace libMesh
55 {
56 
57 
58 
59 //--------------------------------------------------------------
60 // Xdr class definition
61 
70 class Xdr
71 {
72 
73 public:
74 
79  Xdr (const std::string& name="", const libMeshEnums::XdrMODE m=UNKNOWN);
80 
84  ~Xdr ();
85 
89  void open (const std::string& name);
90 
94  void close();
95 
100  bool is_open() const;
101 
106  bool reading() const { return ((mode == DECODE) || (mode == READ)); }
107 
112  bool writing() const { return ((mode == ENCODE) || (mode == WRITE)); }
113 
118  XdrMODE access_mode () const { return mode; }
119 
120  // Data access methods
121 
125  template <typename T>
126  void data(T& a, const char* comment="");
127 
131  template <typename T>
132  Xdr& operator << (T& a) { libmesh_assert (writing()); data(a); return *this; }
133 
137  template <typename T>
138  Xdr& operator >> (T& a) { libmesh_assert (reading()); data(a); return *this; }
139 
143  template <typename T>
144  void data_stream (T *val, const unsigned int len, const unsigned int line_break=libMesh::invalid_uint);
145 
149  void comment (std::string &);
150 
154  void set_version(int ver) { version_number = ver; }
155 
159  int version() const { return version_number; }
160 
161 private:
162 
166  template <typename T>
167  void do_read(T& a);
168 
169  template <typename T>
170  void do_read(std::complex<T>& a);
171 
172  template <typename T>
173  void do_read(std::vector<T>& a);
174 
175  template <typename T>
176  void do_read(std::vector<std::complex<T> >& a);
177 
181  template <typename T>
182  void do_write(T& a);
183 
184  template <typename T>
185  void do_write(std::complex<T>& a);
186 
187  template <typename T>
188  void do_write(std::vector<T>& a);
189 
190  template <typename T>
191  void do_write(std::vector<std::complex<T> >& a);
192 
196  const XdrMODE mode;
197 
201  std::string file_name;
202 
203 #ifdef LIBMESH_HAVE_XDR
204 
211  XDR* xdrs;
212 
216  FILE* fp;
217 
218 #endif
219 
224 
229 
233  const int comm_len;
235 
240 
245 };
246 
247 
248 } // namespace libMesh
249 
250 
251 #endif // LIBMESH_XDR_CXX_H

Site Created By: libMesh Developers
Last modified: February 07 2014 16:57:07 UTC

Hosted By:
SourceForge.net Logo