WPILibC++ 2025.1.1
Loading...
Searching...
No Matches
config.hpp
Go to the documentation of this file.
1// Copyright (C) 2015-2023 Jonathan Müller and foonathan/memory contributors
2// SPDX-License-Identifier: Zlib
3
4/// \file
5/// Configuration macros.
6
7#ifndef WPI_MEMORY_CONFIG_HPP_INCLUDED
8#define WPI_MEMORY_CONFIG_HPP_INCLUDED
9
10#include <cstddef>
11
12#if !defined(DOXYGEN)
13#define WPI_MEMORY_IMPL_IN_CONFIG_HPP
14#include "config_impl.hpp"
15#undef WPI_MEMORY_IMPL_IN_CONFIG_HPP
16#endif
17
18// exception support
19#ifndef WPI_HAS_EXCEPTION_SUPPORT
20#if defined(__GNUC__) && !defined(__EXCEPTIONS)
21#define WPI_HAS_EXCEPTION_SUPPORT 0
22#elif defined(_MSC_VER) && !_HAS_EXCEPTIONS
23#define WPI_HAS_EXCEPTION_SUPPORT 0
24#else
25#define WPI_HAS_EXCEPTION_SUPPORT 1
26#endif
27#endif
28
29#if WPI_HAS_EXCEPTION_SUPPORT
30#define WPI_THROW(Ex) throw(Ex)
31#else
32#include <cstdlib>
33#define WPI_THROW(Ex) ((Ex), std::abort())
34#endif
35
36// hosted implementation
37#ifndef WPI_HOSTED_IMPLEMENTATION
38#if !_MSC_VER && !__STDC_HOSTED__
39#define WPI_HOSTED_IMPLEMENTATION 0
40#else
41#define WPI_HOSTED_IMPLEMENTATION 1
42#endif
43#endif
44
45// log prefix
46#define WPI_MEMORY_LOG_PREFIX "wpi::memory"
47
48// version
49#define WPI_MEMORY_VERSION \
50 (WPI_MEMORY_VERSION_MAJOR * 100 + WPI_MEMORY_VERSION_MINOR)
51
52// use this macro to mark implementation-defined types
53// gives it more semantics and useful with doxygen
54// add PREDEFINED: WPI_IMPL_DEFINED():=implementation_defined
55#ifndef WPI_IMPL_DEFINED
56#define WPI_IMPL_DEFINED(...) __VA_ARGS__
57#endif
58
59// use this macro to mark base class which only purpose is EBO
60// gives it more semantics and useful with doxygen
61// add PREDEFINED: WPI_EBO():=
62#ifndef WPI_EBO
63#define WPI_EBO(...) __VA_ARGS__
64#endif
65
66#ifndef WPI_ALIAS_TEMPLATE
67// defines a template alias
68// usage:
69// template <typename T>
70// WPI_ALIAS_TEMPLATE(bar, foo<T, int>);
71// useful for doxygen
72#ifdef DOXYGEN
73#define WPI_ALIAS_TEMPLATE(Name, ...) \
74 class Name : public __VA_ARGS__ \
75 { \
76 }
77#else
78#define WPI_ALIAS_TEMPLATE(Name, ...) using Name = __VA_ARGS__
79#endif
80#endif
81
82#ifdef DOXYGEN
83// dummy definitions of config macros for doxygen
84
85/// The major version number.
86/// \ingroup memory_core
87#define WPI_MEMORY_VERSION_MAJOR 1
88
89/// The minor version number.
90/// \ingroup memory_core
91#define WPI_MEMORY_VERSION_MINOR 1
92
93/// The total version number of the form \c Mmm.
94/// \ingroup memory_core
95#define WPI_MEMORY_VERSION \
96 (WPI_MEMORY_VERSION_MAJOR * 100 + WPI_MEMORY_VERSION_MINOR)
97
98/// Whether or not the allocation size will be checked,
99/// i.e. the \ref wpi::memory::bad_allocation_size thrown.
100/// \ingroup memory_core
101#define WPI_MEMORY_CHECK_ALLOCATION_SIZE 1
102
103/// Whether or not internal assertions in the library are enabled.
104/// \ingroup memory_core
105#define WPI_MEMORY_DEBUG_ASSERT 1
106
107/// Whether or not allocated memory will be filled with special values.
108/// \ingroup memory_core
109#define WPI_MEMORY_DEBUG_FILL 1
110
111/// The size of the fence memory, it has no effect if \ref WPI_MEMORY_DEBUG_FILL is \c false.
112/// \note For most allocators, the actual value doesn't matter and they use appropriate defaults to ensure alignment etc.
113/// \ingroup memory_core
114#define WPI_MEMORY_DEBUG_FENCE 1
115
116/// Whether or not leak checking is enabled.
117/// \ingroup memory_core
118#define WPI_MEMORY_DEBUG_LEAK_CHECK 1
119
120/// Whether or not the deallocation functions will check for pointers that were never allocated by an allocator.
121/// \ingroup memory_core
122#define WPI_MEMORY_DEBUG_POINTER_CHECK 1
123
124/// Whether or not the deallocation functions will check for double free errors.
125/// This option makes no sense if \ref WPI_MEMORY_DEBUG_POINTER_CHECK is \c false.
126/// \ingroup memory_core
127#define WPI_MEMORY_DEBUG_DOUBLE_DEALLOC_CHECK 1
128
129/// Whether or not everything is in namespace <tt>wpi::memory</tt>.
130/// If \c false, a namespace alias <tt>namespace memory = wpi::memory</tt> is automatically inserted into each header,
131/// allowing to qualify everything with <tt>wpi::</tt>.
132/// \note This option breaks in combination with using <tt>using namespace wpi;</tt>.
133/// \ingroup memory_core
134#define WPI_MEMORY_NAMESPACE_PREFIX 1
135
136/// The mode of the automatic \ref wpi::memory::temporary_stack creation.
137/// Set to `2` to enable automatic lifetime management of the per-thread stack through nifty counter.
138/// Then all memory will be freed upon program termination automatically.
139/// Set to `1` to disable automatic lifetime managment of the per-thread stack,
140/// requires managing it through the \ref wpi::memory::temporary_stack_initializer.
141/// Set to `0` to disable the per-thread stack completely.
142/// \ref wpi::memory::get_temporary_stack() will abort the program upon call.
143/// \ingroup memory_allocator
144#define WPI_MEMORY_TEMPORARY_STACK_MODE 2
145#endif
146
147#endif // WPI_MEMORY_CONFIG_HPP_INCLUDED