Program Listing for File macros.hpp

Return to documentation for file (rcppsw/common/macros.hpp)

#pragma once

/*******************************************************************************
 * Includes
 ******************************************************************************/
#include "rcsw/common/common.h"

/*******************************************************************************
 * General Macros
 ******************************************************************************/
#define NS_START_(ns) namespace ns {
#define NS_END_(ns) }

#define NS_START(...) RCSW_XFOR_EACH1(NS_START_, __VA_ARGS__)

#define NS_END(...) RCSW_XFOR_EACH1(NS_END_, __VA_ARGS__)

#define RCPPSW_PTRREF_DECLDEF_CONST(Func, Member)                       \
  std::add_pointer<const decltype(Member)>::type Func(void) const {           \
    return &Member;                                                     \
  }

#define RCPPSW_PTRREF_DECLDEF(Func, Member, ...)                       \
  std::add_pointer<__VA_ARGS__ decltype(Member)>::type Func(void) {     \
    return &Member;                                                     \
  }

#define RCPPSW_WRAP_DECLDEF(Func, Callable, ...)                                \
  RCPPSW_WRAP_DECLDEF_AS(Func, Callable, Func, __VA_ARGS__)

#define RCPPSW_WRAP_DECLDEF_AS(Func, Callable, NewName, ...)            \
  template <typename... Args>                                           \
  auto NewName(Args&&... args)                                          \
      __VA_ARGS__->decltype(std::declval<decltype(Callable)>().Func(args...)) { \
    return (Callable).Func(std::forward<Args>(args)...);                \
  }

#define RCPPSW_WRAP_DECLDEF_OVERRIDE(Func, Callable, ...)                 \
  auto Func(void)                                                       \
      __VA_ARGS__->decltype(std::declval<decltype(Callable)>().Func()) override { \
    return (Callable).Func();                                             \
  }

#define RCPPSW_WRAP_DECL(Ret, Func, ...) Ret Func(void) __VA_ARGS__

#define RCPPSW_WRAP_DEF(Class, Func, Handle, ...)                      \
  auto Class::Func(void)                                               \
      __VA_ARGS__->decltype(std::declval<decltype(Handle)>().Func()) { \
    return (Handle).Func();                                            \
  }

#define RCPPSW_WRAP_DEFP(Class, Func, Handle, NullRet, ...)             \
  auto Class::Func(void)                                                \
      __VA_ARGS__->decltype(std::declval<decltype(*Handle)>().Func()) { \
    if (nullptr == Handle) {                                            \
      return NullRet;                                                   \
    }                                                                   \
    return (Handle)->Func();                                            \
  }

#define RCPPSW_WRAP_DECL_OVERRIDE(Ret, Func, ...) \
  Ret Func(void) __VA_ARGS__ override RCPPSW_PURE

#define RCPPSW_WRAP_DEF_OVERRIDE(Class, Func, Handle, ...) \
  RCPPSW_WRAP_DEF(Class, Func, Handle, __VA_ARGS__)

#define RCPPSW_WRAP_DEFP_OVERRIDE(Class, Func, Handle, NullRet, ...) \
  RCPPSW_WRAP_DEFP(Class, Func, Handle, NullRet, __VA_ARGS__)

#define RCPPSW_IS_ODD(n) RCSW_IS_ODD(n)

/*******************************************************************************
 * Compiler Macros
 ******************************************************************************/
#define RCPPSW_CONST RCSW_CONST
#define RCPPSW_COLD RCSW_COLD
#define RCPPSW_PURE RCSW_PURE
#define RCPPSW_DEAD RCSW_DEAD
#define RCPPSW_UNUSED RCSW_UNUSED
#define RCPPSW_EXPORT RCSW_EXPORT

#define RCPPSW_NODISCARD [[nodiscard]]

#define RCPPSW_LIB_INIT __attribute__((constructor))

#define RCPPSW_LIB_FINI __attribute__((destructor))

#define RCPPSW_ATTR(...) RCSW_ATTR(__VA_ARGS__)
#define RCPPSW_CHECK(cond) RCSW_CHECK(cond)
#define RCPPSW_IS_BETWEENC(n, lb, ub) RCSW_IS_BETWEENC(n, lb, ub)
#define RCPPSW_LIKELY(cond) RCSW_LIKELY(cond)
#define RCPPSW_UNLIKELY(cond) RCSW_UNLIKELY(cond)
#define RCPPSW_FPC_RET_V(cond) RCSW_FPC_RET_V(cond)
#define RCPPSW_IS_EVEN(n) RCSW_IS_EVEN(n)
#define RCPPSW_JOIN(x, y) RCSW_JOIN(x, y)

/*******************************************************************************
 * Warning Disable Macros
 ******************************************************************************/
#define RCPPSW_WARNING_DISABLE_PUSH(...) RCSW_WARNING_DISABLE_PUSH(__VA_ARGS__)

#define RCPPSW_WARNING_DISABLE_POP(...) RCSW_WARNING_DISABLE_POP(__VA_ARGS__)

#define RCPPSW_WARNING_DISABLE(...) RCSW_WARNING_DISABLE(__VA_ARGS__)

/* clang-format off */

#if defined(__INTEL_COMPILER)

#define RCPPSW_WARNING_DISABLE_MISSING_VAR_DECL(...)

#define RCPPSW_WARNING_DISABLE_MISSING_PROTOTYPE(...) \
  RCPPSW_WARNING_DISABLE(1418)

#define RCPPSW_WARNING_DISABLE_GLOBAL_CTOR(...)

#define RCPPSW_WARNING_DISABLE_SUGGEST_OVERRIDE(...)

#define RCPPSW_WARNING_DISABLE_USELESS_CAST(...)

#define RCPPSW_WARNING_DISABLE_OLD_STYLE_CAST(...)

#elif defined(__clang__)

#define RCPPSW_WARNING_DISABLE_MISSING_VAR_DECL(...) \
  RCPPSW_WARNING_DISABLE(-Wmissing-variable-declarations)

#define RCPPSW_WARNING_DISABLE_MISSING_PROTOTYPE(...) \
  RCPPSW_WARNING_DISABLE(-Wmissing-prototypes)

#define RCPPSW_WARNING_DISABLE_GLOBAL_CTOR(...) \
  RCPPSW_WARNING_DISABLE(-Wglobal-constructors)

#define RCPPSW_WARNING_DISABLE_OVERLOADED_VIRTUAL(...)

#define RCPPSW_WARNING_DISABLE_EFFCXX(...)      \
  RCPPSW_WARNING_DISABLE(-Weffc++)

#define RCPPSW_WARNING_DISABLE_SUGGEST_OVERRIDE(...)

#define RCPPSW_WARNING_DISABLE_USELESS_CAST(...)

#define RCPPSW_WARNING_DISABLE_OLD_STYLE_CAST(...)

#elif defined(__GNUC__)

#define RCPPSW_WARNING_DISABLE_MISSING_VAR_DECL(...)

#define RCPPSW_WARNING_DISABLE_MISSING_PROTOTYPE(...)

#define RCPPSW_WARNING_DISABLE_GLOBAL_CTOR(...)

#define RCPPSW_WARNING_DISABLE_OVERLOADED_VIRTUAL(...) \
  RCPPSW_WARNING_DISABLE(-Woverloaded-virtual)

#define RCPPSW_WARNING_DISABLE_EFFCXX(...) \
  RCPPSW_WARNING_DISABLE(-Weffc++)

#define RCPPSW_WARNING_DISABLE_SUGGEST_OVERRIDE(...) \
  RCPPSW_WARNING_DISABLE(-Wsuggest-override)

#define RCPPSW_WARNING_DISABLE_USELESS_CAST(...) \
  RCPPSW_WARNING_DISABLE(-Wuseless-cast)

#define RCPPSW_WARNING_DISABLE_OLD_STYLE_CAST(...) \
  RCPPSW_WARNING_DISABLE(-Wold-style-cast)

#endif /* __INTEL_COMPILER__ */
/* clang-format on */