The wrapper for file operations.
More...
List of all members.
Public Member Functions |
void | close () |
| Closes previously opened file.
|
void | create (const std::string &fileName) |
| Creates new file in file system.
|
| File () |
| The default constructor.
|
int | getFd () const |
| Returns the handle of an opened file.
|
void | open (const std::string fileName) |
| Opens existing file in read/write mode.
|
bool | opened () const |
| FIXME.
|
void | openReadOnly (const std::string &fileName) |
| Opens existing file in read-only mode.
|
size_t | read (void *buf, size_t bufSize) |
| Reads data from an opened file.
|
void | readTextFile (StringVector &lines) |
| FIXME.
|
void | readTextFile (std::string &text) |
| FIXME.
|
size_t | write (const void *buf, size_t bufSize) |
| Writes data to an opened file.
|
virtual | ~File () |
| The destructor.
|
Static Public Member Functions |
static std::string | baseName (const std::string &fileName) |
| Returns the file name without parent directories.
|
static std::string | baseNameFromUrl (const std::string &fileName) |
static bool | isDir (const std::string &fileName) |
| Checks if file is a directory.
|
static bool | isRegFile (const std::string &fileName) |
| Checks if file is a regular file.
|
static bool | isSymLink (const std::string &fileName) |
| Checks if file is a symlink.
|
static void | move (const std::string &oldFileName, const std::string &newFileName) |
| FIXME.
|
static void | readAhead (const std::string &fileName) |
| FIXME.
|
static void | unlink (const std::string &fileName) |
| Removes the file or remove the hard link if there are more than one.
|
Protected Attributes |
int | m_fd |
Detailed Description
This class wraps mostly often used operations with files. It is generally purposed to take care over the error code returned by system calls and throw SystemException in case of problems.
- See also:
- Directory SystemException
Member Function Documentation
std::string File::baseName |
( |
const std::string & |
fileName | ) |
[static] |
This method returns the provided string from the last slash character until the its end or the string itself if there are no slashes.
- Parameters:
-
[in] | The | file name to take base part from |
- Returns:
- The file name without parent directories
void Deepsolver::File::close |
( |
| ) |
|
This method closes previously opened file. If file is already closed or never be opened it is not an error, in this case nothing is done. This method is always called automatically on object destruction.
void File::create |
( |
const std::string & |
fileName | ) |
|
This method creates new file with specified name. The directory the new file should be placed in must exist. The new file is created with flags O_RDWR | O_CREAT | O_TRUNC and 0666 mode. If something is wrong and new file cannot be created the SystemException is thrown with corresponding information.
- Parameters:
-
[in] | fileName | The name of a file to create |
int Deepsolver::File::getFd |
( |
| ) |
const [inline] |
This method returns the handle of opened file provided by operating system. It should never be called for closed file or for files never be opened.
- Returns:
- The handle of opened file
bool File::isDir |
( |
const std::string & |
fileName | ) |
[static] |
bool File::isRegFile |
( |
const std::string & |
fileName | ) |
[static] |
bool File::isSymLink |
( |
const std::string & |
fileName | ) |
[static] |
void Deepsolver::File::open |
( |
const std::string |
fileName | ) |
|
This method opens an existing file and associates the current object with handle of opened file. In case the ::open() system call had returned an error value the SystemException is thrown with corresponding information.
- Parameters:
-
[in] | fileName | The name of file to open |
void File::openReadOnly |
( |
const std::string & |
fileName | ) |
|
This method opens an existing file in read-only mode and associates the current object with handle of opened file. In case the ::open() system call had returned an error value the SystemException is thrown with corresponding information.
- Parameters:
-
[in] | fileName | The name of file to open |
size_t Deepsolver::File::read |
( |
void * |
buf, |
|
|
size_t |
bufSize |
|
) |
| |
Length of the buffer is not limited. In case of large buffer this method produces several subsequent calls of corresponding system function. In addition this method takes care to be sure the operation is performed completely until entire requested data is read or error occurred.
- Parameters:
-
[out] | buf | The buffer to save read data to |
[in] | bufSize | The size of provided buffer |
- Returns:
- The number of read bytes, can be less then bufSize only in case of reading near the end of file
void File::unlink |
( |
const std::string & |
fileName | ) |
[static] |
This method removes the hard link to the file. Usually the file has only one hard link and it means the file will be removed at all.
- Parameters:
-
[in] | fileName | The name of the file to remove hard link to |
size_t Deepsolver::File::write |
( |
const void * |
buf, |
|
|
size_t |
bufSize |
|
) |
| |
Length of the buffer is not limited. In case of large buffer this method produces several subsequent calls of corresponding system function. In addition this method takes care to be sure the operation is performed completely until entire buffer content is written or error occurred.
- Parameters:
-
[in] | buf | The buffer with the data to write |
[in] | bufSize | The size of provided data |
- Returns:
- The number of successfully written bytes