IBR-DTNSuite  0.8
ibrcommon/ibrcommon/data/iobuffer.h
Go to the documentation of this file.
00001 /*
00002  * iobuffer.h
00003  *
00004  *  Created on: 14.02.2011
00005  *      Author: morgenro
00006  */
00007 
00008 #ifndef IOBUFFER_H_
00009 #define IOBUFFER_H_
00010 
00011 #include "ibrcommon/Exceptions.h"
00012 #include <streambuf>
00013 #include "ibrcommon/thread/Conditional.h"
00014 
00015 namespace ibrcommon
00016 {
00021         class iobuffer : public std::basic_streambuf<char, std::char_traits<char> >
00022         {
00023         public:
00024                 iobuffer(const size_t buffer = 2048);
00025                 virtual ~iobuffer();
00026 
00030                 void finalize();
00031 
00032         protected:
00033                 virtual int sync();
00034                 virtual std::char_traits<char>::int_type overflow(std::char_traits<char>::int_type = std::char_traits<char>::eof());
00035                 virtual std::char_traits<char>::int_type underflow();
00036 
00037         private:
00038                 ibrcommon::Conditional _data_cond;
00039 
00040                 bool _eof;
00041 
00042                 size_t _data_size;
00043 
00044                 // length of the data buffer
00045                 size_t _buf_size;
00046 
00047                 // input buffer
00048                 char *_input_buf;
00049 
00050                 // interim buffer
00051                 char *_interim_buf;
00052 
00053                 // output buffer
00054                 char *_output_buf;
00055         };
00056 }
00057 
00058 #endif /* IOBUFFER_H_ */