Program Listing for File fpc.h

Return to documentation for file (rcsw/common/fpc.h)

#pragma once

/*******************************************************************************
 * Includes
 ******************************************************************************/
#include <assert.h>
#include "rcsw/rcsw.h"

/*******************************************************************************
 * Constant Definitions
 ******************************************************************************/
/* \cond INTERNAL */
#define LIBRA_FPC_NONE 0
#define LIBRA_FPC_ABORT 1
#define LIBRA_FPC_RETURN 2

#if defined(LIBRA_FPC_INHERIT) && !defined(LIBRA_FPC)
#error LIBRA_FPC_INHERIT defined but LIBRA_FPC not defined!
#endif

/*
 * If rcsw is used in a context where this is not defined it is almost
 * assuredly an error, buuuttttt RCSW might be needed to compile in weird
 * environments.
 */
#if !defined(LIBRA_FPC)
#define LIBRA_FPC LIBRA_FPC_RETURN
#endif
/* \endcond */

#define RCSW_FPC LIBRA_FPC

#define RCSW_FPC_RETURN LIBRA_FPC_RETURN

#define RCSW_FPC_ABORT LIBRA_FPC_ABORT

#define RCSW_FPC_NONE LIBRA_FPC_NONE

/*******************************************************************************
 * Function Precondition Checking Macros
 ******************************************************************************/
#define RCSW_FPC_RET_NV(X, v)                                        \
  {                                                                  \
    if (!RCSW_UNLIKELY(X)) {                                         \
      errno = EINVAL;                                                \
      return v;                                                      \
    }                                                                \
  }

#define RCSW_FPC_RET_V(X)                       \
  {                                             \
    if (!RCSW_UNLIKELY(X)) {                    \
      errno = EINVAL;                           \
      return;                                   \
    }                                           \
  }

#define RCSW_FPC_ASSERT(X) { assert(X); }

#define RCSW_FPC_ABORT_NV(X, v) RCSW_FPC_ASSERT(X)

#define RCSW_FPC_ABORT_V(X) RCSW_FPC_ASSERT(X)

#if(RCSW_FPC == RCSW_FPC_RETURN)

#define RCSW_FPC_NV(v, ...)                             \
  { RCSW_XFOR_EACH2(RCSW_FPC_RET_NV, v, __VA_ARGS__); }

#define RCSW_FPC_V(...)                                 \
  { RCSW_XFOR_EACH1(RCSW_FPC_RET_V, __VA_ARGS__); }

#elif(RCSW_FPC == RCSW_FPC_ABORT)

#define RCSW_FPC_NV(v, ...)                                     \
  { RCSW_XFOR_EACH2(RCSW_FPC_ABORT_NV, v, __VA_ARGS__); }

#define RCSW_FPC_V(...)                                 \
    { RCSW_XFOR_EACH1(RCSW_FPC_ABORT_V, __VA_ARGS__); }

#else

#define RCSW_FPC_NV(v, ...)
#define RCSW_FPC_V(...)

#endif /* RCSW_FPC */