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

Constructor & Destructor Documentation

◆ ReverseBytes()

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

Constructor.

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

Definition at line 372 of file utility.h.

372  :
373  _do_reverse (rb)
374 {}

Member Function Documentation

◆ operator()()

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

380 {
381  // Possibly reverse the byte ordering
382  if (this->reverse())
383  {
384  unsigned char * b = (unsigned char *) &data;
385 
386  int i=0;
387  int j=(sizeof(T) - 1);
388 
389  while (i < j)
390  {
391  std::swap (b[i], b[j]);
392  i++; j--;
393  }
394  }
395 
396  return data;
397 }

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

◆ reverse()

bool libMesh::Utility::ReverseBytes::reverse ( ) const
inlineprivate
Returns
The value of the reverse flag.

Definition at line 360 of file utility.h.

360 { return _do_reverse; }

References _do_reverse.

Referenced by operator()().

Member Data Documentation

◆ _do_reverse

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

flag

Definition at line 365 of file utility.h.

Referenced by reverse().


The documentation for this class was generated from the following file:
swap
void swap(Iterator &lhs, Iterator &rhs)
swap, used to implement op=
Definition: variant_filter_iterator.h:478
libMesh::Utility::ReverseBytes::_do_reverse
const bool _do_reverse
flag
Definition: utility.h:365
data
IterBase * data
Ideally this private member data should have protected access.
Definition: variant_filter_iterator.h:337
libMesh::Utility::ReverseBytes::reverse
bool reverse() const
Definition: utility.h:360