HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
Data Structures | Namespaces | Macros | Typedefs | Functions
utility.hpp File Reference

Utilities used by the HikoGUI library itself. More...

#include <cstddef>
#include <string>
#include <chrono>

Go to the source code of this file.

Data Structures

struct  hi::v1::override_t
 Tag used for special functions or constructions to do a override compared to another function of the same na,e. More...
 
struct  hi::v1::unusable_t
 A type that can not be constructed, copied, moved or destructed. More...
 

Namespaces

namespace  hi
 geometry/margins.hpp
 
namespace  hi::v1
 The HikoGUI API version 1.
 

Macros

#define hilet   auto const
 Invariant should be the default for variables.
 
#define hi_forward(x)   std::forward<decltype(x)>(x)
 Forward a value, based on the decltype of the value.
 
#define hi_return_if_valid(expression)
 Return the result of an expression if the expression is valid.
 
#define hi_num_va_args_impl(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, _63, N, ...)   N
 
#define hi_num_va_args_(...)   hi_num_va_args_impl(__VA_ARGS__)
 
#define hi_num_va_args(...)
 Get the number of arguments.
 
#define hi_parans   ()
 
#define hi_expand1(...)   __VA_ARGS__
 
#define hi_expand2(...)   hi_expand1(hi_expand1(hi_expand1(hi_expand1(__VA_ARGS__))))
 
#define hi_expand3(...)   hi_expand2(hi_expand2(hi_expand2(hi_expand2(__VA_ARGS__))))
 
#define hi_expand4(...)   hi_expand3(hi_expand3(hi_expand3(hi_expand3(__VA_ARGS__))))
 
#define hi_expand(...)   hi_expand4(hi_expand4(hi_expand4(hi_expand4(__VA_ARGS__))))
 Re-evaluate text up to 256 times by the pre-processor.
 
#define hi_for_each_again()   hi_for_each_helper
 
#define hi_for_each_helper(macro, first_arg, ...)   macro(first_arg) __VA_OPT__(hi_for_each_again hi_parans(macro, __VA_ARGS__))
 
#define hi_for_each(macro, ...)   __VA_OPT__(hi_expand(hi_for_each_helper(macro, __VA_ARGS__)))
 Evaluate a macro for each argument.
 
#define hi_stringify_(x)   #x
 
#define hi_stringify(x)   hi_stringify_(x)
 
#define hi_cat_(a, b)   a##b
 
#define hi_cat(a, b)   hi_cat_(a, b)
 
#define hi_return_on_self_assignment(other)
 
#define hi_get_overloaded_macro2(_1, _2, name, ...)   name
 Get an overloaded macro for 1 or 2 arguments.
 
#define hi_unreachable()   std::terminate()
 
#define hi_assume(condition)   static_assert(sizeof(condition) == 1)
 
#define hi_force_inline   inline
 
#define hi_no_inline
 
#define hi_restrict
 
#define hi_warning_push()
 
#define hi_warning_pop()
 
#define hi_msvc_pragma(a)
 
#define hi_warning_ignore_clang(a)
 
#define msvc_pragma(a)
 
#define hi_typename
 
#define ssizeof(x)   (static_cast<ssize_t>(sizeof(x)))
 

Typedefs

using hi::v1::ssize_t = std::ptrdiff_t
 Signed size/index into an array.
 

Functions

 hi_warning_ignore_msvc (26472)
 
 hi_warning_ignore_msvc (26473)
 
constexpr std::size_t hi::v1::operator""_uz (unsigned long long lhs) noexcept
 
constexpr std::size_t hi::v1::operator""_zu (unsigned long long lhs) noexcept
 
constexpr std::ptrdiff_t hi::v1::operator""_z (unsigned long long lhs) noexcept
 
template<typename T , typename U >
bool hi::v1::compare_store (T &lhs, U &&rhs) noexcept
 Compare then store if there was a change.
 
template<typename T , typename U >
bool hi::v1::compare_store (std::atomic< T > &lhs, U &&rhs) noexcept
 Compare then store if there was a change.
 
template<class T , class U >
constexpr auto && hi::v1::forward_like (U &&x) noexcept
 

Detailed Description

Utilities used by the HikoGUI library itself.

This file includes required definitions.

Macro Definition Documentation

◆ hi_expand

#define hi_expand ( ...)    hi_expand4(hi_expand4(hi_expand4(hi_expand4(__VA_ARGS__))))

Re-evaluate text up to 256 times by the pre-processor.

Parameters
...The text which needs to be re-evaluated by the pre-processor.

◆ hi_for_each

#define hi_for_each ( macro,
... )   __VA_OPT__(hi_expand(hi_for_each_helper(macro, __VA_ARGS__)))

Evaluate a macro for each argument.

Parameters
macroA macro that accepts a single argument.
...A set of arguments to be passed one-by-one to macro.

◆ hi_forward

#define hi_forward ( x)    std::forward<decltype(x)>(x)

Forward a value, based on the decltype of the value.

◆ hi_get_overloaded_macro2

#define hi_get_overloaded_macro2 ( _1,
_2,
name,
... )   name

Get an overloaded macro for 1 or 2 arguments.

This macro allows dispatching to other macros based on the number of arguments.

#define foo1(a) bar(a)
#define foo2(a, b) bar(a, b)
#define foo(...) hi_get_overloaded_macro2(__VA_ARGS__, foo2, foo1)(__VA_ARGS__)

◆ hi_num_va_args

#define hi_num_va_args ( ...)
Value:
hi_num_va_args_(__VA_ARGS__ __VA_OPT__(,) \
63,62,61,60, \
59,58,57,56,55,54,53,52,51,50, \
49,48,47,46,45,44,43,42,41,40, \
39,38,37,36,35,34,33,32,31,30, \
29,28,27,26,25,24,23,22,21,20, \
19,18,17,16,15,14,13,12,11,10, \
9,8,7,6,5,4,3,2,1,0)

Get the number of arguments.

Parameters
...A set of arguments
Returns
The number of arguments pass to this macro.

◆ hi_return_if_valid

#define hi_return_if_valid ( expression)
Value:
do { \
if constexpr (requires { expression; }) { \
return expression; \
} \
} while (false)

Return the result of an expression if the expression is valid.

This macro uses a requires {} expression to determine if the expression is valid.

Parameters
expressionThe expression to evaluate if it is valid.

◆ hi_return_on_self_assignment

#define hi_return_on_self_assignment ( other)
Value:
if (&(other) == this) [[unlikely]] \
return *this;

◆ hilet

#define hilet   auto const

Invariant should be the default for variables.

C++ does have an invariant but it requires you to enter the 'const' keyword which is easy to forget. Using a single keyword 'hilet' for an invariant makes it easier to notice when you have defined a variant.

Function Documentation

◆ hi_warning_ignore_msvc()

hi_warning_ignore_msvc ( 26472 )

Get a bit from an array of unsigned integers. The integers are arranged in little-endian order.

Parameters
lhsThe array of integers from which to take the bit.
indexThe index of the bit
Returns
The value of the bit, either 0 or 1, with the same type as the integers of the array.

Set a bit from an array of unsigned integers. The integers are arranged in little-endian order.

Parameters
rThe array of integers on which to set the bit.
indexThe index of the bit
valueThe value of the bit, either 0 or 1.

Shift logical left with carry chain.

Parameters
lhsThe original value
rhsThe count by how much to shift lhs left.
carryThe carry data to or with the lower bits.
Returns
(result, carry); the carry which can be used to pass into the next iteration.

Shift logical right with carry chain.

Parameters
lhsThe original value
rhsThe count by how much to shift lhs right.
carryThe carry data to or with the lower bits.
Returns
(result, carry); the carry which can be used to pass into the next iteration.

Shift arithmetic right with carry chain.

Parameters
lhsThe original value
rhsThe count by how much to shift lhs right.
Returns
(result, carry); the carry which can be used to pass into the next iteration.

Add two numbers with carry chain.

Parameters
lhsThe left hand side
rhsThe right hand side
carryFrom the previous add in the chain
Returns
(result, carry) pair

Multiply with carry. The carry is a high-word of the multiplication result and has the same size as the inputs. The accumulator is used when doing long-multiplication from the previous row. This function does not overflow even if all the arguments are at max.

Parameters
lhsThe left hand side.
rhsThe right hand side.
carryThe carry-input; carry-output from the previous mul_carry().
accumulatorThe column value during a long multiply.
Returns
low, high of the result.

Wide divide. Can be used to divide a wide unsigned integer by a unsigned integer, as long as the result fits in an unsigned integer.

Parameters
lhs_loThe low side of a wide left-hand-side
lhs_hiThe high side of a wide left-hand-side
rhsThe right hand side
Returns
The result.

Bit scan reverse.

Parameters
lhsThe array of unsigned integers to find the highest set bit off.
nThe number of unsigned integers in the array.
Returns
index of leading one, or -1 when rhs is zero.

Invert unsigned integers using a carry-chain Technically this is not an carry chain.

Parameters
rThe result of the inversion.
rhsThe right hand side operand.
nThe number of digits of r and rhs.

shift logical right using a carry-chain

Parameters
rThe result of the logical-shift-right.
lhsThe left hand side operand of the lsr.
rhsThe right hand side operand of the lsr, the number of bits to shift.
nThe number of digits of r, lhs and rhs.

shift logical right using a carry-chain

Parameters
rThe result of the logical-shift-right.
lhsThe left hand side operand of the lsr.
rhsThe right hand side operand of the lsr, the number of bits to shift.
nThe number of digits of r, lhs and rhs.

shift arithmetic right using a carry-chain This sign-extends the left most bit.

Parameters
rThe result of the logical-shift-right.
lhsThe left hand side operand of the lsr.
rhsThe right hand side operand of the lsr, the number of bits to shift.
nThe number of digits of r, lhs and rhs.

and-operation unsigned integers using a carry-chain

Parameters
rThe result of the and-operation.
lhsThe left hand side operand of the and-operation.
rhsThe right hand side operand of the and-operation.
nThe number of digits of r, lhs and rhs.

or-operation unsigned integers using a carry-chain

Parameters
rThe result of the and-operation.
lhsThe left hand side operand of the or-operation.
rhsThe right hand side operand of the or-operation.
nThe number of digits of r, lhs and rhs.

xor-operation unsigned integers using a carry-chain

Parameters
rThe result of the and-operation.
lhsThe left hand side operand of the xor-operation.
rhsThe right hand side operand of the xor-operation.
nThe number of digits of r, lhs and rhs.

Negate unsigned integers using a carry-chain This is a two's compliment negate.

Parameters
rThe result of the addition.
rhsThe left hand side operand of the addition.
nThe number of digits of r, lhs and rhs.

Add unsigned integers using a carry-chain

Parameters
rThe result of the addition.
lhsThe left hand side operand of the addition.
rhsThe right hand side operand of the addition.
nThe number of digits of r, lhs and rhs.

Subtract unsigned integers using a carry-chain

Parameters
rThe result of the addition.
lhsThe left hand side operand of the addition.
rhsThe right hand side operand of the addition.
nThe number of digits of r, lhs and rhs.

Multiply unsigned integers using a carry-chain

Note
r May not alias with lhs or rhs.
Parameters
rThe result of the multiplication.
lhsThe left hand side operand.
rhsThe right hand side operand.
nThe number of digits of r, lhs and rhs.

Divide unsigned integers using a carry-chain This function does a bit-wise division.

Note
quotient and remainder may not alias with lhs or rhs or with each other.
Parameters
quotientThe result of the division.
remainderThe remainder of the division.
lhsThe left hand side operand.
rhsThe right hand side operand.
nThe number of digits of quotient, remainder, lhs and rhs.

signed divide unsigned integers using a carry-chain This function does a bit-wise division. This function will allocate memory when one or both operands are negative.

Note
quotient and remainder may not alias with lhs or rhs or with each other.
Parameters
quotientThe result of the division.
remainderThe remainder of the division. The remainder has same sign as lhs.
lhsThe left hand side operand.
rhsThe right hand side operand.
nThe number of digits of quotient, remainder, lhs and rhs.