|
lcls2
C++ API: public headers of xtcdata, psalg, psdaq and psana
|
Small binary file wrapper around a C FILE: open() for reading or writing (chosen at construction), raw read()/write(), and >> / << operators that read or write the bytes of basic types. More...
#include <LMF_IO.hh>
Public Member Functions | |
| MyFILE (bool mode_reading_) | |
| Set the mode (true reads, false writes) and clear error, eof, position and filesize; no file is open. | |
| ~MyFILE () | |
| Call close() (which sets error to 1 if no file was open), then reset error and eof. | |
| bool | open (__int8 *name) |
| Open name with fopen(): "rb" in read mode, recording the file size by seeking to the end and back, or "wb" in write mode. | |
| void | close () |
| Close the file if one is open (otherwise set error to 1), then reset position, filesize and eof. | |
| unsigned __int64 | tell () |
| Return the position kept by this class (bytes read or written since open, or the last seek()). | |
| void | seek (unsigned __int64 pos) |
| fseeko() to pos from the start of the file; on success set the position to pos, otherwise set error to 1. | |
| void | read (__int8 *string, __int32 length_bytes) |
| Read length_bytes bytes into string with fread(). | |
| void | read (unsigned __int32 *dest, __int32 length_bytes) |
| Read length_bytes bytes into dest with fread(). | |
| void | write (const __int8 *string, __int32 length) |
| Write length bytes from string with fwrite() (the result is not checked), advance the position and raise filesize to it if needed. | |
| void | flush () |
| Call fflush() on the file. | |
| MyFILE & | operator>> (unsigned __int8 &c) |
| Read sizeof(unsigned __int8) bytes into c with read(). | |
| MyFILE & | operator>> (__int8 &c) |
| Read sizeof(__int8) bytes into c with read(). | |
| MyFILE & | operator>> (unsigned __int16 &l) |
| Read sizeof(unsigned __int16) bytes into l with read(). | |
| MyFILE & | operator>> (unsigned __int32 &l) |
| Read sizeof(unsigned __int32) bytes into l with read(). | |
| MyFILE & | operator>> (unsigned __int64 &l) |
| Read sizeof(unsigned __int64) bytes into l with read(). | |
| MyFILE & | operator>> (__int16 &s) |
| Read sizeof(__int16) bytes into s with read(). | |
| MyFILE & | operator>> (__int32 &l) |
| Read sizeof(__int32) bytes into l with read(). | |
| MyFILE & | operator>> (__int64 &l) |
| Read sizeof(__int64) bytes into l with read(). | |
| MyFILE & | operator>> (double &d) |
| Read sizeof(double) bytes into d with read(). | |
| MyFILE & | operator>> (bool &d) |
| Read sizeof(bool) bytes into d with read(). | |
| MyFILE & | operator<< (unsigned __int8 c) |
| Write the sizeof(unsigned __int8) bytes of c with write(). | |
| MyFILE & | operator<< (__int8 c) |
| Write the sizeof(__int8) bytes of c with write(). | |
| MyFILE & | operator<< (unsigned __int16 l) |
| Write the sizeof(unsigned __int16) bytes of l with write(). | |
| MyFILE & | operator<< (unsigned __int32 l) |
| Write the sizeof(unsigned __int32) bytes of l with write(). | |
| MyFILE & | operator<< (unsigned __int64 l) |
| Write the sizeof(unsigned __int64) bytes of l with write(). | |
| MyFILE & | operator<< (__int16 s) |
| Write the sizeof(__int16) bytes of s with write(). | |
| MyFILE & | operator<< (__int32 l) |
| Write the sizeof(__int32) bytes of l with write(). | |
| MyFILE & | operator<< (__int64 l) |
| Write the sizeof(__int64) bytes of l with write(). | |
| MyFILE & | operator<< (double d) |
| Write the sizeof(double) bytes of d with write(). | |
| MyFILE & | operator<< (bool d) |
| Write the sizeof(bool) bytes of d with write(). | |
Public Attributes | |
| FILE * | file |
| Underlying C FILE, or 0 when no file is open. | |
| __int32 | error |
| Set to 1 on failures (open, close without a file, short read, failed seek); cleared only by the constructor and destructor. | |
| bool | eof |
| Set when a short read reaches the end of the file; cleared by the constructor, open() and close(). | |
| unsigned __int64 | filesize |
| File size: measured by open() in read mode, or the largest position written in write mode; 0 after close(). | |
Small binary file wrapper around a C FILE: open() for reading or writing (chosen at construction), raw read()/write(), and >> / << operators that read or write the bytes of basic types.
It keeps its own position and file size and reports problems through error and eof instead of exceptions.
|
inline |
Set the mode (true reads, false writes) and clear error, eof, position and filesize; no file is open.
|
inline |
Call close() (which sets error to 1 if no file was open), then reset error and eof.
|
inline |
Close the file if one is open (otherwise set error to 1), then reset position, filesize and eof.
|
inline |
Call fflush() on the file.
|
inline |
Open name with fopen(): "rb" in read mode, recording the file size by seeking to the end and back, or "wb" in write mode.
Returns false and sets error to 1 if a file is already open or fopen() fails; otherwise true.
Write the sizeof(__int16) bytes of s with write().
Write the sizeof(__int32) bytes of l with write().
Write the sizeof(__int64) bytes of l with write().
Write the sizeof(__int8) bytes of c with write().
|
inline |
Write the sizeof(bool) bytes of d with write().
|
inline |
Write the sizeof(double) bytes of d with write().
Write the sizeof(unsigned __int16) bytes of l with write().
Write the sizeof(unsigned __int32) bytes of l with write().
Write the sizeof(unsigned __int64) bytes of l with write().
Write the sizeof(unsigned __int8) bytes of c with write().
Read sizeof(__int16) bytes into s with read().
Read sizeof(__int32) bytes into l with read().
Read sizeof(__int64) bytes into l with read().
Read sizeof(__int8) bytes into c with read().
|
inline |
Read sizeof(bool) bytes into d with read().
|
inline |
Read sizeof(double) bytes into d with read().
Read sizeof(unsigned __int16) bytes into l with read().
Read sizeof(unsigned __int32) bytes into l with read().
Read sizeof(unsigned __int64) bytes into l with read().
Read sizeof(unsigned __int8) bytes into c with read().
Read length_bytes bytes into string with fread().
On a short read set error to 1, and eof if the end of the file was reached; the position always advances by length_bytes.
Read length_bytes bytes into dest with fread().
On a short read set error to 1, and eof if the end of the file was reached; the position always advances by length_bytes.
| void MyFILE::seek | ( | unsigned __int64 | pos | ) |
fseeko() to pos from the start of the file; on success set the position to pos, otherwise set error to 1.
Defined in LMF_IO.cc.
|
inline |
Return the position kept by this class (bytes read or written since open, or the last seek()).
Write length bytes from string with fwrite() (the result is not checked), advance the position and raise filesize to it if needed.
| bool MyFILE::eof |
| __int32 MyFILE::error |
Set to 1 on failures (open, close without a file, short read, failed seek); cleared only by the constructor and destructor.
| FILE* MyFILE::file |
Underlying C FILE, or 0 when no file is open.
| unsigned __int64 MyFILE::filesize |