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.

185 line
4.0 KiB

  1. #pragma once
  2. #include <new>
  3. #include <type_traits>
  4. #include <cstddef>
  5. #include <cstdint>
  6. #ifdef GP_TESTS
  7. class static_mapper;
  8. #else
  9. namespace gp {
  10. class c_allocator;
  11. }
  12. #endif
  13. /**
  14. * @brief This namespace contains the configuration.
  15. *
  16. * This namespace is expected to be fully defined in an include accessible from the root
  17. * of your header list:
  18. * \code{.cpp}
  19. * #include "gp_config.hpp"
  20. * \endcode
  21. *
  22. * The code line above should always be the one including that config and that namespace.
  23. */
  24. namespace gp_config{
  25. namespace rendering {
  26. /**
  27. * @brief The default type used for rendering processes
  28. */
  29. using default_type = float;
  30. /**
  31. * @brief The small enough value used in signed distance function resolution
  32. */
  33. constexpr default_type epsilon = 0.01;
  34. /**
  35. * @brief The default color type
  36. */
  37. #define GP_CONFIG__RENDERING__COLOR_T vec4
  38. }
  39. /**
  40. * @brief This namespace contains artificial limitations put on the runtime
  41. */
  42. namespace limits {
  43. /**
  44. * @brief the total number of processes the system is allowed to have
  45. */
  46. constexpr size_t max_processes = 4096;
  47. /**
  48. * @brief the maximum size a channel can address
  49. */
  50. constexpr size_t channel_max_size = 1 << 20;
  51. /**
  52. * @brief the default size a channel will take
  53. */
  54. constexpr size_t channel_default_size = 1 << 16;
  55. /**
  56. * @brief the number of open files each process is allowed to have
  57. */
  58. constexpr size_t max_fd_per_process = 128;
  59. /**
  60. * @brief the stack size for the new stacks generated by the concurrency system
  61. */
  62. constexpr size_t process_stack = 1024;
  63. /**
  64. * @brief expected stack alignment
  65. */
  66. constexpr size_t process_stack_align_to = 16;
  67. /**
  68. * @brief presents the direction of stack growth
  69. */
  70. constexpr size_t stack_grow_upwards = false;
  71. #if __cpp_lib_hardware_interference_size >= 201603
  72. constexpr size_t hardware_constructive_interference_size = std::hardware_constructive_interference_size;
  73. constexpr size_t hardware_destructive_interference_size = std::hardware_destructive_interference_size;
  74. #else
  75. constexpr size_t hardware_constructive_interference_size = 128;
  76. constexpr size_t hardware_destructive_interference_size = 128;
  77. #endif
  78. constexpr size_t loggers_segment_size = 128;
  79. }
  80. namespace memory_module{
  81. constexpr bool is_ok = true;
  82. constexpr bool prefer_constant_memory = true;
  83. }
  84. typedef uint32_t file_descriptor_t;
  85. /**
  86. * @brief set to true to enable exceptions
  87. */
  88. constexpr bool has_exceptions = false;
  89. /**
  90. * @brief set to true to activate bounds checking
  91. */
  92. constexpr bool has_buffer_bounds = true;
  93. //
  94. //
  95. //
  96. /**
  97. * @brief A value used to determine the strength used by random number generators
  98. *
  99. * Value of 8 is considered not cryptographically secure
  100. * Value of 12 offers a good compromise of performance and robustness
  101. * Value of 20 offers maximum robustness
  102. */
  103. constexpr size_t arc4random_strength = 20;
  104. /**
  105. * @brief an exception that represents an assertion failure
  106. */
  107. struct assert_failure{
  108. assert_failure(const char* reason)
  109. : what_str{reason}
  110. {}
  111. const char* what_str;
  112. const char* what() {return what_str;}
  113. };
  114. /**
  115. * @brief UNUSED
  116. */
  117. constexpr size_t assert_buffer_size = 0;
  118. /**
  119. * @brief an assertion function
  120. */
  121. constexpr auto assertion = [](bool pred, const char* reason) -> void{
  122. if(!pred) {
  123. //log_failure(reason);
  124. if constexpr (has_exceptions)
  125. throw assert_failure(reason);
  126. }
  127. };
  128. enum class cbor_tag {
  129. datetime = 0,
  130. unix_time = 1,
  131. ubignum = 2,
  132. nbignum = 3,
  133. decimal = 4,
  134. bigfloat = 5,
  135. cose_encrypt0 = 16,
  136. cose_mac0 = 17,
  137. cose_sign1 = 18,
  138. expected_base64url = 21,
  139. expected_base64 = 22,
  140. expected_base16 = 23,
  141. encoded_cbor = 24,
  142. url = 32,
  143. base64url = 33,
  144. base64 = 34,
  145. regexp = 35,
  146. mime = 36,
  147. cose_encrypt = 96,
  148. cose_mac = 97,
  149. cose_sign = 98,
  150. signature = 55799
  151. };
  152. }
  153. /**
  154. * @brief a list of error codes
  155. */
  156. enum class gp_errorcodes : int {
  157. /**
  158. * @brief this error code is activated upon reaching a skipstone limit that seems like infinity.
  159. */
  160. infinite_skipstone = 3000
  161. };