omni/graph/exec/unstable/Assert.h

File members: omni/graph/exec/unstable/Assert.h

// Copyright (c) 2022-2023, NVIDIA CORPORATION. All rights reserved.
//
// NVIDIA CORPORATION and its licensors retain all intellectual property
// and proprietary rights in and to this software, related documentation
// and any modifications thereto. Any use, reproduction, disclosure or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA CORPORATION is strictly prohibited.
//

#pragma once

#include <carb/Defines.h>
#include <carb/extras/Debugging.h>

#include <omni/Expected.h>
#include <omni/core/Assert.h>
#include <omni/core/ResultError.h>
#include <omni/graph/exec/unstable/IBase.h>

#define OMNI_GRAPH_EXEC_ASSERT(cond, ...) OMNI_ASSERT(cond, ##__VA_ARGS__)

#define OMNI_GRAPH_EXEC_FATAL_UNLESS_ARG(arg_)                                                                         \
    OMNI_FATAL_UNLESS((arg_), "argument '" CARB_STRINGIFY(arg_) "' must not be null")

#define OMNI_GRAPH_EXEC_FATAL_UNLESS(arg_, ...) OMNI_FATAL_UNLESS((arg_), "'" CARB_STRINGIFY(arg_) "' must be true")

#define OMNI_GRAPH_EXEC_FATAL(msg_) OMNI_FATAL_UNLESS(false, msg_)

#define OMNI_GRAPH_EXEC_CAST_OR_FATAL(var_, type_, obj_)                                                               \
    auto var_ = omni::graph::exec::unstable::cast<type_>(obj_);                                                        \
    OMNI_FATAL_UNLESS((var_), "'" CARB_STRINGIFY(obj_) "' must implement the '" CARB_STRINGIFY(type_) "' interface")

#define OMNI_STATIC_ASSERT_CAN_BE_PASSED_BY_VALUE_IN_ABI(type_)                                                        \
    static_assert(std::is_standard_layout<type_>::value,                                                               \
                  CARB_STRINGIFY(type_) " is expected to be passable by value in the abi (standard layout)");          \
    static_assert(std::is_trivially_copyable<type_>::value,                                                            \
                  CARB_STRINGIFY(type_) " is expected to be passable by value in the abi (trivially copyable)");       \
    static_assert(std::is_trivially_destructible<type_>::value,                                                        \
                  CARB_STRINGIFY(type_) " is expected to be passable by value in the abi (trivially destructible)")

#define OMNI_STATIC_ASSERT_MUST_BE_PASSED_BY_POINTER_IN_ABI(type_)                                                     \
    static_assert(std::is_standard_layout<type_>::value,                                                               \
                  CARB_STRINGIFY(type_) " is expected to be passable by pointer in the abi (standard layout)");        \
    static_assert(!(std::is_trivially_copyable<type_>::value && std::is_trivially_destructible<type_>::value),         \
                  CARB_STRINGIFY(type_) " can be passed by value in the ABI but is not marked as so")

#define OMNI_GRAPH_EXEC_RETURN_EXPECTED(expected_, unexpected_)                                                        \
    do                                                                                                                 \
    {                                                                                                                  \
        auto result_ = (unexpected_);                                                                                  \
        if (OMNI_SUCCEEDED(result_))                                                                                   \
        {                                                                                                              \
            return omni::expected<decltype(expected_), omni::core::Result>(expected_);                                 \
        }                                                                                                              \
        else                                                                                                           \
        {                                                                                                              \
            return omni::unexpected<omni::core::Result>(result_);                                                      \
        }                                                                                                              \
    } while (0)