Image Component Library (ICL)
|
Utility class for file handling (reading files is buffered) More...
#include <File.h>
Public Types | |
enum | OpenMode { readBinary = 0, readText = 1, writeBinary = 2, writeText = 3, notOpen = 4 } |
mode to open files More... | |
Public Types inherited from icl::utils::ShallowCopyable< FileImpl, FileImplDelOp > | |
typedef ShallowCopyable< FileImpl, FileImplDelOp > | ParentSC |
Public Member Functions | |
File () | |
Create a null file. More... | |
File (const std::string &name) | |
Create a file with given filename. More... | |
File (const std::string &name, OpenMode om) | |
Create a file with given filename which is opened imediately with given openmode. More... | |
~File () | |
Destructor (enshures that the file is closed) More... | |
bool | exists () const |
returns whether the file is open, or can be opened for reading More... | |
bool | isDirectory () const |
returns whether the file is a directory More... | |
bool | isOpen () const |
returns whether the file is already opened More... | |
bool | isBinary () const |
returns if the file was opened for binary data transfer More... | |
std::string | getDir () const |
returns the path postfix of the files url ( "../data.txt" -> "../") More... | |
std::string | getBaseName () const |
returns the files basename ( "../data.txt" -> "data") More... | |
std::string | getSuffix () const |
returns the files suffix ( "../data.txt" -> ".txt") More... | |
std::string | getName () const |
returns whole file url ( "../data.txt" -> "../data.txt") More... | |
void | write (const void *data, int len) |
writes len bytes from data into the file More... | |
void | writeLine (const void *data, int len) |
writes len bytes from data into the file and an additional Line-Break More... | |
void | write (const std::string &text) |
writes a string into the file More... | |
void | setPrecision (const std::string &p="%8f") |
sets floating point precision More... | |
File & | operator<< (char c) |
writes a character into the file More... | |
File & | operator<< (unsigned char uc) |
writes an unsigned character into the file More... | |
File & | operator<< (int i) |
writes an integer into the file More... | |
File & | operator<< (unsigned int ui) |
writes a unsigned integer into the file More... | |
File & | operator<< (float f) |
writes a float into the file More... | |
File & | operator<< (double d) |
writes a double into the file More... | |
File & | operator<< (const std::string &s) |
writes a string into the file More... | |
std::string | readLine () const |
reads the next line of the file (buffered) More... | |
std::string & | readLine (std::string &dst) const |
reads the next line of the file into a given string More... | |
const std::vector< icl8u > & | readAll () const |
reads the whole data of the file into an internal buffer and returns it More... | |
const icl8u * | getCurrentDataPointer () const |
returns the pointer to the internal file buffer at current position More... | |
const icl8u * | getFileDataPointer () const |
returns the pointer to the internal file buffers begin More... | |
std::vector< icl8u > | read (int len) const |
reads len bytes from the file (buffered) More... | |
int | read (int len, void *dst) const |
reads max. len bytes into the destination pointer More... | |
bool | hasMoreLines () const |
returns whether more lines can be read from this file More... | |
int | bytesAvailable () const |
returns the number of to-be-read bytes in the file More... | |
int | getFileSize () const |
returns the number of bytes in this file only in read-mode More... | |
void | open (OpenMode om) |
opens the file with given openmode ("rw" is not yet supported!) More... | |
void | reopen (OpenMode om) |
re-opens the file with given openmode ("rw" is not yet supported!) More... | |
void | close () |
closes the file More... | |
void | erase () |
erases the file More... | |
void | reset () |
jumps to the beginning of the file (only in read mode) More... | |
void * | getHandle () const |
returns the file handle More... | |
bool | canRead () const |
returns whether this file was opened with read access More... | |
bool | canWrite () const |
returns whether this file was opened with write access More... | |
OpenMode | getOpenMode () const |
returns the current OpenMode of this file of notOpen More... | |
Public Member Functions inherited from icl::utils::ShallowCopyable< FileImpl, FileImplDelOp > | |
bool | isNull () const |
returns wheter the objects implementation holds a null pointer More... | |
Static Public Member Functions | |
static std::string | read_file (const std::string &filename, bool textMode=true) |
static utility method that reads a whole file as single string More... | |
static std::vector< std::string > | read_lines (const std::string &filename) |
static utility method that reads a whole file as lines (text-mode only) More... | |
static void | write_file (const std::string &filename, const std::string &text, bool textMode=true) |
static utility method that writes a single string to a file More... | |
static void | write_lines (const std::string &filename, const std::vector< std::string > &lines) |
static utility method that writes lines to a file (adding after each line) More... | |
Additional Inherited Members | |
Protected Member Functions inherited from icl::utils::ShallowCopyable< FileImpl, FileImplDelOp > | |
ShallowCopyable (FileImpl *t=0) | |
create a the implementation with a given T* value More... | |
Protected Attributes inherited from icl::utils::ShallowCopyable< FileImpl, FileImplDelOp > | |
SmartPtrBase< FileImpl, FileImplDelOp > | impl |
shared pointer for the classes implementation More... | |
Utility class for file handling (reading files is buffered)
The File class implements an implicit gzip writing and reading. This feature is enabled if ICL_HAVE_LIB_Z is defined during the compilation process.
If the File's given filename has a ".gz" postfix, read and write calls are applied using gzread and gzwrite from the libz.
In addition the implementation of the File class was split into two parts: The File itself and its certain implementation, which is defined invisibly for the user. This implementation is shared by shallow copied instances using the ICL SmartPtr class. This mechanism provides save shallow copies using reference counting.
icl::utils::File::File | ( | ) |
Create a null file.
icl::utils::File::File | ( | const std::string & | name | ) |
Create a file with given filename.
icl::utils::File::File | ( | const std::string & | name, |
OpenMode | om | ||
) |
Create a file with given filename which is opened imediately with given openmode.
icl::utils::File::~File | ( | ) |
Destructor (enshures that the file is closed)
int icl::utils::File::bytesAvailable | ( | ) | const |
returns the number of to-be-read bytes in the file
bool icl::utils::File::canRead | ( | ) | const |
returns whether this file was opened with read access
bool icl::utils::File::canWrite | ( | ) | const |
returns whether this file was opened with write access
void icl::utils::File::close | ( | ) |
closes the file
void icl::utils::File::erase | ( | ) |
erases the file
bool icl::utils::File::exists | ( | ) | const |
returns whether the file is open, or can be opened for reading
std::string icl::utils::File::getBaseName | ( | ) | const |
returns the files basename ( "../data.txt" -> "data")
const icl8u* icl::utils::File::getCurrentDataPointer | ( | ) | const |
returns the pointer to the internal file buffer at current position
std::string icl::utils::File::getDir | ( | ) | const |
returns the path postfix of the files url ( "../data.txt" -> "../")
const icl8u* icl::utils::File::getFileDataPointer | ( | ) | const |
returns the pointer to the internal file buffers begin
int icl::utils::File::getFileSize | ( | ) | const |
returns the number of bytes in this file only in read-mode
void* icl::utils::File::getHandle | ( | ) | const |
returns the file handle
std::string icl::utils::File::getName | ( | ) | const |
returns whole file url ( "../data.txt" -> "../data.txt")
OpenMode icl::utils::File::getOpenMode | ( | ) | const |
returns the current OpenMode of this file of notOpen
std::string icl::utils::File::getSuffix | ( | ) | const |
returns the files suffix ( "../data.txt" -> ".txt")
bool icl::utils::File::hasMoreLines | ( | ) | const |
returns whether more lines can be read from this file
bool icl::utils::File::isBinary | ( | ) | const |
returns if the file was opened for binary data transfer
bool icl::utils::File::isDirectory | ( | ) | const |
returns whether the file is a directory
bool icl::utils::File::isOpen | ( | ) | const |
returns whether the file is already opened
void icl::utils::File::open | ( | OpenMode | om | ) |
opens the file with given openmode ("rw" is not yet supported!)
Throws a FileOpenException if file can not be opened
File& icl::utils::File::operator<< | ( | char | c | ) |
writes a character into the file
File& icl::utils::File::operator<< | ( | unsigned char | uc | ) |
writes an unsigned character into the file
File& icl::utils::File::operator<< | ( | int | i | ) |
writes an integer into the file
File& icl::utils::File::operator<< | ( | unsigned int | ui | ) |
writes a unsigned integer into the file
File& icl::utils::File::operator<< | ( | float | f | ) |
writes a float into the file
File& icl::utils::File::operator<< | ( | double | d | ) |
writes a double into the file
File& icl::utils::File::operator<< | ( | const std::string & | s | ) |
writes a string into the file
std::vector<icl8u> icl::utils::File::read | ( | int | len | ) | const |
reads len bytes from the file (buffered)
if less than len bytes are available in the file, a zero length vector is returned
int icl::utils::File::read | ( | int | len, |
void * | dst | ||
) | const |
reads max. len bytes into the destination pointer
|
static |
static utility method that reads a whole file as single string
|
static |
static utility method that reads a whole file as lines (text-mode only)
const std::vector<icl8u>& icl::utils::File::readAll | ( | ) | const |
reads the whole data of the file into an internal buffer and returns it
std::string icl::utils::File::readLine | ( | ) | const |
reads the next line of the file (buffered)
only available in non-binary mode
std::string& icl::utils::File::readLine | ( | std::string & | dst | ) | const |
reads the next line of the file into a given string
breaks on newlines or on eof
void icl::utils::File::reopen | ( | OpenMode | om | ) |
re-opens the file with given openmode ("rw" is not yet supported!)
Throws a FileOpenException if file can not be opened
void icl::utils::File::reset | ( | ) |
jumps to the beginning of the file (only in read mode)
void icl::utils::File::setPrecision | ( | const std::string & | p = "%8f" | ) |
sets floating point precision
void icl::utils::File::write | ( | const void * | data, |
int | len | ||
) |
writes len bytes from data into the file
void icl::utils::File::write | ( | const std::string & | text | ) |
writes a string into the file
|
static |
static utility method that writes a single string to a file
|
static |
static utility method that writes lines to a file (adding
after each line)
void icl::utils::File::writeLine | ( | const void * | data, |
int | len | ||
) |
writes len bytes from data into the file and an additional Line-Break
only in non-binary mode!