Public Member Functions | Private Member Functions | Private Attributes

chomp::multiwork::mwData Class Reference

This class is used to convert data structures into a single sequence of bytes and to retrieve this data for the purpose of communication between a coordinator and workers. More...

#include <mwdata.h>

List of all members.

Public Member Functions

 mwData ()
 The default constructor of empty data.
 ~mwData ()
 The destructor.
 mwData (const mwData &x)
 The copy constructor.
mwDataoperator= (const mwData &x)
 The assignment operator.
mwDataSwap (mwData &x)
 Swaps the data with another data structure.
mwDataTake (mwData &x)
 Takes the data from another data structure and makes the other data empty.
mwDataTake (unsigned char *buffer, int length)
 Takes raw data that was allocated with the "new" operator.
mwDataTake (char *buffer, int length)
 Takes raw data that was allocated with the "new" operator.
const char * Buffer () const
 Returns a pointer to the data buffer.
int Length () const
 Returns the length of all the data in the buffer.
mwDataRewind ()
 Rewinds the buffer to the beginning for reading.
mwDataReset ()
 Forgets the buffer and makes the data empty.
int Position (int newpos)
 Sets the current reading position in the buffer.
int Position () const
 Returns the current reading position in the buffer.
mwDataAppend (const char *buffer, int length)
 Appends raw data to the buffer.
mwDataAppend (const unsigned char *buffer, int length)
 Appends raw data to the buffer.
mwDataAppend (const mwData &x)
 Appends the entire data buffer to the data.
const char * Current () const
 Returns the currently pointed data in the buffer.
mwDataAppend (const int &x)
mwDataRetrieve (int &x)
mwDataAppend (const unsigned int &x)
mwDataRetrieve (unsigned int &x)
mwDataAppend (const short &x)
mwDataRetrieve (short &x)
mwDataAppend (const unsigned short &x)
mwDataRetrieve (unsigned short &x)
mwDataAppend (const long &x)
mwDataRetrieve (long &x)
mwDataAppend (const unsigned long &x)
mwDataRetrieve (unsigned long &x)
mwDataAppend (const long long &x)
mwDataRetrieve (long long &x)
mwDataAppend (const unsigned long long &x)
mwDataRetrieve (unsigned long long &x)
mwDataAppend (const char &x)
mwDataRetrieve (char &x)
mwDataAppend (const unsigned char &x)
mwDataRetrieve (unsigned char &x)
mwDataAppend (const bool &x)
mwDataRetrieve (bool &x)
mwDataAppend (const float &x)
mwDataRetrieve (float &x)
mwDataAppend (const double &x)
mwDataRetrieve (double &x)
mwDataAppend (const std::string &x)
mwDataRetrieve (std::string &x)
mwDataAppend (const char *x)
mwDataRetrieve (char *x)
mwDataAppend (const unsigned char *x)
mwDataRetrieve (unsigned char *x)
mwDataSkipString ()
 Skips a zero-terminated string in the buffer.

Private Member Functions

void IncreaseBuffer (int n)
 Increases the buffer by the given number of bytes (or more) beyond the current position.
mwDataAppendBytes (const unsigned char *x, int n)
 Appends a data piece to the buffer and swaps bytes if necessary.
mwDataRetrieveBytes (unsigned char *x, int n)
 Retrieve a data piece from the buffer and swaps bytes if necessary.

Private Attributes

unsigned char * buf
 The data buffer.
int len
 The length of the data in the buffer and the write position.
int allocated
 The length of the allocated buffer memory space.
int pos
 The current read position in the buffer.

Detailed Description

This class is used to convert data structures into a single sequence of bytes and to retrieve this data for the purpose of communication between a coordinator and workers.

It is assumed that 'int' has at least 32 bits and 'double' has 64 bits. For 'bool', 'long long' and 'string', see the corresponding constants. In the buffer: 'char' = 8-bit, 'short' = 16-bit, 'int' = 32-bit, 'long' and 'long long' = 64-bit, 'float' = 32-bit, 'double' = 64-bit (all big endian). NOTE: Until January 21, 2010 'long' was supposed to be 32 bits long.

Definition at line 67 of file mwdata.h.


Constructor & Destructor Documentation

chomp::multiwork::mwData::mwData (  )  [inline]

The default constructor of empty data.

Definition at line 196 of file mwdata.h.

References allocated, buf, len, and pos.

{
        buf = (unsigned char *) 0;
        len = 0;
        allocated = 0;
        pos = 0;
        return;
} /* mwData::mwData */

chomp::multiwork::mwData::~mwData (  )  [inline]

The destructor.

Definition at line 309 of file mwdata.h.

References buf.

{
        if (buf)
                delete [] buf;
        return;
} /* mwData::~mwData */

chomp::multiwork::mwData::mwData ( const mwData x  )  [inline]

The copy constructor.

Definition at line 205 of file mwdata.h.

References allocated, buf, len, and pos.

{
        len = x. len;
        allocated = x. allocated;
        pos = x. pos;
        if (allocated)
        {
                buf = new unsigned char [allocated];
                if (!buf)
                        throw "No memory for mwData copying constructor.";
                for (int i = 0; i < len; ++ i)
                        buf [i] = x. buf [i];
        }
        else
                buf = (unsigned char *) 0;
        return;
} /* mwData::mwData */


Member Function Documentation

mwData & chomp::multiwork::mwData::Append ( const char *  buffer,
int  length 
) [inline]

Appends raw data to the buffer.

Definition at line 402 of file mwdata.h.

Referenced by Append().

{
        return Append ((const unsigned char *) x, n);
} /* mwData::Append */

mwData & chomp::multiwork::mwData::Append ( const int &  x  )  [inline]

Definition at line 466 of file mwdata.h.

References buf, IncreaseBuffer(), and len.

{
        IncreaseBuffer (4);
        buf [len ++] = (unsigned char) ((x >> 24) & 0xFF);
        buf [len ++] = (unsigned char) ((x >> 16) & 0xFF);
        buf [len ++] = (unsigned char) ((x >> 8) & 0xFF);
        buf [len ++] = (unsigned char) (x & 0xFF);
        return *this;
} /* mwData::Append */

mwData & chomp::multiwork::mwData::Append ( const unsigned int &  x  )  [inline]

Definition at line 487 of file mwdata.h.

References buf, IncreaseBuffer(), and len.

{
        IncreaseBuffer (4);
        buf [len ++] = (unsigned char) ((x >> 24) & 0xFF);
        buf [len ++] = (unsigned char) ((x >> 16) & 0xFF);
        buf [len ++] = (unsigned char) ((x >> 8) & 0xFF);
        buf [len ++] = (unsigned char) (x & 0xFF);
        return *this;
} /* mwData::Append */

mwData & chomp::multiwork::mwData::Append ( const char &  x  )  [inline]

Definition at line 687 of file mwdata.h.

References buf, IncreaseBuffer(), and len.

{
        IncreaseBuffer (1);
        buf [len ++] = (unsigned char) x;
        return *this;
} /* mwData::Append */

mwData & chomp::multiwork::mwData::Append ( const unsigned char &  x  )  [inline]

Definition at line 702 of file mwdata.h.

References buf, IncreaseBuffer(), and len.

{
        IncreaseBuffer (1);
        buf [len ++] = x;
        return *this;
} /* mwData::Append */

mwData & chomp::multiwork::mwData::Append ( const bool &  x  )  [inline]

Definition at line 719 of file mwdata.h.

References buf, IncreaseBuffer(), and len.

{
        IncreaseBuffer (1);
        buf [len ++] = x ? '\1' : '\0';
        return *this;
} /* mwData::Append */

mwData & chomp::multiwork::mwData::Append ( const float &  x  )  [inline]

Definition at line 736 of file mwdata.h.

References AppendBytes(), and IncreaseBuffer().

{
        IncreaseBuffer (4);
        return AppendBytes ((const unsigned char *) &x, 4);
} /* mwData::Append */

mwData & chomp::multiwork::mwData::Append ( const short &  x  )  [inline]

Definition at line 508 of file mwdata.h.

References buf, IncreaseBuffer(), and len.

{
        IncreaseBuffer (2);
        buf [len ++] = (unsigned char) ((x >> 8) & 0xFF);
        buf [len ++] = (unsigned char) (x & 0xFF);
        return *this;
} /* mwData::Append */

mwData & chomp::multiwork::mwData::Append ( const double &  x  )  [inline]

Definition at line 749 of file mwdata.h.

References AppendBytes(), and IncreaseBuffer().

{
        IncreaseBuffer (8);
        return AppendBytes ((const unsigned char *) &x, 8);
} /* mwData::Append */

mwData & chomp::multiwork::mwData::Append ( const std::string &  x  )  [inline]

Definition at line 764 of file mwdata.h.

References Append(), and IncreaseBuffer().

{
        const char *str = x. c_str ();
        int length = 0;
        while (str [length ++]);
        IncreaseBuffer (length);
        return Append (reinterpret_cast<const unsigned char *> (str),
                length);
} /* mwData::Append */

mwData & chomp::multiwork::mwData::Append ( const unsigned short &  x  )  [inline]

Definition at line 525 of file mwdata.h.

References buf, IncreaseBuffer(), and len.

{
        IncreaseBuffer (2);
        buf [len ++] = (unsigned char) ((x >> 8) & 0xFF);
        buf [len ++] = (unsigned char) (x & 0xFF);
        return *this;
} /* mwData::Append */

mwData & chomp::multiwork::mwData::Append ( const char *  x  )  [inline]

Definition at line 808 of file mwdata.h.

References Append().

{
        return Append (reinterpret_cast<const unsigned char *> (x));
} /* mwData::Append */

mwData & chomp::multiwork::mwData::Append ( const unsigned char *  x  )  [inline]

Definition at line 788 of file mwdata.h.

References Append(), and IncreaseBuffer().

{
        int length = 0;
        while (x [length ++]);
        IncreaseBuffer (length);
        return Append (x, length);
} /* mwData::Append */

mwData & chomp::multiwork::mwData::Append ( const unsigned char *  buffer,
int  length 
) [inline]

Appends raw data to the buffer.

Definition at line 394 of file mwdata.h.

References buf, IncreaseBuffer(), and len.

{
        IncreaseBuffer (n);
        for (int i = 0; i < n; ++ i)
                buf [len ++] = *(x ++);
        return *this;
} /* mwData::Append */

mwData & chomp::multiwork::mwData::Append ( const long &  x  )  [inline]

Definition at line 542 of file mwdata.h.

References buf, IncreaseBuffer(), and len.

{
        IncreaseBuffer (8);
#if (__LONG_MAX__ > 2147483647)
        buf [len ++] = (unsigned char) (((unsigned long) x >> 56) & 0xFF);
        buf [len ++] = (unsigned char) ((x >> 48) & 0xFF);
        buf [len ++] = (unsigned char) ((x >> 40) & 0xFF);
        buf [len ++] = (unsigned char) ((x >> 32) & 0xFF);
        buf [len ++] = (unsigned char) ((x >> 24) & 0xFF);
#else
        buf [len ++] = 0;
        buf [len ++] = 0;
        buf [len ++] = 0;
        buf [len ++] = 0;
        buf [len ++] = (unsigned char) (((unsigned long) x >> 24) & 0xFF);
#endif
        buf [len ++] = (unsigned char) ((x >> 16) & 0xFF);
        buf [len ++] = (unsigned char) ((x >> 8) & 0xFF);
        buf [len ++] = (unsigned char) (x & 0xFF);
        return *this;
} /* mwData::Append */

mwData & chomp::multiwork::mwData::Append ( const unsigned long &  x  )  [inline]

Definition at line 584 of file mwdata.h.

References buf, IncreaseBuffer(), and len.

{
        IncreaseBuffer (8);
#if (__LONG_MAX__ > 2147483647)
        buf [len ++] = (unsigned char) ((x >> 56) & 0xFF);
        buf [len ++] = (unsigned char) ((x >> 48) & 0xFF);
        buf [len ++] = (unsigned char) ((x >> 40) & 0xFF);
        buf [len ++] = (unsigned char) ((x >> 32) & 0xFF);
#else
        buf [len ++] = 0;
        buf [len ++] = 0;
        buf [len ++] = 0;
        buf [len ++] = 0;
#endif
        buf [len ++] = (unsigned char) ((x >> 24) & 0xFF);
        buf [len ++] = (unsigned char) ((x >> 16) & 0xFF);
        buf [len ++] = (unsigned char) ((x >> 8) & 0xFF);
        buf [len ++] = (unsigned char) (x & 0xFF);
        return *this;
} /* mwData::Append */

mwData & chomp::multiwork::mwData::Append ( const mwData x  )  [inline]

Appends the entire data buffer to the data.

Definition at line 430 of file mwdata.h.

References Append(), Buffer(), and Length().

{
        return Append (x. Buffer (), x. Length ());
} /* mwData::Append */

mwData & chomp::multiwork::mwData::Append ( const long long &  x  )  [inline]

Definition at line 627 of file mwdata.h.

References buf, IncreaseBuffer(), and len.

{
        IncreaseBuffer (8);
        buf [len ++] = (unsigned char) ((x >> 56) & 0xFF);
        buf [len ++] = (unsigned char) ((x >> 48) & 0xFF);
        buf [len ++] = (unsigned char) ((x >> 40) & 0xFF);
        buf [len ++] = (unsigned char) ((x >> 32) & 0xFF);
        buf [len ++] = (unsigned char) ((x >> 24) & 0xFF);
        buf [len ++] = (unsigned char) ((x >> 16) & 0xFF);
        buf [len ++] = (unsigned char) ((x >> 8) & 0xFF);
        buf [len ++] = (unsigned char) (x & 0xFF);
        return *this;
} /* mwData::Append */

mwData & chomp::multiwork::mwData::Append ( const unsigned long long &  x  )  [inline]

Definition at line 656 of file mwdata.h.

References buf, IncreaseBuffer(), and len.

{
        IncreaseBuffer (8);
        buf [len ++] = (unsigned char) ((x >> 56) & 0xFF);
        buf [len ++] = (unsigned char) ((x >> 48) & 0xFF);
        buf [len ++] = (unsigned char) ((x >> 40) & 0xFF);
        buf [len ++] = (unsigned char) ((x >> 32) & 0xFF);
        buf [len ++] = (unsigned char) ((x >> 24) & 0xFF);
        buf [len ++] = (unsigned char) ((x >> 16) & 0xFF);
        buf [len ++] = (unsigned char) ((x >> 8) & 0xFF);
        buf [len ++] = (unsigned char) (x & 0xFF);
        return *this;
} /* mwData::Append */

mwData & chomp::multiwork::mwData::AppendBytes ( const unsigned char *  x,
int  n 
) [inline, private]

Appends a data piece to the buffer and swaps bytes if necessary.

Definition at line 349 of file mwdata.h.

References buf, IncreaseBuffer(), and len.

Referenced by Append().

{
        // increase the buffer if necessary
        IncreaseBuffer (n);

        // if the system is big-endian, the bytes must be copied directly
        const int testnumber = 1;
        if (!*((char *) &testnumber))
        {
                for (int i = 0; i < n; ++ i)
                        buf [len ++] = *(x ++);
        }
        // otherwise the bytes must be copied in the reverse order
        else
        {
                x += n;
                for (int i = 0; i < n; ++ i)
                        buf [len ++] = *(-- x);
        }
        return *this;
} /* mwData::AppendBytes */

const char * chomp::multiwork::mwData::Buffer (  )  const [inline]

Returns a pointer to the data buffer.

Definition at line 316 of file mwdata.h.

References buf.

Referenced by Append().

{
        return reinterpret_cast<const char *> (buf);
} /* mwData::Buffer */

const char * chomp::multiwork::mwData::Current (  )  const [inline]

Returns the currently pointed data in the buffer.

Definition at line 425 of file mwdata.h.

References buf, and pos.

{
        return (const char *) (buf + pos);
} /* mwData::Current */

void chomp::multiwork::mwData::IncreaseBuffer ( int  n  )  [inline, private]

Increases the buffer by the given number of bytes (or more) beyond the current position.

Definition at line 326 of file mwdata.h.

References allocated, buf, and len.

Referenced by Append(), and AppendBytes().

{
        // if it is not necessary to increase the buffer, do nothing
        if (len + n <= allocated)
                return;

        // allocate a new buffer
        int allocated1 = allocated + allocated + n;
        unsigned char *buf1 = new unsigned char [allocated1];
        if (!buf1)
                throw "Not enough memory to increase mwData buffer.";

        // copy the previous buffer to the new one
        for (int i = 0; i < len; ++ i)
                buf1 [i] = buf [i];
                
        // replace the old buffer with the new one
        delete [] buf;
        buf = buf1;
        allocated = allocated1;
        return;
} /* mwData::IncreaseBuffer */

int chomp::multiwork::mwData::Length (  )  const [inline]

Returns the length of all the data in the buffer.

Definition at line 321 of file mwdata.h.

References len.

Referenced by Append().

{
        return len;
} /* mwData::Length */

mwData & chomp::multiwork::mwData::operator= ( const mwData x  )  [inline]

The assignment operator.

Definition at line 223 of file mwdata.h.

References allocated, buf, len, and pos.

{
        if (this == &x)
                return *this;
        if (buf)
                delete [] buf;
        len = x. len;
        allocated = x. allocated;
        pos = x. pos;
        if (allocated)
        {
                buf = new unsigned char [allocated];
                if (!buf)
                        throw "No memory for mwData assignment operator.";
                for (int i = 0; i < len; ++ i)
                        buf [i] = x. buf [i];
        }
        else
                buf = (unsigned char *) 0;
        return *this;
} /* mwData::operator = */

int chomp::multiwork::mwData::Position ( int  newpos  )  [inline]

Sets the current reading position in the buffer.

Definition at line 452 of file mwdata.h.

References len, and pos.

{
        if ((newpos >= 0) && (newpos <= len))
                pos = newpos;
        return pos;
} /* mwData::Position */

int chomp::multiwork::mwData::Position (  )  const [inline]

Returns the current reading position in the buffer.

Definition at line 459 of file mwdata.h.

References pos.

{
        return pos;
} /* mwData::Position */

mwData & chomp::multiwork::mwData::Reset (  )  [inline]

Forgets the buffer and makes the data empty.

Definition at line 441 of file mwdata.h.

References allocated, buf, len, and pos.

{
        len = 0;
        pos = 0;
        allocated = 0;
        if (buf)
                delete [] buf;
        buf = 0;
        return *this;
} /* mwData::Reset */

mwData & chomp::multiwork::mwData::Retrieve ( long &  x  )  [inline]

Definition at line 564 of file mwdata.h.

References buf, len, and pos.

{
        if (len - pos < 8)
                return *this;
#if (__LONG_MAX__ > 2147483647)
        x = (long) (buf [pos ++]) << 56;
        x |= (long) (buf [pos ++]) << 48;
        x |= (long) (buf [pos ++]) << 40;
        x |= (long) (buf [pos ++]) << 32;
        x |= (long) (buf [pos ++]) << 24;
#else
        pos += 4;
        x = (long) (buf [pos ++]) << 24;
#endif
        x |= (long) (buf [pos ++]) << 16;
        x |= (long) (buf [pos ++]) << 8;
        x |= (long) (buf [pos ++]);
        return *this;
} /* mwData::Retrieve */

mwData & chomp::multiwork::mwData::Retrieve ( std::string &  x  )  [inline]

Definition at line 774 of file mwdata.h.

References buf, len, and pos.

{
        int pos0 = pos;
        while ((pos0 < len) && buf [pos0])
                ++ pos0;
        if (pos0 >= len)
                return *this;
        x = std::string (reinterpret_cast<const char *> (buf + pos));
        pos = pos0 + 1;
        return *this;
} /* mwData::Retrieve */

mwData & chomp::multiwork::mwData::Retrieve ( int &  x  )  [inline]

Definition at line 476 of file mwdata.h.

References buf, len, and pos.

Referenced by Retrieve().

{
        if (len - pos < 4)
                return *this;
        x = (int) (buf [pos ++]) << 24;
        x |= (int) (buf [pos ++]) << 16;
        x |= (int) (buf [pos ++]) << 8;
        x |= buf [pos ++];
        return *this;
} /* mwData::Retrieve */

mwData & chomp::multiwork::mwData::Retrieve ( unsigned short &  x  )  [inline]

Definition at line 533 of file mwdata.h.

References buf, len, and pos.

{
        if (len - pos < 2)
                return *this;
        x = (unsigned short) ((unsigned short) (buf [pos ++]) << 8);
        x |= buf [pos ++];
        return *this;
} /* mwData::Retrieve */

mwData & chomp::multiwork::mwData::Retrieve ( char &  x  )  [inline]

Definition at line 694 of file mwdata.h.

References buf, len, and pos.

{
        if (len - pos < 1)
                return *this;
        x = (char) (buf [pos ++]);
        return *this;
} /* mwData::Retrieve */

mwData & chomp::multiwork::mwData::Retrieve ( unsigned int &  x  )  [inline]

Definition at line 497 of file mwdata.h.

References buf, len, and pos.

{
        if (len - pos < 4)
                return *this;
        x = (int) (buf [pos ++]) << 24;
        x |= (int) (buf [pos ++]) << 16;
        x |= (int) (buf [pos ++]) << 8;
        x |= buf [pos ++];
        return *this;
} /* mwData::Retrieve */

mwData & chomp::multiwork::mwData::Retrieve ( unsigned char &  x  )  [inline]

Definition at line 709 of file mwdata.h.

References buf, len, and pos.

{
        if (len - pos < 1)
                return *this;
        x = buf [pos ++];
        return *this;
} /* mwData::Retrieve */

mwData & chomp::multiwork::mwData::Retrieve ( unsigned char *  x  )  [inline]

Definition at line 796 of file mwdata.h.

References buf, len, and pos.

{
        int pos0 = pos;
        while ((pos0 < len) && buf [pos0])
                ++ pos0;
        if (pos0 >= len)
                return *this;
        while (pos <= pos0)
                *(x ++) = buf [pos ++];
        return *this;
} /* mwData::Retrieve */

mwData & chomp::multiwork::mwData::Retrieve ( bool &  x  )  [inline]

Definition at line 726 of file mwdata.h.

References buf, len, and pos.

{
        if (len - pos < 1)
                return *this;
        x = buf [pos ++] ? true : false;
        return *this;
} /* mwData::Retrieve */

mwData & chomp::multiwork::mwData::Retrieve ( unsigned long long &  x  )  [inline]

Definition at line 670 of file mwdata.h.

References buf, len, and pos.

{
        if (len - pos < 8)
                return *this;
        x = (long long) (buf [pos ++]) << 56;
        x |= (long long) (buf [pos ++]) << 48;
        x |= (long long) (buf [pos ++]) << 40;
        x |= (long long) (buf [pos ++]) << 32;
        x |= (long long) (buf [pos ++]) << 24;
        x |= (long long) (buf [pos ++]) << 16;
        x |= (long long) (buf [pos ++]) << 8;
        x |= buf [pos ++];
        return *this;
} /* mwData::Retrieve */

mwData & chomp::multiwork::mwData::Retrieve ( double &  x  )  [inline]

Definition at line 755 of file mwdata.h.

References len, pos, and RetrieveBytes().

{
        if (len - pos < 8)
                return *this;
        return RetrieveBytes ((unsigned char *) &x, 8);
} /* mwData::Retrieve */

mwData & chomp::multiwork::mwData::Retrieve ( char *  x  )  [inline]

Definition at line 813 of file mwdata.h.

References Retrieve().

{
        return Retrieve ((unsigned char *) x);
} /* mwData::Retrieve */

mwData & chomp::multiwork::mwData::Retrieve ( short &  x  )  [inline]

Definition at line 516 of file mwdata.h.

References buf, len, and pos.

{
        if (len - pos < 2)
                return *this;
        x = (short) ((short) (buf [pos ++]) << 8);
        x |= buf [pos ++];
        return *this;
} /* mwData::Retrieve */

mwData & chomp::multiwork::mwData::Retrieve ( float &  x  )  [inline]

Definition at line 742 of file mwdata.h.

References len, pos, and RetrieveBytes().

{
        if (len - pos < 4)
                return *this;
        return RetrieveBytes ((unsigned char *) &x, 4);
} /* mwData::Retrieve */

mwData & chomp::multiwork::mwData::Retrieve ( unsigned long &  x  )  [inline]

Definition at line 605 of file mwdata.h.

References buf, len, and pos.

{
        if (len - pos < 8)
                return *this;
#if (__LONG_MAX__ > 2147483647)
        x = (long) (buf [pos ++]) << 56;
        x |= (long) (buf [pos ++]) << 48;
        x |= (long) (buf [pos ++]) << 40;
        x |= (long) (buf [pos ++]) << 32;
        x |= (long) (buf [pos ++]) << 24;
#else
        pos += 4;
        x = (long) (buf [pos ++]) << 24;
#endif
        x |= (long) (buf [pos ++]) << 16;
        x |= (long) (buf [pos ++]) << 8;
        x |= (long) (buf [pos ++]);
        return *this;
} /* mwData::Retrieve */

mwData & chomp::multiwork::mwData::Retrieve ( long long &  x  )  [inline]

Definition at line 641 of file mwdata.h.

References buf, len, and pos.

{
        if (len - pos < 8)
                return *this;
        x = (long long) (buf [pos ++]) << 56;
        x |= (long long) (buf [pos ++]) << 48;
        x |= (long long) (buf [pos ++]) << 40;
        x |= (long long) (buf [pos ++]) << 32;
        x |= (long long) (buf [pos ++]) << 24;
        x |= (long long) (buf [pos ++]) << 16;
        x |= (long long) (buf [pos ++]) << 8;
        x |= buf [pos ++];
        return *this;
} /* mwData::Retrieve */

mwData & chomp::multiwork::mwData::RetrieveBytes ( unsigned char *  x,
int  n 
) [inline, private]

Retrieve a data piece from the buffer and swaps bytes if necessary.

Definition at line 371 of file mwdata.h.

References buf, len, and pos.

Referenced by Retrieve().

{
        // if there is not enough data in the buffer, do nothing
        if (len - pos < n)
                return *this;

        // if the system is big-endian, the bytes must be just copied
        const int testnumber = 1;
        if (!*((char *) &testnumber))
        {
                for (int i = 0; i < n; ++ i)
                        *(x ++) = buf [pos ++];
        }
        // otherwise the bytes must be swapped
        else
        {
                x += n;
                for (int i = 0; i < n; ++ i)
                        *(-- x) = buf [pos ++];
        }
        return *this;
} /* mwData::RetrieveBytes */

mwData & chomp::multiwork::mwData::Rewind (  )  [inline]

Rewinds the buffer to the beginning for reading.

Definition at line 435 of file mwdata.h.

References pos.

{
        pos = 0;
        return *this;
} /* mwData::Rewind */

mwData & chomp::multiwork::mwData::SkipString (  )  [inline]

Skips a zero-terminated string in the buffer.

Definition at line 820 of file mwdata.h.

References buf, len, and pos.

{
        while ((pos < len) && buf [pos])
                ++ pos;
        if (pos < len)
                ++ pos;
        return *this;
} /* mwData::SkipString */

mwData & chomp::multiwork::mwData::Swap ( mwData x  )  [inline]

Swaps the data with another data structure.

Definition at line 245 of file mwdata.h.

References allocated, buf, len, and pos.

{
        // swap the buffers
        unsigned char *buf0;
        buf0 = buf;
        buf = x. buf;
        x. buf = buf0;

        // swap the numbers
        int number;
        number = pos;
        pos = x. pos;
        x. pos = number;
        number = len;
        len = x. len;
        x. len = number;
        number = allocated;
        allocated = x. allocated;
        x. allocated = number;
        
        return *this;
} /* mwData::Swap */

mwData & chomp::multiwork::mwData::Take ( char *  buffer,
int  length 
) [inline]

Takes raw data that was allocated with the "new" operator.

Definition at line 304 of file mwdata.h.

References Take().

{
        return Take ((unsigned char *) buffer, length);
} /* mwData::Take */

mwData & chomp::multiwork::mwData::Take ( mwData x  )  [inline]

Takes the data from another data structure and makes the other data empty.

Definition at line 274 of file mwdata.h.

References allocated, buf, len, and pos.

Referenced by Take().

{
        if (buf)
                delete [] buf;
        buf = x. buf;
        x. buf = 0;

        pos = x. pos;
        x. pos = 0;
        
        len = x. len;
        x. len = 0;
        
        allocated = x. allocated;
        x. allocated = 0;
        
        return *this;
} /* mwData::Take */

mwData & chomp::multiwork::mwData::Take ( unsigned char *  buffer,
int  length 
) [inline]

Takes raw data that was allocated with the "new" operator.

Definition at line 293 of file mwdata.h.

References allocated, buf, len, and pos.

{
        if (buf)
                delete [] buf;
        buf = buffer;
        pos = 0;
        len = length;
        allocated = length;
        return *this;
} /* mwData::Take */


Member Data Documentation

The length of the allocated buffer memory space.

Definition at line 176 of file mwdata.h.

Referenced by IncreaseBuffer(), mwData(), operator=(), Reset(), Swap(), and Take().

unsigned char* chomp::multiwork::mwData::buf [private]

The length of the data in the buffer and the write position.

Definition at line 173 of file mwdata.h.

Referenced by Append(), AppendBytes(), IncreaseBuffer(), Length(), mwData(), operator=(), Position(), Reset(), Retrieve(), RetrieveBytes(), SkipString(), Swap(), and Take().

The current read position in the buffer.

Definition at line 179 of file mwdata.h.

Referenced by Current(), mwData(), operator=(), Position(), Reset(), Retrieve(), RetrieveBytes(), Rewind(), SkipString(), Swap(), and Take().


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