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.