Initial checkin. SimulatedStream implementation that takes a single

offset and length. Will be used for data streams embedded in icbs.
Mostly complete, completely untested.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5698 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Tyler Dauwalder
2003-12-18 09:29:28 +00:00
parent 0ab79adc28
commit 2019a4454a
2 changed files with 83 additions and 0 deletions
@@ -0,0 +1,51 @@
//----------------------------------------------------------------------
// This software is part of the OpenBeOS distribution and is covered
// by the OpenBeOS license.
//
// Copyright (c) 2003 Tyler Dauwalder, [email protected]
//----------------------------------------------------------------------
/*! \file EmbeddedStream.cpp
*/
#include "EmbeddedStream.h"
#include <stdlib.h>
#include <string.h>
EmbeddedStream::EmbeddedStream(DataStream &stream, off_t offset, size_t size)
: SimulatedStream(stream)
, fOffset(offset)
, fSize(size)
{
}
/*! \brief Returns the largest extent in the underlying data stream
corresponding to the extent starting at byte position \a pos of
byte length \a size in the output parameter \a extent.
NOTE: If the position is at or beyond the end of the stream, the
function will return B_OK, but the value of extent.size will be 0.
*/
status_t
EmbeddedStream::_GetExtent(off_t pos, size_t size, data_extent &extent)
{
if (pos >= fSize) {
// end of stream
extent.offset = fOffset + fSize;
extent.size = 0;
} else {
// valid position
extent.offset = fOffset + pos;
extent.size = fSize - pos;
}
return B_OK;
}
/*! \brief Returns the current size of the stream.
*/
off_t
EmbeddedStream::_Size()
{
return fSize;
}
@@ -0,0 +1,32 @@
//----------------------------------------------------------------------
// This software is part of the OpenBeOS distribution and is covered
// by the OpenBeOS license.
//
// Copyright (c) 2003 Tyler Dauwalder, [email protected]
//----------------------------------------------------------------------
/*! \file EmbeddedStream.h
*/
#ifndef _EMBEDDED_STREAM_H
#define _EMBEDDED_STREAM_H
#include "SimulatedStream.h"
/*! \brief AbstractExtentStream implementation that takes a single,
not-neccessarily-block-aligned extent.
*/
class EmbeddedStream : public SimulatedStream {
public:
EmbeddedStream(DataStream &stream, off_t offset, size_t size);
protected:
virtual status_t _GetExtent(off_t pos, size_t size, data_extent &extent);
virtual off_t _Size();
private:
off_t fOffset;
size_t fSize;
};
#endif // _EMBEDDED_STREAM_H