Nemo  2.3.46
BinaryStorageBuffer Class Reference

A class to store any kind of data in a char buffer before unloading it in a binary data file. More...

#include <binarystoragebuffer.h>

+ Collaboration diagram for BinaryStorageBuffer:

Public Member Functions

 BinaryStorageBuffer ()
 
 ~BinaryStorageBuffer ()
 
char * getBuffer () const
 
unsigned int getByteLength () const
 
unsigned int getBytesOut () const
 
void clear ()
 
void set_buff ()
 
void set_buff (void *zone, unsigned int length)
 
void extend_buff ()
 
void store (void *stream, unsigned int nb_bytes)
 
void read (void *out, unsigned int nb_bytes)
 
void BSBread (void *out, unsigned int nb_bytes)
 

Private Attributes

char * _buff
 
unsigned int _len
 
unsigned int _bytes_in
 
unsigned int _bytes_out
 

Detailed Description

A class to store any kind of data in a char buffer before unloading it in a binary data file.

Constructor & Destructor Documentation

BinaryStorageBuffer::BinaryStorageBuffer ( )
inline
48 : _buff(NULL),_len(0),_bytes_in(0),_bytes_out(0) {}
char * _buff
Definition: binarystoragebuffer.h:43
unsigned int _len
Definition: binarystoragebuffer.h:44
unsigned int _bytes_out
Definition: binarystoragebuffer.h:44
unsigned int _bytes_in
Definition: binarystoragebuffer.h:44
BinaryStorageBuffer::~BinaryStorageBuffer ( )
inline

References _buff.

49 {if(_buff != NULL) delete[]_buff;}
char * _buff
Definition: binarystoragebuffer.h:43

Member Function Documentation

void BinaryStorageBuffer::BSBread ( void *  out,
unsigned int  nb_bytes 
)
inline

References read().

Referenced by BinaryDataLoader::extractPop().

165  { read(out,nb_bytes); }
void read(void *out, unsigned int nb_bytes)
Definition: binarystoragebuffer.h:147
void BinaryStorageBuffer::clear ( )
inline

References _buff.

Referenced by BinaryDataLoader::clear(), and BinaryDataSaver::printData().

55  {
56  if(_buff != NULL) delete [] _buff;
57  _buff = NULL;
58  _len = _bytes_in = _bytes_out = 0;
59  }
char * _buff
Definition: binarystoragebuffer.h:43
unsigned int _len
Definition: binarystoragebuffer.h:44
unsigned int _bytes_out
Definition: binarystoragebuffer.h:44
unsigned int _bytes_in
Definition: binarystoragebuffer.h:44
void BinaryStorageBuffer::extend_buff ( )
inline

References _buff, fatal(), and MAX_BUFF.

Referenced by store().

102  {
103 #ifdef _DEBUG_
104  std::cout<<"BinaryStorageBuffer::extend_buff"<<std::flush;
105 #endif
106 
107  char *old_buff, *new_buff;
108 
109  old_buff = _buff;
110 
111  new_buff = new char[_len + MAX_BUFF];
112 
113  if(new_buff == NULL) fatal("BinaryStorageBuffer::extend_buff::memory exhausted !!\n");
114 
115  memcpy(new_buff,_buff,_len);
116 
117  _buff = new_buff;
118 
119  _len += MAX_BUFF;
120 
121  delete [] old_buff;
122 
123 #ifdef _DEBUG_
124  std::cout<<"["<<_len/1024<<"kB]"<<std::endl;
125 #endif
126  }
#define MAX_BUFF
Definition: binarystoragebuffer.h:36
char * _buff
Definition: binarystoragebuffer.h:43
void fatal(const char *str,...)
Definition: output.cc:90
unsigned int _len
Definition: binarystoragebuffer.h:44
char* BinaryStorageBuffer::getBuffer ( ) const
inline

References _buff.

Referenced by BinaryDataSaver::printData().

51 {return _buff;}
char * _buff
Definition: binarystoragebuffer.h:43
unsigned int BinaryStorageBuffer::getByteLength ( ) const
inline

References _bytes_in.

Referenced by BinaryDataSaver::FHwrite(), BinaryDataSaver::printData(), Metapop::store_data(), and BinaryDataSaver::storeData().

52 {return _bytes_in;}
unsigned int _bytes_in
Definition: binarystoragebuffer.h:44
unsigned int BinaryStorageBuffer::getBytesOut ( ) const
inline

References _bytes_out.

Referenced by Metapop::retrieve_data().

53 {return _bytes_out;}
unsigned int _bytes_out
Definition: binarystoragebuffer.h:44
void BinaryStorageBuffer::read ( void *  out,
unsigned int  nb_bytes 
)
inline

References _bytes_out, and fatal().

Referenced by BSBread(), TTWolbachia::retrieve_data(), TTQuanti::retrieve_data(), TTDispersal::retrieve_data(), TProtoDispersal::retrieve_data(), TTNeutralGenes::retrieve_data(), TTDeletMutations_bitstring::retrieve_data(), TProtoQuanti::retrieve_data(), Individual::retrieve_data(), TProtoNeutralGenes::retrieve_data(), TProtoDeletMutations_bitstring::retrieve_data(), and Metapop::retrieve_data().

148  {
149 
150  if(((_bytes_out + nb_bytes) > _bytes_in) )
151  fatal("BinaryStorageBuffer::read::attempt to read beyond buffer length (asked %i bytes)\n",nb_bytes);
152  else {
153  char *tab = (char*)out;
154  if(nb_bytes == 1) {
155  (*tab) = _buff[_bytes_out];
156  } else {
157  for(unsigned int i = 0; i < nb_bytes; ++i)
158  tab[i] = _buff[_bytes_out + i];
159  }
160  }
161  _bytes_out += nb_bytes;
162  }
char * _buff
Definition: binarystoragebuffer.h:43
void fatal(const char *str,...)
Definition: output.cc:90
unsigned int _bytes_out
Definition: binarystoragebuffer.h:44
unsigned int _bytes_in
Definition: binarystoragebuffer.h:44
void BinaryStorageBuffer::set_buff ( )
inline

References _buff, fatal(), and MAX_BUFF.

Referenced by BinaryDataSaver::execute(), and BinaryDataLoader::extractPop().

64  {
65 #ifdef __DEBUG__
66  std::cout<<"BinaryStorageBuffer::set_buff";
67 #endif
68 
69  if(_buff != NULL) delete [] _buff;
70 
71  _buff = new char[MAX_BUFF];
72 
73  if(_buff == NULL) fatal("BinaryStorageBuffer::set_buff::memory exhausted !!\n");
74 
75  _len = MAX_BUFF;
76  _bytes_in = 0;
77  memset(_buff,'\0',MAX_BUFF);
78 
79 #ifdef _DEBUG_
80  std::cout<<"[ok]"<<std::endl;
81 #endif
82  }
#define MAX_BUFF
Definition: binarystoragebuffer.h:36
char * _buff
Definition: binarystoragebuffer.h:43
void fatal(const char *str,...)
Definition: output.cc:90
unsigned int _len
Definition: binarystoragebuffer.h:44
unsigned int _bytes_in
Definition: binarystoragebuffer.h:44
void BinaryStorageBuffer::set_buff ( void *  zone,
unsigned int  length 
)
inline

References _buff.

87  {
88  if(_buff != NULL) delete [] _buff;
89 
90  _buff = new char [length];
91 
92  memcpy(_buff, zone, length);
93 
94  _bytes_in = _len = length ;
95 
96  _bytes_out = 0;
97  }
char * _buff
Definition: binarystoragebuffer.h:43
unsigned int _len
Definition: binarystoragebuffer.h:44
unsigned int _bytes_out
Definition: binarystoragebuffer.h:44
unsigned int _bytes_in
Definition: binarystoragebuffer.h:44
void BinaryStorageBuffer::store ( void *  stream,
unsigned int  nb_bytes 
)
inline

References _bytes_in, and extend_buff().

Referenced by BinaryDataSaver::printData(), TTWolbachia::store_data(), TTQuanti::store_data(), TTDispersal::store_data(), TProtoDispersal::store_data(), TTNeutralGenes::store_data(), TTDeletMutations_bitstring::store_data(), TProtoQuanti::store_data(), Individual::store_data(), TProtoNeutralGenes::store_data(), TProtoDeletMutations_bitstring::store_data(), Metapop::store_data(), and BinaryDataSaver::storeData().

131  {
132 
133  while( !((_bytes_in + nb_bytes) < _len) ) extend_buff();
134 
135  if(nb_bytes == 1) {
136  _buff[_bytes_in] = *(char*)stream;
137  } else {
138  char *tab = (char*)stream;
139  for(unsigned int i = 0; i < nb_bytes; i++)
140  _buff[_bytes_in + i] = tab[i];
141  }
142  _bytes_in += nb_bytes;
143  }
char * _buff
Definition: binarystoragebuffer.h:43
void extend_buff()
Definition: binarystoragebuffer.h:101
unsigned int _len
Definition: binarystoragebuffer.h:44
unsigned int _bytes_in
Definition: binarystoragebuffer.h:44

Member Data Documentation

char* BinaryStorageBuffer::_buff
private
unsigned int BinaryStorageBuffer::_bytes_in
private

Referenced by getByteLength(), and store().

unsigned int BinaryStorageBuffer::_bytes_out
private

Referenced by getBytesOut(), and read().

unsigned int BinaryStorageBuffer::_len
private

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

Generated for Nemo v2.3.0 by  doxygen 1.8.8 --
Catalogued on GSR