33#ifndef _CHOMP_MULTIWORK_MWDATA_H_
34#define _CHOMP_MULTIWORK_MWDATA_H_
89 mwData &
Take (
unsigned char *buffer,
int length);
95 const char *
Buffer ()
const;
116 mwData &
Append (
const unsigned char *buffer,
int length);
197 buf = (
unsigned char *) 0;
213 throw "No memory for mwData copying constructor.";
214 for (
int i = 0; i <
len; ++ i)
218 buf = (
unsigned char *) 0;
235 throw "No memory for mwData assignment operator.";
236 for (
int i = 0; i <
len; ++ i)
240 buf = (
unsigned char *) 0;
305 return Take ((
unsigned char *) buffer, length);
317 return reinterpret_cast<const char *
> (
buf);
333 unsigned char *buf1 =
new unsigned char [allocated1];
335 throw "Not enough memory to increase mwData buffer.";
338 for (
int i = 0; i <
len; ++ i)
354 const int testnumber = 1;
355 if (!*((
char *) &testnumber))
357 for (
int i = 0; i < n; ++ i)
364 for (
int i = 0; i < n; ++ i)
377 const int testnumber = 1;
378 if (!*((
char *) &testnumber))
380 for (
int i = 0; i < n; ++ i)
387 for (
int i = 0; i < n; ++ i)
396 for (
int i = 0; i < n; ++ i)
403 return Append ((
const unsigned char *) x, n);
426 return (
const char *) (
buf +
pos);
453 if ((newpos >= 0) && (newpos <=
len))
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);
479 x = (int) (
buf [
pos ++]) << 24;
480 x |= (int) (
buf [
pos ++]) << 16;
481 x |= (int) (
buf [
pos ++]) << 8;
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);
500 x = (int) (
buf [
pos ++]) << 24;
501 x |= (int) (
buf [
pos ++]) << 16;
502 x |= (int) (
buf [
pos ++]) << 8;
510 buf [
len ++] = (
unsigned char) ((x >> 8) & 0xFF);
511 buf [
len ++] = (
unsigned char) (x & 0xFF);
519 x = (short) ((
short) (
buf [
pos ++]) << 8);
527 buf [
len ++] = (
unsigned char) ((x >> 8) & 0xFF);
528 buf [
len ++] = (
unsigned char) (x & 0xFF);
536 x = (
unsigned short) ((
unsigned short) (
buf [
pos ++]) << 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);
555 buf [
len ++] = (
unsigned char) (((
unsigned long) x >> 24) & 0xFF);
557 buf [
len ++] = (
unsigned char) ((x >> 16) & 0xFF);
558 buf [
len ++] = (
unsigned char) ((x >> 8) & 0xFF);
559 buf [
len ++] = (
unsigned char) (x & 0xFF);
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;
575 x = (long) (
buf [
pos ++]) << 24;
577 x |= (long) (
buf [
pos ++]) << 16;
578 x |= (long) (
buf [
pos ++]) << 8;
579 x |= (long) (
buf [
pos ++]);
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);
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);
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;
616 x = (long) (
buf [
pos ++]) << 24;
618 x |= (long) (
buf [
pos ++]) << 16;
619 x |= (long) (
buf [
pos ++]) << 8;
620 x |= (long) (
buf [
pos ++]);
629 buf [
len ++] = (
unsigned char) ((x >> 56) & 0xFF);
630 buf [
len ++] = (
unsigned char) ((x >> 48) & 0xFF);
631 buf [
len ++] = (
unsigned char) ((x >> 40) & 0xFF);
632 buf [
len ++] = (
unsigned char) ((x >> 32) & 0xFF);
633 buf [
len ++] = (
unsigned char) ((x >> 24) & 0xFF);
634 buf [
len ++] = (
unsigned char) ((x >> 16) & 0xFF);
635 buf [
len ++] = (
unsigned char) ((x >> 8) & 0xFF);
636 buf [
len ++] = (
unsigned char) (x & 0xFF);
644 x = (
long long) (
buf [
pos ++]) << 56;
645 x |= (
long long) (
buf [
pos ++]) << 48;
646 x |= (
long long) (
buf [
pos ++]) << 40;
647 x |= (
long long) (
buf [
pos ++]) << 32;
648 x |= (
long long) (
buf [
pos ++]) << 24;
649 x |= (
long long) (
buf [
pos ++]) << 16;
650 x |= (
long long) (
buf [
pos ++]) << 8;
658 buf [
len ++] = (
unsigned char) ((x >> 56) & 0xFF);
659 buf [
len ++] = (
unsigned char) ((x >> 48) & 0xFF);
660 buf [
len ++] = (
unsigned char) ((x >> 40) & 0xFF);
661 buf [
len ++] = (
unsigned char) ((x >> 32) & 0xFF);
662 buf [
len ++] = (
unsigned char) ((x >> 24) & 0xFF);
663 buf [
len ++] = (
unsigned char) ((x >> 16) & 0xFF);
664 buf [
len ++] = (
unsigned char) ((x >> 8) & 0xFF);
665 buf [
len ++] = (
unsigned char) (x & 0xFF);
673 x = (
long long) (
buf [
pos ++]) << 56;
674 x |= (
long long) (
buf [
pos ++]) << 48;
675 x |= (
long long) (
buf [
pos ++]) << 40;
676 x |= (
long long) (
buf [
pos ++]) << 32;
677 x |= (
long long) (
buf [
pos ++]) << 24;
678 x |= (
long long) (
buf [
pos ++]) << 16;
679 x |= (
long long) (
buf [
pos ++]) << 8;
689 buf [
len ++] = (
unsigned char) x;
697 x = (char) (
buf [
pos ++]);
721 buf [
len ++] = x ?
'\1' :
'\0';
729 x =
buf [
pos ++] ? true :
false;
738 return AppendBytes ((
const unsigned char *) &x, 4);
751 return AppendBytes ((
const unsigned char *) &x, 8);
765 const char *str = x. c_str ();
767 while (str [length ++]);
769 return Append (
reinterpret_cast<const unsigned char *
> (str),
776 while ((pos0 <
len) &&
buf [pos0])
780 x = std::string (
reinterpret_cast<const char *
> (
buf +
pos));
790 while (x [length ++]);
792 return Append (x, length);
798 while ((pos0 <
len) &&
buf [pos0])
809 return Append (
reinterpret_cast<const unsigned char *
> (x));
814 return Retrieve ((
unsigned char *) x);
833 return m. Append (x);
839 return m. Retrieve (x);
844 return m. Append (x);
849 return m. Append (x);
854 return m. Retrieve (x);
859 return m. Retrieve (x);
863inline std::ostream &
operator << (std::ostream &s,
const mwData &m)
866 s.
write (m. Buffer (), m. Length ());
870inline std::istream &
operator >> (std::istream &s, mwData &m)
873 int pos = 0, len = 0;
882 char *newbuf =
new char [len];
885 for (
int i = 0; i < pos; ++ i)
886 newbuf [i] = buf [i];
890 buf [pos ++] = (
unsigned char) (ch);
897 char *newbuf =
new char [pos];
898 for (
int i = 0; i < pos; ++ i)
899 newbuf [i] = buf [i];
901 m. Take (newbuf, pos);
This class is used to convert data structures into a single sequence of bytes and to retrieve this da...
mwData & Swap(mwData &x)
Swaps the data with another data structure.
mwData & Take(mwData &x)
Takes the data from another data structure and makes the other data empty.
unsigned char * buf
The data buffer.
mwData & SkipString()
Skips a zero-terminated string in the buffer.
int Length() const
Returns the length of all the data in the buffer.
int pos
The current read position in the buffer.
mwData & Append(const char *buffer, int length)
Appends raw data to the buffer.
int len
The length of the data in the buffer and the write position.
mwData & Retrieve(int &x)
int Position() const
Returns the current reading position in the buffer.
const char * Current() const
Returns the currently pointed data in the buffer.
void IncreaseBuffer(int n)
Increases the buffer by the given number of bytes (or more) beyond the current position.
const char * Buffer() const
Returns a pointer to the data buffer.
mwData & Rewind()
Rewinds the buffer to the beginning for reading.
int allocated
The length of the allocated buffer memory space.
mwData & RetrieveBytes(unsigned char *x, int n)
Retrieve a data piece from the buffer and swaps bytes if necessary.
mwData & Reset()
Forgets the buffer and makes the data empty.
mwData & operator=(const mwData &x)
The assignment operator.
mwData & AppendBytes(const unsigned char *x, int n)
Appends a data piece to the buffer and swaps bytes if necessary.
mwData()
The default constructor of empty data.
This file contains the basic configuration of the MultiWork module, mainly as a definition of a serie...
int write(std::ostream &out, const coordtype *c, int dim, char parenthesis=40, char closing=0)
void swap(mwWorkerData &data1, mwWorkerData &data2)
mwData & operator>>(mwData &m, type &x)
mwData & operator<<(mwData &m, const type &x)
This namespace contains the entire CHomP library interface.