21
common/resource_traits/cxx_dynamic_array_traits.hpp
Normal file
21
common/resource_traits/cxx_dynamic_array_traits.hpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
namespace nkg::resource_traits {
|
||||
|
||||
template<typename element_t>
|
||||
struct cxx_dynamic_array_traits {
|
||||
using handle_t = element_t*;
|
||||
|
||||
static constexpr handle_t invalid_value = nullptr;
|
||||
|
||||
[[nodiscard]]
|
||||
static bool is_valid(const handle_t& handle) noexcept {
|
||||
return handle != invalid_value;
|
||||
}
|
||||
|
||||
static void release(const handle_t& handle) {
|
||||
delete[] handle;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
21
common/resource_traits/cxx_object_traits.hpp
Normal file
21
common/resource_traits/cxx_object_traits.hpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
namespace nkg::resource_traits {
|
||||
|
||||
template<typename object_t>
|
||||
struct cxx_object_traits {
|
||||
using handle_t = object_t*;
|
||||
|
||||
static constexpr handle_t invalid_value = nullptr;
|
||||
|
||||
[[nodiscard]]
|
||||
static bool is_valid(const handle_t& handle) noexcept {
|
||||
return handle != invalid_value;
|
||||
}
|
||||
|
||||
static void release(const handle_t& handle) {
|
||||
delete handle;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
20
common/resource_traits/keystone/keystone_alloc.hpp
Normal file
20
common/resource_traits/keystone/keystone_alloc.hpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
#include <keystone/keystone.h>
|
||||
|
||||
namespace nkg::resource_traits::keystone {
|
||||
|
||||
struct keystone_alloc {
|
||||
using handle_t = unsigned char*;
|
||||
|
||||
static constexpr handle_t invalid_value = nullptr;
|
||||
|
||||
[[nodiscard]]
|
||||
static bool is_valid(const handle_t& handle) noexcept {
|
||||
return handle != invalid_value;
|
||||
}
|
||||
|
||||
static void release(const handle_t& handle) noexcept {
|
||||
ks_free(handle);
|
||||
}
|
||||
};
|
||||
}
|
||||
21
common/resource_traits/keystone/keystone_handle.hpp
Normal file
21
common/resource_traits/keystone/keystone_handle.hpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
#include <keystone/keystone.h>
|
||||
|
||||
namespace nkg::resource_traits::keystone {
|
||||
|
||||
struct keystone_handle {
|
||||
using handle_t = ks_engine*;
|
||||
|
||||
static constexpr handle_t invalid_value = nullptr;
|
||||
|
||||
[[nodiscard]]
|
||||
static bool is_valid(const handle_t& handle) noexcept {
|
||||
return handle != invalid_value;
|
||||
}
|
||||
|
||||
static void release(const handle_t& handle) {
|
||||
ks_close(handle);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
21
common/resource_traits/openssl/bignum.hpp
Normal file
21
common/resource_traits/openssl/bignum.hpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
#include <openssl/bn.h>
|
||||
|
||||
namespace nkg::resource_traits::openssl {
|
||||
|
||||
struct bignum {
|
||||
using handle_t = BIGNUM*;
|
||||
|
||||
static constexpr handle_t invalid_value = nullptr;
|
||||
|
||||
[[nodiscard]]
|
||||
static bool is_valid(const handle_t& handle) noexcept {
|
||||
return handle != invalid_value;
|
||||
}
|
||||
|
||||
static void release(const handle_t& handle) noexcept {
|
||||
BN_free(handle);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
21
common/resource_traits/openssl/bio.hpp
Normal file
21
common/resource_traits/openssl/bio.hpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
#include <openssl/bio.h>
|
||||
|
||||
namespace nkg::resource_traits::openssl {
|
||||
|
||||
struct bio {
|
||||
using handle_t = BIO*;
|
||||
|
||||
static constexpr handle_t invalid_value = nullptr;
|
||||
|
||||
[[nodiscard]]
|
||||
static bool is_valid(const handle_t& handle) noexcept {
|
||||
return handle != invalid_value;
|
||||
}
|
||||
|
||||
static void release(const handle_t& handle) noexcept {
|
||||
BIO_free(handle);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
21
common/resource_traits/openssl/bio_chain.hpp
Normal file
21
common/resource_traits/openssl/bio_chain.hpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
#include <openssl/bio.h>
|
||||
|
||||
namespace nkg::resource_traits::openssl {
|
||||
|
||||
struct bio_chain {
|
||||
using handle_t = BIO*;
|
||||
|
||||
static constexpr handle_t invalid_value = nullptr;
|
||||
|
||||
[[nodiscard]]
|
||||
static bool is_valid(const handle_t& handle) noexcept {
|
||||
return handle != invalid_value;
|
||||
}
|
||||
|
||||
static void release(const handle_t& handle) noexcept {
|
||||
BIO_free_all(handle);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
21
common/resource_traits/openssl/rsa.hpp
Normal file
21
common/resource_traits/openssl/rsa.hpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
#include <openssl/rsa.h>
|
||||
|
||||
namespace nkg::resource_traits::openssl {
|
||||
|
||||
struct rsa {
|
||||
using handle_t = RSA*;
|
||||
|
||||
static constexpr handle_t invalid_value = nullptr;
|
||||
|
||||
[[nodiscard]]
|
||||
static bool is_valid(const handle_t& handle) noexcept {
|
||||
return handle != invalid_value;
|
||||
}
|
||||
|
||||
static void release(const handle_t& handle) noexcept {
|
||||
RSA_free(handle);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
21
common/resource_traits/unicorn/unicorn_alloc.hpp
Normal file
21
common/resource_traits/unicorn/unicorn_alloc.hpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
#include <unicorn/unicorn.h>
|
||||
|
||||
namespace nkg::resource_traits::unicorn {
|
||||
|
||||
struct unicorn_alloc {
|
||||
using handle_t = void*;
|
||||
|
||||
static constexpr handle_t invalid_value = nullptr;
|
||||
|
||||
[[nodiscard]]
|
||||
static bool is_valid(const handle_t& handle) noexcept {
|
||||
return handle != invalid_value;
|
||||
}
|
||||
|
||||
static void release(const handle_t& handle) {
|
||||
uc_free(handle);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
21
common/resource_traits/unicorn/unicorn_handle.hpp
Normal file
21
common/resource_traits/unicorn/unicorn_handle.hpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
#include <unicorn/unicorn.h>
|
||||
|
||||
namespace nkg::resource_traits::unicorn {
|
||||
|
||||
struct unicorn_handle {
|
||||
using handle_t = uc_engine*;
|
||||
|
||||
static constexpr handle_t invalid_value = nullptr;
|
||||
|
||||
[[nodiscard]]
|
||||
static bool is_valid(const handle_t& handle) noexcept {
|
||||
return handle != invalid_value;
|
||||
}
|
||||
|
||||
static void release(const handle_t& handle) {
|
||||
uc_close(handle);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
21
common/resource_traits/unix_os/file_descriptor.hpp
Normal file
21
common/resource_traits/unix_os/file_descriptor.hpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
#include <unistd.h>
|
||||
|
||||
namespace nkg::resource_traits::unix_os {
|
||||
|
||||
struct file_descriptor {
|
||||
using handle_t = int;
|
||||
|
||||
static constexpr handle_t invalid_value = -1;
|
||||
|
||||
[[nodiscard]]
|
||||
static bool is_valid(const handle_t& handle) noexcept {
|
||||
return handle != invalid_value;
|
||||
}
|
||||
|
||||
static void release(const handle_t& handle) {
|
||||
close(handle);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
19
common/resource_traits/unix_os/map_view.hpp
Normal file
19
common/resource_traits/unix_os/map_view.hpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
namespace nkg::resource_traits::unix_os {
|
||||
|
||||
struct map_view {
|
||||
using handle_t = void*;
|
||||
|
||||
static inline const handle_t invalid_value = MAP_FAILED;
|
||||
|
||||
[[nodiscard]]
|
||||
static bool is_valid(const handle_t& handle) noexcept {
|
||||
return handle != invalid_value;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user