libMesh::Utility::ReverseBytes Class Reference

#include <utility.h>

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)

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

Definition at line 299 of file utility.h.

299  :
300  _do_reverse (rb)
301  {}

Member Function Documentation

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

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

Definition at line 306 of file utility.h.

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

307  {
308  // Possibly reverse the byte ordering
309  if (this->reverse())
310  {
311  unsigned char* b = (unsigned char*) &data;
313  register int i=0;
314  register int j=(sizeof(T) - 1);
316  while (i < j)
317  {
318  std::swap (b[i], b[j]);
319  i++; j--;
320  }
321  }
323  return data;
324  }
bool libMesh::Utility::ReverseBytes::reverse ( ) const

Returns the value of the reverse flag.

Definition at line 286 of file utility.h.

References _do_reverse.

Referenced by operator()().

286 { return _do_reverse; }

Member Data Documentation

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


Definition at line 291 of file utility.h.

Referenced by reverse().

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

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

Hosted By: Logo