23#ifndef BAGEL_BOFLIB_FILE_H
24#define BAGEL_BOFLIB_FILE_H
26#include "common/algorithm.h"
27#include "common/memstream.h"
28#include "common/stream.h"
29#include "bagel/boflib/stdinc.h"
30#include "bagel/boflib/object.h"
31#include "bagel/boflib/error.h"
36#define CBF_TEXT 0x00000001
37#define CBF_BINARY 0x00000002
38#define CBF_READONLY 0x00000004
39#define CBF_OVERWRITE 0x00000008
40#define CBF_SHARED 0x00000010
41#define CBF_CREATE 0x00000020
42#define CBF_SAVEFILE 0x100
44#define CBF_DEFAULT (CBF_BINARY | CBF_READONLY)
46#define CBOFFILE_TEXT CBF_TEXT
47#define CBOFFILE_READONLY CBF_READONLY
48#define CBOFFILE_OVERWRITE CBF_OVERWRITE
50#define CBOFFILE_DEFAULT CBF_DEFAULT
59 bool eos()
const override {
60 return _owner->
pos() >= _owner->
size();
62 uint32
read(
void *dataPtr, uint32 dataSize)
override {
63 int bytesToCopy = MIN<int>(dataSize, _owner->
size() - _owner->
pos());
64 const byte *src = _owner->getData() + _owner->
pos();
66 seek(bytesToCopy, SEEK_CUR);
89 int64
pos()
const override {
92 bool seek(int64 offset,
int whence = SEEK_SET)
override {
95 int64
size()
const override {
102 char _szFileName[MAX_FNAME];
104 uint32 _lFlags = CBF_DEFAULT;
117 CBofFile(
const char *pszFileName, uint32 lFlags = CBF_DEFAULT);
129 ErrorCode
open(
const char *pszFileName, uint32 lFlags = CBF_DEFAULT);
136 ErrorCode
create(
const char *pszFileName, uint32 lFlags = CBF_DEFAULT | CBF_CREATE);
149 virtual ErrorCode
read(
void *pDestBuf, int32 lBytes);
157 virtual ErrorCode
write(
const void *pSrcBuf, int32 lBytes);
ErrorCode seek(uint32 lPos)
Definition: file.h:168
ErrorCode open(const char *pszFileName, uint32 lFlags=(0x00000002|0x00000004))
virtual ErrorCode read(void *pDestBuf, int32 lBytes)
virtual ErrorCode close()
ErrorCode create(const char *pszFileName, uint32 lFlags=(0x00000002|0x00000004)|0x00000020)
ErrorCode seekToBeginning()
Definition: file.h:176
ErrorCode setPosition(uint32 lPos)
CBofFile(const char *pszFileName, uint32 lFlags=(0x00000002|0x00000004))
virtual ErrorCode write(const void *pSrcBuf, int32 lBytes)
bool eos() const override
Definition: file.h:59
uint32 read(void *dataPtr, uint32 dataSize) override
Definition: file.h:62
int64 size() const override
Definition: file.h:95
int64 pos() const override
Definition: file.h:89
bool seek(int64 offset, int whence=SEEK_SET) override
Definition: file.h:92
Definition: memstream.h:194
int64 size() const override
Definition: memstream.h:250
int64 pos() const override
Definition: memstream.h:249
bool seek(int64 offs, int whence=SEEK_SET) override
Definition: memstream.h:254
virtual bool seek(int64 offset, int whence=SEEK_SET)=0
virtual uint32 write(const void *dataPtr, uint32 dataSize)=0
Out copy(In first, In last, Out dst)
Definition: algorithm.h:52