rcolyer.net
RC Lib  Version 202403231100
Namespaces | Macros | Functions
Macros.h File Reference

Provides a set of convenience macros for metaprogramming and debugging. More...

#include "RCconfig.h"
#include <dlfcn.h>

Go to the source code of this file.

Namespaces

 RC
 

Macros

#define RC_NOP(...)   __VA_ARGS__
 Evaluates to whatever is passed in. Does no operation.
 
#define RC_CAT(a, b)   RC_CAT_HELP(a,b)
 Concatenates two tokens.
 
#define RC_EMPTY(...)   RC_EMPTY_HELP(RC_EMPTY_HELP2(__VA_ARGS__))
 Returns 1 if no arguments passed, 0 if arguments are passed.
 
#define RC_ARGS_NUM(...)   RC_ARGNUMCAT(RC_ARGS_EVAL,RC_EMPTY(__VA_ARGS__))(__VA_ARGS__)
 Returns the number of arguments passed to the macro, from 0 to 63.
 
#define RC_ARGS_EACH(Macro, ...)   RC_EV(RC_ARGS_EACH_HELP(RC_EMPTY(__VA_ARGS__))(Macro,__VA_ARGS__))
 Does RC_ARGS_EACH(Macro,a,b,c) --> Macro(a)Macro(b)Macro(c), for any number of parameters up to 342 or compiler limits.
 
#define RC_ARGS_BET(func, bet, ...)   RC_ARGS_BET_HELP(func,bet,__VA_ARGS__)
 Does RC_ARGS_BET(Func,Between,a,b,c) --> Func(a)Between Func(b)Between Func(c) More...
 
#define RC_ARGS_LIST(func, ...)   RC_EV(RC_ARGS_LIST_FIRST(RC_EMPTY(__VA_ARGS__))(func,__VA_ARGS__))
 Does RC_ARGS_LIST(Func,a,b,c) --> Func(a),Func(b),Func(c) More...
 
#define RC_ARGS_PAIR(odd, even, ...)   RC_EV(RC_ARGS_PAIR_FIRST(RC_EMPTY(__VA_ARGS__))(odd,even,__VA_ARGS__))
 Does RC_ARGS_PAIR(Odd,Even,a,b,c,d) --> Odd(a)Even(b),Odd(c)Even(d) More...
 
#define RC_ARGS_DECLIST(...)   RC_ARGS_PAIR(RC_NOP,RC_NOP,__VA_ARGS__)
 Does "RC_ARGS_DECLIST(int,a,int,b)" --> "int a,int b".
 
#define RC_ARGS_PARAMLIST(...)   RC_ARGS_PAIR(RC_ARGS_EAT,RC_NOP,__VA_ARGS__)
 Does "RC_ARGS_PARAMLIST(int,a,int,b)" --> "a,b".
 
#define RC_DEBOUT(...)   RC_DEBOUT_STREAM << __FILE__ << ":" << __LINE__ RC_ARGS_EACH(RC_DEBOUT_HELP,__VA_ARGS__) << std::endl;
 Use RC_DEBOUT(var1, ..., varN) for a flushed stderr debug printout of variables. More...
 
#define RC_UNUSED_PARAM(v)   v __attribute__((unused))
 Use in function headers as void func(int RC_UNUSED_PARAM(x)) to suppress warnings about non-use.
 
#define RC_DYNAMIC_LOAD_FUNC_RAW(FuncName, Library)
 Use as RC_DYNAMIC_LOAD_FUNC_RAW(FuncName,Library) to load FuncName from the dynamic library file Library. More...
 
#define RC_CONSTWRAP(Ret, Func, ...)   RC_CONSTWRAP_HELP(Ret,Func,__LINE__,__VA_ARGS__)
 Use to metaprogrammatically generate paired const and non-const getters. More...
 
#define RC_GetTc(T)
 Generates wrappers for const Get_T functions. More...
 
#define RC_GetT(T)
 Generates wrappers for Get_T functions. More...
 
#define RC_DEFAULT_COMPARISON()
 Given == and <, generates !=, >, <=, and >=. More...
 
#define RC_STREAM_RAWWRAP(Type)
 Provides stream output for a class via Raw. More...
 
#define RC_DefaultCopyMove(ClassName)
 Provides explicit default copy and move constructors and assignment. More...
 
#define RC_ForIndex(i, cont)   for (decltype(cont.size()) i = 0; i < cont.size(); ++i)
 Creates i of type equivalent to cont.size(), and loops over [0,cont.size). Use like: RC_ForIndex(i, cont) { cout << cont[i]; }.
 
#define RC_ForEach(e, cont)   for(decltype(cont.size()) RC_ForEach_i=0; RC_ForEach_i<cont.size(); ++RC_ForEach_i)if(bool RC_ForEach_b=false);else for(auto&& e=cont[RC_ForEach_i];RC_ForEach_b^=1;)
 Provides element auto&& e derived from the cont operator[], and loops over [0,cont.size). Like a range-based for loop, but using operator[]. Use like: RC_ForEach(e, cont) { cout << e; }.
 
#define RC_ForRange(i, start, past_end)   for (decltype(past_end) i = start; i < past_end; ++i)
 Creates a for loop over i with type deduction from the past_end.
 
#define RC_Repeat(times)   for (decltype(times) RC_Repeat_i = 0; RC_Repeat_i < times; ++RC_Repeat_i)
 Repeats the following block the specified times, with automatic type deduction.
 

Functions

template<class T >
void RC::UnusedVar (const T &)
 Mark an unused variable to suppress warnings.
 

Detailed Description

Provides a set of convenience macros for metaprogramming and debugging.

Macro Definition Documentation

◆ RC_ARGS_BET

#define RC_ARGS_BET (   func,
  bet,
  ... 
)    RC_ARGS_BET_HELP(func,bet,__VA_ARGS__)

Does RC_ARGS_BET(Func,Between,a,b,c) --> Func(a)Between Func(b)Between Func(c)

For example: cout RC_ARGS_BET(<< int, << ", ", 1.4, 2.5, 3.6); --> cout << int(1.4) << ", " << int(2.5) << ", " << int(3.5);

See also
RC_ARGS_EACH

◆ RC_ARGS_LIST

#define RC_ARGS_LIST (   func,
  ... 
)    RC_EV(RC_ARGS_LIST_FIRST(RC_EMPTY(__VA_ARGS__))(func,__VA_ARGS__))

Does RC_ARGS_LIST(Func,a,b,c) --> Func(a),Func(b),Func(c)

See also
RC_ARGS_EACH

◆ RC_ARGS_PAIR

#define RC_ARGS_PAIR (   odd,
  even,
  ... 
)    RC_EV(RC_ARGS_PAIR_FIRST(RC_EMPTY(__VA_ARGS__))(odd,even,__VA_ARGS__))

Does RC_ARGS_PAIR(Odd,Even,a,b,c,d) --> Odd(a)Even(b),Odd(c)Even(d)

See also
RC_ARGS_LIST

◆ RC_CONSTWRAP

#define RC_CONSTWRAP (   Ret,
  Func,
  ... 
)    RC_CONSTWRAP_HELP(Ret,Func,__LINE__,__VA_ARGS__)

Use to metaprogrammatically generate paired const and non-const getters.

The first parameter is the return type, and the second the function name. Subsequent parameters are pairs of type and variable name for function parameters. Access member variable x with "self.x". E.g.: RC_CONSTWRAP(int&, MyFunc, size_t, index) { return self.array[index]; }

◆ RC_DEBOUT

#define RC_DEBOUT (   ...)    RC_DEBOUT_STREAM << __FILE__ << ":" << __LINE__ RC_ARGS_EACH(RC_DEBOUT_HELP,__VA_ARGS__) << std::endl;

Use RC_DEBOUT(var1, ..., varN) for a flushed stderr debug printout of variables.

This also prints the file name and line number, and can be used to mark when execution reaches a point with no variables as RC_DEBOUT(). The default destination stream of std::cerr can be changed by defining RC_DEBOUT_STREAM in RCconfig.h or earlier.

◆ RC_DEFAULT_COMPARISON

#define RC_DEFAULT_COMPARISON ( )
Value:
/** \brief True if not equal. */ \
template<class AnyValidType> \
inline bool operator!= (const AnyValidType& other) const { \
return !((*this) == other); \
} \
/** \brief True if other is less than this object. */ \
template<class AnyValidType> \
inline bool operator> (const AnyValidType& other) const { \
return other < (*this); \
} \
/** \brief True if other is not less than this object. */ \
template<class AnyValidType> \
inline bool operator<= (const AnyValidType& other) const { \
return !(other < (*this)); \
} \
/** \brief True if this object is not less than other. */ \
template<class AnyValidType> \
inline bool operator>= (const AnyValidType& other) const { \
return !((*this) < other); \
}
bool operator!=(const RStr &lhs, const RStr &rhs)
True if lhs does not equal rhs.
Definition: RStr.h:2276
bool operator>(const RStr &lhs, const RStr &rhs)
True if lhs is greater than rhs.
Definition: RStr.h:2286
bool operator>=(const RStr &lhs, const RStr &rhs)
True if lhs is greater than or equal to rhs.
Definition: RStr.h:2296
bool operator<=(const RStr &lhs, const RStr &rhs)
True if lhs is less than or equal to rhs.
Definition: RStr.h:2291

Given == and <, generates !=, >, <=, and >=.

◆ RC_DefaultCopyMove

#define RC_DefaultCopyMove (   ClassName)
Value:
/** \brief Default copy constructor. */ \
ClassName(const ClassName&) = default; \
/** \brief Default move constructor. */ \
ClassName(ClassName&&) = default; \
/** \brief Default copy assignment operator. */ \
ClassName& operator=(const ClassName&) & = default; \
/** \brief Default move assignment operator. */ \
ClassName& operator=(ClassName&&) & = default;

Provides explicit default copy and move constructors and assignment.

◆ RC_DYNAMIC_LOAD_FUNC_RAW

#define RC_DYNAMIC_LOAD_FUNC_RAW (   FuncName,
  Library 
)
Value:
void* FuncName##_library = dlopen(Library, RTLD_LAZY | RTLD_GLOBAL); \
static decltype(&FuncName) FuncName = (FuncName##_library) ? \
reinterpret_cast<decltype(FuncName)> \
(dlsym(FuncName##_library,#FuncName)): 0;

Use as RC_DYNAMIC_LOAD_FUNC_RAW(FuncName,Library) to load FuncName from the dynamic library file Library.

This creates a static function pointer named FuncName in-place to provide access to the loaded library. As it overrides FuncName, the previous declaration of FuncName MUST be in an outer scope (outside of the function where this is called). For example, include the original definition from a header, and use this inside of a function or namespace. After this macro, call FuncName with the same syntax as you would the previously declared FuncName. This macro is defined for both Linux and Windows. In the event of an error, FuncName is null. This must be checked in the current version of this macro. A safer version with exception throws is RC_DYNAMIC_LOAD_FUNC.

◆ RC_GetT

#define RC_GetT (   T)
Value:
/** \brief Overloaded function to extract type T from this class.
@param x The reference to which the value will be assigned. */ \
inline void Get(T &x) { x = Get_##T(); }

Generates wrappers for Get_T functions.

◆ RC_GetTc

#define RC_GetTc (   T)
Value:
/** \brief Overloaded function to extract type T from this class.
@param x The reference to which the value will be assigned. */ \
inline void Get(T &x) const { x = Get_##T(); }

Generates wrappers for const Get_T functions.

◆ RC_STREAM_RAWWRAP

#define RC_STREAM_RAWWRAP (   Type)
Value:
/** \brief A convenience stream output for displaying the enclosed \
object. */ \
template <class T> \
inline std::ostream& operator<< (std::ostream &out, Type<T> obj) { \
return (out << obj.Raw()); \
}
std::ostream & operator<<(std::ostream &out, APtr< T > obj)
A convenience stream output for displaying the enclosed object.
Definition: APtr.h:120

Provides stream output for a class via Raw.

email address
— (c) 2015