#include <file.h>
Public Types | |
enum | SeekType { ST_CURRENT, ST_START, ST_END } |
Start point for seeking in file. More... | |
Public Member Functions | |
virtual | ~File () |
bool | Open (const string &fileName, const char *accessMode) |
void | Close () |
bool | Eof () const |
long | GetSize () const |
bool | IsOpened () const |
bool | IsBinary () const |
int | GetLine () const |
const string & | GetFilePath () const |
long | Tell () const |
bool | Seek (long offset, SeekType origin) |
bool | Flush () |
size_t | Write (const void *buffer, size_t size) |
size_t | Read (void *buffer, size_t size) |
byte_t * | ReadAll () |
char * | ReadAllToString () |
bool | WriteLine (const string &line) |
bool | PrintF (const char *format,...) |
bool | ReadLine (string &line) |
size_t | WriteInt (int val) |
size_t | WriteShort (short val) |
size_t | WriteLong (long val) |
size_t | WriteChar (char val) |
size_t | WriteUInt (unsigned int val) |
size_t | WriteUShort (unsigned short val) |
size_t | WriteULong (unsigned long val) |
size_t | WriteUChar (unsigned char val) |
size_t | WriteFloat (float val) |
size_t | WriteDouble (double val) |
int | ReadInt () |
short | ReadShort () |
long | ReadLong () |
char | ReadChar () |
unsigned int | ReadUInt () |
unsigned short | ReadUShort () |
unsigned long | ReadULong () |
unsigned char | ReadUChar () |
float | ReadFloat () |
double | ReadDouble () |
Static Public Member Functions | |
static size_t | OnRead (void *ptr, size_t size, size_t nmemb, void *source) |
static size_t | OnWrite (const void *ptr, size_t size, size_t count, void *source) |
static int | OnSeek (void *source, long offset, int whence) |
static int | OnSeek64 (void *source, __int64 offset, int whence) |
static long | OnTell (void *source) |
static int | OnClose (void *source) |
static int | OnFlush (void *source) |
Protected Member Functions | |
File () | |
File (FILE *file, const char *file_path, bool binary) | |
Protected Attributes | |
ushort_t | act_line |
Actual line number. | |
bool | opened |
Whether file is opened. | |
bool | binary |
Whether file was opend as binary;. | |
FILE * | file |
Ansi C file pointer. | |
string | file_path |
Path to the file. | |
Friends | |
class | FileServer |
enum File::SeekType |
File::~File | ( | ) | [virtual] |
Destructor.
File::File | ( | ) | [protected] |
Constructor. It is private because only FileServer may create objects.
File::File | ( | FILE * | file, | |
const char * | file_path, | |||
bool | binary | |||
) | [protected] |
Given file stream will be set directly. Used in FileServer to wraps standart streams.
file | Opened file stream. | |
file_path | Name and full path of the stream. | |
binary | Whether the stream is binary. |
True
if success.
bool File::Open | ( | const string & | file_path, | |
const char * | access_mode | |||
) |
Opens the specified file.
file_path | The full name of the file to open. | |
access_mode | The access mode ("(r|w|a)[+]"). |
True
if success. void File::Close | ( | ) |
Closes the file.
bool File::Eof | ( | ) | const |
Is the file at the end.
long File::GetSize | ( | ) | const |
Returns size of file in bytes.
bool File::IsOpened | ( | ) | const [inline] |
Determines whether the file is opened.
bool File::IsBinary | ( | ) | const [inline] |
Determines whether the file was opened with binary flag.
int File::GetLine | ( | ) | const [inline] |
Gets current line number (incremented by WriteLine() and ReadLine())
const string & File::GetFilePath | ( | ) | const [inline] |
Gets full file name and path.
long File::Tell | ( | ) | const |
Gets current position of file pointer.
bool File::Seek | ( | long | offset, | |
SeekType | origin | |||
) |
Sets the file pointer to given absolute or relative position.
offset | The offset. | |
origin | Position from which to count. |
bool File::Flush | ( | ) | [inline] |
Flushes a stream.
size_t File::Write | ( | const void * | buffer, | |
size_t | size | |||
) |
Writes a number of bytes to the file.
buffer | Buffer with data. | |
size | Number of bytes to write. |
size_t File::Read | ( | void * | buffer, | |
size_t | size | |||
) |
Reads a number of bytes from the file.
buffer | Buffer for data. | |
size | Number of bytes to read. |
byte_t * File::ReadAll | ( | ) |
Reads whole file into memory buffer.
This function does not depend on current position in the file. This position will not be changed. Buffer is creted using NEW operator so user has to delete it hisself.
NULL
is returned. char * File::ReadAllToString | ( | ) |
bool File::WriteLine | ( | const string & | line | ) |
Writes a string to the file.
line | The string to write. |
bool File::PrintF | ( | const char * | format, | |
... | ||||
) |
Writes a formatted string to the file.
format | Standart format string like in printf. |
bool File::ReadLine | ( | string & | line | ) |
Reads one line from the file up to the first newline character or up to the end of the buffer.
line | Buffer for line. |
False
if eof is reached. size_t File::WriteInt | ( | int | val | ) | [inline] |
Writes a 32bit integer to the file.
val | A 32 bit int value. |
size_t File::WriteShort | ( | short | val | ) | [inline] |
Writes a 16bit integer to the file.
val | A 16 bit int value. |
size_t File::WriteLong | ( | long | val | ) | [inline] |
Writes a 64bit integer to the file.
val | A 64 bit int value. |
size_t File::WriteChar | ( | char | val | ) | [inline] |
Writes a 8bit integer to the file.
val | A 8 bit int value. |
size_t File::WriteUInt | ( | unsigned int | val | ) | [inline] |
Writes a unsigned 32bit integer to the file.
val | A 32 unsigned bit int value. |
size_t File::WriteUShort | ( | unsigned short | val | ) | [inline] |
Writes a unsigned 16bit integer to the file.
val | A unsigned 16 bit int value. |
size_t File::WriteULong | ( | unsigned long | val | ) | [inline] |
Writes a unsigned 64bit integer to the file.
val | A unsigned 64 bit int value. |
size_t File::WriteUChar | ( | unsigned char | val | ) | [inline] |
Writes a unsigned 8bit integer to the file.
val | A unsigned 8 bit int value. |
size_t File::WriteFloat | ( | float | val | ) | [inline] |
Writes a float to the file.
val | A 32 bit float value. |
size_t File::WriteDouble | ( | double | val | ) | [inline] |
Writes a double to the file.
val | A 64 bit double value. |
int File::ReadInt | ( | ) | [inline] |
Reads a 32 bit integer from the file.
short File::ReadShort | ( | ) | [inline] |
Reads a 16 bit integer from the file.
long File::ReadLong | ( | ) | [inline] |
Reads a 64 bit integer from the file.
char File::ReadChar | ( | ) | [inline] |
Reads a 8 bit integer from the file.
unsigned int File::ReadUInt | ( | ) | [inline] |
Reads a unsigned 32 bit integer from the file.
unsigned short File::ReadUShort | ( | ) | [inline] |
Reads a unsigned 16 bit integer from the file.
unsigned long File::ReadULong | ( | ) | [inline] |
Reads a unsigned 64 bit integer from the file.
unsigned char File::ReadUChar | ( | ) | [inline] |
Reads a 8 unsigned bit integer from the file.
float File::ReadFloat | ( | ) | [inline] |
Reads a float from the file.
double File::ReadDouble | ( | ) | [inline] |
Reads a double from the file.
size_t File::OnRead | ( | void * | ptr, | |
size_t | size, | |||
size_t | count, | |||
void * | source | |||
) | [inline, static] |
Wraps our file access into callback function used in external libraries.
ptr | Pointer to memory buffer. | |
size | Size of block. | |
count | Number of blocks we want to read. | |
source | Pointer to File object. |
size_t File::OnWrite | ( | const void * | ptr, | |
size_t | size, | |||
size_t | count, | |||
void * | source | |||
) | [inline, static] |
Wraps our file access into callback function used in external libraries.
ptr | Pointer to memory buffer. | |
size | Size of block. | |
count | Number of blocks we want to write. | |
source | Pointer to File object. |
int File::OnSeek | ( | void * | source, | |
long | offset, | |||
int | whence | |||
) | [inline, static] |
Wraps our file access into callback function used in external libraries.
source | Pointer to File object. | |
offset | Offset for seeking. | |
whence | Start point for seeking. |
int File::OnSeek64 | ( | void * | source, | |
__int64 | offset, | |||
int | whence | |||
) | [inline, static] |
Wraps our file access into callback function used in external libraries.
source | Pointer to File object. | |
offset | Offset for seeking. | |
whence | Start point for seeking. |
long File::OnTell | ( | void * | source | ) | [inline, static] |
Wraps our file access into callback function used in external libraries.
source | Pointer to File object. |
int File::OnClose | ( | void * | source | ) | [inline, static] |
Wraps our file access into callback function used in external libraries.
source | Pointer to File object. |
int File::OnFlush | ( | void * | source | ) | [inline, static] |
Wraps our file access into callback function used in external libraries.
source | Pointer to File object. |
friend class FileServer [friend] |
ushort_t File::act_line [protected] |
Actual line number.
bool File::opened [protected] |
Whether file is opened.
bool File::binary [protected] |
Whether file was opend as binary;.
FILE* File::file [protected] |
Ansi C file pointer.
string File::file_path [protected] |
Path to the file.