CppCMS
|
00001 #ifndef BOOSTER_STREAMBUF_H 00002 #define BOOSTER_STREAMBUF_H 00003 00004 #include <booster/config.h> 00005 #include <streambuf> 00006 #include <stdio.h> 00007 #include <booster/hold_ptr.h> 00008 #include <memory> 00009 #include <vector> 00010 00011 namespace booster { 00012 00018 00019 class io_device { 00020 public: 00024 typedef enum { 00025 set, 00026 cur, 00027 end 00028 } pos_type; 00029 00036 virtual size_t read(char * /*pos*/,size_t /*length*/) 00037 { 00038 return 0; 00039 } 00046 virtual size_t write(char const * /*pos*/,size_t /*length*/) 00047 { 00048 return 0; 00049 } 00058 virtual long long seek(long long /*position*/,pos_type /*pos*/ = set) 00059 { 00060 return -1; 00061 } 00062 virtual ~io_device() 00063 { 00064 } 00065 }; 00066 00070 class BOOSTER_API streambuf : public std::streambuf { 00071 public: 00072 00076 streambuf(); 00077 ~streambuf(); 00078 00082 void device(std::auto_ptr<io_device> d); 00086 void device(io_device &d); 00087 00091 void reset_device(); 00092 00096 io_device &device(); 00101 void set_buffer_size(size_t n); 00102 00103 protected: 00104 00105 // Seek 00106 00107 virtual std::streampos seekoff( std::streamoff off, 00108 std::ios_base::seekdir way, 00109 std::ios_base::openmode m = std::ios_base::in | std::ios_base::out); 00110 virtual std::streampos seekpos( std::streampos pos, 00111 std::ios_base::openmode m = std::ios_base::in | std::ios_base::out); 00112 00113 // Get 00114 00115 virtual int underflow(); 00116 virtual int pbackfail(int c = EOF); 00117 00118 // Put 00119 00120 virtual int overflow(int c = EOF); 00121 virtual int sync(); 00122 00123 private: 00124 00125 std::vector<char> buffer_out_; 00126 std::vector<char> buffer_in_; 00127 00128 size_t buffer_size_; 00129 00130 struct _data; 00131 hold_ptr<_data> d; // for future use 00132 00133 std::auto_ptr<io_device> device_auto_ptr_; 00134 io_device *device_; 00135 00136 }; 00137 } // booster 00138 00139 00140 #endif