libMesh
Public Member Functions | Private Member Functions | Private Attributes | List of all members
libMesh::Xdr Class Reference

This class implements a C++ interface to the XDR (eXternal Data Representation) format. More...

#include <xdr_cxx.h>

Public Member Functions

 Xdr (const std::string &name="", const XdrMODE m=UNKNOWN)
 Constructor. More...
 
 ~Xdr ()
 Destructor. More...
 
void open (const std::string &name)
 Opens the file. More...
 
void close ()
 Closes the file if it is open. More...
 
bool is_open () const
 
bool is_eof ()
 
bool reading () const
 
bool writing () const
 
XdrMODE access_mode () const
 
template<typename T >
void data (T &a, const char *comment="")
 Inputs or outputs a single value. More...
 
template<typename T >
Xdroperator<< (T &a)
 Same, but provides an ostream like interface. More...
 
template<typename T >
Xdroperator>> (T &a)
 Same, but provides an istream like interface. More...
 
template<typename T >
void data_stream (T *val, const unsigned int len, const unsigned int line_break=libMesh::invalid_uint)
 Inputs or outputs a raw data stream. More...
 
void comment (std::string &)
 Writes or reads (ignores) a comment line. More...
 
void set_version (int ver)
 Sets the version of the file that is being read. More...
 
int version () const
 Gets the version of the file that is being read. More...
 

Private Member Functions

template<typename T >
void do_read (T &a)
 Helper method for reading different data types. More...
 
template<typename T >
void do_read (std::complex< T > &a)
 
template<typename T >
void do_read (std::vector< T > &a)
 
template<typename T >
void do_read (std::vector< std::complex< T >> &a)
 
template<typename T >
void do_write (T &a)
 Helper method for writing different data types. More...
 
template<typename T >
void do_write (std::complex< T > &a)
 
template<typename T >
void do_write (std::vector< T > &a)
 
template<typename T >
void do_write (std::vector< std::complex< T >> &a)
 

Private Attributes

const XdrMODE mode
 The mode used for accessing the file. More...
 
std::string file_name
 The file name. More...
 
std::unique_ptr< XDR > xdrs
 Pointer to the standard XDR struct. More...
 
FILE * fp
 File pointer. More...
 
std::unique_ptr< std::istream > in
 The input file stream. More...
 
std::unique_ptr< std::ostream > out
 The output file stream. More...
 
const int comm_len
 A buffer to put comment strings into. More...
 
char comm [xdr_MAX_STRING_LENGTH]
 
bool gzipped_file
 Are we reading/writing zipped files? More...
 
bool bzipped_file
 
bool xzipped_file
 
int version_number
 Version of the file being read. More...
 

Detailed Description

This class implements a C++ interface to the XDR (eXternal Data Representation) format.

XDR is useful for creating platform-independent binary files. This class was created to handle equation system output as a replacement for XdrIO since that is somewhat limited.

Author
Benjamin Kirk
Date
2003 C++ interface for the XDR (eXternal Data Representation) format.

Definition at line 66 of file xdr_cxx.h.

Constructor & Destructor Documentation

◆ Xdr()

libMesh::Xdr::Xdr ( const std::string &  name = "",
const XdrMODE  m = UNKNOWN 
)

Constructor.

Takes the filename and the mode. Valid modes are ENCODE, DECODE, READ, and WRITE.

◆ ~Xdr()

libMesh::Xdr::~Xdr ( )

Destructor.

Closes the file if it is open.

Member Function Documentation

◆ access_mode()

XdrMODE libMesh::Xdr::access_mode ( ) const
Returns
The mode used to access the file. Valid modes are ENCODE, DECODE, READ, or WRITE.

Definition at line 123 of file xdr_cxx.h.

References mode.

123 { return mode; }
const XdrMODE mode
The mode used for accessing the file.
Definition: xdr_cxx.h:201

◆ close()

void libMesh::Xdr::close ( )

Closes the file if it is open.

◆ comment()

void libMesh::Xdr::comment ( std::string &  )

Writes or reads (ignores) a comment line.

◆ data()

template<typename T >
void libMesh::Xdr::data ( T &  a,
const char *  comment = "" 
)

Inputs or outputs a single value.

Referenced by operator<<(), and operator>>().

◆ data_stream()

template<typename T >
void libMesh::Xdr::data_stream ( T *  val,
const unsigned int  len,
const unsigned int  line_break = libMesh::invalid_uint 
)

Inputs or outputs a raw data stream.

◆ do_read() [1/4]

template<typename T >
void libMesh::Xdr::do_read ( T &  a)
private

Helper method for reading different data types.

◆ do_read() [2/4]

template<typename T >
void libMesh::Xdr::do_read ( std::complex< T > &  a)
private

◆ do_read() [3/4]

template<typename T >
void libMesh::Xdr::do_read ( std::vector< T > &  a)
private

◆ do_read() [4/4]

template<typename T >
void libMesh::Xdr::do_read ( std::vector< std::complex< T >> &  a)
private

◆ do_write() [1/4]

template<typename T >
void libMesh::Xdr::do_write ( T &  a)
private

Helper method for writing different data types.

◆ do_write() [2/4]

template<typename T >
void libMesh::Xdr::do_write ( std::complex< T > &  a)
private

◆ do_write() [3/4]

template<typename T >
void libMesh::Xdr::do_write ( std::vector< T > &  a)
private

◆ do_write() [4/4]

template<typename T >
void libMesh::Xdr::do_write ( std::vector< std::complex< T >> &  a)
private

◆ is_eof()

bool libMesh::Xdr::is_eof ( )
Returns
true if the Xdr file being read is at End-Of-File.
Note
This is not a const method - the only portable way to test for an impending EOF is to peek at the next byte of the file first, which may set the eof flag on the istream.

◆ is_open()

bool libMesh::Xdr::is_open ( ) const
Returns
true if the Xdr file is open, false if it is closed.

◆ open()

void libMesh::Xdr::open ( const std::string &  name)

Opens the file.

◆ operator<<()

template<typename T >
Xdr& libMesh::Xdr::operator<< ( T &  a)

Same, but provides an ostream like interface.

Definition at line 137 of file xdr_cxx.h.

References data(), and writing().

137 { libmesh_assert (writing()); data(a); return *this; }
bool writing() const
Definition: xdr_cxx.h:117
void data(T &a, const char *comment="")
Inputs or outputs a single value.

◆ operator>>()

template<typename T >
Xdr& libMesh::Xdr::operator>> ( T &  a)

Same, but provides an istream like interface.

Definition at line 143 of file xdr_cxx.h.

References data(), and reading().

143 { libmesh_assert (reading()); data(a); return *this; }
bool reading() const
Definition: xdr_cxx.h:111
void data(T &a, const char *comment="")
Inputs or outputs a single value.

◆ reading()

bool libMesh::Xdr::reading ( ) const
Returns
true if the file is opened in a reading state, false otherwise.

Definition at line 111 of file xdr_cxx.h.

References libMesh::DECODE, mode, and libMesh::READ.

Referenced by operator>>().

111 { return ((mode == DECODE) || (mode == READ)); }
const XdrMODE mode
The mode used for accessing the file.
Definition: xdr_cxx.h:201

◆ set_version()

void libMesh::Xdr::set_version ( int  ver)

Sets the version of the file that is being read.

Definition at line 159 of file xdr_cxx.h.

References version_number.

159 { version_number = ver; }
int version_number
Version of the file being read.
Definition: xdr_cxx.h:247

◆ version()

int libMesh::Xdr::version ( ) const

Gets the version of the file that is being read.

Definition at line 164 of file xdr_cxx.h.

References version_number.

164 { return version_number; }
int version_number
Version of the file being read.
Definition: xdr_cxx.h:247

◆ writing()

bool libMesh::Xdr::writing ( ) const
Returns
true if the file is opened in a writing state, false otherwise.

Definition at line 117 of file xdr_cxx.h.

References libMesh::ENCODE, mode, and libMesh::WRITE.

Referenced by operator<<().

117 { return ((mode == ENCODE) || (mode == WRITE)); }
const XdrMODE mode
The mode used for accessing the file.
Definition: xdr_cxx.h:201

Member Data Documentation

◆ bzipped_file

bool libMesh::Xdr::bzipped_file
private

Definition at line 242 of file xdr_cxx.h.

◆ comm

char libMesh::Xdr::comm[xdr_MAX_STRING_LENGTH]
private

Definition at line 237 of file xdr_cxx.h.

◆ comm_len

const int libMesh::Xdr::comm_len
private

A buffer to put comment strings into.

Definition at line 236 of file xdr_cxx.h.

◆ file_name

std::string libMesh::Xdr::file_name
private

The file name.

Definition at line 206 of file xdr_cxx.h.

◆ fp

FILE* libMesh::Xdr::fp
private

File pointer.

Definition at line 219 of file xdr_cxx.h.

◆ gzipped_file

bool libMesh::Xdr::gzipped_file
private

Are we reading/writing zipped files?

Definition at line 242 of file xdr_cxx.h.

◆ in

std::unique_ptr<std::istream> libMesh::Xdr::in
private

The input file stream.

Definition at line 226 of file xdr_cxx.h.

◆ mode

const XdrMODE libMesh::Xdr::mode
private

The mode used for accessing the file.

Definition at line 201 of file xdr_cxx.h.

Referenced by access_mode(), reading(), and writing().

◆ out

std::unique_ptr<std::ostream> libMesh::Xdr::out
private

The output file stream.

Definition at line 231 of file xdr_cxx.h.

◆ version_number

int libMesh::Xdr::version_number
private

Version of the file being read.

Definition at line 247 of file xdr_cxx.h.

Referenced by set_version(), and version().

◆ xdrs

std::unique_ptr<XDR> libMesh::Xdr::xdrs
private

Pointer to the standard XDR struct.

See the standard header file rpc/rpc.h for more information.

Definition at line 214 of file xdr_cxx.h.

◆ xzipped_file

bool libMesh::Xdr::xzipped_file
private

Definition at line 242 of file xdr_cxx.h.


The documentation for this class was generated from the following file: