Cupt
|
high-level interface to file routines More...
#include <cupt/file.hpp>
Public Member Functions | |
File (const string &path, const char *mode, string &error) | |
constructor More... | |
virtual | ~File () |
destructor | |
File & | rawGetLine (const char *&buffer, size_t &size) |
reads new line More... | |
File & | getLine (string &line) |
reads new line More... | |
File & | getRecord (string &record) |
reads new record More... | |
File & | getBlock (char *buffer, size_t &size) |
reads new block More... | |
void | getFile (string &block) |
reads all available data from current position More... | |
void | put (const string &data) |
writes data More... | |
void | put (const char *data, size_t size) |
writes data More... | |
bool | eof () const |
checks for the end of file condition | |
void | seek (size_t newPosition) |
seeks to a new position More... | |
size_t | tell () const |
gets current file position | |
void | lock (int flags) |
perform flock(2) on file More... | |
high-level interface to file routines
cupt::File::File | ( | const string & | path, |
const char * | mode, | ||
string & | error | ||
) |
constructor
Constructs new object for a regular file or reading shell pipe.
path | path to file or shell command, see mode | |
mode | any value, accepted as mode in fopen(3) ; or "pr" / "pw" - special values to treat path as shell pipe with an opened handle for reading / writing, respectively | |
[out] | error | if open fails, human readable error will be placed here |
File& cupt::File::getBlock | ( | char * | buffer, |
size_t & | size | ||
) |
reads new block
Reads up to size characters from current position to buffer.
buffer | buffer to read in | |
[in,out] | size | before: up limit on character count, after: number of bytes read |
void cupt::File::getFile | ( | string & | block | ) |
reads all available data from current position
It's usually used just after opening the file and for small files.
block | container for read data |
File& cupt::File::getLine | ( | string & | line | ) |
reads new line
Reads new line. Newline character from the end is strip if present.
End of file must be checked by querying eof right after getLine. You can use line only if eof returned false.
[out] | line | container for read data |
File& cupt::File::getRecord | ( | string & | record | ) |
reads new record
Reads new record, that is, a sequence of characters which ends with double newline character ("\n\n"
).
If the end of file was encountered when reading, newline character(s) will be not added.
End of file must be checked by querying eof right after getRecord. You can use record only if eof returned false.
[out] | record | container for read data |
void cupt::File::lock | ( | int | flags | ) |
perform flock(2)
on file
flags | flags passed to flock |
void cupt::File::put | ( | const string & | data | ) |
writes data
data | data to write |
void cupt::File::put | ( | const char * | data, |
size_t | size | ||
) |
writes data
data | pointer to the data buffer |
size | size of the buffer |
File& cupt::File::rawGetLine | ( | const char *& | buffer, |
size_t & | size | ||
) |
reads new line
Reads new line (that is, a sequence of characters which ends with newline character ("\n"
)).
If the end of file was encountered when reading, newline character will be not added.
[in,out] | buffer | will contain a pointer to read data |
[out] | size | the size (in bytes) of the buffer, a value 0 means end of file |
void cupt::File::seek | ( | size_t | newPosition | ) |