1 //----------------------------------------------------------------------
2 // This software is part of the OpenBeOS distribution and is covered
3 // by the OpenBeOS license.
5 // Copyright (c) 2003 Tyler Dauwalder, tyler@dauwalder.net
6 //----------------------------------------------------------------------
8 /*! \file SimulatedStream.h
11 #ifndef _SIMULATED_STREAM_H
12 #define _SIMULATED_STREAM_H
14 #include "DataStream.h"
16 /*! \brief Abstract DataStream wrapper around another DataStream and a sequence of
17 extents in said stream that allows for easy write access to said sequence
18 of extents as though they were a continuous chunk of data.
20 NOTE: The SimulatedStream object never modifies the data stream position
21 of the underlying data stream; all read/write/zero calls use the underlying
22 stream's ReadAt()/WriteAt()/ZeroAt() functions.
24 class SimulatedStream
: public DataStream
{
26 SimulatedStream(DataStream
&stream
);
27 virtual status_t
InitCheck() const;
29 virtual ssize_t
Read(void *buffer
, size_t size
);
30 virtual ssize_t
ReadAt(off_t pos
, void *buffer
, size_t size
);
32 virtual ssize_t
Write(const void *buffer
, size_t size
);
33 virtual ssize_t
WriteAt(off_t pos
, const void *buffer
, size_t size
);
35 virtual ssize_t
Write(BDataIO
&data
, size_t size
);
36 virtual ssize_t
WriteAt(off_t pos
, BDataIO
&data
, size_t size
);
38 virtual ssize_t
Zero(size_t size
);
39 virtual ssize_t
ZeroAt(off_t pos
, size_t size
);
41 virtual off_t
Seek(off_t pos
, uint32 seek_mode
);
42 virtual off_t
Position() const { return fPosition
; }
44 virtual status_t
SetSize(off_t size
) { return B_ERROR
; }
48 data_extent(off_t offset
= 0, size_t size
= 0)
58 /*! \brief Should be implemented to return (via the output parameter
59 \a extent) the largest extent in the underlying data stream corresponding
60 to the extent in the simulated data stream starting at byte position
61 \a pos of byte length \a size.
63 NOTE: If the position is at or beyond the end of the simulated stream, the
64 function should return B_OK, and the value of extent.size should be 0.
66 virtual status_t
_GetExtent(off_t pos
, size_t size
, data_extent
&extent
) = 0;
68 /*! \brief Should be implemented to return the current size of the stream.
70 virtual off_t
_Size() = 0;
77 #endif // _SIMULATED_STREAM_H