ByteStream.h

00001 // $Id: ByteStream.h 21 2010-09-05 04:18:17Z cschwarz1 $
00002 
00003 #ifndef BASE_BYTESTREAM_H
00004 #define BASE_BYTESTREAM_H
00005 
00006 #include "Condition.h"
00007 #include "String.h"
00008 
00009 namespace base {
00016     class PPBASE_EXPORT ByteStream {
00017     public:
00023         ByteStream(size_t size = 0);
00024 
00026         ~ByteStream();
00027 
00033         void allocate(size_t size);
00034 
00036         void clear();
00037 
00043         bool empty();
00044 
00050         bool eos();
00051 
00057         size_t getWaitsRead() const;
00058 
00064         size_t getWaitsWrite() const;
00065 
00075         size_t read(void *buffer, size_t len, bool exact = true);
00076 
00078         size_t read(base::String &buffer, size_t len, bool exact = true);
00079 
00081         void reset();
00082 
00089         void seteos(bool immediate);
00090 
00099         size_t write(const void *buffer, size_t len, bool exact = true);
00100 
00102         size_t write(const base::String &buffer, bool exact = true);
00103 
00104     private:
00105         char      *_buffer;    
00106         Condition  _condrd;    
00107         Condition  _condwr;    
00108         bool       _eos;       
00109         bool       _eosp;      
00110         bool       _full;      
00111         Mutex      _mutex;     
00112         size_t     _nwaitrd;   
00113         size_t     _nwaitwr;   
00114         char      *_readptr;   
00115         size_t     _size;      
00116         bool       _waitrd;    
00117         bool       _waitwr;    
00118         char      *_writeptr;  
00119 
00120         DISALLOW_COPY_CONSTRUCTOR_AND_ASSIGNMENT(ByteStream);
00121     };
00122 }
00123 
00124 #endif