Bayeux  3.4.1
Core Foundation library for SuperNEMO
memory_streambuf.h
Go to the documentation of this file.
1 #ifndef DATATOOLS_MEMORY_STREAMBUF_H
3 #define DATATOOLS_MEMORY_STREAMBUF_H
4 
5 // Standard Library:
6 #include <streambuf>
7 #include <iostream>
8 #include <vector>
9 #include <stdexcept>
10 
11 // This project:
12 #include <datatools/exception.h>
13 
14 namespace datatools {
15 
18  : public std::streambuf
19  {
20  public:
21 
22  typedef char byte_t;
23 
25  array_input_buffer(const byte_t * array_, size_t array_size_);
26 
27  };
28 
29 
32  : private virtual array_input_buffer
33  , public std::istream
34  {
35  public:
36 
38  iarraystream(const byte_t * array_, size_t array_size_);
39 
40  };
41 
42 
45  : public std::streambuf
46  {
47  public:
49  vector_input_buffer(std::vector<char> & vec_);
50 
51  };
52 
53 
56  : private virtual vector_input_buffer
57  , public std::istream
58  {
59  public:
60 
62  ivectorstream(std::vector<char> &);
63 
64  };
65 
66 
69  : public std::streambuf
70  {
71  public:
72  static const size_t MIN_CAPACITY = 128;
73  static const size_t MIN_INCREMENT = 128;
74  static const size_t DEFAULT_CAPACITY = 1024;
75  static const size_t DEFAULT_INCREMENT = 0;
76 
77  typedef std::vector<char>::const_iterator iterator;
78 
79  public:
80 
82  vector_output_buffer(size_t capacity_ = 1000,
83  size_t increment_ = 1000,
84  size_t max_capacity_ = 0);
85 
86  virtual ~vector_output_buffer();
87 
88  const std::vector<char>& buffer() const;
89 
90  void set_max_capacity(size_t max_capacity_);
91 
92  void reset(size_t capacity_ = 1000,
93  size_t increment_ = 1000,
94  size_t max_capacity_ = 0);
95 
96  size_t get_size() const;
97 
98  const char* get_address() const;
99 
100  protected:
101 
102  void _init(size_t capacity_);
103 
104  void _set_increment(size_t increment_);
105 
106 
107  public:
108  void dump() const;
109 
110  int overflow(int c_);
111 
112  private:
113 
114  size_t _max_capacity_;
115  size_t _increment_;
116  std::vector<char> _buffer_;
117 
118  };
119 
122  : public vector_output_buffer
123  , public std::ostream
124  {
125  public:
126  ovectorstream(size_t capacity_ = DEFAULT_CAPACITY,
127  size_t increment_ = DEFAULT_INCREMENT,
128  size_t max_capacity_ = 0);
129  /*
130  : vector_output_buffer(capacity, increment, max_capacity),
131  std::ostream(this) {}
132  */
133  };
134 
135 } // end of namespace datatools
136 
137 #endif // DATATOOLS_MEMORY_STREAMBUF_H
138 
139 // Local Variables: --
140 // mode: c++ --
141 // c-file-style: "gnu" --
142 // tab-width: 2 --
143 // End: --
array_input_buffer(const byte_t *array_, size_t array_size_)
Constructor.
ovectorstream(size_t capacity_=DEFAULT_CAPACITY, size_t increment_=DEFAULT_INCREMENT, size_t max_capacity_=0)
void _set_increment(size_t increment_)
std::istream interface for a std::vector of characters (std::vector<char>)
Definition: memory_streambuf.h:55
static const size_t MIN_CAPACITY
Definition: memory_streambuf.h:72
std::vector< char >::const_iterator iterator
Definition: memory_streambuf.h:77
static const size_t DEFAULT_CAPACITY
Definition: memory_streambuf.h:74
void _init(size_t capacity_)
Utility macros for exception handling.
char byte_t
Definition: memory_streambuf.h:22
const std::vector< char > & buffer() const
vector_input_buffer(std::vector< char > &vec_)
Constructor.
Input stream buffer associated to a plain array of characters (char *)
Definition: memory_streambuf.h:17
static const size_t DEFAULT_INCREMENT
Definition: memory_streambuf.h:75
ivectorstream(std::vector< char > &)
Constructor.
Input stream buffer associated to a std::vector of characters (std::vector<char>)
Definition: memory_streambuf.h:44
Output stream buffer associated to a std::vector of characters (std::vector<char>)
Definition: memory_streambuf.h:68
static const size_t MIN_INCREMENT
Definition: memory_streambuf.h:73
vector_output_buffer(size_t capacity_=1000, size_t increment_=1000, size_t max_capacity_=0)
Constructor.
std::ostream interface for a std::vector of characters (std::vector<char>)
Definition: memory_streambuf.h:121
std::istream interface for a plain array of characters (char *)
Definition: memory_streambuf.h:31
void reset(size_t capacity_=1000, size_t increment_=1000, size_t max_capacity_=0)
The Bayeux/datatools library top-level namespace.
Definition: algo.h:13
iarraystream(const byte_t *array_, size_t array_size_)
Constructor.
const char * get_address() const
void set_max_capacity(size_t max_capacity_)