EXRTranslator now uses the StreamBuffer class

added StreamBuffer::Position()


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24069 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval 2008-02-22 22:00:41 +00:00
parent e26a124818
commit 45ff9decad
4 changed files with 36 additions and 5 deletions

View File

@ -8,7 +8,7 @@
IStreamWrapper::IStreamWrapper(const char *filename, BPositionIO *stream) IStreamWrapper::IStreamWrapper(const char *filename, BPositionIO *stream)
: IStream(filename), : IStream(filename),
fStream(stream) fStream(stream, 2048)
{ {
} }
@ -21,7 +21,7 @@ IStreamWrapper::~IStreamWrapper()
bool bool
IStreamWrapper::read(char c[/*n*/], int n) IStreamWrapper::read(char c[/*n*/], int n)
{ {
int actual = fStream->Read(c, n); int actual = fStream.Read(c, n);
if (actual < B_OK) { if (actual < B_OK) {
} }
@ -32,12 +32,12 @@ IStreamWrapper::read(char c[/*n*/], int n)
Int64 Int64
IStreamWrapper::tellg() IStreamWrapper::tellg()
{ {
return fStream->Position(); return fStream.Position();
} }
void void
IStreamWrapper::seekg(Int64 pos) IStreamWrapper::seekg(Int64 pos)
{ {
fStream->Seek(pos, SEEK_SET); fStream.Seek(pos);
} }

View File

@ -8,6 +8,8 @@
#include <DataIO.h> #include <DataIO.h>
#include <ImfIO.h> #include <ImfIO.h>
#include "StreamBuffer.h"
using namespace Imf; using namespace Imf;
class IStreamWrapper : public IStream { class IStreamWrapper : public IStream {
@ -20,7 +22,7 @@ class IStreamWrapper : public IStream {
virtual void seekg(Int64 pos); virtual void seekg(Int64 pos);
private: private:
BPositionIO *fStream; StreamBuffer fStream;
}; };
#endif /* ISTREAM_WRAPPER_H */ #endif /* ISTREAM_WRAPPER_H */

View File

@ -202,6 +202,33 @@ StreamBuffer::Seek(off_t position)
return false; return false;
} }
// ---------------------------------------------------------------
// Position
//
// Returns the current position in the stream.
//
// Preconditions: fBuffer must be allocated and fBufferSize
// must be valid
//
// Parameters:
//
// Postconditions:
//
// Returns: the position
// ---------------------------------------------------------------
off_t
StreamBuffer::Position()
{
off_t position = fStream->Position();
if (fToRead)
position -= fPos;
else
position += fLen;
return position;
}
// --------------------------------------------------------------- // ---------------------------------------------------------------
// _ReadStream // _ReadStream
// //

View File

@ -31,6 +31,8 @@ public:
bool Seek(off_t position); bool Seek(off_t position);
// seek the stream to the given position // seek the stream to the given position
off_t Position();
// return the actual position
private: private:
ssize_t _ReadStream(); ssize_t _ReadStream();
// Load the stream buffer from the stream // Load the stream buffer from the stream