summaryrefslogtreecommitdiff
path: root/cabinet/magic.hpp
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@gmail.com>2026-06-04 19:42:02 +0200
committerFelix Morgner <felix.morgner@gmail.com>2026-06-04 19:42:02 +0200
commit11df846b1ec951dd35feb9b0bad42486c7b94dca (patch)
tree3e94acde315473011793cad482f23f1adf02fc98 /cabinet/magic.hpp
parent240e7804156c5c374d4cf1216161f4feefd3fcb1 (diff)
downloadcabinet-11df846b1ec951dd35feb9b0bad42486c7b94dca.tar.xz
cabinet-11df846b1ec951dd35feb9b0bad42486c7b94dca.zip
magic: refactor construction
Diffstat (limited to 'cabinet/magic.hpp')
-rw-r--r--cabinet/magic.hpp17
1 files changed, 15 insertions, 2 deletions
diff --git a/cabinet/magic.hpp b/cabinet/magic.hpp
index 02af9c2..25cf60b 100644
--- a/cabinet/magic.hpp
+++ b/cabinet/magic.hpp
@@ -3,6 +3,9 @@
#include <magic.h>
+#include <expected>
+#include <string_view>
+#include <system_error>
#include <utility>
namespace cab
@@ -40,13 +43,23 @@ namespace cab
no_simh = MAGIC_NO_CHECK_SIMH,
};
- magic(flags flags);
+ auto static open(flags flags, std::string_view database = {}) noexcept -> std::expected<magic, std::error_code>;
+
~magic();
+ magic(magic const &) = delete;
+ magic(magic && other) noexcept;
+
+ auto operator=(magic const &) -> magic & = delete;
+ auto operator=(magic && other) noexcept -> magic &;
private:
- magic_t m_cookie{};
+ explicit magic(::magic_t cookie) noexcept;
+
+ ::magic_t m_cookie{};
};
+ auto swap(magic & lhs, magic & rhs) noexcept -> void;
+
constexpr auto operator|(magic::flags lhs, magic::flags rhs) noexcept -> magic::flags
{
return static_cast<magic::flags>(std::to_underlying(lhs) | std::to_underlying(rhs));