General Purpose library for Freestanding C++ and POSIX systems
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.0 KiB

  1. #pragma once
  2. #include <cstdint>
  3. #include <cstddef>
  4. #include <cstdlib>
  5. #include <type_traits>
  6. namespace gp_config{
  7. namespace memory_module{
  8. enum class memory_mode_t{
  9. other,
  10. clib,
  11. buffer,
  12. arena_buffer
  13. };
  14. constexpr memory_mode_t memory_mode = memory_mode_t::clib;
  15. template<memory_mode_t T = memory_mode_t::other>
  16. constexpr void*(*memory_allocator)(std::size_t)=nullptr;
  17. template<memory_mode_t T = memory_mode_t::other>
  18. constexpr void(*memory_deallocator)(void*)=nullptr;
  19. // C Standard library memory usage
  20. template<>
  21. constexpr void*(*memory_allocator<memory_mode_t::clib>)(std::size_t) = malloc;
  22. template<>
  23. constexpr void(*memory_deallocator<memory_mode_t::clib>)(void*) = free;
  24. // Buffer memory usage only
  25. template<>
  26. constexpr void*(*memory_allocator<memory_mode_t::buffer>)(std::size_t) = nullptr;
  27. template<>
  28. constexpr void(*memory_deallocator<memory_mode_t::buffer>)(void*) = nullptr;
  29. // Buffer of arena memory usage
  30. template<>
  31. constexpr void*(*memory_allocator<memory_mode_t::arena_buffer>)(std::size_t) = nullptr;
  32. template<>
  33. constexpr void(*memory_deallocator<memory_mode_t::arena_buffer>)(void*) = nullptr;
  34. constexpr bool is_ok =
  35. ( memory_allocator<memory_mode> != nullptr )
  36. && ( memory_deallocator<memory_mode> != nullptr );
  37. }
  38. constexpr bool has_exceptions = true;
  39. constexpr bool has_buffer_bounds = true;
  40. // Value of 8 is considered not cryptographically secure
  41. // Value of 12 offers a good compromise of performance and robustness
  42. // Value of 20 offers maximum robustness
  43. constexpr size_t arc4random_strength = 20;
  44. struct assert_failure{
  45. assert_failure(const char* reason)
  46. : what_str{reason}
  47. {}
  48. const char* what_str;
  49. const char* what() {return what_str;}
  50. };
  51. constexpr size_t assert_buffer_size = 0;
  52. constexpr auto assertion = [](bool pred, const char* reason) -> void{
  53. if constexpr (has_exceptions)
  54. if(!pred) throw assert_failure(reason);
  55. };
  56. }
  57. enum class gp_errorcodes : int {
  58. infinite_skipstone = 3000
  59. };