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

This Functor simply takes an object and reverses its byte representation. More...

#include <utility.h>

Public Member Functions

 ReverseBytes (const bool dr)
 Constructor. More...
template<typename T >
operator() (T &data) const
 Functor. More...

Private Member Functions

bool reverse () const

Private Attributes

const bool _do_reverse
 flag More...

Detailed Description

This Functor simply takes an object and reverses its byte representation.

This is useful for changing endian-ness for file IO. This class has been tested on x86 architectures with 4-byte words.

Definition at line 286 of file utility.h.

Constructor & Destructor Documentation

libMesh::Utility::ReverseBytes::ReverseBytes ( const bool  dr)


Takes a bool, determines if we will actually do byte reversing.

Definition at line 321 of file utility.h.

321  :
322  _do_reverse (rb)
323 {}
const bool _do_reverse
Definition: utility.h:314

Member Function Documentation

template<typename T >
T libMesh::Utility::ReverseBytes::operator() ( T &  data) const


Takes the data to reverse and performs the byte-ordering reversal.

Definition at line 328 of file utility.h.

References data, reverse(), and swap().

329 {
330  // Possibly reverse the byte ordering
331  if (this->reverse())
332  {
333  unsigned char * b = (unsigned char *) &data;
335  int i=0;
336  int j=(sizeof(T) - 1);
338  while (i < j)
339  {
340  std::swap (b[i], b[j]);
341  i++; j--;
342  }
343  }
345  return data;
346 }
void swap(Iterator &lhs, Iterator &rhs)
swap, used to implement op=
IterBase * data
Ideally this private member data should have protected access.
bool libMesh::Utility::ReverseBytes::reverse ( ) const
The value of the reverse flag.

Definition at line 309 of file utility.h.

Referenced by operator()().

309 { return _do_reverse; }
const bool _do_reverse
Definition: utility.h:314

Member Data Documentation

const bool libMesh::Utility::ReverseBytes::_do_reverse


Definition at line 314 of file utility.h.

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