Kea 2.5.9
filesystem.h
Go to the documentation of this file.
1// Copyright (C) 2021-2024 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#ifndef KEA_UTIL_FILESYSTEM_H
8#define KEA_UTIL_FILESYSTEM_H
9
10#include <string>
11
12namespace isc {
13namespace util {
14namespace file {
15
22std::string
23getContent(const std::string& file_name);
24
30bool
31exists(const std::string& path);
32
39bool
40isDir(const std::string& path);
41
48bool
49isFile(const std::string& path);
50
52struct Path {
56 Path(std::string const& path);
57
63 std::string str() const;
64
70 std::string parentPath() const;
71
77 std::string stem() const;
78
84 std::string extension() const;
85
91 std::string filename() const;
92
104 Path& replaceExtension(std::string const& replacement = std::string());
105
115 Path& replaceParentPath(std::string const& replacement = std::string());
116
117private:
119 std::string parent_path_;
120
122 std::string stem_;
123
125 std::string extension_;
126};
127
128} // namespace file
129} // namespace util
130} // namespace isc
131
132#endif // KEA_UTIL_FILESYSTEM_H
string getContent(string const &file_name)
Get the content of a regular file.
Definition: filesystem.cc:32
bool isFile(string const &path)
Check if there is a file at the given path.
Definition: filesystem.cc:64
bool exists(string const &path)
Check if there is a file or directory at the given path.
Definition: filesystem.cc:49
bool isDir(string const &path)
Check if there is a directory at the given path.
Definition: filesystem.cc:55
Defines the logger used by the top-level component of kea-lfc.
Paths on a filesystem.
Definition: filesystem.h:52
Path & replaceParentPath(std::string const &replacement=std::string())
Trims {replacement} and replaces this instance's parent path with it.
Definition: filesystem.cc:155
std::string extension() const
Get the extension of the file.
Definition: filesystem.cc:129
Path & replaceExtension(std::string const &replacement=std::string())
Identifies the extension in {replacement}, trims it, and replaces this instance's extension with it.
Definition: filesystem.cc:139
std::string stem() const
Get the base name of the file without the extension.
Definition: filesystem.cc:124
std::string parentPath() const
Get the parent path.
Definition: filesystem.cc:119
std::string filename() const
Get the name of the file, extension included.
Definition: filesystem.cc:134
std::string str() const
Get the path in textual format.
Definition: filesystem.cc:114