diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2021-05-16 01:14:29 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2021-05-16 01:14:29 +0300 |
commit | 1f7066186a040243fc3b4132f7b19af5d894bc5a (patch) | |
tree | 42470f6aebe62cec049c3d2c8a2248f27b4ffed2 | |
parent | File: add get_size/query_id (diff) | |
download | winapi-common-1f7066186a040243fc3b4132f7b19af5d894bc5a.tar.gz winapi-common-1f7066186a040243fc3b4132f7b19af5d894bc5a.zip |
File: make public child of Handle
-rw-r--r-- | include/winapi/file.hpp | 19 | ||||
-rw-r--r-- | src/file.cpp | 44 |
2 files changed, 29 insertions, 34 deletions
diff --git a/include/winapi/file.hpp b/include/winapi/file.hpp index 78187d9..e9f8510 100644 --- a/include/winapi/file.hpp +++ b/include/winapi/file.hpp @@ -21,7 +21,7 @@ namespace winapi { bool operator==(const FILE_ID_128& a, const FILE_ID_128& b); -class File : private Handle { +class File : public Handle { public: struct ID { const FILE_ID_INFO impl; @@ -32,23 +32,18 @@ public: } }; - static Handle open_r(const std::string&); - static Handle open_r(const CanonicalPath&); - static Handle open_read_attributes(const std::string&); - static Handle open_read_attributes(const CanonicalPath&); - static Handle open_w(const std::string&); - static Handle open_w(const CanonicalPath&); + static File open_r(const std::string&); + static File open_r(const CanonicalPath&); + static File open_read_attributes(const std::string&); + static File open_read_attributes(const CanonicalPath&); + static File open_w(const std::string&); + static File open_w(const CanonicalPath&); static void remove(const std::string&); static void remove(const CanonicalPath&); explicit File(Handle&& handle) : Handle(std::move(handle)) {} - using Handle::close; - - using Handle::read; - using Handle::write; - std::size_t get_size() const; ID query_id() const; diff --git a/src/file.cpp b/src/file.cpp index 2b04f80..4f1d2a9 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -58,7 +58,7 @@ private: CreateFileParams() = default; }; -Handle open_file(const std::wstring& path, const CreateFileParams& params) { +File open_file(const std::wstring& path, const CreateFileParams& params) { SECURITY_ATTRIBUTES attributes; std::memset(&attributes, 0, sizeof(attributes)); attributes.nLength = sizeof(attributes); @@ -76,7 +76,7 @@ Handle open_file(const std::wstring& path, const CreateFileParams& params) { throw error::windows(GetLastError(), "CreateFileW"); } - return Handle{handle}; + return File{Handle{handle}}; } void remove_file(const std::wstring& path) { @@ -89,22 +89,38 @@ void remove_file(const std::wstring& path) { } // namespace -Handle File::open_r(const std::string& path) { +File File::open_r(const std::string& path) { return open_file(to_system_path(path), CreateFileParams::read()); } -Handle File::open_r(const CanonicalPath& path) { +File File::open_r(const CanonicalPath& path) { return open_file(to_system_path(path), CreateFileParams::read()); } -Handle File::open_read_attributes(const std::string& path) { +File File::open_read_attributes(const std::string& path) { return open_file(to_system_path(path), CreateFileParams::read_attributes()); } -Handle File::open_read_attributes(const CanonicalPath& path) { +File File::open_read_attributes(const CanonicalPath& path) { return open_file(to_system_path(path), CreateFileParams::read_attributes()); } +File File::open_w(const std::string& path) { + return open_file(to_system_path(path), CreateFileParams::write()); +} + +File File::open_w(const CanonicalPath& path) { + return open_file(to_system_path(path), CreateFileParams::write()); +} + +void File::remove(const std::string& path) { + remove_file(to_system_path(path)); +} + +void File::remove(const CanonicalPath& path) { + remove_file(to_system_path(path)); +} + std::size_t File::get_size() const { LARGE_INTEGER size; @@ -129,20 +145,4 @@ File::ID File::query_id() const { return {id}; } -Handle File::open_w(const std::string& path) { - return open_file(to_system_path(path), CreateFileParams::write()); -} - -Handle File::open_w(const CanonicalPath& path) { - return open_file(to_system_path(path), CreateFileParams::write()); -} - -void File::remove(const std::string& path) { - remove_file(to_system_path(path)); -} - -void File::remove(const CanonicalPath& path) { - remove_file(to_system_path(path)); -} - } // namespace winapi |