CppCMS
streambuf.h
1 #ifndef BOOSTER_STREAMBUF_H
2 #define BOOSTER_STREAMBUF_H
3 
4 #include <booster/config.h>
5 #include <streambuf>
6 #include <stdio.h>
7 #include <booster/hold_ptr.h>
8 #include <booster/auto_ptr_inc.h>
9 #include <vector>
10 
11 namespace booster {
12 
18 
19  class io_device {
20  public:
24  typedef enum {
25  set,
26  cur,
27  end
28  } pos_type;
29 
36  virtual size_t read(char * /*pos*/,size_t /*length*/)
37  {
38  return 0;
39  }
46  virtual size_t write(char const * /*pos*/,size_t /*length*/)
47  {
48  return 0;
49  }
58  virtual long long seek(long long /*position*/,pos_type /*pos*/ = set)
59  {
60  return -1;
61  }
62  virtual ~io_device()
63  {
64  }
65  };
66 
70  class BOOSTER_API streambuf : public std::streambuf {
71  public:
72 
76  streambuf();
77  ~streambuf();
78 
82  void device(std::auto_ptr<io_device> d);
86  void device(io_device &d);
87 
91  void reset_device();
92 
96  io_device &device();
101  void set_buffer_size(size_t n);
102 
103  protected:
104 
105  // Seek
106 
107  virtual std::streampos seekoff( std::streamoff off,
108  std::ios_base::seekdir way,
109  std::ios_base::openmode m = std::ios_base::in | std::ios_base::out);
110  virtual std::streampos seekpos( std::streampos pos,
111  std::ios_base::openmode m = std::ios_base::in | std::ios_base::out);
112 
113  // Get
114 
115  virtual int underflow();
116  virtual int pbackfail(int c = EOF);
117 
118  // Put
119 
120  virtual int overflow(int c = EOF);
121  virtual int sync();
122 
123  private:
124 
125  std::vector<char> buffer_out_;
126  std::vector<char> buffer_in_;
127 
128  size_t buffer_size_;
129 
130  struct _data;
131  hold_ptr<_data> d; // for future use
132 
133  std::auto_ptr<io_device> device_auto_ptr_;
134  io_device *device_;
135 
136  };
137 } // booster
138 
139 
140 #endif
this is an implementation of generic streambuffer
Definition: streambuf.h:70
This class is a base class of generic I/O device that can be used in very simple manner with booster:...
Definition: streambuf.h:19
virtual long long seek(long long, pos_type=set)
Definition: streambuf.h:58
virtual size_t write(char const *, size_t)
Definition: streambuf.h:46
virtual size_t read(char *, size_t)
Definition: streambuf.h:36
Set relatively to end of file (i.e. SEEK_END)
Definition: streambuf.h:27
pos_type
Definition: streambuf.h:24
Set relatively to current position (i.e. SEEK_CUR)
Definition: streambuf.h:26
Booster library namespace. The library that implements Boost Like API in ABI backward compatible way...
Definition: application.h:23