Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
common.cpp
Go to the documentation of this file.
1 #include <xstream/common.h>
2 #include <algorithm>
3 
4 #include "debug.h"
5 
6 namespace xstream {
7 
8  static const size_t buffer_size = 4000 * 1024;
9  static const size_t out_buffer_size = static_cast < size_t > (buffer_size * 1.02 + 12); //see manual
10 
11  buffer::buffer(size_t s)
12  : buf(0), size(0)
13  {
14  LOG("buffer::buffer ("<<s<<")");
15  resize(s);
16  }
17 
18  void buffer::grow(unsigned int f)
19  {
20  LOG("buffer::grow " << f);
21  if (f < 1) {
22  LOG("\tERROR: just tried to grow to a smaller size");
23  return;
24  }
25  const size_t new_s = size * f;
26  char* new_b = new char[new_s];
27 
28  std::copy(buf, buf + size, new_b);
29  delete[] buf;
30 
31  size = new_s;
32  buf = new_b;
33  }
34 
35  void buffer::resize(size_t s)
36  {
37  LOG("buffer::resize " << s);
38  if (buf) {
39  LOG("\tdeleting buf");
40  delete[] buf;
41  }
42  size = s;
43  buf = new char[size];
44  }
45 
47  {
48  LOG("buffer::~buffer");
49  delete[] buf;
50  }
51 
52  common_buffer::common_buffer(std::streambuf * sb)
53  :_sb (sb), in(buffer_size), out(out_buffer_size)
54  {
55  LOG("common_buffer");
56  }
57 
59  LOG("~common_buffer");
60  }
61 
62 }//namespace xstream
debugging/logging support
size_t size
Definition: common.h:50
common_buffer(std::streambuf *sb)
construct using a streambuf
Definition: common.cpp:52
buffer(size_t size)
Definition: common.cpp:11
static const size_t buffer_size
Definition: common.cpp:8
TF1 * f
Definition: FitGains.C:21
char * buf
Definition: common.h:49
void resize(size_t size)
resets the size of the buffer
Definition: common.cpp:35
void grow(unsigned int factor=2)
increases the size of buffer
Definition: common.cpp:18
common objects
#define LOG(s)
Definition: debug.h:30
~buffer()
deallocates buffer
Definition: common.cpp:46
static const size_t out_buffer_size
Definition: common.cpp:9