#include <mmsfile.h>
Public Member Functions | |
virtual size_t | write_cb (char *buffer, size_t size, size_t nitems, void *outstream) |
Virtual function for the curl write callback. | |
MMSFile (string name, MMSFileMode mode=MMSFM_READ, bool usecache=true) | |
Constructor of class MMSFile. | |
virtual | ~MMSFile () |
Destructor of class MMSFile. | |
string | getName (const bool effectiveUrl=false) |
Returns the name of the file which was set with the constructor MMSFile(). | |
MMSFileMode | getMode () |
Returns the open mode of the file which was set with the constructor MMSFile(). | |
MMSFileType | getType () |
Returns the type of the file. If set to MMSFT_NOTSET, the file was not opened. | |
int | getLastError () |
Returns the error of the last method call or 0, if no error has occured. | |
int | endOfFile () |
Returns the end of file status. | |
bool | rewindFile () |
Moves the file pointer to the beginning of the file. | |
bool | setFilePos (long offset, MMSFilePosOrigin origin=MMSFPO_SET) |
Moves the file pointer to a specified position. | |
bool | getFilePos (long *pos) |
Gets the current postion of the file pointer. | |
bool | readBuffer (void *ptr, size_t *ritems, size_t size, size_t nitems) |
Reads data from the file. | |
bool | readBufferEx (void **ptr, size_t *ritems, size_t size=1, size_t nitems=0xffffffff) |
Reads data from the file. | |
bool | getString (char *ptr, size_t size) |
Gets a string from the file. | |
bool | getStringEx (char **ptr, size_t size=0xffffffff) |
Gets a string from the file. | |
bool | getLine (char **ptr) |
Gets a line from the file. | |
bool | getLine (string &line) |
Gets a line from the file. | |
bool | getChar (char *ptr) |
Read a character from the file. | |
bool | writeBuffer (void *ptr, size_t *ritems, size_t size, size_t nitems) |
Writes data to the file. | |
Private Member Functions | |
void | resetAll () |
Internal function which resets the most private variables. | |
bool | fillCurlBuffer (size_t want, unsigned waittime=20) |
Internal function which work with the own curl buffer. | |
void | freeCurlBuffer (size_t want) |
Internal function which work with the own curl buffer. | |
bool | openFile () |
Internal function which opens a file. | |
bool | closeFile () |
Internal function which closes a file. | |
Private Attributes | |
string | name |
ALL files: name of the file. | |
MMSFileMode | mode |
ALL files: open mode. | |
bool | usecache |
ALL files: use a separate cache for all file types? | |
MMSFileType | type |
ALL files: type of file. | |
int | lasterror |
ALL files: last error (0 if last call was sucessfull). | |
FILE * | file |
MMSFT_FILE: pointer to a file. | |
CURLM * | mhandle |
MMSFT_URL: pointer to a multi handle, if an url is used. | |
CURL * | curl |
MMSFT_URL: pointer to a curl, if an url is used. | |
char * | buffer |
MMSFT_URL: buffer to cached data from url. | |
unsigned | buf_len |
MMSFT_URL: buffer length. | |
unsigned | buf_pos |
MMSFT_URL: fill pointer within buffer. | |
int | still_progr |
MMSFT_URLL: url fetch is not finished and working in background. | |
char * | cache |
USECACHE=TRUE: pointer to the whole file data. | |
size_t | cache_fsize |
USECACHE=TRUE: file size. | |
size_t | cache_fpos |
USECACHE=TRUE: current position in cache. |
With this class you can access normal files (/mms/data/file) and urls (http://address/file) with one interface.
Definition at line 95 of file mmsfile.h.
MMSFile::MMSFile | ( | string | name, | |
MMSFileMode | mode = MMSFM_READ , |
|||
bool | usecache = true | |||
) |
Constructor of class MMSFile.
name | name of the file ("/mms/data/file" or "http://address/file") | |
mode | optional, open mode (default is MMSFM_READ) see definition of MMSFileMode | |
usecache | optional, enable caching for this file (default is true) |
Definition at line 370 of file mmsfile.cpp.
MMSFile::~MMSFile | ( | ) | [virtual] |
void MMSFile::resetAll | ( | ) | [private] |
Internal function which resets the most private variables.
Definition at line 95 of file mmsfile.cpp.
bool MMSFile::fillCurlBuffer | ( | size_t | want, | |
unsigned | waittime = 20 | |||
) | [private] |
void MMSFile::freeCurlBuffer | ( | size_t | want | ) | [private] |
bool MMSFile::openFile | ( | ) | [private] |
bool MMSFile::closeFile | ( | ) | [private] |
size_t MMSFile::write_cb | ( | char * | buffer, | |
size_t | size, | |||
size_t | nitems, | |||
void * | outstream | |||
) | [virtual] |
string MMSFile::getName | ( | const bool | effectiveUrl = false |
) |
Returns the name of the file which was set with the constructor MMSFile().
effectiveUrl | [in] if set and filetype is MMSFT_URL the effective URL will be returned. |
Definition at line 390 of file mmsfile.cpp.
MMSFileMode MMSFile::getMode | ( | ) |
Returns the open mode of the file which was set with the constructor MMSFile().
Definition at line 404 of file mmsfile.cpp.
MMSFileType MMSFile::getType | ( | ) |
Returns the type of the file. If set to MMSFT_NOTSET, the file was not opened.
Definition at line 409 of file mmsfile.cpp.
int MMSFile::getLastError | ( | ) |
Returns the error of the last method call or 0, if no error has occured.
Definition at line 414 of file mmsfile.cpp.
int MMSFile::endOfFile | ( | ) |
Returns the end of file status.
It returns EOF (value -1) if the end of the file ist reached. If no error has occured but the end is not reached, the method returns 0. If the return value is 1, a error has occured, use getLastError() to determine the error.
Definition at line 419 of file mmsfile.cpp.
bool MMSFile::rewindFile | ( | ) |
bool MMSFile::setFilePos | ( | long | offset, | |
MMSFilePosOrigin | origin = MMSFPO_SET | |||
) |
Moves the file pointer to a specified position.
offset | number of bytes from the origin | |
origin | optional, initial position, see definiton of MMSFilePosOrigin |
Definition at line 531 of file mmsfile.cpp.
bool MMSFile::getFilePos | ( | long * | pos | ) |
Gets the current postion of the file pointer.
pos | address of a long for storing the current position |
Definition at line 617 of file mmsfile.cpp.
bool MMSFile::readBuffer | ( | void * | ptr, | |
size_t * | ritems, | |||
size_t | size, | |||
size_t | nitems | |||
) |
Reads data from the file.
ptr | storage location for data | |
ritems | address of a size_t for returning the number of full items actually read | |
size | item size in bytes | |
nitems | maximum number of items to be read |
Definition at line 671 of file mmsfile.cpp.
bool MMSFile::readBufferEx | ( | void ** | ptr, | |
size_t * | ritems, | |||
size_t | size = 1 , |
|||
size_t | nitems = 0xffffffff | |||
) |
Reads data from the file.
ptr | address of a pointer for returning the allocated memory | |
ritems | address of a size_t for returning the number of full items actually read | |
size | optional, item size in bytes | |
nitems | optional, maximum number of items to be read |
If you do not use the optional parameters, the method reads the whole file.
Definition at line 802 of file mmsfile.cpp.
bool MMSFile::getString | ( | char * | ptr, | |
size_t | size | |||
) |
Gets a string from the file.
This method reads up to the next
or up to size bytes in the current line. If a
is found, it is the last byte in the returned storage.
ptr | storage location for data | |
size | maximum number of bytes to be read |
Definition at line 867 of file mmsfile.cpp.
bool MMSFile::getStringEx | ( | char ** | ptr, | |
size_t | size = 0xffffffff | |||
) |
Gets a string from the file.
This method reads up to the next
or up to size bytes in the current line. If a
is found, it is the last byte in the returned storage.
ptr | address of a pointer for returning the allocated memory | |
size | optional, maximum number of bytes to be read |
If you do not use the parameter size, the method reads the whole line up to the next
.
Definition at line 1014 of file mmsfile.cpp.
bool MMSFile::getLine | ( | char ** | ptr | ) |
Gets a line from the file.
This method reads up to the next
in the current line. The
will be stripped from the returned storage.
ptr | address of a pointer for returning the allocated memory |
Definition at line 1081 of file mmsfile.cpp.
bool MMSFile::getLine | ( | string & | line | ) |
Gets a line from the file.
This method reads up to the next
in the current line. The
will be stripped from the returned storage.
ptr | address of a pointer for returning the allocated memory |
Definition at line 1096 of file mmsfile.cpp.
bool MMSFile::getChar | ( | char * | ptr | ) |
Read a character from the file.
ptr | address of a character for returning the byte which is to read |
Definition at line 1117 of file mmsfile.cpp.
bool MMSFile::writeBuffer | ( | void * | ptr, | |
size_t * | ritems, | |||
size_t | size, | |||
size_t | nitems | |||
) |
Writes data to the file.
ptr | storage location for data | |
ritems | address of a size_t for returning the number of full items actually written | |
size | item size in bytes | |
nitems | number of items to be written |
Definition at line 1131 of file mmsfile.cpp.
string MMSFile::name [private] |
MMSFileMode MMSFile::mode [private] |
bool MMSFile::usecache [private] |
MMSFileType MMSFile::type [private] |
int MMSFile::lasterror [private] |
FILE* MMSFile::file [private] |
CURLM* MMSFile::mhandle [private] |
CURL* MMSFile::curl [private] |
char* MMSFile::buffer [private] |
unsigned MMSFile::buf_len [private] |
unsigned MMSFile::buf_pos [private] |
int MMSFile::still_progr [private] |
char* MMSFile::cache [private] |
size_t MMSFile::cache_fsize [private] |
size_t MMSFile::cache_fpos [private] |