zipios++
2.0.2
Zipios++ – a small C++ library that provides easy access to .zip files.
|
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... | |
FilePath & | operator= (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 |
Read the file mode. More... | |
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... | |
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.
Definition at line 46 of file filepath.hpp.
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.
[in] | path | A string representation of the path. |
Definition at line 103 of file filepath.cpp.
References m_stat.
|
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.
Definition at line 124 of file filepath.cpp.
References m_checked, m_exists, m_path, and m_stat.
Referenced by exists(), fileSize(), isBlockSpecial(), isCharSpecial(), isDirectory(), isFifo(), isRegular(), isSocket(), and lastModificationTime().
bool zipios::FilePath::exists | ( | ) | const |
This function calls check() and then returns true if the file exists on disk.
Definition at line 358 of file filepath.cpp.
std::string zipios::FilePath::filename | ( | ) | const |
This function returns the filename part of the FilePath object by pruning the path off.
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.
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.
Definition at line 414 of file filepath.cpp.
bool zipios::FilePath::isCharSpecial | ( | ) | const |
This function returns true if the file exists and is a character special file.
Definition at line 400 of file filepath.cpp.
bool zipios::FilePath::isDirectory | ( | ) | const |
This function returns true if the file exists and is a directory.
Definition at line 386 of file filepath.cpp.
References check(), m_exists, and m_stat.
Referenced by zipios::DirectoryCollection::DirectoryCollection(), zipios::DirectoryEntry::DirectoryEntry(), zipios::FileEntry::isDirectory(), and zipios::DirectoryCollection::loadEntries().
bool zipios::FilePath::isFifo | ( | ) | const |
This function returns true if the file exists and is a pipe file.
Definition at line 442 of file filepath.cpp.
bool zipios::FilePath::isRegular | ( | ) | const |
This function returns true if the file exists and is a regular file.
Definition at line 372 of file filepath.cpp.
References check(), m_exists, and m_stat.
Referenced by zipios::DirectoryCollection::DirectoryCollection(), and zipios::DirectoryEntry::DirectoryEntry().
bool zipios::FilePath::isSocket | ( | ) | const |
This function returns true if the file exists and is a socket file.
Definition at line 428 of file filepath.cpp.
std::time_t zipios::FilePath::lastModificationTime | ( | ) | const |
This function returns the last modification time of the specified file.
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.
Definition at line 325 of file filepath.cpp.
References m_path.
Referenced by zipios::ZipCentralDirectoryEntry::getHeaderSize(), zipios::ZipLocalEntry::getHeaderSize(), size(), zipios::ZipCentralDirectoryEntry::write(), and zipios::ZipLocalEntry::write().
zipios::FilePath::operator std::string | ( | ) | const |
This operator can be used to retrieve a copy of the path.
Definition at line 165 of file filepath.cpp.
This function concatenates two FilePath objects and returns another FilePath.
A file separator is inserted between both names if appropriate.
[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.
[in] | path | The new path to save in this object. |
Definition at line 152 of file filepath.cpp.
References m_path, and zipios::anonymous_namespace{filepath.cpp}::pruneTrailingSeparator().
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.
[in] | rhs | The right hand side to compare with. |
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.
[in] | rhs | The right hand side to compare with. |
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.
[in] | rhs | The right hand side to compare with. |
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.
Definition at line 345 of file filepath.cpp.
References length().
|
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.
[in] | lhs | The left hand side to compare with. |
[in] | rhs | The right hand side to compare with. |
Definition at line 235 of file filepath.cpp.
|
friend |
This function compares a FilePath object (this) against a string representing a path to know whether the two are the equal.
[in] | lhs | The left hand side to compare with. |
[in] | rhs | The right hand side to compare with. |
Definition at line 268 of file filepath.cpp.
|
mutableprivate |
Definition at line 78 of file filepath.hpp.
Referenced by check().
|
mutableprivate |
Definition at line 79 of file filepath.hpp.
Referenced by check(), exists(), isBlockSpecial(), isCharSpecial(), isDirectory(), isFifo(), isRegular(), and isSocket().
|
private |
Definition at line 76 of file filepath.hpp.
Referenced by check(), filename(), length(), operator+(), operator=(), operator==(), and zipios::operator==().
|
mutableprivate |
Definition at line 77 of file filepath.hpp.
Referenced by check(), FilePath(), fileSize(), isBlockSpecial(), isCharSpecial(), isDirectory(), isFifo(), isRegular(), isSocket(), and lastModificationTime().