carb/assert/IAssert.h

File members: carb/assert/IAssert.h

// Copyright (c) 2019-2022, 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

// NOTE: this interface is included and used in a very low level header.  No more headers than are
//       absolutely necessary should be included from here.
#include "../Interface.h"

#include <stdarg.h>

namespace carb
{
namespace assert
{

using AssertFlags = uint32_t;

constexpr AssertFlags fAssertSkipDialog = 0x00000001;

constexpr AssertFlags fAssertSkipBreakpoint = 0x00000002;

constexpr AssertFlags fAssertNoConsole = 0x00000004;

struct IAssert
{
    CARB_PLUGIN_INTERFACE("carb::assert::IAssert", 1, 0)

    AssertFlags(CARB_ABI* setAssertionFlags)(AssertFlags set, AssertFlags clear);

    uint64_t(CARB_ABI* getAssertionFailureCount)();

    bool(CARB_ABI* reportFailedAssertionV)(
        const char* condition, const char* file, const char* func, int32_t line, const char* fmt, ...);

    bool reportFailedAssertion(
        const char* condition, const char* file, const char* func, int32_t line, const char* fmt = nullptr, ...)
    {
        va_list args;
        bool result;

        va_start(args, fmt);
        result = reportFailedAssertionV(condition, file, func, line, fmt, &args);
        va_end(args);
        return result;
    }
};

} // namespace assert
} // namespace carb

CARB_WEAKLINK CARB_HIDDEN carb::assert::IAssert* g_carbAssert;