|
Xpace
|
#include <file.h>
Classes | |
| class | Cant_Copy |
| thrown if either of the above two fails e.g., if rhs is not read-only More... | |
| struct | Segment |
Public Types | |
| enum | OpenMode { ReadSequential, ReadRandom, WriteSequential, WriteSequentialNew, WriteRandom, WriteRandomNew } |
| enum | Type { Raw, Any, DataStore, DataRefs, DataMap, IndexList, IndexMap } |
| typedef uint64 | Position |
| typedef int64 | Distance |
Public Member Functions | |
| File () | |
| constructor - Create an empty file More... | |
| File (const File &rhs) | |
| creates an independent copy rhs must be read-only; result is read-only copy this More... | |
| File & | operator= (const File &rhs) |
| assign an independent copy rhs must be read-only; result is read-only copy this More... | |
| virtual | ~File () |
| destructor - closes if open More... | |
| virtual bool | open (const String name, OpenMode mode, Type type=Any, size_t bufSize=0) |
| virtual void | fromHandle (FILE *handle, size_t bufSize=0) |
| Open a special file, which is not seekable, such as a pipe. More... | |
| virtual bool | operator! () const |
| virtual String | getName () const |
| virtual size_t | getBufSize () const |
| virtual bool | flush () |
| Make sure all changes are written. More... | |
| virtual bool | close () |
| Close the file, flushing if necessary. More... | |
| virtual bool | remove () |
| delete the file, if it exists file does not have to be open More... | |
| size_t | read (void *dest, size_t bytes) |
| Read from the file. More... | |
| template<typename T > | |
| bool | read (T *dest) |
| Read a T from the file. More... | |
| template<typename T > | |
| T | read () |
| Read a T from the file. More... | |
| String | readString (bool raw=false, size_t maxLen=0x100000) |
| Read thehe remainder of the as a 16-bit char string. More... | |
| String | readString8 (size_t maxLen=0x100000) |
| Read the remainder of the file as an 8-bit char string. More... | |
| size_t | write (const void *src, size_t bytes) |
| Write some data to the file. More... | |
| template<typename T > | |
| bool | write (const T &src) |
| Write a T to the file. More... | |
| bool | writeString (const String &str, bool raw=false) |
| Write a String to the file. More... | |
| template<typename T > | |
| size_t | get (T **dest, size_t bytes) |
| Get by direct access to the file buffer not guaranteed to be valid after successive calls. More... | |
| template<typename T > | |
| size_t | getUntil (T **dest, T delim) |
| Get bytes until a delimiter. More... | |
| template<typename T > | |
| T * | get () |
| Get a T by direct access to the file buffer return not guaranteed to be valid after successive calls. More... | |
| virtual Position | getLength () const |
| Get file length. More... | |
| virtual Position | getLength (const String name) |
| Get length of a file by name. More... | |
| virtual Position | getPos () const |
| Get current position. More... | |
| virtual bool | seek (Position pos) |
| Move current position. More... | |
| bool | seekRel (Distance dist) |
| Move current position. More... | |
| size_t | bufRemains () const |
| bool | copy (File *targ, File::Position size) |
| copy from this file to another More... | |
Static Public Attributes | |
| static const Position | errorPosition |
Protected Types | |
| enum | { SEQ_BUF_SIZE = 65536, RAND_BUF_SIZE = 16384 } |
| enum | { OS_BUF_SIZE = 4096 } |
Protected Member Functions | |
| virtual bool | seekFile (uint64) |
| virtual size_t | fillBuffer () |
| virtual size_t | fileRead (byte *dest, size_t bytes) |
| virtual size_t | fileWrite (const byte *src, size_t bytes) |
Protected Attributes | |
| String | name |
| OpenMode | mode |
| Type | type |
| the file's type More... | |
| bool | writable |
| opened for write More... | |
| bool | bufDirty |
| is buffer modified More... | |
| bool | seekable |
| is not a special file More... | |
| uint64 | bufOffset |
| offset of buffer in file More... | |
| size_t | bufSize |
| actual buffer size More... | |
| byte * | buffer |
| buffer More... | |
| byte * | current |
| current position in buffer More... | |
| byte * | end |
| end of data in buffer More... | |
| FILE * | hd |
| typedef uint64 Xpace::File::Position |
| typedef int64 Xpace::File::Distance |
| enum Xpace::File::Type |
|
protected |
| Xpace::File::File | ( | ) |
constructor - Create an empty file
| Xpace::File::File | ( | const File & | rhs | ) |
creates an independent copy rhs must be read-only; result is read-only copy this
|
virtual |
destructor - closes if open
assign an independent copy rhs must be read-only; result is read-only copy this
|
virtual |
| name | full path name |
| mode | file open mode |
| type | the file's type; an attempt to open an existing file of the wrong type will fail |
| bufSize | if 0, use defaults |
|
virtual |
Open a special file, which is not seekable, such as a pipe.
| handle | OS handle |
| bufSize | if 0, use defaults |
|
inlinevirtual |
|
inlinevirtual |
Definition at line 442 of file file.h.
References getBufSize(), and name.
Referenced by Xpace::File::Cant_Copy::Cant_Copy(), Xpace::File_Cant_Close::File_Cant_Close(), Xpace::File_Cant_Read::File_Cant_Read(), Xpace::File_Cant_Write::File_Cant_Write(), Xpace::File_Corrupt::File_Corrupt(), and operator!().
|
inlinevirtual |
|
virtual |
Make sure all changes are written.
|
virtual |
Close the file, flushing if necessary.
|
virtual |
delete the file, if it exists file does not have to be open
|
inline |
|
inline |
|
inline |
Read a T from the file.
| File_Cant_Read | iff unsuccessful |
Definition at line 484 of file file.h.
References get().
Referenced by getBufSize(), and read().
Read thehe remainder of the as a 16-bit char string.
| raw | read remainder of file as one string, otherwise read string written with writeString |
| maxLen | read no more than this many chars |
| String Xpace::File::readString8 | ( | size_t | maxLen = 0x100000 | ) |
Read the remainder of the file as an 8-bit char string.
| maxLen | read no more than this many chars |
|
inline |
|
inline |
Write a String to the file.
| str | String to be written |
| raw | if false, write for readString(), if true just write chars |
|
inline |
Get by direct access to the file buffer not guaranteed to be valid after successive calls.
| dest | ptr to data file buffer |
| count | number of Ts requested |
Definition at line 495 of file file.h.
References getUntil().
|
inline |
|
inline |
Get a T by direct access to the file buffer return not guaranteed to be valid after successive calls.
Definition at line 593 of file file.h.
References write().
Referenced by getUntil(), and read().
|
virtual |
Get file length.
Get length of a file by name.
| name | full path name |
|
virtual |
Get current position.
Referenced by Xpace::File_Cant_Read::File_Cant_Read(), Xpace::File_Cant_Write::File_Cant_Write(), and Xpace::File_Corrupt::File_Corrupt().
Move current position.
| pos | seek to this position |
Move current position.
| dist | move this amount |
Definition at line 634 of file file.h.
References bufRemains().
Referenced by write().
|
inline |
| bool Xpace::File::copy | ( | File * | targ, |
| File::Position | size | ||
| ) |
copy from this file to another
| targ | copy to this file |
| size | copy this many bytes |
|
protectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
|
protected |
|
protected |