bit7z 4.1.0
A C++ library for interfacing with the 7-zip shared libs.
Loading...
Searching...
No Matches
bit7zlibraryloader.hpp
1/*
2 * bit7z - A C++ static library to interface with the 7-zip shared libraries.
3 * Copyright (c) Riccardo Ostani - All Rights Reserved.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
8 */
9
10#ifndef BIT7ZLIBRARYLOADER_HPP
11#define BIT7ZLIBRARYLOADER_HPP
12
13#include "bit7zlibrary.hpp"
14#include "bitdefines.hpp"
15#include "bittypes.hpp"
16
17#include <system_error>
18
19namespace bit7z {
20
31class Bit7zLibraryLoader final {
32 public:
37
43 explicit Bit7zLibraryLoader( const tstring& libraryPath );
44
45 Bit7zLibraryLoader( const Bit7zLibraryLoader& ) = delete;
46
48
49 auto operator=( const Bit7zLibraryLoader& ) -> Bit7zLibraryLoader& = delete;
50
51 auto operator=( Bit7zLibraryLoader&& ) -> Bit7zLibraryLoader& = delete;
52
57
67 void load( const tstring& libraryPath );
68
79 void load( const tstring& libraryPath, std::error_code& ec ) noexcept;
80
88 BIT7Z_NODISCARD
89 auto library() const -> const Bit7zLibrary&;
90
94 void unload() noexcept;
95
101 BIT7Z_NODISCARD
102 auto isLoaded() const noexcept -> bool;
103
111 BIT7Z_NODISCARD
112 auto operator->() const -> const Bit7zLibrary*;
113
121 /* implicit */ operator const Bit7zLibrary&() const; //NOLINT(*-explicit-conversions)
122
123 private:
124 /* We can't use std::optional here since bit7z's public API is still C++14.
125 * Alternatively, we could move the internal's Optional class to the public API, and use it here.
126 * Ultimately, I preferred to not pollute the public API with yet another class and
127 * simply reimplemented a very bare-bones optional storage. */
128 union {
129 byte_t mEmpty;
130 Bit7zLibrary mLibrary;
131 };
132
133 bool mLoaded;
134};
135
136} // namespace bit7z
137
138#endif //BIT7ZLIBRARYLOADER_HPP
The Bit7zLibrary class allows accessing the basic functionalities provided by the 7z DLLs.
Definition bit7zlibrary.hpp:55
void unload() noexcept
Unloads the currently loaded library, if any.
void load(const tstring &libraryPath)
Loads the specified 7-zip shared library.
Bit7zLibraryLoader() noexcept
Constructs an empty Bit7zLibraryLoader without loading any library.
auto isLoaded() const noexcept -> bool
Checks whether a 7-zip shared library is currently loaded.
auto library() const -> const Bit7zLibrary &
Returns a reference to the loaded Bit7zLibrary.
The main namespace of the bit7z library.
Definition bit7zlibrary.hpp:29
unsigned char byte_t
A type representing a byte.
Definition bittypes.hpp:38
std::basic_string< tchar > tstring
Definition bittypes.hpp:104