Deepsolver
Public Member Functions | Static Public Member Functions | Protected Attributes
Deepsolver::File Class Reference

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 a 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
 Returns the opening state of this object.
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)
 Reads the file as a text file and saves lines in a string vector.
void readTextFile (std::string &text)
 Reads the file as a text file and saves lines as one long string value.
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 &url)
 Extracts the file name of a URL.
static bool isDir (const std::string &fileName)
 Checks if the file is a directory.
static bool isRegFile (const std::string &fileName)
 Checks if the file is a regular file.
static bool isSymLink (const std::string &fileName)
 Checks if the file is a symlink.
static void move (const std::string &oldFileName, const std::string &newFileName)
 Moves (renames) file inside of the same file system.
static void readAhead (const std::string &fileName)
 Loads file content into file system cache.
static void unlink (const std::string &fileName)
 Removes the file or remove the hard link.

Protected Attributes

int m_fd

Detailed Description

This class simplifies the mostly popular operations with files. It is generally purposed to take care over the error code returned by system calls and throw SystemException if there are any problems.

See also:
Directory SystemException

Member Function Documentation

std::string File::baseName ( const std::string &  fileName) [static]
Parameters:
[in]Thefile name to take base part from
Returns:
The file name without parent directories
std::string File::baseNameFromUrl ( const std::string &  url) [static]
Parameters:
[inurl The URL value to extract file name from
Returns:
The extracted file name
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 at all. This method is always called automatically on object destruction.

void File::create ( const std::string &  fileName)
Parameters:
[in]fileNameThe name of the file to create
int Deepsolver::File::getFd ( ) const [inline]
Returns:
The handle of the opened file
bool File::isDir ( const std::string &  fileName) [static]
Parameters:
[in]fileNameThe name of the file to check
Returns:
Non-zero if the file is a directory or zero otherwise
bool File::isRegFile ( const std::string &  fileName) [static]
Parameters:
[in]fileNameThe name of the file to check
Returns:
Non-zero if the file is a regular file (not a directory, not a symlink etc) or zero otherwise
bool File::isSymLink ( const std::string &  fileName) [static]
Parameters:
[in]fileNameThe name of the file to check
Returns:
Non-zero if the file is a symlink or zero otherwise
void File::move ( const std::string &  oldFileName,
const std::string &  newFileName 
) [static]
Parameters:
[inoldFileName The path to move file from
[in]newFileName The path to move file to
void Deepsolver::File::open ( const std::string  fileName)
Parameters:
[in]fileNameThe name of the file to open
bool Deepsolver::File::opened ( ) const [inline]
Returns:
Non-zero if current object is associated with opened file or zero otherwise
void File::openReadOnly ( const std::string &  fileName)
Parameters:
[in]fileNameThe name of the file to open
size_t Deepsolver::File::read ( void *  buf,
size_t  bufSize 
)

The length of the buffer is not limited. In case of providing the large buffer this method makes several reading attempts of smaller size. 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]bufThe buffer to save read data to
[in]bufSizeThe size of the provided buffer
Returns:
The number of read bytes, can be less then bufSize only if reading near the end of file
void File::readAhead ( const std::string &  fileName) [static]
Parameters:
[in]fileNameThe path of the file to load data from
void File::readTextFile ( StringVector &  lines)
Parameters:
[out]linesThe reference to a string vector to save lines to
void File::readTextFile ( std::string &  text)
Parameters:
[out]textThe reference to a string object to save read data to
void File::unlink ( const std::string &  fileName) [static]
Parameters:
[in]fileNameThe name of the file to remove hard link to
size_t Deepsolver::File::write ( const void *  buf,
size_t  bufSize 
)

The length of the buffer is not limited. In case of providing the large buffer this method makes several writing attempts of smaller size. In addition this method takes care to be sure the operation is performed completely until entire requested data is written or error occurred.

Parameters:
[in]bufThe buffer to write data from
[in]bufSizeThe size of the provided buffer
Returns:
The number of the successfully written bytes