$extrastylesheet
libMesh::Utility::ReverseBytes Class Reference

#include <utility.h>

List of all members.

Public Member Functions

 ReverseBytes (const bool dr)
template<typename T >
operator() (T &data) const

Private Member Functions

bool reverse () const

Private Attributes

const bool _do_reverse

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 263 of file utility.h.


Constructor & Destructor Documentation

libMesh::Utility::ReverseBytes::ReverseBytes ( const bool  dr) [inline, explicit]

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

Definition at line 299 of file utility.h.

                                         :
  _do_reverse (rb)
{}

Member Function Documentation

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

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

Definition at line 306 of file utility.h.

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

{
  // Possibly reverse the byte ordering
  if (this->reverse())
    {
      unsigned char* b = (unsigned char*) &data;

      int i=0;
      int j=(sizeof(T) - 1);

      while (i < j)
        {
          std::swap (b[i], b[j]);
          i++; j--;
        }
    }

  return data;
}
bool libMesh::Utility::ReverseBytes::reverse ( ) const [inline, private]

Returns the value of the reverse flag.

Definition at line 286 of file utility.h.

References _do_reverse.

Referenced by operator()().

{ return _do_reverse; }

Member Data Documentation

flag

Definition at line 291 of file utility.h.

Referenced by reverse().


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