21 #ifndef FASTUIDRAW_UTIL_HPP 22 #define FASTUIDRAW_UTIL_HPP 35 #define FASTUIDRAW_ROUND_UP_MULTIPLE_OF4(X) (((X) + 3u) & ~3u) 42 #define FASTUIDRAW_NUMBER_BLOCK4_NEEDED(X) (FASTUIDRAW_ROUND_UP_MULTIPLE_OF4(X) >> 2u) 51 #define FASTUIDRAW_MAX_VALUE_FROM_NUM_BITS(X) ( (uint32_t(1) << uint32_t(X)) - uint32_t(1) ) 59 #define FASTUIDRAW_MASK(BIT0, NUMBITS) (FASTUIDRAW_MAX_VALUE_FROM_NUM_BITS(NUMBITS) << uint32_t(BIT0)) 67 #define FASTUIDRAW_MAX_VALUE_FROM_NUM_BITS_U64(X) ( (uint64_t(1) << uint64_t(X)) - uint64_t(1) ) 75 #define FASTUIDRAW_MASK_U64(BIT0, NUMBITS) (FASTUIDRAW_MAX_VALUE_FROM_NUM_BITS_U64(NUMBITS) << uint64_t(BIT0)) 84 #define FASTUIDRAWunused(X) do { (void)(X); } while(0) 93 #ifdef FASTUIDRAW_DEBUG 94 #define FASTUIDRAWassert(X) do { \ 96 fastuidraw::assert_fail("Assertion '" #X "' failed", __FILE__, __LINE__); \ 99 #define FASTUIDRAWassert(X) 109 #define FASTUIDRAWmessaged_assert(X, Y) do { \ 111 fastuidraw::assert_fail(Y, __FILE__, __LINE__); \ 118 #define FASTUIDRAWstatic_assert(X) static_assert(X, #X) 126 assert_fail(
const char *str,
const char *file,
int line);
192 return v && !(v & (v - uint32_t(1u)));
204 return v && !(v & (v - uint64_t(1u)));
261 uint32_t bitfield_value)
264 input_value | bitfield_value:
265 input_value & (~bitfield_value);
279 uint64_t bitfield_value)
282 input_value | bitfield_value:
283 input_value & (~bitfield_value);
294 pack_bits(uint32_t bit0, uint32_t num_bits, uint32_t value)
297 mask = (1u << num_bits) - 1u;
300 return (value & mask) << bit0;
314 mask = (uint64_t(1u) << num_bits) - uint64_t(1u);
317 return (value & mask) << bit0;
333 mask = (uint32_t(1u) << num_bits) - uint32_t(1u);
334 return (value >> bit0) & mask;
350 mask = (uint64_t(1u) << num_bits) - uint64_t(1u);
351 return (value >> bit0) & mask;
366 q =
reinterpret_cast<const char*
>(&f);
367 return *
reinterpret_cast<const uint32_t*
>(q);
382 q =
reinterpret_cast<const char*
>(&v);
383 return *
reinterpret_cast<const float*
>(q);
432 template<
typename W = T>
535 static constexpr value_type value =
true;
563 static constexpr value_type value =
false;
624 template<
typename T,
typename S>
636 template<
typename T,
typename S>
uint32_t unpack_bits(uint32_t bit0, uint32_t num_bits, uint32_t value)
Class for type traits to indicate true. Functionally, a simplified version of std::true_type.
uint32_t uint32_log2(uint32_t v)
bool uint64_is_power_of_2(uint64_t v)
all classes and functions of FastUIDraw are in the namespace fastuidraw.
void operator+=(const W &v)
uint32_t number_bits_required(uint32_t v)
return_code
Enumeration for simple return codes for functions for success or failure.
constexpr value_type operator()() const noexcept
uint64_t uint64_log2(uint64_t v)
uint64_t uint64_unpack_bits(uint64_t bit0, uint64_t num_bits, uint64_t value)
range_type< T > create_range(T a, T b)
uint32_t next_power_of_2(uint32_t v)
bool is_power_of_2(uint32_t v)
uint64_t uint64_number_bits_required(uint64_t v)
uint64_t uint64_apply_bit_flag(uint64_t input_value, bool to_apply, uint64_t bitfield_value)
uint32_t pack_float(float f)
float unpack_float(uint32_t v)
uint32_t pack_bits(uint32_t bit0, uint32_t num_bits, uint32_t value)
Class for type traits to indicate true. Functionally, a simplified version of std::false_type.
remove_const< S >::type type
A class reprenting the STL range [m_begin, m_end).
const char * c_string
Conveniant typedef for C-style strings.
uint64_t uint64_pack_bits(uint64_t bit0, uint64_t num_bits, uint64_t value)
void assert_fail(const char *str, const char *file, int line)
uint32_t apply_bit_flag(uint32_t input_value, bool to_apply, uint32_t bitfield_value)
Class for which copy ctor and assignment operator are private functions.
void operator-=(const W &v)
#define FASTUIDRAWassert(X)
uint64_t uint64_next_power_of_2(uint64_t v)
constexpr value_type operator()() const noexcept