neuray API Programmer's Manual

base/assert.h File Reference

Description

Assertions and compile-time assertions. See Base API Assertions.

Code Example

base/assert.h

‎/***************************************************************************************************
 * Copyright 2023 NVIDIA Corporation. All rights reserved.
 **************************************************************************************************/

#ifndef MI_BASE_ASSERT_H
#define MI_BASE_ASSERT_H

#include <mi/base/config.h>

namespace mi {

namespace base {















#ifndef mi_static_assert
#ifdef _MSC_VER
// Special case for Visual Studio 7.1, since __LINE__ would not work.
#define mi_static_assert(expr)                                               \
    typedef mi::base::static_assert_test<static_cast<int>(                   \
        sizeof(mi::base::static_assert_failure<static_cast<bool>((expr))>))> \
            MI_BASE_JOIN(static_assert_instance, __COUNTER__)
#else // _MSC_VER
#ifdef MI_COMPILER_GCC
#define mi_static_assert_attribute __attribute__((unused))
#else
#define mi_static_assert_attribute
#endif
#define mi_static_assert(expr)                                               \
    typedef mi::base::static_assert_test<static_cast<int>(                   \
        sizeof(mi::base::static_assert_failure<static_cast<bool>((expr))>))> \
            MI_BASE_JOIN(static_assert_instance, __LINE__) mi_static_assert_attribute
#endif // _MSC_VER
#endif // mi_static_assert

// helper definitions for the mi_static_assert above.
template <bool> struct static_assert_failure;
template <>     struct static_assert_failure<true> {};
template <int>  struct static_assert_test {};

#if       defined( mi_base_assert) && ! defined( mi_base_assert_msg) \
     || ! defined( mi_base_assert) &&   defined( mi_base_assert_msg)
error "Only one of mi_base_assert and mi_base_assert_msg has been defined. Please define both."
#else
#ifndef mi_base_assert

#define mi_base_assert(expr) (static_cast<void>(0)) // valid but void null stmt

#define mi_base_assert_msg(expr, msg) (static_cast<void>(0)) // valid but void null stmt

// Just for doxygen, begin

#define mi_base_assert_enabled
#undef mi_base_assert_enabled

// Just for doxygen, end

#else // mi_base_assert

#define mi_base_assert_enabled

#endif // mi_base_assert
#endif // mi_base_assert xor mi_base_assert_msg

#if defined(__FUNCSIG__)
#  define MI_BASE_ASSERT_FUNCTION __FUNCSIG__
#elif defined( __cplusplus) && defined(__GNUC__) && defined(__GNUC_MINOR__) \
        && ((__GNUC__ << 16) + __GNUC_MINOR__ >= (2 << 16) + 6)
#  define MI_BASE_ASSERT_FUNCTION    __PRETTY_FUNCTION__
#else
#  if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
#    define MI_BASE_ASSERT_FUNCTION    __func__
#  else
#    define MI_BASE_ASSERT_FUNCTION    ("unknown")
#  endif
#endif
 // end group mi_base_assert

} // namespace base

} // namespace mi

#endif // MI_BASE_ASSERT_H

Namespaces

namespace 
Common namespace for APIs of NVIDIA Advanced Rendering Center GmbH. More...
namespace 
Namespace for the Base API. More...

Defines

#define  ("unknown")
Expands to a string constant that describes the function in which the macro has been expanded. More...
#define  ( expr) (static_cast<void>(0))
Base API assertion macro (without message). More...
#define 
Indicates whether assertions are actually enabled. More...
#define  ( expr, msg) (static_cast<void>(0))
Base API assertion macro (with message). More...
#define  ( expr)
Compile time assertion that raises a compilation error if the constant expression expr evaluates to false. More...