#include <stdio.h>
Go to the source code of this file.
Classes | |
struct | mdio_File_t |
File base class. More... | |
Typedefs | |
typedef mdio_File_t | mdio_File |
File base class. | |
Enumerations | |
enum | { MDIO_ERROR = -1, MDIO_LENGTH_ERRMSG = 240 } |
enum | { MDIO_FILE_TEXT = 0x001, MDIO_FILE_BINARY = 0x002, MDIO_FILE_READ = 0x004, MDIO_FILE_WRITE = 0x008 } |
File type flags. More... | |
enum | { MDIO_ERROR_NONE, MDIO_ERROR_WARN, MDIO_ERROR_BADVAL, MDIO_ERROR_NOMEM, MDIO_ERROR_OPEN, MDIO_ERROR_CLOSE, MDIO_ERROR_READ, MDIO_ERROR_WRITE, MDIO_ERROR_SEEK, MDIO_ERROR_SYNTAX, MDIO_ERROR_UNXEOF, MDIO_LENGTH_ERRORLIST } |
Error numbers. More... | |
enum | { MDIO_EOF = 0x001, MDIO_SEEK_SET = SEEK_SET, MDIO_SEEK_CUR = SEEK_CUR, MDIO_SEEK_END = SEEK_END } |
Functions | |
mdio_File * | mdio_createFile (void) |
Constructor. | |
void | mdio_destroyFile (mdio_File *) |
Destructor. | |
int | mdio_openFile (mdio_File *, const char *name, int filetype) |
Open file. | |
int | mdio_closeFile (mdio_File *) |
Close file. | |
int | mdio_readLineFile (mdio_File *, char **pbuf, int *pbuflen) |
Read entire line from text file. | |
int | mdio_readTextFile (mdio_File *, char *buf, int buflen) |
Read from text file. | |
int | mdio_writeTextFile (mdio_File *, const char *buf) |
Write to text file. | |
int | mdio_readBinaryFile (mdio_File *, void *buffer, int elemsz, int n) |
Read from binary file. | |
int | mdio_writeBinaryFile (mdio_File *, const void *buffer, int elemsz, int n) |
Write to binary file. | |
int | mdio_seekFile (mdio_File *, long offset, int whence) |
Seek position within binary file. | |
int | mdio_isEndOfFile (mdio_File *) |
Return nonzero if end-of-file has been reached, otherwise return 0. | |
int | mdio_setErrorFile (mdio_File *, int errnum) |
Set error status on file. | |
int | mdio_setErrorMessageFile (mdio_File *, int errnum, const char *msg) |
Set error status on file with customized message. | |
void | mdio_setErrorHandlerFile (mdio_File *, int(*errhandler)(mdio_File *)) |
Set error handler routine. | |
const char * | mdio_getNameFile (mdio_File *) |
Returns the name of the file. | |
int | mdio_getTypeFile (mdio_File *) |
Returns the type of the file. | |
int | mdio_getErrorFile (mdio_File *) |
Returns the current error number set for the file. | |
int | mdio_getBytenumFile (mdio_File *) |
Returns the current byte position for the file. | |
int | mdio_getLinenumFile (mdio_File *) |
Returns the current line number for the file. | |
const char * | mdio_getErrorMessageFile (mdio_File *) |
Returns the current diagnostic error message for the file. | |
void | mdio_resetErrorFile (mdio_File *) |
Resets the error status for the file. | |
int | mdio_initializeFile (mdio_File *) |
Alternative constructor. | |
void | mdio_cleanupFile (mdio_File *) |
Alternative destructor. |
mdio_File
class performs the actual I/O along with diagnostic and error handling capabilities. It is the base class for the specialized reader and writer classes. For accessing supported types of MD files, instead use the higher level "derived" classes.
The file I/O routines are a somewhat simplified version of the C standard I/O library function calls. The fact that the actual I/O calls are hidden behind this layer means that the implementation could depend on the file type, for example, use of mmap()
for large trajectory files.
|
File base class. Members should be treated as private. |
|
|
|
File type flags.
|
|
|
|
|
Alternative destructor.
Use to destroy a preallocated file object (i.e. one constructed using |
|
Close file.
|
|
Constructor. Creates dynamically allocated file object.
|
|
Destructor. Frees dynamically allocated file object. |
|
Alternative constructor.
Use to construct a preallocated file object. See |
|
Open file.
name string is expected to persist until the file is closed with mdio_closeFile() .
For
|
|
Read from binary file.
n elements each of size elemsz bytes into the memory buffer pointed to by buffer . Similar to fread() .
|
|
Read entire line from text file.
char buffer is nil-terminated. The address pbuf needs to point to memory that can be managed using realloc() so that the buffer can be expanded arbitrarily to contain the entire line, with the updated length stored back to pbuflen . The caller is responsible for later freeing the memory allocation.
|
|
Read from text file.
buflen - 1 characters. Similar to fgets() .
|
|
Seek position within binary file.
|
|
Set error status on file.
An illegal value for
If the error handler has been set (see
|
|
Set error handler routine.
mdio_setErrorFile() or mdio_setErrorMessageFile() . The default error handler prints to stderr the error diagnostic message. It can be replaced by a user-defined error handling routine or resetting to NULL .
Any of the following routines are available to the error handler: |
|
Set error status on file with customized message.
mdio_setErrorFile() with the addition that the msg string will be appended to the diagnostic message. |
|
Write to binary file.
n ![]() elemsz bytes stored in buffer to the file. Similar to fwrite() .
|
|
Write to text file.
fputs() .
|