From 3a8cd292f3842abed67cd9889c9852cf979f1922 Mon Sep 17 00:00:00 2001 From: Tatsuya Yatagawa Date: Mon, 20 Jul 2020 12:42:00 +0900 Subject: [PATCH] Add several methods that are not in this repo but in STL. --- filesystem/path.h | 12 ++++++++++++ path_demo.cpp | 3 +++ 2 files changed, 15 insertions(+) diff --git a/filesystem/path.h b/filesystem/path.h index ed00f3f..1052808 100644 --- a/filesystem/path.h +++ b/filesystem/path.h @@ -225,6 +225,10 @@ class path { return oss.str(); } + std::string string() const { + return str(); + } + void set(const std::string &str, path_type type = native_path) { m_type = type; if (type == windows_path) { @@ -431,4 +435,12 @@ inline bool create_directories(const path& p) { #endif } +inline bool exists(const path& p) { + return p.exists(); +} + +inline bool is_directory(const path& p) { + return p.is_directory(); +} + NAMESPACE_END(filesystem) diff --git a/path_demo.cpp b/path_demo.cpp index 266c661..e03b400 100644 --- a/path_demo.cpp +++ b/path_demo.cpp @@ -25,17 +25,20 @@ int main(int argc, char **argv) { cout << "some/path.ext:operator==() (unequal) = " << (path("some/path.ext") == path("another/path.ext")) << endl; cout << "nonexistant:exists = " << path("nonexistant").exists() << endl; + cout << "nonexistant:exists = " << exists(path("nonexistant")) << endl; cout << "nonexistant:is_file = " << path("nonexistant").is_file() << endl; cout << "nonexistant:is_directory = " << path("nonexistant").is_directory() << endl; cout << "nonexistant:filename = " << path("nonexistant").filename() << endl; cout << "nonexistant:extension = " << path("nonexistant").extension() << endl; cout << "filesystem/path.h:exists = " << path("filesystem/path.h").exists() << endl; + cout << "filesystem/path.h:exists = " << exists(path("filesystem/path.h")) << endl; cout << "filesystem/path.h:is_file = " << path("filesystem/path.h").is_file() << endl; cout << "filesystem/path.h:is_directory = " << path("filesystem/path.h").is_directory() << endl; cout << "filesystem/path.h:filename = " << path("filesystem/path.h").filename() << endl; cout << "filesystem/path.h:extension = " << path("filesystem/path.h").extension() << endl; cout << "filesystem/path.h:make_absolute = " << path("filesystem/path.h").make_absolute() << endl; cout << "../filesystem:exists = " << path("../filesystem").exists() << endl; + cout << "../filesystem:exists = " << exists(path("../filesystem")) << endl; cout << "../filesystem:is_file = " << path("../filesystem").is_file() << endl; cout << "../filesystem:is_directory = " << path("../filesystem").is_directory() << endl; cout << "../filesystem:extension = " << path("../filesystem").extension() << endl;