38 ifstream file(file_name, ios::in);
39 if (!file.is_open()) {
50 return (::stat(path.c_str(), &statbuf) == 0);
56 if (::stat(path.c_str(), &statbuf) < 0) {
59 return ((statbuf.st_mode & S_IFMT) == S_IFDIR);
65 if (::stat(path.c_str(), &statbuf) < 0) {
68 return ((statbuf.st_mode & S_IFMT) == S_IFREG);
72 umask(orig_umask_ | mask);
80 if (!full_name.empty()) {
81 bool dir_present =
false;
83 size_t last_slash = full_name.find_last_of(
'/');
84 if (last_slash != string::npos) {
87 parent_path_ = full_name.substr(0, last_slash + 1);
88 if (last_slash == full_name.size()) {
99 size_t last_dot = full_name.find_last_of(
'.');
100 if ((last_dot == string::npos) || (dir_present && (last_dot < last_slash))) {
105 stem_ = full_name.substr(last_slash + 1);
111 extension_ = full_name.substr(last_dot);
114 if ((last_dot - last_slash) > 1) {
115 stem_ = full_name.substr(last_slash + 1, last_dot - last_slash - 1);
122 return (parent_path_ + stem_ + extension_);
127 return (parent_path_);
142 return (stem_ + extension_);
147 string const trimmed_replacement(
trim(replacement));
148 if (trimmed_replacement.empty()) {
149 extension_ = string();
151 size_t const last_dot(trimmed_replacement.find_last_of(
'.'));
152 if (last_dot == string::npos) {
153 extension_ =
"." + trimmed_replacement;
155 extension_ = trimmed_replacement.substr(last_dot);
163 string const trimmed_replacement(
trim(replacement));
164 if (trimmed_replacement.empty()) {
165 parent_path_ = string();
166 }
else if (trimmed_replacement.at(trimmed_replacement.size() - 1) ==
'/') {
167 parent_path_ = trimmed_replacement;
169 parent_path_ = trimmed_replacement +
'/';
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
string getContent(string const &file_name)
Get the content of a regular file.
bool isFile(string const &path)
Check if there is a file at the given path.
bool exists(string const &path)
Check if there is a file or directory at the given path.
bool isDir(string const &path)
Check if there is a directory at the given path.
string trim(const string &input)
Trim leading and trailing spaces.
Defines the logger used by the top-level component of kea-lfc.
Path(std::string const &path)
Constructor.
Path & replaceParentPath(std::string const &replacement=std::string())
Trims {replacement} and replaces this instance's parent path with it.
std::string extension() const
Get the extension of the file.
Path & replaceExtension(std::string const &replacement=std::string())
Identifies the extension in {replacement}, trims it, and replaces this instance's extension with it.
std::string stem() const
Get the base name of the file without the extension.
std::string parentPath() const
Get the parent path.
std::string filename() const
Get the name of the file, extension included.
std::string str() const
Get the path in textual format.
Umask(mode_t mask)
Constructor.