Add private BDataPositionIOWrapper
Implements the BPositionIO interface on top of a BDataIO, requiring the {Read,Write}At() accesses to be sequential.
This commit is contained in:
parent
44c4771163
commit
05b565f4f2
1
headers/build/private/support/DataPositionIOWrapper.h
Normal file
1
headers/build/private/support/DataPositionIOWrapper.h
Normal file
@ -0,0 +1 @@
|
||||
#include <../private/support/DataPositionIOWrapper.h>
|
37
headers/private/support/DataPositionIOWrapper.h
Normal file
37
headers/private/support/DataPositionIOWrapper.h
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2014, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _DATA_POSITION_IO_WRAPPER_H_
|
||||
#define _DATA_POSITION_IO_WRAPPER_H_
|
||||
|
||||
|
||||
#include <DataIO.h>
|
||||
|
||||
|
||||
class BDataPositionIOWrapper : public BPositionIO {
|
||||
public:
|
||||
BDataPositionIOWrapper(BDataIO* io);
|
||||
~BDataPositionIOWrapper();
|
||||
|
||||
virtual ssize_t Read(void* buffer, size_t size);
|
||||
virtual ssize_t Write(const void* buffer, size_t size);
|
||||
|
||||
virtual ssize_t ReadAt(off_t position, void* buffer,
|
||||
size_t size);
|
||||
virtual ssize_t WriteAt(off_t position, const void* buffer,
|
||||
size_t size);
|
||||
|
||||
virtual off_t Seek(off_t position, uint32 seekMode);
|
||||
virtual off_t Position() const;
|
||||
|
||||
virtual status_t SetSize(off_t size);
|
||||
virtual status_t GetSize(off_t* size) const;
|
||||
|
||||
private:
|
||||
BDataIO* fIO;
|
||||
off_t fPosition;
|
||||
};
|
||||
|
||||
|
||||
#endif // _DATA_POSITION_IO_WRAPPER_H_
|
@ -12,6 +12,7 @@ BuildPlatformMergeObjectPIC <libbe_build>support_kit.o :
|
||||
ByteOrder.cpp
|
||||
CompressionAlgorithm.cpp
|
||||
DataIO.cpp
|
||||
DataPositionIOWrapper.cpp
|
||||
Flattenable.cpp
|
||||
List.cpp
|
||||
Locker.cpp
|
||||
|
103
src/kits/support/DataPositionIOWrapper.cpp
Normal file
103
src/kits/support/DataPositionIOWrapper.cpp
Normal file
@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright 2014, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#include <DataPositionIOWrapper.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
BDataPositionIOWrapper::BDataPositionIOWrapper(BDataIO* io)
|
||||
:
|
||||
BPositionIO(),
|
||||
fIO(io),
|
||||
fPosition(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
BDataPositionIOWrapper::~BDataPositionIOWrapper()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
BDataPositionIOWrapper::Read(void* buffer, size_t size)
|
||||
{
|
||||
ssize_t bytesRead = fIO->Read(buffer, size);
|
||||
if (bytesRead > 0)
|
||||
fPosition += bytesRead;
|
||||
|
||||
return bytesRead;
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
BDataPositionIOWrapper::Write(const void* buffer, size_t size)
|
||||
{
|
||||
ssize_t bytesWritten = fIO->Write(buffer, size);
|
||||
if (bytesWritten > 0)
|
||||
fPosition += bytesWritten;
|
||||
|
||||
return bytesWritten;
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
BDataPositionIOWrapper::ReadAt(off_t position, void* buffer, size_t size)
|
||||
{
|
||||
if (position != fPosition)
|
||||
return B_NOT_SUPPORTED;
|
||||
|
||||
return Read(buffer, size);
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
BDataPositionIOWrapper::WriteAt(off_t position, const void* buffer,
|
||||
size_t size)
|
||||
{
|
||||
if (position != fPosition)
|
||||
return B_NOT_SUPPORTED;
|
||||
|
||||
return Write(buffer, size);
|
||||
}
|
||||
|
||||
|
||||
off_t
|
||||
BDataPositionIOWrapper::Seek(off_t position, uint32 seekMode)
|
||||
{
|
||||
switch (seekMode) {
|
||||
case SEEK_CUR:
|
||||
return position == 0 ? B_OK : B_NOT_SUPPORTED;
|
||||
case SEEK_SET:
|
||||
return position == fPosition ? B_OK : B_NOT_SUPPORTED;
|
||||
case SEEK_END:
|
||||
return B_NOT_SUPPORTED;
|
||||
default:
|
||||
return B_BAD_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
off_t
|
||||
BDataPositionIOWrapper::Position() const
|
||||
{
|
||||
return fPosition;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BDataPositionIOWrapper::SetSize(off_t size)
|
||||
{
|
||||
return size == fPosition ? B_OK : B_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BDataPositionIOWrapper::GetSize(off_t* size) const
|
||||
{
|
||||
return B_NOT_SUPPORTED;
|
||||
}
|
@ -26,6 +26,7 @@ for architectureObject in [ MultiArchSubDirSetup ] {
|
||||
ByteOrder.cpp
|
||||
CompressionAlgorithm.cpp
|
||||
DataIO.cpp
|
||||
DataPositionIOWrapper.cpp
|
||||
DateTime.cpp
|
||||
Flattenable.cpp
|
||||
List.cpp
|
||||
|
Loading…
Reference in New Issue
Block a user