keystone_handle.hpp 841 B

123456789101112131415161718192021222324252627282930313233343536
  1. #pragma once
  2. #include <keystone/keystone.h>
  3. namespace nkg::resource_traits::keystone {
  4. struct keystone_handle {
  5. using handle_t = ks_engine*;
  6. static constexpr handle_t invalid_value = nullptr;
  7. [[nodiscard]]
  8. static bool is_valid(const handle_t& handle) noexcept {
  9. return handle != invalid_value;
  10. }
  11. static void release(const handle_t& handle) {
  12. ks_close(handle);
  13. }
  14. };
  15. struct keystone_alloc {
  16. using handle_t = unsigned char*;
  17. static constexpr handle_t invalid_value = nullptr;
  18. [[nodiscard]]
  19. static bool is_valid(const handle_t& handle) noexcept {
  20. return handle != invalid_value;
  21. }
  22. static void release(const handle_t& handle) noexcept {
  23. ks_free(handle);
  24. }
  25. };
  26. }