Nemo  2.4.0b
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
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
 
off_t getBuffLength () const
 
off_t getTotByteRecorded () const
 
unsigned int getBytesOut () const
 
void clear ()
 
void emptyBuffer ()
 
void store (void *stream, unsigned int nb_bytes)
 
void set_buff (BinaryDataSaver *owner)
 
void set_buff (void *zone, size_t length)
 
void extend_buff ()
 
void read (void *out, unsigned int nb_bytes)
 
void BSBread (void *out, unsigned int nb_bytes)
 

Private Attributes

char * _buff
 
unsigned int _num_buckets
 
off_t _len
 
off_t _bytes_in
 
off_t _bytes_out
 
off_t _tot_bytes_in
 
BinaryDataSaver_myDataSaver
 

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::BinaryStorageBuffer ( )
inline
55  : _buff(NULL),_len(0),_bytes_in(0),_bytes_out(0),
off_t _tot_bytes_in
Definition: binarystoragebuffer.h:49
unsigned int _num_buckets
Definition: binarystoragebuffer.h:48
char * _buff
Definition: binarystoragebuffer.h:47
off_t _len
Definition: binarystoragebuffer.h:49
BinaryDataSaver * _myDataSaver
Definition: binarystoragebuffer.h:51
off_t _bytes_out
Definition: binarystoragebuffer.h:49
off_t _bytes_in
Definition: binarystoragebuffer.h:49

◆ ~BinaryStorageBuffer()

BinaryStorageBuffer::~BinaryStorageBuffer ( )
inline
57 {if(_buff != NULL) delete[]_buff;}

References _buff.

Member Function Documentation

◆ BSBread()

void BinaryStorageBuffer::BSBread ( void *  out,
unsigned int  nb_bytes 
)
inline
180  { read(out,nb_bytes); }
void read(void *out, unsigned int nb_bytes)
Definition: binarystoragebuffer.h:162

References read().

Referenced by BinaryDataLoader::extractPop().

◆ clear()

void BinaryStorageBuffer::clear ( )
inline
64  {
65  if(_buff != NULL) delete [] _buff;
66  _buff = NULL;
67  _len = _bytes_in = _bytes_out = 0;
68  _num_buckets = 0; _tot_bytes_in = 0L;
69  }

References _buff, _bytes_in, _bytes_out, _len, _num_buckets, and _tot_bytes_in.

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

◆ emptyBuffer()

void BinaryStorageBuffer::emptyBuffer ( )
inline
72  {
73  memset(_buff,'\0',_len);
74  _bytes_in = _bytes_out = 0;
75  }

References _buff, _bytes_in, _bytes_out, and _len.

Referenced by BinaryDataSaver::printData().

◆ extend_buff()

void BinaryStorageBuffer::extend_buff ( )
inline
134  {
135 #ifdef _DEBUG_
136  std::cout<<"BinaryStorageBuffer::extend_buff"<<std::flush;
137 #endif
138 
139  char *old_buff, *new_buff;
140 
141  old_buff = _buff;
142 
143  new_buff = new char[_len + MAX_BUFF];
144 
145  if(new_buff == NULL) fatal("BinaryStorageBuffer::extend_buff::memory exhausted !!\n");
146 
147  memcpy(new_buff,_buff,_len);
148 
149  _buff = new_buff;
150 
151  _len += MAX_BUFF;
152 
153  delete [] old_buff;
154 
155 #ifdef _DEBUG_
156  std::cout<<"["<<_len<<" B]"<<std::endl;
157 #endif
158  }
#define MAX_BUFF
Definition: binarystoragebuffer.h:36
void fatal(const char *str,...)
Definition: output.cc:96

References _buff, _len, fatal(), and MAX_BUFF.

Referenced by store().

◆ getBuffer()

char* BinaryStorageBuffer::getBuffer ( ) const
inline
59 {return _buff;}

References _buff.

Referenced by BinaryDataSaver::printData(), and BinaryDataSaver::printOffsetTable().

◆ getBuffLength()

off_t BinaryStorageBuffer::getBuffLength ( ) const
inline

◆ getBytesOut()

unsigned int BinaryStorageBuffer::getBytesOut ( ) const
inline
62 {return _bytes_out;}

References _bytes_out.

Referenced by Metapop::retrieve_data().

◆ getTotByteRecorded()

off_t BinaryStorageBuffer::getTotByteRecorded ( ) const
inline
61 {return _tot_bytes_in;}

References _tot_bytes_in.

Referenced by Metapop::store_data().

◆ read()

void BinaryStorageBuffer::read ( void *  out,
unsigned int  nb_bytes 
)
inline
163  {
164 
165  if(((_bytes_out + nb_bytes) > _bytes_in) )
166  fatal("BinaryStorageBuffer::read::attempt to read beyond buffer length (asked %i bytes)\n",nb_bytes);
167  else {
168  char *tab = (char*)out;
169  if(nb_bytes == 1) {
170  (*tab) = _buff[_bytes_out];
171  } else {
172  for(unsigned int i = 0; i < nb_bytes; ++i)
173  tab[i] = _buff[_bytes_out + i];
174  }
175  }
176  _bytes_out += nb_bytes;
177  }

References _buff, _bytes_in, _bytes_out, and fatal().

Referenced by BSBread(), Individual::retrieve_data(), Metapop::retrieve_data(), TProtoBDMI::retrieve_data(), TT_BDMI::retrieve_data(), TTDeletMutations_bitstring::retrieve_data(), TProtoDeletMutations_bitstring::retrieve_data(), TTDispersal::retrieve_data(), TProtoDispersal::retrieve_data(), TTNeutralGenes::retrieve_data(), TProtoNeutralGenes::retrieve_data(), TTQuanti_continuous::retrieve_data(), TTQuanti_diallelic::retrieve_data(), TProtoQuanti::retrieve_data(), TTQuanti_diallelic_bitstring::retrieve_data(), and TTWolbachia::retrieve_data().

◆ set_buff() [1/2]

void BinaryStorageBuffer::set_buff ( BinaryDataSaver owner)
inline
84  {
85 #ifdef _DEBUG_
86  std::cout<<"BinaryStorageBuffer::set_buff";
87 #endif
88 
89  _myDataSaver = owner;
90 
91  if(_buff != NULL) delete [] _buff;
92 
93  _buff = new char[MAX_BUFF];
94 
95  if(_buff == NULL) fatal("BinaryStorageBuffer::set_buff::memory exhausted !!\n");
96 
97  _len = MAX_BUFF;
98 
99  _bytes_in = 0;
100 
101  _num_buckets = 0;
102 
103  _tot_bytes_in = 0L;
104 
105  memset(_buff,'\0',MAX_BUFF);
106 
107 #ifdef _DEBUG_
108  std::cout<<"[ok]"<<std::endl;
109 #endif
110  }

References _buff, _bytes_in, _len, _myDataSaver, _num_buckets, _tot_bytes_in, fatal(), and MAX_BUFF.

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

◆ set_buff() [2/2]

void BinaryStorageBuffer::set_buff ( void *  zone,
size_t  length 
)
inline
115  {
116  if(_buff != NULL) delete [] _buff;
117 
118  _buff = new char [length];
119 
120  memcpy(_buff, zone, length);
121 
122  _bytes_in = _len = length ;
123 
125 
126  _bytes_out = 0;
127 
128  _num_buckets = 0;
129  }

References _buff, _bytes_in, _bytes_out, _len, _num_buckets, and _tot_bytes_in.

◆ store()

void BinaryStorageBuffer::store ( void *  stream,
unsigned int  nb_bytes 
)
17 {
18 
19  while( !((_bytes_in + nb_bytes) < _len) ) extend_buff();
20 
21  if(nb_bytes == 1) {
22 
23  _buff[_bytes_in] = *(char*)stream;
24 
25  } else {
26 
27  char *tab = (char*)stream;
28 
29  for(unsigned int i = 0; i < nb_bytes; i++)
30  _buff[_bytes_in + i] = tab[i];
31  }
32 
33  _bytes_in += nb_bytes;
34 
35  _tot_bytes_in += nb_bytes;
36 
37  if(_bytes_in > MAX_BUCKET) {
38 
39  // cout<<"\n BinaryStorageBuffer::store::bucket "<<_num_buckets<<" is full, emptying\n";
40 
41  // tell the binary data saver to empty to bucket to file
43 
44  // cout<<"wrote "<<_tot_bytes_in<<"B so far\n";
45 
46  _num_buckets++;
47 
48  _bytes_in = 0;
49  }
50 }
#define MAX_BUCKET
Definition: binarystoragebuffer.h:38
void printData()
Definition: binarydatasaver.cc:368
void extend_buff()
Definition: binarystoragebuffer.h:133

References _buff, _bytes_in, _len, _myDataSaver, _num_buckets, _tot_bytes_in, extend_buff(), MAX_BUCKET, and BinaryDataSaver::printData().

Referenced by BinaryDataSaver::printOffsetTable(), Individual::store_data(), Metapop::store_data(), TProtoBDMI::store_data(), TT_BDMI::store_data(), TTDeletMutations_bitstring::store_data(), TProtoDeletMutations_bitstring::store_data(), TTDispersal::store_data(), TProtoDispersal::store_data(), TTNeutralGenes::store_data(), TProtoNeutralGenes::store_data(), TTQuanti_continuous::store_data(), TTQuanti_diallelic::store_data(), TProtoQuanti::store_data(), TTQuanti_diallelic_bitstring::store_data(), TTWolbachia::store_data(), and BinaryDataSaver::storeData().

Member Data Documentation

◆ _buff

char* BinaryStorageBuffer::_buff
private

◆ _bytes_in

off_t BinaryStorageBuffer::_bytes_in
private

◆ _bytes_out

off_t BinaryStorageBuffer::_bytes_out
private

◆ _len

off_t BinaryStorageBuffer::_len
private

◆ _myDataSaver

BinaryDataSaver* BinaryStorageBuffer::_myDataSaver
private

Referenced by set_buff(), and store().

◆ _num_buckets

unsigned int BinaryStorageBuffer::_num_buckets
private

Referenced by clear(), set_buff(), and store().

◆ _tot_bytes_in

off_t BinaryStorageBuffer::_tot_bytes_in
private

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

Generated for Nemo v2.4.0b by  doxygen 1.9.1 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR