carb/assert/AssertUtils.h

File members: carb/assert/AssertUtils.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

#include "../Framework.h"

#define CARB_ASSERT_GLOBALS()

namespace carb
{
namespace assert
{

inline void registerAssertForClient() noexcept
{
    g_carbAssert = getFramework()->tryAcquireInterface<IAssert>();
}

inline void deregisterAssertForClient() noexcept
{
    g_carbAssert = nullptr;
}

inline bool disableDialog(bool disable)
{
    if (g_carbAssert)
    {
        return !!(g_carbAssert->setAssertionFlags(disable ? fAssertSkipDialog : 0, disable ? 0 : fAssertSkipDialog) &
                  fAssertSkipDialog);
    }
    return false;
}

inline bool useBreakpoint(bool enabled)
{
    if (g_carbAssert)
    {
        return !(g_carbAssert->setAssertionFlags(enabled ? 0 : fAssertSkipBreakpoint, enabled ? fAssertSkipBreakpoint : 0) &
                 fAssertSkipBreakpoint);
    }
    return true;
}

inline bool showToConsole(bool enabled)
{
    if (g_carbAssert)
    {
        return !(g_carbAssert->setAssertionFlags(enabled ? 0 : fAssertNoConsole, enabled ? fAssertNoConsole : 0) &
                 fAssertNoConsole);
    }
    return true;
}

inline uint64_t getFailureCount()
{
    return g_carbAssert ? g_carbAssert->getAssertionFailureCount() : 0;
}

} // namespace assert
} // namespace carb