The Original CHomP Software
Public Member Functions | Private Member Functions | Private Attributes | List of all members
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>

Public Member Functions

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

Private Member Functions

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

Private Attributes

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

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 66 of file mwdata.h.

Constructor & Destructor Documentation

◆ mwData() [1/2]

chomp::multiwork::mwData::mwData ( )
inline

The default constructor of empty data.

Definition at line 195 of file mwdata.h.

196{
197 buf = (unsigned char *) 0;
198 len = 0;
199 allocated = 0;
200 pos = 0;
201 return;
202} /* mwData::mwData */
unsigned char * buf
The data buffer.
Definition: mwdata.h:169
int pos
The current read position in the buffer.
Definition: mwdata.h:178
int len
The length of the data in the buffer and the write position.
Definition: mwdata.h:172
int allocated
The length of the allocated buffer memory space.
Definition: mwdata.h:175

References allocated, buf, len, and pos.

◆ ~mwData()

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

The destructor.

Definition at line 308 of file mwdata.h.

309{
310 if (buf)
311 delete [] buf;
312 return;
313} /* mwData::~mwData */

References buf.

◆ mwData() [2/2]

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

The copy constructor.

Definition at line 204 of file mwdata.h.

205{
206 len = x. len;
207 allocated = x. allocated;
208 pos = x. pos;
209 if (allocated)
210 {
211 buf = new unsigned char [allocated];
212 if (!buf)
213 throw "No memory for mwData copying constructor.";
214 for (int i = 0; i < len; ++ i)
215 buf [i] = x. buf [i];
216 }
217 else
218 buf = (unsigned char *) 0;
219 return;
220} /* mwData::mwData */

References allocated, buf, len, and pos.

Member Function Documentation

◆ Append() [1/15]

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

Definition at line 686 of file mwdata.h.

687{
688 IncreaseBuffer (1);
689 buf [len ++] = (unsigned char) x;
690 return *this;
691} /* mwData::Append */
void IncreaseBuffer(int n)
Increases the buffer by the given number of bytes (or more) beyond the current position.
Definition: mwdata.h:325

References buf, IncreaseBuffer(), and len.

◆ Append() [2/15]

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

Appends raw data to the buffer.

Definition at line 401 of file mwdata.h.

402{
403 return Append ((const unsigned char *) x, n);
404} /* mwData::Append */
mwData & Append(const char *buffer, int length)
Appends raw data to the buffer.
Definition: mwdata.h:401

References Append().

Referenced by Append().

◆ Append() [3/15]

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

Definition at line 807 of file mwdata.h.

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

References Append().

◆ Append() [4/15]

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

Definition at line 748 of file mwdata.h.

749{
750 IncreaseBuffer (8);
751 return AppendBytes ((const unsigned char *) &x, 8);
752} /* mwData::Append */
mwData & AppendBytes(const unsigned char *x, int n)
Appends a data piece to the buffer and swaps bytes if necessary.
Definition: mwdata.h:348

References AppendBytes(), and IncreaseBuffer().

◆ Append() [5/15]

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

Definition at line 735 of file mwdata.h.

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

References AppendBytes(), and IncreaseBuffer().

◆ Append() [6/15]

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

Definition at line 465 of file mwdata.h.

466{
467 IncreaseBuffer (4);
468 buf [len ++] = (unsigned char) ((x >> 24) & 0xFF);
469 buf [len ++] = (unsigned char) ((x >> 16) & 0xFF);
470 buf [len ++] = (unsigned char) ((x >> 8) & 0xFF);
471 buf [len ++] = (unsigned char) (x & 0xFF);
472 return *this;
473} /* mwData::Append */

References buf, IncreaseBuffer(), and len.

◆ Append() [7/15]

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

Definition at line 541 of file mwdata.h.

542{
543 IncreaseBuffer (8);
544#if (__LONG_MAX__ > 2147483647)
545 buf [len ++] = (unsigned char) (((unsigned long) x >> 56) & 0xFF);
546 buf [len ++] = (unsigned char) ((x >> 48) & 0xFF);
547 buf [len ++] = (unsigned char) ((x >> 40) & 0xFF);
548 buf [len ++] = (unsigned char) ((x >> 32) & 0xFF);
549 buf [len ++] = (unsigned char) ((x >> 24) & 0xFF);
550#else
551 buf [len ++] = 0;
552 buf [len ++] = 0;
553 buf [len ++] = 0;
554 buf [len ++] = 0;
555 buf [len ++] = (unsigned char) (((unsigned long) x >> 24) & 0xFF);
556#endif
557 buf [len ++] = (unsigned char) ((x >> 16) & 0xFF);
558 buf [len ++] = (unsigned char) ((x >> 8) & 0xFF);
559 buf [len ++] = (unsigned char) (x & 0xFF);
560 return *this;
561} /* mwData::Append */

References buf, IncreaseBuffer(), and len.

◆ Append() [8/15]

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

Appends the entire data buffer to the data.

Definition at line 429 of file mwdata.h.

430{
431 return Append (x. Buffer (), x. Length ());
432} /* mwData::Append */
int Length() const
Returns the length of all the data in the buffer.
Definition: mwdata.h:320
const char * Buffer() const
Returns a pointer to the data buffer.
Definition: mwdata.h:315

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

◆ Append() [9/15]

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

Definition at line 507 of file mwdata.h.

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

References buf, IncreaseBuffer(), and len.

◆ Append() [10/15]

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

Definition at line 701 of file mwdata.h.

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

References buf, IncreaseBuffer(), and len.

◆ Append() [11/15]

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

Appends raw data to the buffer.

Definition at line 393 of file mwdata.h.

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

References buf, IncreaseBuffer(), and len.

◆ Append() [12/15]

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

Definition at line 787 of file mwdata.h.

788{
789 int length = 0;
790 while (x [length ++]);
791 IncreaseBuffer (length);
792 return Append (x, length);
793} /* mwData::Append */

References Append(), and IncreaseBuffer().

◆ Append() [13/15]

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

Definition at line 486 of file mwdata.h.

487{
488 IncreaseBuffer (4);
489 buf [len ++] = (unsigned char) ((x >> 24) & 0xFF);
490 buf [len ++] = (unsigned char) ((x >> 16) & 0xFF);
491 buf [len ++] = (unsigned char) ((x >> 8) & 0xFF);
492 buf [len ++] = (unsigned char) (x & 0xFF);
493 return *this;
494} /* mwData::Append */

References buf, IncreaseBuffer(), and len.

◆ Append() [14/15]

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

Definition at line 583 of file mwdata.h.

584{
585 IncreaseBuffer (8);
586#if (__LONG_MAX__ > 2147483647)
587 buf [len ++] = (unsigned char) ((x >> 56) & 0xFF);
588 buf [len ++] = (unsigned char) ((x >> 48) & 0xFF);
589 buf [len ++] = (unsigned char) ((x >> 40) & 0xFF);
590 buf [len ++] = (unsigned char) ((x >> 32) & 0xFF);
591#else
592 buf [len ++] = 0;
593 buf [len ++] = 0;
594 buf [len ++] = 0;
595 buf [len ++] = 0;
596#endif
597 buf [len ++] = (unsigned char) ((x >> 24) & 0xFF);
598 buf [len ++] = (unsigned char) ((x >> 16) & 0xFF);
599 buf [len ++] = (unsigned char) ((x >> 8) & 0xFF);
600 buf [len ++] = (unsigned char) (x & 0xFF);
601 return *this;
602} /* mwData::Append */

References buf, IncreaseBuffer(), and len.

◆ Append() [15/15]

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

Definition at line 524 of file mwdata.h.

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

References buf, IncreaseBuffer(), and len.

◆ AppendBytes()

mwData & chomp::multiwork::mwData::AppendBytes ( const unsigned char *  x,
int  n 
)
inlineprivate

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

Definition at line 348 of file mwdata.h.

349{
350 // increase the buffer if necessary
351 IncreaseBuffer (n);
352
353 // if the system is big-endian, the bytes must be copied directly
354 const int testnumber = 1;
355 if (!*((char *) &testnumber))
356 {
357 for (int i = 0; i < n; ++ i)
358 buf [len ++] = *(x ++);
359 }
360 // otherwise the bytes must be copied in the reverse order
361 else
362 {
363 x += n;
364 for (int i = 0; i < n; ++ i)
365 buf [len ++] = *(-- x);
366 }
367 return *this;
368} /* mwData::AppendBytes */

References buf, IncreaseBuffer(), and len.

Referenced by Append().

◆ Buffer()

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

Returns a pointer to the data buffer.

Definition at line 315 of file mwdata.h.

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

References buf.

Referenced by Append().

◆ Current()

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

Returns the currently pointed data in the buffer.

Definition at line 424 of file mwdata.h.

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

References buf, and pos.

◆ IncreaseBuffer()

void chomp::multiwork::mwData::IncreaseBuffer ( int  n)
inlineprivate

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

Definition at line 325 of file mwdata.h.

326{
327 // if it is not necessary to increase the buffer, do nothing
328 if (len + n <= allocated)
329 return;
330
331 // allocate a new buffer
332 int allocated1 = allocated + allocated + n;
333 unsigned char *buf1 = new unsigned char [allocated1];
334 if (!buf1)
335 throw "Not enough memory to increase mwData buffer.";
336
337 // copy the previous buffer to the new one
338 for (int i = 0; i < len; ++ i)
339 buf1 [i] = buf [i];
340
341 // replace the old buffer with the new one
342 delete [] buf;
343 buf = buf1;
344 allocated = allocated1;
345 return;
346} /* mwData::IncreaseBuffer */

References allocated, buf, and len.

Referenced by Append(), and AppendBytes().

◆ Length()

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

Returns the length of all the data in the buffer.

Definition at line 320 of file mwdata.h.

321{
322 return len;
323} /* mwData::Length */

References len.

Referenced by Append().

◆ operator=()

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

The assignment operator.

Definition at line 222 of file mwdata.h.

223{
224 if (this == &x)
225 return *this;
226 if (buf)
227 delete [] buf;
228 len = x. len;
229 allocated = x. allocated;
230 pos = x. pos;
231 if (allocated)
232 {
233 buf = new unsigned char [allocated];
234 if (!buf)
235 throw "No memory for mwData assignment operator.";
236 for (int i = 0; i < len; ++ i)
237 buf [i] = x. buf [i];
238 }
239 else
240 buf = (unsigned char *) 0;
241 return *this;
242} /* mwData::operator = */

References allocated, buf, len, and pos.

◆ Position() [1/2]

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

Returns the current reading position in the buffer.

Definition at line 458 of file mwdata.h.

459{
460 return pos;
461} /* mwData::Position */

References pos.

◆ Position() [2/2]

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

Sets the current reading position in the buffer.

Definition at line 451 of file mwdata.h.

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

References len, and pos.

◆ Reset()

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

Forgets the buffer and makes the data empty.

Definition at line 440 of file mwdata.h.

441{
442 len = 0;
443 pos = 0;
444 allocated = 0;
445 if (buf)
446 delete [] buf;
447 buf = 0;
448 return *this;
449} /* mwData::Reset */

References allocated, buf, len, and pos.

◆ Retrieve() [1/12]

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

Definition at line 693 of file mwdata.h.

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

References buf, len, and pos.

◆ Retrieve() [2/12]

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

Definition at line 812 of file mwdata.h.

813{
814 return Retrieve ((unsigned char *) x);
815} /* mwData::Retrieve */
mwData & Retrieve(int &x)
Definition: mwdata.h:475

References Retrieve().

◆ Retrieve() [3/12]

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

Definition at line 754 of file mwdata.h.

755{
756 if (len - pos < 8)
757 return *this;
758 return RetrieveBytes ((unsigned char *) &x, 8);
759} /* mwData::Retrieve */
mwData & RetrieveBytes(unsigned char *x, int n)
Retrieve a data piece from the buffer and swaps bytes if necessary.
Definition: mwdata.h:370

References len, pos, and RetrieveBytes().

◆ Retrieve() [4/12]

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

Definition at line 741 of file mwdata.h.

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

References len, pos, and RetrieveBytes().

◆ Retrieve() [5/12]

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

Definition at line 475 of file mwdata.h.

476{
477 if (len - pos < 4)
478 return *this;
479 x = (int) (buf [pos ++]) << 24;
480 x |= (int) (buf [pos ++]) << 16;
481 x |= (int) (buf [pos ++]) << 8;
482 x |= buf [pos ++];
483 return *this;
484} /* mwData::Retrieve */

References buf, len, and pos.

Referenced by Retrieve().

◆ Retrieve() [6/12]

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

Definition at line 563 of file mwdata.h.

564{
565 if (len - pos < 8)
566 return *this;
567#if (__LONG_MAX__ > 2147483647)
568 x = (long) (buf [pos ++]) << 56;
569 x |= (long) (buf [pos ++]) << 48;
570 x |= (long) (buf [pos ++]) << 40;
571 x |= (long) (buf [pos ++]) << 32;
572 x |= (long) (buf [pos ++]) << 24;
573#else
574 pos += 4;
575 x = (long) (buf [pos ++]) << 24;
576#endif
577 x |= (long) (buf [pos ++]) << 16;
578 x |= (long) (buf [pos ++]) << 8;
579 x |= (long) (buf [pos ++]);
580 return *this;
581} /* mwData::Retrieve */

References buf, len, and pos.

◆ Retrieve() [7/12]

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

Definition at line 515 of file mwdata.h.

516{
517 if (len - pos < 2)
518 return *this;
519 x = (short) ((short) (buf [pos ++]) << 8);
520 x |= buf [pos ++];
521 return *this;
522} /* mwData::Retrieve */

References buf, len, and pos.

◆ Retrieve() [8/12]

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

Definition at line 708 of file mwdata.h.

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

References buf, len, and pos.

◆ Retrieve() [9/12]

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

Definition at line 795 of file mwdata.h.

796{
797 int pos0 = pos;
798 while ((pos0 < len) && buf [pos0])
799 ++ pos0;
800 if (pos0 >= len)
801 return *this;
802 while (pos <= pos0)
803 *(x ++) = buf [pos ++];
804 return *this;
805} /* mwData::Retrieve */

References buf, len, and pos.

◆ Retrieve() [10/12]

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

Definition at line 496 of file mwdata.h.

497{
498 if (len - pos < 4)
499 return *this;
500 x = (int) (buf [pos ++]) << 24;
501 x |= (int) (buf [pos ++]) << 16;
502 x |= (int) (buf [pos ++]) << 8;
503 x |= buf [pos ++];
504 return *this;
505} /* mwData::Retrieve */

References buf, len, and pos.

◆ Retrieve() [11/12]

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

Definition at line 604 of file mwdata.h.

605{
606 if (len - pos < 8)
607 return *this;
608#if (__LONG_MAX__ > 2147483647)
609 x = (long) (buf [pos ++]) << 56;
610 x |= (long) (buf [pos ++]) << 48;
611 x |= (long) (buf [pos ++]) << 40;
612 x |= (long) (buf [pos ++]) << 32;
613 x |= (long) (buf [pos ++]) << 24;
614#else
615 pos += 4;
616 x = (long) (buf [pos ++]) << 24;
617#endif
618 x |= (long) (buf [pos ++]) << 16;
619 x |= (long) (buf [pos ++]) << 8;
620 x |= (long) (buf [pos ++]);
621 return *this;
622} /* mwData::Retrieve */

References buf, len, and pos.

◆ Retrieve() [12/12]

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

Definition at line 532 of file mwdata.h.

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

References buf, len, and pos.

◆ RetrieveBytes()

mwData & chomp::multiwork::mwData::RetrieveBytes ( unsigned char *  x,
int  n 
)
inlineprivate

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

Definition at line 370 of file mwdata.h.

371{
372 // if there is not enough data in the buffer, do nothing
373 if (len - pos < n)
374 return *this;
375
376 // if the system is big-endian, the bytes must be just copied
377 const int testnumber = 1;
378 if (!*((char *) &testnumber))
379 {
380 for (int i = 0; i < n; ++ i)
381 *(x ++) = buf [pos ++];
382 }
383 // otherwise the bytes must be swapped
384 else
385 {
386 x += n;
387 for (int i = 0; i < n; ++ i)
388 *(-- x) = buf [pos ++];
389 }
390 return *this;
391} /* mwData::RetrieveBytes */

References buf, len, and pos.

Referenced by Retrieve().

◆ Rewind()

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

Rewinds the buffer to the beginning for reading.

Definition at line 434 of file mwdata.h.

435{
436 pos = 0;
437 return *this;
438} /* mwData::Rewind */

References pos.

◆ SkipString()

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

Skips a zero-terminated string in the buffer.

Definition at line 819 of file mwdata.h.

820{
821 while ((pos < len) && buf [pos])
822 ++ pos;
823 if (pos < len)
824 ++ pos;
825 return *this;
826} /* mwData::SkipString */

References buf, len, and pos.

◆ Swap()

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

Swaps the data with another data structure.

Definition at line 244 of file mwdata.h.

245{
246 // swap the buffers
247 unsigned char *buf0;
248 buf0 = buf;
249 buf = x. buf;
250 x. buf = buf0;
251
252 // swap the numbers
253 int number;
254 number = pos;
255 pos = x. pos;
256 x. pos = number;
257 number = len;
258 len = x. len;
259 x. len = number;
260 number = allocated;
261 allocated = x. allocated;
262 x. allocated = number;
263
264 return *this;
265} /* mwData::Swap */

References allocated, buf, len, and pos.

◆ Take() [1/3]

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

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

Definition at line 303 of file mwdata.h.

304{
305 return Take ((unsigned char *) buffer, length);
306} /* mwData::Take */
mwData & Take(mwData &x)
Takes the data from another data structure and makes the other data empty.
Definition: mwdata.h:273

References Take().

◆ Take() [2/3]

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

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

Definition at line 273 of file mwdata.h.

274{
275 if (buf)
276 delete [] buf;
277 buf = x. buf;
278 x. buf = 0;
279
280 pos = x. pos;
281 x. pos = 0;
282
283 len = x. len;
284 x. len = 0;
285
286 allocated = x. allocated;
287 x. allocated = 0;
288
289 return *this;
290} /* mwData::Take */

References allocated, buf, len, and pos.

Referenced by Take().

◆ Take() [3/3]

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

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

Definition at line 292 of file mwdata.h.

293{
294 if (buf)
295 delete [] buf;
296 buf = buffer;
297 pos = 0;
298 len = length;
299 allocated = length;
300 return *this;
301} /* mwData::Take */

References allocated, buf, len, and pos.

Member Data Documentation

◆ allocated

int chomp::multiwork::mwData::allocated
private

The length of the allocated buffer memory space.

Definition at line 175 of file mwdata.h.

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

◆ buf

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

◆ len

int chomp::multiwork::mwData::len
private

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

Definition at line 172 of file mwdata.h.

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

◆ pos

int chomp::multiwork::mwData::pos
private

The current read position in the buffer.

Definition at line 178 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: