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

324  :
325  _do_reverse (rb)
326 {}

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

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

332 {
333  // Possibly reverse the byte ordering
334  if (this->reverse())
335  {
336  unsigned char * b = (unsigned char *) &data;
337 
338  int i=0;
339  int j=(sizeof(T) - 1);
340 
341  while (i < j)
342  {
343  std::swap (b[i], b[j]);
344  i++; j--;
345  }
346  }
347 
348  return data;
349 }
void swap(Iterator &lhs, Iterator &rhs)
IterBase * data

◆ reverse()

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

Definition at line 312 of file utility.h.

References _do_reverse.

Referenced by operator()().

312 { return _do_reverse; }

Member Data Documentation

◆ _do_reverse

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

flag

Definition at line 317 of file utility.h.

Referenced by reverse().


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