Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions includes/rtm/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#pragma once

////////////////////////////////////////////////////////////////////////////////
// The MIT License (MIT)
//
// Copyright (c) 2025 Nicholas Frechette & Realtime Math contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
////////////////////////////////////////////////////////////////////////////////

// This file gathers all defines that can be used to control RTM's behavior
// along with context.

//////////////////////////////////////////////////////////////////////////
// This library uses a simple system to handle asserts. Asserts are fatal and must terminate
// otherwise the behavior is undefined if execution continues.
//
// A total of 4 behaviors are supported:
// - We can print to stderr and abort
// - We can throw and exception
// - We can call a custom function
// - Do nothing and strip the check at compile time (default behavior)
//
// Aborting:
// In order to enable the aborting behavior, simply define the macro RTM_ON_ASSERT_ABORT:
// #define RTM_ON_ASSERT_ABORT
//
// Throwing:
// In order to enable the throwing behavior, simply define the macro RTM_ON_ASSERT_THROW:
// #define RTM_ON_ASSERT_THROW
// Note that the type of the exception thrown is rtm::runtime_assert.
//
// Custom function:
// In order to enable the custom function calling behavior, define the macro RTM_ON_ASSERT_CUSTOM
// with the name of the function to call:
// #define RTM_ON_ASSERT_CUSTOM on_custom_assert_impl
// Note that the function signature is as follow:
// void on_custom_assert_impl(const char* expression, int line, const char* file, const char* format, ...) {}
//
// You can also define your own assert implementation by defining the RTM_ASSERT macro as well:
// #define RTM_ON_ASSERT_CUSTOM
// #define RTM_ASSERT(expression, format, ...) checkf(expression, ANSI_TO_TCHAR(format), #__VA_ARGS__)
//
// [Custom String Format Specifier]
// Note that if you use a custom function, you may need to override the RTM_ASSERT_STRING_FORMAT_SPECIFIER
// to properly handle ANSI/Unicode support. The C++11 standard does not support a way to say that '%s'
// always means an ANSI string (with 'const char*' as type). MSVC does support '%hs' but other compilers
// do not.
//
// No checks:
// By default if no macro mentioned above is defined, all asserts will be stripped
// at compile time.
//////////////////////////////////////////////////////////////////////////

// You can uncomment one of these or specify it on the compilation command line
//#define RTM_ON_ASSERT_ABORT
//#define RTM_ON_ASSERT_THROW
//#define RTM_ON_ASSERT_CUSTOM(expression, line, file, format, ...) (void)expression

// See [Custom String Format Specifier] for details
#if !defined(RTM_ASSERT_STRING_FORMAT_SPECIFIER)
#define RTM_ASSERT_STRING_FORMAT_SPECIFIER "%s"
#endif

// You can disable deprecation warnings by defining RTM_NO_DEPRECATION
//#define RTM_NO_DEPRECATION

// By default, RTM uses the intrinsics of the target platform as specified on the
// compiler command line. You can disable SIMD intrinsic usage by defining RTM_NO_INTRINSICS
//#define RTM_NO_INTRINSICS

// If you use C++20 or greater, you can disable std::bit_cast usage by defining RTM_NO_BIT_CAST
// This is sometimes necessary if you compile with a modern compiler but use an older stdlib
// that does not contain the bit_cast header
//#define RTM_NO_BIT_CAST
6 changes: 4 additions & 2 deletions includes/rtm/impl/bit_cast.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@
// SOFTWARE.
////////////////////////////////////////////////////////////////////////////////

#include "rtm/config.h"
#include "rtm/version.h"
#include "rtm/impl/compiler_utils.h"
#include "rtm/impl/detect_cpp_version.h"

#if RTM_CPP_VERSION >= RTM_CPP_VERSION_20
// Use RTM_NO_BIT_CAST to disable std::bit_cast
#if RTM_CPP_VERSION >= RTM_CPP_VERSION_20 && !defined(RTM_NO_BIT_CAST)
#include <bit>
#endif

Expand All @@ -44,7 +46,7 @@ namespace rtm
// C++20 introduced std::bit_cast which is safer than reinterpret_cast
//////////////////////////////////////////////////////////////////////////

#if RTM_CPP_VERSION >= RTM_CPP_VERSION_20
#if RTM_CPP_VERSION >= RTM_CPP_VERSION_20 && !defined(RTM_NO_BIT_CAST)
using std::bit_cast;
#else
template<class dest_type_t, class src_type_t>
Expand Down
47 changes: 2 additions & 45 deletions includes/rtm/impl/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,58 +25,15 @@
// SOFTWARE.
////////////////////////////////////////////////////////////////////////////////

#include "rtm/config.h"
#include "rtm/version.h"
#include "rtm/impl/compiler_utils.h"
#include "rtm/impl/detect_compiler.h"
#include "rtm/impl/detect_cpp_version.h"

RTM_IMPL_FILE_PRAGMA_PUSH

//////////////////////////////////////////////////////////////////////////
// This library uses a simple system to handle asserts. Asserts are fatal and must terminate
// otherwise the behavior is undefined if execution continues.
//
// A total of 4 behaviors are supported:
// - We can print to stderr and abort
// - We can throw and exception
// - We can call a custom function
// - Do nothing and strip the check at compile time (default behavior)
//
// Aborting:
// In order to enable the aborting behavior, simply define the macro RTM_ON_ASSERT_ABORT:
// #define RTM_ON_ASSERT_ABORT
//
// Throwing:
// In order to enable the throwing behavior, simply define the macro RTM_ON_ASSERT_THROW:
// #define RTM_ON_ASSERT_THROW
// Note that the type of the exception thrown is rtm::runtime_assert.
//
// Custom function:
// In order to enable the custom function calling behavior, define the macro RTM_ON_ASSERT_CUSTOM
// with the name of the function to call:
// #define RTM_ON_ASSERT_CUSTOM on_custom_assert_impl
// Note that the function signature is as follow:
// void on_custom_assert_impl(const char* expression, int line, const char* file, const char* format, ...) {}
//
// You can also define your own assert implementation by defining the RTM_ASSERT macro as well:
// #define RTM_ON_ASSERT_CUSTOM
// #define RTM_ASSERT(expression, format, ...) checkf(expression, ANSI_TO_TCHAR(format), #__VA_ARGS__)
//
// [Custom String Format Specifier]
// Note that if you use a custom function, you may need to override the RTM_ASSERT_STRING_FORMAT_SPECIFIER
// to properly handle ANSI/Unicode support. The C++11 standard does not support a way to say that '%s'
// always means an ANSI string (with 'const char*' as type). MSVC does support '%hs' but other compilers
// do not.
//
// No checks:
// By default if no macro mentioned above is defined, all asserts will be stripped
// at compile time.
//////////////////////////////////////////////////////////////////////////

// See [Custom String Format Specifier] for details
#if !defined(RTM_ASSERT_STRING_FORMAT_SPECIFIER)
#define RTM_ASSERT_STRING_FORMAT_SPECIFIER "%s"
#endif
// See config.h for details on how to configure asserts for your project

#if defined(RTM_ON_ASSERT_ABORT)

Expand Down
1 change: 1 addition & 0 deletions includes/rtm/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
// SOFTWARE.
////////////////////////////////////////////////////////////////////////////////

#include "rtm/config.h"
#include "rtm/impl/detect_arch.h"
#include "rtm/impl/detect_compiler.h"

Expand Down
Loading