2001-10-06 14:13:28 +00:00
|
|
|
#ifndef CBUFFEREDOUTPUTSTREAM_H
|
|
|
|
#define CBUFFEREDOUTPUTSTREAM_H
|
|
|
|
|
|
|
|
#include "CStreamBuffer.h"
|
|
|
|
#include "IOutputStream.h"
|
2002-06-02 22:57:50 +00:00
|
|
|
#include "CCondVar.h"
|
2001-10-06 14:13:28 +00:00
|
|
|
|
|
|
|
class CMutex;
|
|
|
|
class IJob;
|
|
|
|
|
|
|
|
class CBufferedOutputStream : public IOutputStream {
|
2002-04-29 14:40:01 +00:00
|
|
|
public:
|
2001-10-06 14:13:28 +00:00
|
|
|
CBufferedOutputStream(CMutex*, IJob* adoptedCloseCB);
|
|
|
|
~CBufferedOutputStream();
|
|
|
|
|
|
|
|
// the caller is expected to lock the mutex before calling
|
|
|
|
// methods unless otherwise noted.
|
|
|
|
|
|
|
|
// manipulators
|
|
|
|
|
|
|
|
// peek() returns a buffer of n bytes (which must be <= getSize()).
|
|
|
|
// pop() discards the next n bytes.
|
2001-10-14 16:58:01 +00:00
|
|
|
const void* peek(UInt32 n);
|
|
|
|
void pop(UInt32 n);
|
2001-10-06 14:13:28 +00:00
|
|
|
|
|
|
|
// accessors
|
|
|
|
|
|
|
|
// return the number of bytes in the buffer
|
2001-10-14 16:58:01 +00:00
|
|
|
UInt32 getSize() const;
|
2001-10-06 14:13:28 +00:00
|
|
|
|
|
|
|
// IOutputStream overrides
|
|
|
|
// these all lock the mutex for their duration
|
2001-10-14 16:58:01 +00:00
|
|
|
virtual void close();
|
|
|
|
virtual UInt32 write(const void*, UInt32 count);
|
|
|
|
virtual void flush();
|
2001-10-06 14:13:28 +00:00
|
|
|
|
2002-04-29 14:40:01 +00:00
|
|
|
private:
|
2001-10-06 14:13:28 +00:00
|
|
|
CMutex* m_mutex;
|
|
|
|
IJob* m_closeCB;
|
2002-06-02 22:57:50 +00:00
|
|
|
CCondVar<bool> m_empty;
|
2001-10-06 14:13:28 +00:00
|
|
|
CStreamBuffer m_buffer;
|
|
|
|
bool m_closed;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|