16 #ifndef DABC_BinaryFile
17 #define DABC_BinaryFile
45 virtual size_t fwrite(
const void* ptr,
size_t sz,
size_t nmemb,
Handle f)
46 {
return ((f==0) || (ptr==0)) ? 0 :
::fwrite(ptr, sz, nmemb, (FILE*) f); }
48 virtual size_t fread(
void* ptr,
size_t sz,
size_t nmemb,
Handle f)
49 {
return ((f==0) || (ptr==0)) ? 0 :
::fread(ptr, sz, nmemb, (FILE*) f); }
52 {
return f==0 ? false :
::feof((FILE*)f)>0; }
55 {
return f==0 ? false :
::fflush((FILE*)f)==0; }
57 virtual bool fseek(
Handle f,
long int offset,
bool relative =
true)
58 {
return f==0 ? false :
::fseek((FILE*)f, offset, relative ? SEEK_CUR : SEEK_SET) == 0; }
62 virtual Object*
fmatch(
const char* fmask,
bool select_files =
true);
64 virtual bool mkdir(
const char* path);
70 virtual bool GetFileStrPar(
Handle h,
const char* parname,
char* sbuf,
int sbuflen) {
if (sbuf) *sbuf = 0;
return false; }
201 if (fname==0 || *fname==0) {
202 fprintf(stderr,
"file name not specified\n");
210 fprintf(stderr,
"File open failed %s for reading\n", fname);
216 fprintf(stderr,
"Failure reading file %s header\n", fname);
231 if (fname==0 || *fname==0) {
232 fprintf(stderr,
"file name not specified\n");
240 fprintf(stderr,
"File open failed %s for writing\n", fname);
248 fprintf(stderr,
"Failure writing file %s header", fname);
268 if (!
isWriting() || (size==0))
return false;
271 fprintf(stderr,
"writing of previous buffer was not completed, remained %u bytes\n", (
unsigned)
fBufHdr.
datalength);
280 fprintf(stderr,
"fail to write buffer header\n");
290 if (!
isWriting() || (ptr==0) || (sz==0))
return false;
293 fprintf(stderr,
"Appropriate header was not written for buffer %u\n", (
unsigned) sz);
301 fprintf(stderr,
"fail to write buffer payload of size %u\n", (
unsigned) sz);
322 fprintf(stderr,
"reading of previous buffer was not completed, remained %u bytes\n", (
unsigned)
fBufHdr.
datalength);
327 fprintf(stderr,
"fail to read buffer header\n");
339 if (!
isReading() || (ptr==0) || (sz==0))
return false;
342 fprintf(stderr,
"Appropriate header was not read from buffer %u\n", (
unsigned) sz);
350 fprintf(stderr,
"fail to write buffer payload of size %u\n", (
unsigned) sz);
360 if ((ptr==0) || (sz==0) || (*sz == 0))
return false;
362 uint64_t maxsz = *sz; *sz = 0;
367 fprintf(stderr,
"Provided buffer %u is smaller than stored in the file %u\n", (
unsigned) maxsz, (
unsigned) *sz);
Base class for file writing/reading in DABC.
FileInterface::Handle fd
if true, io object owned by file
bool GetStrPar(const char *parname, char *sbuf, int sbuflen)
Return string file parameter.
int GetIntPar(const char *parname)
Return integer file parameter.
bool IsRFIO()
Returns true when RFIO is used.
void SetIO(FileInterface *_io, bool _ioowner=false)
bool CloseBasicFile()
reading/writing mode
bool iowoner
interface to the file system
bool fReadingMode
file descriptor
Generic file storage for DABC buffers.
const BinaryFileHeader & hdr() const
bool WriteBufPayload(const void *ptr, uint64_t sz)
bool ReadBufPayload(void *ptr, uint64_t sz)
bool OpenReading(const char *fname)
BinaryFileHeader fFileHdr
bool OpenWriting(const char *fname)
bool ReadBufHeader(uint64_t *size, uint64_t *typ=0)
bool WriteBufHeader(uint64_t size, uint64_t typ=0)
bool ReadBuffer(void *ptr, uint64_t *sz, uint64_t *typ=0)
BinaryFile()
buffer header
BinaryFileBufHeader fBufHdr
file header
bool WriteBuffer(const void *ptr, uint64_t sz, uint64_t typ=0)
Defines and implements basic POSIX file interface.
virtual bool GetFileStrPar(Handle h, const char *parname, char *sbuf, int sbuflen)
Method returns file-specific string parameter.
void * Handle
File handle descriptor.
virtual bool mkdir(const char *path)
virtual bool fseek(Handle f, long int offset, bool relative=true)
virtual int GetFileIntPar(Handle h, const char *parname)
Method returns file-specific int parameter.
virtual size_t fwrite(const void *ptr, size_t sz, size_t nmemb, Handle f)
virtual bool feof(Handle f)
virtual void fclose(Handle f)
virtual bool fflush(Handle f)
virtual size_t fread(void *ptr, size_t sz, size_t nmemb, Handle f)
virtual Handle fopen(const char *fname, const char *mode, const char *=0)
virtual Object * fmatch(const char *fmask, bool select_files=true)
Produce list of files, object must be explicitly destroyed with ref.Destroy call One could decide if ...
Base class for most of the DABC classes.