Poster of Linux kernelThe best gift for a Linux geek
Utility::ReverseBytes

Utility::ReverseBytes

Section: C Library Functions (3) Updated: Thu Apr 7 2011
Local index Up
 

NAME

Utility::ReverseBytes -  

SYNOPSIS


#include <utility.h>  

Public Member Functions


ReverseBytes (const bool dr)

template<typename T > 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 271 of file utility.h.  

Constructor & Destructor Documentation

 

Utility::ReverseBytes::ReverseBytes (const booldr) [inline]Constructor. Takes a bool, determines if we will actually do byte reversing.

Definition at line 306 of file utility.h.

                                           :
    _do_reverse (rb)
  {}
 

Member Function Documentation

 

template<typename T > T Utility::ReverseBytes::operator() (T &data) const [inline]Functor. Takes the data to reverse and performs the byte-ordering reversal.

Definition at line 313 of file utility.h.

References reverse().

  {
    // Possibly reverse the byte ordering
    if (this->reverse())
      {
        unsigned char* b = (unsigned char*) &data;
        
        register int i=0;
        register int j=(sizeof(T) - 1);
        
        while (i < j)
          {
            std::swap (b[i], b[j]);
            i++; j--;
          }
      }

    return data;
  }
 

bool Utility::ReverseBytes::reverse () const [inline, private]Returns the value of the reverse flag.

Definition at line 293 of file utility.h.

References _do_reverse.

Referenced by operator()().

{ return _do_reverse; };
 

Member Data Documentation

 

const bool Utility::ReverseBytes::_do_reverse [private]flag

Definition at line 293 of file utility.h.

Referenced by reverse().

 

Author

Generated automatically by Doxygen for libMesh from the source code.


 

Index

NAME
SYNOPSIS
Public Member Functions
Private Member Functions
Private Attributes
Detailed Description
Constructor & Destructor Documentation
Utility::ReverseBytes::ReverseBytes (const booldr) [inline]Constructor. Takes a bool, determines if we will actually do byte reversing.
Member Function Documentation
template<typename T > T Utility::ReverseBytes::operator() (T &data) const [inline]Functor. Takes the data to reverse and performs the byte-ordering reversal.
bool Utility::ReverseBytes::reverse () const [inline, private]Returns the value of the reverse flag.
Member Data Documentation
const bool Utility::ReverseBytes::_do_reverse [private]flag
Author

This document was created by man2html, using the manual pages.
Time: 21:58:00 GMT, April 16, 2011