ResourceTraitsKeystone.hpp 1022 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #pragma once
  2. #include <keystone/keystone.h>
  3. #include "ExceptionKeystone.hpp"
  4. namespace ARL::ResourceTraits {
  5. struct KeystoneHandle {
  6. using HandleType = ks_engine*;
  7. static inline const HandleType InvalidValue = nullptr;
  8. [[nodiscard]]
  9. static bool IsValid(const HandleType& Handle) noexcept {
  10. return Handle != InvalidValue;
  11. }
  12. static void Release(const HandleType& Handle) {
  13. auto err = ks_close(Handle);
  14. if (err != KS_ERR_OK) {
  15. throw ARL::KeystoneError(__FILE__, __LINE__, err, "ks_close failed.");
  16. }
  17. }
  18. };
  19. struct KeystoneMalloc {
  20. using HandleType = uint8_t*;
  21. static inline const HandleType InvalidValue = nullptr;
  22. [[nodiscard]]
  23. static bool IsValid(const HandleType& Handle) noexcept {
  24. return Handle != InvalidValue;
  25. }
  26. static void Release(const HandleType& Handle) noexcept {
  27. ks_free(Handle);
  28. }
  29. };
  30. }