Public Member Functions

base::MemFile Class Reference

A data store that keeps data in memory up to a certain limit, and switches to a temporary file if the limit is exceeded. More...

#include <libppbase/base/MemFile.h>

Inheritance diagram for base::MemFile:
base_cgi::CGIFile base_http::HTTPPart base_soap::SOAPAttachment base_http::HTTPRequest base_http::HTTPResponse

List of all members.

Public Member Functions

 MemFile (size_t limit=1048576)
 Constructor.
 ~MemFile ()
 Destructor.
MemFileclone () const
 Clones a mem file.
size_t getPos () const
 Returns the file position.
const char * getSourceBuffer (size_t *rsize=NULL) const
 Returns the source memory buffer.
FilegetSourceFile () const
 Returns the source file.
StringgetSourceString () const
 Returns the source memory buffer of type string.
bool isInMemory () const
 Checks if the data is in memory.
const char * loadIntoMemory (size_t *rsize=NULL)
 Loads the data into memory, if it is not there already.
size_t read (void *buf, size_t count, bool exact=false)
 Reads some bytes from the data.
size_t read (String &buf, size_t count, bool exact=false)
 Reads some bytes from the data.
bool readln (String &rbuf, bool strip=false)
 Reads a line of data.
FilesaveToFile ()
 Saves the data to a file, if it is not there already.
void seek (size_t pos)
 Sets the file positon.
void seekBOF ()
 Sets the file position to the beginning of the data.
void seekEOF ()
 Sets the file position to the end of the data.
void setLimit (size_t limit)
 Sets the memory limit.
void setSource (const MemFile *source)
 Sets the data source from another memfile object.
void setSourceBuffer (const char *buf, size_t bufsize, bool own=false)
 Associates this object with a new data source.
void setSourceFile (File *file, bool own=false)
 Associates this object with a new data source.
void setSourceFile (const String &name, int flags=File::ofReadOnly)
 Associates this object with a new data source.
void setSourceString (String *str, bool own=false)
 Associates this object with a new data source.
size_t size () const
 Returns the file size.
void truncate (size_t len)
 Truncates the data to a given size.
size_t write (const void *buf, size_t count, bool exact=true)
 Writes some bytes to the file.
size_t write (const String &buf, bool exact=true)
 Writes some bytes to the file.

Detailed Description

A data store that keeps data in memory up to a certain limit, and switches to a temporary file if the limit is exceeded.

Author:
Christoph Schwarz
Version:
$Id: MemFile.h 21 2010-09-05 04:18:17Z cschwarz1 $

Constructor & Destructor Documentation

base::MemFile::MemFile ( size_t  limit = 1048576  ) 

Constructor.

Parameters:
limit memory limit in bytes

Member Function Documentation

MemFile* base::MemFile::clone (  )  const

Clones a mem file.

The cloned mem file starts at position 0. If this mem file owns the underlying data source, it generates a clone of the data source too. If not, the original data source is just passed.

Returns:
the clone
size_t base::MemFile::getPos (  )  const

Returns the file position.

Returns:
the file position
const char* base::MemFile::getSourceBuffer ( size_t *  rsize = NULL  )  const

Returns the source memory buffer.

Parameters:
rsize returns the data size in bytes
Returns:
the memory buffer, in case the data is still in memory
File* base::MemFile::getSourceFile (  )  const

Returns the source file.

Returns:
the file, in case the memory limit has been exceeded
String* base::MemFile::getSourceString (  )  const

Returns the source memory buffer of type string.

Returns:
the memory buffer
bool base::MemFile::isInMemory (  )  const

Checks if the data is in memory.

Returns:
true if the data is in memory, false if it is in the temp file
const char* base::MemFile::loadIntoMemory ( size_t *  rsize = NULL  ) 

Loads the data into memory, if it is not there already.

Parameters:
rsize returns the data size in bytes
Returns:
a pointer to the data in memory
size_t base::MemFile::read ( void *  buf,
size_t  count,
bool  exact = false 
)

Reads some bytes from the data.

Parameters:
buf buffer to read bytes into
count number of bytes to read
exact flag: read exactly this many bytes
Returns:
number of bytes read
size_t base::MemFile::read ( String buf,
size_t  count,
bool  exact = false 
)

Reads some bytes from the data.

Parameters:
buf buffer to read bytes into
count number of bytes to read
exact flag: read exactly this many bytes
Returns:
number of bytes read
bool base::MemFile::readln ( String rbuf,
bool  strip = false 
)

Reads a line of data.

Parameters:
rbuf buffer to read the line into
strip flag: strip CR/LF from the end of the line
Returns:
false if there is no more line
File* base::MemFile::saveToFile (  ) 

Saves the data to a file, if it is not there already.

Returns:
the file
void base::MemFile::seek ( size_t  pos  ) 

Sets the file positon.

Parameters:
pos byte offset of new file position
void base::MemFile::setLimit ( size_t  limit  ) 

Sets the memory limit.

Parameters:
limit new memory limit in bytes
void base::MemFile::setSource ( const MemFile source  ) 

Sets the data source from another memfile object.

Parameters:
source the data source
void base::MemFile::setSourceBuffer ( const char *  buf,
size_t  bufsize,
bool  own = false 
)

Associates this object with a new data source.

Parameters:
buf the source buffer
bufsize the number of bytes in the buffer
own true if this object owns the buffer (=frees it when it is destroyed)
void base::MemFile::setSourceFile ( File file,
bool  own = false 
)

Associates this object with a new data source.

Parameters:
file an open file object
own true if this object owns the file (=deletes it when it is destroyed)
void base::MemFile::setSourceFile ( const String name,
int  flags = File::ofReadOnly 
)

Associates this object with a new data source.

Parameters:
name the file name
flags open flags
void base::MemFile::setSourceString ( String str,
bool  own = false 
)

Associates this object with a new data source.

Parameters:
str the source buffer
own true if this object owns the string (=frees it when it is destroyed)
size_t base::MemFile::size (  )  const

Returns the file size.

Returns:
file size in bytes

Reimplemented in base_http::HTTPPart, and base_http::HTTPRequest.

void base::MemFile::truncate ( size_t  len  ) 

Truncates the data to a given size.

Parameters:
len the size to truncate the data to
size_t base::MemFile::write ( const void *  buf,
size_t  count,
bool  exact = true 
)

Writes some bytes to the file.

Parameters:
buf bytes to write
count number of bytes to write
exact flag: write exactly this many bytes, throw an error if they cannot be written
Returns:
number of bytes written
size_t base::MemFile::write ( const String buf,
bool  exact = true 
)

Writes some bytes to the file.

Parameters:
buf bytes to write
exact flag: write exactly this many bytes, throw an error if they cannot be written
Returns:
number of bytes written

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