streambuf.h
#ifndef BOOSTER_STREAMBUF_H
#define BOOSTER_STREAMBUF_H
#include <booster/config.h>
#include <streambuf>
#include <stdio.h>
#include <booster/hold_ptr.h>
#include <memory>
#include <vector>
namespace booster {
class io_device {
public:
typedef enum {
set,
cur,
end
} pos_type;
virtual size_t read(char * /*pos*/,size_t /*length*/)
{
return 0;
}
virtual size_t write(char const * /*pos*/,size_t /*length*/)
{
return 0;
}
virtual long long seek(long long /*position*/,pos_type /*pos*/ = set)
{
return -1;
}
virtual ~io_device()
{
}
};
class BOOSTER_API streambuf : public std::streambuf {
public:
streambuf();
~streambuf();
void device(std::auto_ptr<io_device> d);
void device(io_device &d);
void reset_device();
io_device &device();
void set_buffer_size(size_t n);
protected:
// Seek
virtual std::streampos seekoff( std::streamoff off,
std::ios_base::seekdir way,
std::ios_base::openmode m = std::ios_base::in | std::ios_base::out);
virtual std::streampos seekpos( std::streampos pos,
std::ios_base::openmode m = std::ios_base::in | std::ios_base::out);
// Get
virtual int underflow();
virtual int pbackfail(int c = EOF);
// Put
virtual int overflow(int c = EOF);
virtual int sync();
private:
std::vector<char> buffer_out_;
std::vector<char> buffer_in_;
size_t buffer_size_;
struct _data;
hold_ptr<_data> d; // for future use
std::auto_ptr<io_device> device_auto_ptr_;
io_device *device_;
};
} // booster
#endif
booster::streambuf
this is an implementation of generic streambuffer
Definition: streambuf.h:70
booster::io_device
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
booster::hold_ptr< _data >
booster::io_device::seek
virtual long long seek(long long, pos_type=set)
Definition: streambuf.h:58
booster::io_device::write
virtual size_t write(char const *, size_t)
Definition: streambuf.h:46
booster::io_device::read
virtual size_t read(char *, size_t)
Definition: streambuf.h:36
booster::io_device::set
Set actual position (i.e. SEEK_CUR)
Definition: streambuf.h:25
booster::io_device::end
Set relatively to end of file (i.e. SEEK_END)
Definition: streambuf.h:27
booster::io_device::pos_type
pos_type
Definition: streambuf.h:24
booster::io_device::cur
Set relatively to current position (i.e. SEEK_CUR)
Definition: streambuf.h:26