MMSFile Class Reference

A file class. More...

#include <mmsfile.h>

List of all members.


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.

Detailed Description

A file class.

With this class you can access normal files (/mms/data/file) and urls (http://address/file) with one interface.

Author:
Jens Schneider

Definition at line 95 of file mmsfile.h.


Constructor & Destructor Documentation

MMSFile::MMSFile ( string  name,
MMSFileMode  mode = MMSFM_READ,
bool  usecache = true 
)

Constructor of class MMSFile.

Parameters:
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]

Destructor of class MMSFile.

Definition at line 384 of file mmsfile.cpp.


Member Function Documentation

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]

Internal function which work with the own curl buffer.

Definition at line 110 of file mmsfile.cpp.

void MMSFile::freeCurlBuffer ( size_t  want  )  [private]

Internal function which work with the own curl buffer.

Definition at line 167 of file mmsfile.cpp.

bool MMSFile::openFile (  )  [private]

Internal function which opens a file.

Definition at line 186 of file mmsfile.cpp.

bool MMSFile::closeFile (  )  [private]

Internal function which closes a file.

Definition at line 316 of file mmsfile.cpp.

size_t MMSFile::write_cb ( char *  buffer,
size_t  size,
size_t  nitems,
void *  outstream 
) [virtual]

Virtual function for the curl write callback.

Definition at line 62 of file mmsfile.cpp.

string MMSFile::getName ( const bool  effectiveUrl = false  ) 

Returns the name of the file which was set with the constructor MMSFile().

Parameters:
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.

Returns:
EBADF, EINVAL, ENOENT, ENOMEM, EOF

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.

Returns:
EOF(-1), 0, 1

Definition at line 419 of file mmsfile.cpp.

bool MMSFile::rewindFile (  ) 

Moves the file pointer to the beginning of the file.

Definition at line 481 of file mmsfile.cpp.

bool MMSFile::setFilePos ( long  offset,
MMSFilePosOrigin  origin = MMSFPO_SET 
)

Moves the file pointer to a specified position.

Parameters:
offset number of bytes from the origin
origin optional, initial position, see definiton of MMSFilePosOrigin
Returns:
true if successful

Definition at line 531 of file mmsfile.cpp.

bool MMSFile::getFilePos ( long *  pos  ) 

Gets the current postion of the file pointer.

Parameters:
pos address of a long for storing the current position
Returns:
true if successful

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.

Parameters:
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
Returns:
true if successful
Note:
The pointer ptr must addresses size*nitems bytes in memory.

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.

Parameters:
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
Returns:
true if successful
Note:
This method allocates memory for the data and returns the pointer to it.

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.

Parameters:
ptr storage location for data
size maximum number of bytes to be read
Returns:
true if successful
Note:
The pointer ptr must addresses size bytes in memory.

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.

Parameters:
ptr address of a pointer for returning the allocated memory
size optional, maximum number of bytes to be read
Returns:
true if successful
Note:
This method allocates memory for the data and returns the pointer to it.

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.

Parameters:
ptr address of a pointer for returning the allocated memory
Returns:
true if successful
Note:
This method allocates memory for the data and returns the pointer to it.

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.

Parameters:
ptr address of a pointer for returning the allocated memory
Returns:
true if successful
Note:
This method allocates memory for the data and returns the pointer to it.

Definition at line 1096 of file mmsfile.cpp.

bool MMSFile::getChar ( char *  ptr  ) 

Read a character from the file.

Parameters:
ptr address of a character for returning the byte which is to read
Returns:
true if successful

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.

Parameters:
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
Returns:
true if successful
Note:
The pointer ptr must addresses size*nitems bytes in memory.

Definition at line 1131 of file mmsfile.cpp.


Member Data Documentation

string MMSFile::name [private]

ALL files: name of the file.

Definition at line 98 of file mmsfile.h.

ALL files: open mode.

Definition at line 101 of file mmsfile.h.

bool MMSFile::usecache [private]

ALL files: use a separate cache for all file types?

Definition at line 104 of file mmsfile.h.

ALL files: type of file.

Definition at line 107 of file mmsfile.h.

int MMSFile::lasterror [private]

ALL files: last error (0 if last call was sucessfull).

Definition at line 110 of file mmsfile.h.

FILE* MMSFile::file [private]

MMSFT_FILE: pointer to a file.

Definition at line 113 of file mmsfile.h.

CURLM* MMSFile::mhandle [private]

MMSFT_URL: pointer to a multi handle, if an url is used.

Definition at line 117 of file mmsfile.h.

CURL* MMSFile::curl [private]

MMSFT_URL: pointer to a curl, if an url is used.

Definition at line 120 of file mmsfile.h.

char* MMSFile::buffer [private]

MMSFT_URL: buffer to cached data from url.

Definition at line 130 of file mmsfile.h.

unsigned MMSFile::buf_len [private]

MMSFT_URL: buffer length.

Definition at line 133 of file mmsfile.h.

unsigned MMSFile::buf_pos [private]

MMSFT_URL: fill pointer within buffer.

Definition at line 136 of file mmsfile.h.

int MMSFile::still_progr [private]

MMSFT_URLL: url fetch is not finished and working in background.

Definition at line 139 of file mmsfile.h.

char* MMSFile::cache [private]

USECACHE=TRUE: pointer to the whole file data.

Definition at line 142 of file mmsfile.h.

size_t MMSFile::cache_fsize [private]

USECACHE=TRUE: file size.

Definition at line 145 of file mmsfile.h.

size_t MMSFile::cache_fpos [private]

USECACHE=TRUE: current position in cache.

Definition at line 148 of file mmsfile.h.


The documentation for this class was generated from the following files: