Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
common.h
Go to the documentation of this file.
1 /*! \file xstream/common.h
2  *
3  * \brief common objects
4  */
5 
6 #ifndef XSTREAM_COMMON_H
7 #define XSTREAM_COMMON_H
8 
9 #include <xstream/config.h>
10 
11 #include <streambuf>
12 
13 namespace xstream{
14 
15 
16 /*!
17  * \internal
18  * \brief common base for ostreambufs
19  *
20  */
21 class ostreambuf: public std::streambuf
22 {
23  protected:
24  /*!
25  * \brief remaining characters in the buffer
26  *
27  */
28  std::streamsize inline available() const {
29  return (epptr() - pptr());
30  }
31 
32  /*!
33  * \brief number of characters in the buffer
34  *
35  */
36  std::streamsize inline taken() const {
37  return (pptr() - pbase());
38  }
39 };
40 
41 /*!
42  * \brief buffer management
43  *
44  */
45 
46 class buffer
47 {
48  public:
49  char* buf; /*!< buffer where data is kept */
50  size_t size; /*!< size of buffer */
51 
52  /*
53  * \brief allocates a buffer of size \c size
54  *
55  * \param size length of buffer
56  *
57  */
58  buffer(size_t size);
59 
60  /*!
61  * \brief increases the size of buffer
62  *
63  * \param factor size is updated according to \f$ size'=size*factor \f$
64  * \note old data is copied to the new buffer
65  *
66  */
67  void grow(unsigned int factor=2);
68 
69  /*!
70  * \brief resets the size of the buffer
71  *
72  * \param size new length of the buffer
73  *
74  * \note no copying of data is done
75  *
76  */
77  void resize(size_t size);
78 
79  /*!
80  * \brief deallocates buffer
81  *
82  */
83  ~buffer();
84 };
85 
86 /*!
87  * \brief common base for objects that manage input and output buffers
88  * to use with zlib and bzlib
89  *
90  */
92 {
93  protected:
94  std::streambuf *_sb; /*!< streambuf to read/write from/to */
95  buffer in; /*!< input buffer */
96  buffer out; /*!< output buffer */
97 
98  public:
99  /*!
100  * \brief construct using a streambuf
101  */
102  common_buffer(std::streambuf* sb);
103 
104  ~common_buffer();
105 
106 };
107 
108 }//namespace xstream
109 
110 #endif
common base for objects that manage input and output buffers to use with zlib and bzlib ...
Definition: common.h:91
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
char * buf
Definition: common.h:49
void resize(size_t size)
resets the size of the buffer
Definition: common.cpp:35
std::streamsize available() const
remaining characters in the buffer
Definition: common.h:28
void grow(unsigned int factor=2)
increases the size of buffer
Definition: common.cpp:18
buffer management
Definition: common.h:46
std::streamsize taken() const
number of characters in the buffer
Definition: common.h:36
~buffer()
deallocates buffer
Definition: common.cpp:46
std::streambuf * _sb
Definition: common.h:94