Honeycomb  0.1
Component-Model Framework
Macros
Preprocessor Macros

Macros

#define EVAL(...)    __VA_ARGS__
 Evaluate expression. More...
 
#define STRINGIFY(s)    STRINGIFY_(s)
 Convert token to string. More...
 
#define TOKCAT(a, b)    TOKCAT_(a, b)
 Concatenate tokens together to form a new symbol. More...
 
#define EMPTY
 Symbol evaluates to nothing. More...
 
#define EMPTYFUNC(...)
 Function evaluates to nothing. More...
 
#define UNBRACKET(...)    IFEQUAL(_UNBRACKET_TEST __VA_ARGS__, 1, EVAL __VA_ARGS__, __VA_ARGS__)
 Remove brackets around parameter. More...
 
#define NUMARGS(...)    IFEMPTY(0, _NUMARGS(__VA_ARGS__), __VA_ARGS__)
 Get number of arguments in list. Supports up to 10 args (limited because of high impact on compile-time). More...
 
#define COMMA   ,
 Use to avoid macro interpreting a comma as an argument delimiter. More...
 
#define COMMA_IFNOT(Num, CompareNum)    IFEQUAL(Num, CompareNum, EMPTY, COMMA)
 If Num is not CompareNum, then this will evaluate to a comma. Useful for iteration over function parameters. More...
 
#define IFEMPTY(True, False, ...)    TOKCAT(_IFEMPTY_CASE_, _ISEMPTY(__VA_ARGS__))(EVAL(True), EVAL(False))
 Evaluate true or false depending on whether argument list is empty. More...
 
#define IFEQUAL(Num, CompareNum, True, False)    IFEMPTY(EVAL(True), EVAL(False), TOKCAT(_ITERATE_, TOKCAT(Num, _##CompareNum)))
 Evaluate True if Num == CompareNum, otherwise eval False. More...
 
#define TUPLE_SIZE(t)    EVAL(NUMARGS t)
 Get number of elements in tuple. More...
 
#define TUPLE_ELEM(t, i)    TOKCAT(_TUPLE_ELEM_,TUPLE_SIZE(t))_ ## i t
 Get element in tuple. A tuple is a bracketed parameter list: (e0,e1,e2...). Supports up to 5 elements. More...
 
#define PP_ADD(Lhs, Rhs)    _ADD_0(Lhs, Rhs)
 Add two values, result must be in range [0, ITERATE_MAX]. More...
 
#define PP_SUB(Lhs, Rhs)    _SUBTRACT_0(Lhs, Rhs)
 Subtract two values in range [0, ITERATE_MAX]. More...
 

ITERATE

#define ITERATE_MAX   20
 Max number of iterations supported. More...
 
#define ITERATE(Min, Max, Func)    IFEMPTY(, TOKCAT(_ITERATE_, Min)(Max, Func, 0,,,,,) , TOKCAT(_ITERATE_INIT_##Min##_, Max))
 Iterate calling Func(It, Args...) over range [Min, Max], where Min >= 0 and Max <= ITERATE_MAX. It is the current iteration number. More...
 
#define ITERATE1(Min, Max, Func, a1)    IFEMPTY(, TOKCAT(_ITERATE_, Min)(Max, Func, 1,a1,,,,) , TOKCAT(_ITERATE_INIT_##Min##_, Max))
 
#define ITERATE2(Min, Max, Func, a1, a2)    IFEMPTY(, TOKCAT(_ITERATE_, Min)(Max, Func, 2,a1,a2,,,) , TOKCAT(_ITERATE_INIT_##Min##_, Max))
 
#define ITERATE3(Min, Max, Func, a1, a2, a3)    IFEMPTY(, TOKCAT(_ITERATE_, Min)(Max, Func, 3,a1,a2,a3,,) , TOKCAT(_ITERATE_INIT_##Min##_, Max))
 
#define ITERATE4(Min, Max, Func, a1, a2, a3, a4)    IFEMPTY(, TOKCAT(_ITERATE_, Min)(Max, Func, 4,a1,a2,a3,a4,) , TOKCAT(_ITERATE_INIT_##Min##_, Max))
 
#define ITERATE5(Min, Max, Func, a1, a2, a3, a4, a5)    IFEMPTY(, TOKCAT(_ITERATE_, Min)(Max, Func, 5,a1,a2,a3,a4,a5) , TOKCAT(_ITERATE_INIT_##Min##_, Max))
 

ITERATE_

Clone of ITERATE functions to allow for recursion.

Macros don't support recursion, ITERATE can't called from inside ITERATE. Instead, change the inner recursive call to ITERATE_ or ITERATE__.

#define ITERATE_(Min, Max, Func)    IFEMPTY(, TOKCAT(_ITERATE__, Min)(Max, Func, 0,,,,,) , TOKCAT(_ITERATE_INIT_##Min##_, Max))
 
#define ITERATE1_(Min, Max, Func, a1)    IFEMPTY(, TOKCAT(_ITERATE__, Min)(Max, Func, 1,a1,,,,) , TOKCAT(_ITERATE_INIT_##Min##_, Max))
 
#define ITERATE2_(Min, Max, Func, a1, a2)    IFEMPTY(, TOKCAT(_ITERATE__, Min)(Max, Func, 2,a1,a2,,,) , TOKCAT(_ITERATE_INIT_##Min##_, Max))
 
#define ITERATE3_(Min, Max, Func, a1, a2, a3)    IFEMPTY(, TOKCAT(_ITERATE__, Min)(Max, Func, 3,a1,a2,a3,,) , TOKCAT(_ITERATE_INIT_##Min##_, Max))
 
#define ITERATE4_(Min, Max, Func, a1, a2, a3, a4)    IFEMPTY(, TOKCAT(_ITERATE__, Min)(Max, Func, 4,a1,a2,a3,a4,) , TOKCAT(_ITERATE_INIT_##Min##_, Max))
 
#define ITERATE5_(Min, Max, Func, a1, a2, a3, a4, a5)    IFEMPTY(, TOKCAT(_ITERATE__, Min)(Max, Func, 5,a1,a2,a3,a4,a5) , TOKCAT(_ITERATE_INIT_##Min##_, Max))
 
#define ITERATE__(Min, Max, Func)    IFEMPTY(, TOKCAT(_ITERATE___, Min)(Max, Func, 0,,,,,) , TOKCAT(_ITERATE_INIT_##Min##_, Max))
 
#define ITERATE1__(Min, Max, Func, a1)    IFEMPTY(, TOKCAT(_ITERATE___, Min)(Max, Func, 1,a1,,,,) , TOKCAT(_ITERATE_INIT_##Min##_, Max))
 
#define ITERATE2__(Min, Max, Func, a1, a2)    IFEMPTY(, TOKCAT(_ITERATE___, Min)(Max, Func, 2,a1,a2,,,) , TOKCAT(_ITERATE_INIT_##Min##_, Max))
 
#define ITERATE3__(Min, Max, Func, a1, a2, a3)    IFEMPTY(, TOKCAT(_ITERATE___, Min)(Max, Func, 3,a1,a2,a3,,) , TOKCAT(_ITERATE_INIT_##Min##_, Max))
 
#define ITERATE4__(Min, Max, Func, a1, a2, a3, a4)    IFEMPTY(, TOKCAT(_ITERATE___, Min)(Max, Func, 4,a1,a2,a3,a4,) , TOKCAT(_ITERATE_INIT_##Min##_, Max))
 
#define ITERATE5__(Min, Max, Func, a1, a2, a3, a4, a5)    IFEMPTY(, TOKCAT(_ITERATE___, Min)(Max, Func, 5,a1,a2,a3,a4,a5) , TOKCAT(_ITERATE_INIT_##Min##_, Max))
 

Detailed Description

Macro Definition Documentation

#define COMMA   ,

Use to avoid macro interpreting a comma as an argument delimiter.

#define COMMA_IFNOT (   Num,
  CompareNum 
)    IFEQUAL(Num, CompareNum, EMPTY, COMMA)

If Num is not CompareNum, then this will evaluate to a comma. Useful for iteration over function parameters.

#define EMPTY

Symbol evaluates to nothing.

#define EMPTYFUNC (   ...)

Function evaluates to nothing.

#define EVAL (   ...)    __VA_ARGS__

Evaluate expression.

#define IFEMPTY (   True,
  False,
  ... 
)    TOKCAT(_IFEMPTY_CASE_, _ISEMPTY(__VA_ARGS__))(EVAL(True), EVAL(False))

Evaluate true or false depending on whether argument list is empty.

#define IFEQUAL (   Num,
  CompareNum,
  True,
  False 
)    IFEMPTY(EVAL(True), EVAL(False), TOKCAT(_ITERATE_, TOKCAT(Num, _##CompareNum)))

Evaluate True if Num == CompareNum, otherwise eval False.

#define ITERATE (   Min,
  Max,
  Func 
)    IFEMPTY(, TOKCAT(_ITERATE_, Min)(Max, Func, 0,,,,,) , TOKCAT(_ITERATE_INIT_##Min##_, Max))

Iterate calling Func(It, Args...) over range [Min, Max], where Min >= 0 and Max <= ITERATE_MAX. It is the current iteration number.

If Min > Max then iterate will do nothing, eg. Iterate(1,0,FUNC)

#define ITERATE1 (   Min,
  Max,
  Func,
  a1 
)    IFEMPTY(, TOKCAT(_ITERATE_, Min)(Max, Func, 1,a1,,,,) , TOKCAT(_ITERATE_INIT_##Min##_, Max))
#define ITERATE1_ (   Min,
  Max,
  Func,
  a1 
)    IFEMPTY(, TOKCAT(_ITERATE__, Min)(Max, Func, 1,a1,,,,) , TOKCAT(_ITERATE_INIT_##Min##_, Max))
#define ITERATE1__ (   Min,
  Max,
  Func,
  a1 
)    IFEMPTY(, TOKCAT(_ITERATE___, Min)(Max, Func, 1,a1,,,,) , TOKCAT(_ITERATE_INIT_##Min##_, Max))
#define ITERATE2 (   Min,
  Max,
  Func,
  a1,
  a2 
)    IFEMPTY(, TOKCAT(_ITERATE_, Min)(Max, Func, 2,a1,a2,,,) , TOKCAT(_ITERATE_INIT_##Min##_, Max))
#define ITERATE2_ (   Min,
  Max,
  Func,
  a1,
  a2 
)    IFEMPTY(, TOKCAT(_ITERATE__, Min)(Max, Func, 2,a1,a2,,,) , TOKCAT(_ITERATE_INIT_##Min##_, Max))
#define ITERATE2__ (   Min,
  Max,
  Func,
  a1,
  a2 
)    IFEMPTY(, TOKCAT(_ITERATE___, Min)(Max, Func, 2,a1,a2,,,) , TOKCAT(_ITERATE_INIT_##Min##_, Max))
#define ITERATE3 (   Min,
  Max,
  Func,
  a1,
  a2,
  a3 
)    IFEMPTY(, TOKCAT(_ITERATE_, Min)(Max, Func, 3,a1,a2,a3,,) , TOKCAT(_ITERATE_INIT_##Min##_, Max))
#define ITERATE3_ (   Min,
  Max,
  Func,
  a1,
  a2,
  a3 
)    IFEMPTY(, TOKCAT(_ITERATE__, Min)(Max, Func, 3,a1,a2,a3,,) , TOKCAT(_ITERATE_INIT_##Min##_, Max))
#define ITERATE3__ (   Min,
  Max,
  Func,
  a1,
  a2,
  a3 
)    IFEMPTY(, TOKCAT(_ITERATE___, Min)(Max, Func, 3,a1,a2,a3,,) , TOKCAT(_ITERATE_INIT_##Min##_, Max))
#define ITERATE4 (   Min,
  Max,
  Func,
  a1,
  a2,
  a3,
  a4 
)    IFEMPTY(, TOKCAT(_ITERATE_, Min)(Max, Func, 4,a1,a2,a3,a4,) , TOKCAT(_ITERATE_INIT_##Min##_, Max))
#define ITERATE4_ (   Min,
  Max,
  Func,
  a1,
  a2,
  a3,
  a4 
)    IFEMPTY(, TOKCAT(_ITERATE__, Min)(Max, Func, 4,a1,a2,a3,a4,) , TOKCAT(_ITERATE_INIT_##Min##_, Max))
#define ITERATE4__ (   Min,
  Max,
  Func,
  a1,
  a2,
  a3,
  a4 
)    IFEMPTY(, TOKCAT(_ITERATE___, Min)(Max, Func, 4,a1,a2,a3,a4,) , TOKCAT(_ITERATE_INIT_##Min##_, Max))
#define ITERATE5 (   Min,
  Max,
  Func,
  a1,
  a2,
  a3,
  a4,
  a5 
)    IFEMPTY(, TOKCAT(_ITERATE_, Min)(Max, Func, 5,a1,a2,a3,a4,a5) , TOKCAT(_ITERATE_INIT_##Min##_, Max))
#define ITERATE5_ (   Min,
  Max,
  Func,
  a1,
  a2,
  a3,
  a4,
  a5 
)    IFEMPTY(, TOKCAT(_ITERATE__, Min)(Max, Func, 5,a1,a2,a3,a4,a5) , TOKCAT(_ITERATE_INIT_##Min##_, Max))
#define ITERATE5__ (   Min,
  Max,
  Func,
  a1,
  a2,
  a3,
  a4,
  a5 
)    IFEMPTY(, TOKCAT(_ITERATE___, Min)(Max, Func, 5,a1,a2,a3,a4,a5) , TOKCAT(_ITERATE_INIT_##Min##_, Max))
#define ITERATE_ (   Min,
  Max,
  Func 
)    IFEMPTY(, TOKCAT(_ITERATE__, Min)(Max, Func, 0,,,,,) , TOKCAT(_ITERATE_INIT_##Min##_, Max))
#define ITERATE__ (   Min,
  Max,
  Func 
)    IFEMPTY(, TOKCAT(_ITERATE___, Min)(Max, Func, 0,,,,,) , TOKCAT(_ITERATE_INIT_##Min##_, Max))
#define ITERATE_MAX   20

Max number of iterations supported.

#define NUMARGS (   ...)    IFEMPTY(0, _NUMARGS(__VA_ARGS__), __VA_ARGS__)

Get number of arguments in list. Supports up to 10 args (limited because of high impact on compile-time).

#define PP_ADD (   Lhs,
  Rhs 
)    _ADD_0(Lhs, Rhs)

Add two values, result must be in range [0, ITERATE_MAX].

#define PP_SUB (   Lhs,
  Rhs 
)    _SUBTRACT_0(Lhs, Rhs)

Subtract two values in range [0, ITERATE_MAX].

#define STRINGIFY (   s)    STRINGIFY_(s)

Convert token to string.

#define TOKCAT (   a,
 
)    TOKCAT_(a, b)

Concatenate tokens together to form a new symbol.

#define TUPLE_ELEM (   t,
 
)    TOKCAT(_TUPLE_ELEM_,TUPLE_SIZE(t))_ ## i t

Get element in tuple. A tuple is a bracketed parameter list: (e0,e1,e2...). Supports up to 5 elements.

#define TUPLE_SIZE (   t)    EVAL(NUMARGS t)

Get number of elements in tuple.

#define UNBRACKET (   ...)    IFEQUAL(_UNBRACKET_TEST __VA_ARGS__, 1, EVAL __VA_ARGS__, __VA_ARGS__)

Remove brackets around parameter.