KrisLibrary  1.0.0
Classes | Macros | Typedefs | Functions
File.h File Reference

A unified interface for reading/writing binary data to file. More...

Go to the source code of this file.

Classes

class  File
 A cross-platform class for reading/writing binary data. More...
 

Macros

#define FILEREAD   0x1
 Flags sent to Open: read or write mode (may be bitwise or-ed together)
 
#define FILEWRITE   0x2
 
#define FILECLIENT   0x1
 Flags sent to Open for socket connections: client mode or server mode.
 
#define FILESERVER   0x2
 
#define FILESEEKSTART   0
 Flags sent to Seek.
 
#define FILESEEKCURRENT   1
 
#define FILESEEKEND   2
 
#define _DECLARE_READ_WRITE_FILE_BASIC(type)
 
#define _DEFINE_READ_WRITE_FILE_BASIC(type)
 

Typedefs

typedef int SOCKET
 

Functions

template<class type >
bool ReadFile (File &f, type &t)
 
template<class type >
bool WriteFile (File &f, const type &t)
 
template<class type >
bool ReadArrayFile (File &f, type *t, int n)
 
template<class type >
bool WriteArrayFile (File &f, const type *t, int n)
 
 _DECLARE_READ_WRITE_FILE_BASIC (bool)
 
 _DECLARE_READ_WRITE_FILE_BASIC (char)
 
 _DECLARE_READ_WRITE_FILE_BASIC (signed char)
 
 _DECLARE_READ_WRITE_FILE_BASIC (unsigned char)
 
 _DECLARE_READ_WRITE_FILE_BASIC (short)
 
 _DECLARE_READ_WRITE_FILE_BASIC (int)
 
 _DECLARE_READ_WRITE_FILE_BASIC (long)
 
 _DECLARE_READ_WRITE_FILE_BASIC (unsigned long long)
 
 _DECLARE_READ_WRITE_FILE_BASIC (float)
 
 _DECLARE_READ_WRITE_FILE_BASIC (double)
 
 _DECLARE_READ_WRITE_FILE_BASIC (long double)
 

Detailed Description

A unified interface for reading/writing binary data to file.

A consistent interface for reading/writing data is given by the template methods ReadFile() and WriteFile(). A class can be read/written to file in two ways: 1) Read/WriteFile() can be overloaded to read/write the data directly, or 2) use the default Read/WriteFile(), but define the following methods in the class:

bool Read(File&)
bool Write(File&) const

For structs of contiguous data, the macro _DEFINE_READ_WRITE_FILE_BASIC(T) will overload the the Read/WriteFile functions to automatically read the data from file contiguously for objects of type T.

Macro Definition Documentation

#define _DECLARE_READ_WRITE_FILE_BASIC (   type)
Value:
template <> bool ReadFile(File& f, type& t); \
template <> bool WriteFile(File& f, const type& t); \
template <> bool ReadArrayFile(File& f, type* t,int n); \
template <> bool WriteArrayFile(File& f, const type* t,int n);
bool WriteFile(File &f, const std::vector< type > &v)
WriteFile() for STL vectors. See File.h.
Definition: ioutils.h:81
bool ReadFile(File &f, std::vector< type > &v)
ReadFile() for STL vectors. See File.h.
Definition: ioutils.h:69
A cross-platform class for reading/writing binary data.
Definition: File.h:47
#define _DEFINE_READ_WRITE_FILE_BASIC (   type)
Value:
template <> bool ReadFile(File& f, type& t) \
{ return f.ReadData(&t, sizeof(t)); } \
template <> bool WriteFile(File& f, const type& t) \
{ return f.WriteData(&t, sizeof(t)); } \
template <> bool ReadArrayFile(File& f, type* t,int n) \
{ return f.ReadData(t, sizeof(type)*n); } \
template <> bool WriteArrayFile(File& f, const type* t,int n) \
{ return f.WriteData(t, sizeof(type)*n); }
bool WriteFile(File &f, const std::vector< type > &v)
WriteFile() for STL vectors. See File.h.
Definition: ioutils.h:81
bool ReadFile(File &f, std::vector< type > &v)
ReadFile() for STL vectors. See File.h.
Definition: ioutils.h:69
A cross-platform class for reading/writing binary data.
Definition: File.h:47