zipios++  2.0.2 Zipios++ – a small C++ library that provides easy access to .zip files.
zipios::FilePath Class Reference

Handle a file path and name and its statistics. More...

#include <filepath.hpp>

Public Member Functions

FilePath (std::string const &path="")
Initialize a FilePath object. More...

bool exists () const
Check whether the file exists. More...

std::string filename () const
Retrieve the basename. More...

size_t fileSize () const
Get the size of the file. More...

bool isBlockSpecial () const
Check whether the file is a block special file. More...

bool isCharSpecial () const
Check whether the file is a character special file. More...

bool isDirectory () const
Check whether the file is a directory. More...

bool isFifo () const
Check whether the file is a pipe. More...

bool isRegular () const
Check whether the file is a regular file. More...

bool isSocket () const
Check whether the file is a socket. More...

std::time_t lastModificationTime () const
Get the last modification time of the file. More...

size_t length () const
Get the length of the string. More...

operator std::string () const
Retrieve the path. More...

FilePath operator+ (FilePath const &name) const
Append the a child name to this path. More...

FilePathoperator= (std::string const &path)
Replace the path with a new path. More...

bool operator== (char const *rhs) const
Check whether two FilePath represent the same file. More...

bool operator== (std::string const &rhs) const
Check whether two FilePath represent the same file. More...

bool operator== (FilePath const &rhs) const
Check whether two FilePath represent the same file. More...

size_t size () const
Get the length of the string. More...

Private Member Functions

void check () const

Private Attributes

bool m_checked = false

bool m_exists = false

std::string m_path

os_stat_t m_stat

Friends

bool operator== (char const *lhs, FilePath const &rhs)
Check whether two FilePath represent the same file. More...

bool operator== (std::string const &lhs, FilePath const &rhs)
Check whether two FilePath represent the same file. More...

Detailed Description

The FilePath class represents a path to a file or directory name. FilePath has member functions to check if the file path is a valid file system entity, and to check what kind of file system entity it is, e.g. is it a file, a directory, a pipe, etc.

It also knows of the last modification time and size of the file.

Warning
The information about a file is cached so at the time it gets used the file on disk may have changed, it may even have been deleted.

Definition at line 46 of file filepath.hpp.

Constructor & Destructor Documentation

 zipios::FilePath::FilePath ( std::string const & path = "" )

The constructor saves the path and if check_exists is true, read the file statistics, especially the st_mode.

Parameters
 [in] path A string representation of the path.
exists()
pruneTrailingSeparator()

Definition at line 103 of file filepath.cpp.

References m_stat.

Member Function Documentation

 void zipios::FilePath::check ( ) const
private

This function sets m_checked to true, stat()'s the path, to see if it exists and to determine what type of file it is. All the query functions call check() before they test a flag to make sure it is set appropriately.

This means stat()'ing is deferred until it becomes necessary. But also it is cached meaning that if the file changes in between we get the old flags.

Todo:
Under MS-Windows, we need to use _wstat() to make it work in Unicode (i.e. UTF-8 to wchar_t then call _wstat()...) Also we want to use the 64 bit variant to make sure that we get a valid size. Any other reference to the stat() command should be replace by using a FilePath().

Definition at line 124 of file filepath.cpp.

References m_checked, m_exists, m_path, and m_stat.

 bool zipios::FilePath::exists ( ) const

This function calls check() and then returns true if the file exists on disk.

Returns
true If the path is a valid file system entity.

Definition at line 358 of file filepath.cpp.

References check(), and m_exists.

 std::string zipios::FilePath::filename ( ) const

This function returns the filename part of the FilePath object by pruning the path off.

Returns
Return the basename of this FilePath filename.

Definition at line 304 of file filepath.cpp.

References zipios::g_separator, and m_path.

Referenced by zipios::FileEntry::getFileName().

 size_t zipios::FilePath::fileSize ( ) const

This function returns the size of the file. The size may be a 64 bit size on 64 bit systems.

Note
If the file represents a directory, the size will be zero.
If the file is not considered valid, the size returned is zero.
Warning
There is also a function called size() which actually checks the length of the path and not the size of the file.
Returns
The last modification as a Unix time.
size()

Definition at line 468 of file filepath.cpp.

References check(), and m_stat.

Referenced by zipios::DirectoryEntry::DirectoryEntry().

 bool zipios::FilePath::isBlockSpecial ( ) const

This function returns true if the file exists and is a block special file.

Returns
true if the path is block special (a block device file).

Definition at line 414 of file filepath.cpp.

References check(), m_exists, and m_stat.

 bool zipios::FilePath::isCharSpecial ( ) const

This function returns true if the file exists and is a character special file.

Returns
true if the path is character special (a character device file).

Definition at line 400 of file filepath.cpp.

References check(), m_exists, and m_stat.

 bool zipios::FilePath::isDirectory ( ) const

This function returns true if the file exists and is a directory.

Returns
true if the path is a directory.

Definition at line 386 of file filepath.cpp.

References check(), m_exists, and m_stat.

 bool zipios::FilePath::isFifo ( ) const

This function returns true if the file exists and is a pipe file.

Returns
true if the path is a FIFO.

Definition at line 442 of file filepath.cpp.

References check(), m_exists, and m_stat.

 bool zipios::FilePath::isRegular ( ) const

This function returns true if the file exists and is a regular file.

Returns
true if the path is a regular file.

Definition at line 372 of file filepath.cpp.

References check(), m_exists, and m_stat.

 bool zipios::FilePath::isSocket ( ) const

This function returns true if the file exists and is a socket file.

Returns
true if the path is a socket.

Definition at line 428 of file filepath.cpp.

References check(), m_exists, and m_stat.

 std::time_t zipios::FilePath::lastModificationTime ( ) const

This function returns the last modification time of the specified file.

Note
If the file is not considered valid, the time returned is zero.
Returns
The last modification as a Unix time.

Definition at line 485 of file filepath.cpp.

References check(), and m_stat.

Referenced by zipios::DirectoryEntry::DirectoryEntry().

 size_t zipios::FilePath::length ( ) const

This function returns the length of the string used to represent this FilePath path and filename.

Returns
The length of the string representing this file path.
size()

Definition at line 325 of file filepath.cpp.

References m_path.

 zipios::FilePath::operator std::string ( ) const

This operator can be used to retrieve a copy of the path.

Returns
The m_path string returned as is (i.e. the whole path).

Definition at line 165 of file filepath.cpp.

 FilePath zipios::FilePath::operator+ ( FilePath const & rhs ) const

This function concatenates two FilePath objects and returns another FilePath.

A file separator is inserted between both names if appropriate.

Warning
Note that the function allows you to append two full paths, or even a relative path (left) to a full path (right), which may result in a new path that is not quite sensible.
Parameters
 [in] rhs The right hand side.

Definition at line 185 of file filepath.cpp.

References zipios::g_separator, and m_path.

 FilePath & zipios::FilePath::operator= ( std::string const & path )

This function replaces the internal path of this FilePath with the new specified path.

Parameters
 [in] path The new path to save in this object.
Returns
A reference to this object.

Definition at line 152 of file filepath.cpp.

 bool zipios::FilePath::operator== ( char const * rhs ) const

This function compares a FilePath object (this) and a C-string to know whether the two are the same.

A null pointer as the C-string is viewed as an empty string.

Parameters
 [in] rhs The right hand side to compare with.
operator == (FilePath const& rhs);

Definition at line 217 of file filepath.cpp.

References m_path.

 bool zipios::FilePath::operator== ( std::string const & rhs ) const

This function compares a FilePath object (this) against a string representing a path to know whether the two are the equal.

Parameters
 [in] rhs The right hand side to compare with.
operator == (FilePath const& rhs);

Definition at line 251 of file filepath.cpp.

References m_path.

 bool zipios::FilePath::operator== ( FilePath const & rhs ) const

This function compares two FilePath objects (this and rhs) to know whether the two are the same.

Note
It is important to know that the compare is rather primitive. The two paths must be equal character by character instead of actually representing exactly the same file. Also relative paths will likely be equal and these may not represent the same file at all.
Parameters
 [in] rhs The right hand side to compare with.
operator == (char const *rhs);
operator == (std::string const& rhs);

Definition at line 291 of file filepath.cpp.

References m_path.

 size_t zipios::FilePath::size ( ) const

This function returns the length of the string used to represent this FilePath path and filename.

Note
This is an overloaded function that calls the length() function. It is defined because the string represents an array of bytes and as such the size() function may be used.
Returns
The length of the string representing this file path.
length()

Definition at line 345 of file filepath.cpp.

References length().

Friends And Related Function Documentation

 bool operator== ( char const * lhs, FilePath const & rhs )
friend

This function compares a FilePath object (this) and a C-string to know whether the two are the same.

A null pointer as the C-string is viewed as an empty string.

Parameters
 [in] lhs The left hand side to compare with. [in] rhs The right hand side to compare with.
operator == (FilePath const& rhs);

Definition at line 235 of file filepath.cpp.

 bool operator== ( std::string const & lhs, FilePath const & rhs )
friend

This function compares a FilePath object (this) against a string representing a path to know whether the two are the equal.

Parameters
 [in] lhs The left hand side to compare with. [in] rhs The right hand side to compare with.
operator == (FilePath const& rhs);

Definition at line 268 of file filepath.cpp.

Member Data Documentation

 bool zipios::FilePath::m_checked = false
mutableprivate

Definition at line 78 of file filepath.hpp.

Referenced by check().

 bool zipios::FilePath::m_exists = false
mutableprivate
 std::string zipios::FilePath::m_path
private

Definition at line 76 of file filepath.hpp.

Referenced by check(), filename(), length(), operator+(), operator=(), operator==(), and zipios::operator==().

 os_stat_t zipios::FilePath::m_stat
mutableprivate

Definition at line 77 of file filepath.hpp.

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