| 1 |
/*! \file macros.hpp |
| 2 |
\brief Preprocessor macros that can customise the cereal library |
| 3 |
|
| 4 |
By default, cereal looks for serialization functions with very |
| 5 |
specific names, that is: serialize, load, save, load_minimal, |
| 6 |
or save_minimal. |
| 7 |
|
| 8 |
This file allows an advanced user to change these names to conform |
| 9 |
to some other style or preference. This is implemented using |
| 10 |
preprocessor macros. |
| 11 |
|
| 12 |
As a result of this, in internal cereal code you will see macros |
| 13 |
used for these function names. In user code, you should name |
| 14 |
the functions like you normally would and not use the macros |
| 15 |
to improve readability. |
| 16 |
\ingroup utility */ |
| 17 |
/* |
| 18 |
Copyright (c) 2014, Randolph Voorhies, Shane Grant |
| 19 |
All rights reserved. |
| 20 |
|
| 21 |
Redistribution and use in source and binary forms, with or without |
| 22 |
modification, are permitted provided that the following conditions are met: |
| 23 |
* Redistributions of source code must retain the above copyright |
| 24 |
notice, this list of conditions and the following disclaimer. |
| 25 |
* Redistributions in binary form must reproduce the above copyright |
| 26 |
notice, this list of conditions and the following disclaimer in the |
| 27 |
documentation and/or other materials provided with the distribution. |
| 28 |
* Neither the name of cereal nor the |
| 29 |
names of its contributors may be used to endorse or promote products |
| 30 |
derived from this software without specific prior written permission. |
| 31 |
|
| 32 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 33 |
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 34 |
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 35 |
DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY |
| 36 |
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 37 |
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 38 |
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 39 |
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 40 |
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 41 |
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 42 |
*/ |
| 43 |
|
| 44 |
#ifndef CEREAL_MACROS_HPP_ |
| 45 |
#define CEREAL_MACROS_HPP_ |
| 46 |
|
| 47 |
#ifndef CEREAL_THREAD_SAFE |
| 48 |
//! Whether cereal should be compiled for a threaded environment |
| 49 |
/*! This macro causes cereal to use mutexes to control access to |
| 50 |
global internal state in a thread safe manner. |
| 51 |
|
| 52 |
Note that even with this enabled you must still ensure that |
| 53 |
archives are accessed by only one thread at a time; it is safe |
| 54 |
to use multiple archives in paralel, but not to access one archive |
| 55 |
from many places simultaneously. */ |
| 56 |
#define CEREAL_THREAD_SAFE 0 |
| 57 |
#endif // CEREAL_THREAD_SAFE |
| 58 |
|
| 59 |
#ifndef CEREAL_SIZE_TYPE |
| 60 |
//! Determines the data type used for size_type |
| 61 |
/*! cereal uses size_type to ensure that the serialized size of |
| 62 |
dynamic containers is compatible across different architectures |
| 63 |
(e.g. 32 vs 64 bit), which may use different underlying types for |
| 64 |
std::size_t. |
| 65 |
|
| 66 |
More information can be found in cereal/details/helpers.hpp. |
| 67 |
|
| 68 |
If you choose to modify this type, ensure that you use a fixed |
| 69 |
size type (e.g. uint32_t). */ |
| 70 |
#define CEREAL_SIZE_TYPE uint64_t |
| 71 |
#endif // CEREAL_SIZE_TYPE |
| 72 |
|
| 73 |
// ###################################################################### |
| 74 |
#ifndef CEREAL_SERIALIZE_FUNCTION_NAME |
| 75 |
//! The serialization/deserialization function name to search for. |
| 76 |
/*! You can define @c CEREAL_SERIALIZE_FUNCTION_NAME to be different assuming |
| 77 |
you do so before this file is included. */ |
| 78 |
#define CEREAL_SERIALIZE_FUNCTION_NAME serialize |
| 79 |
#endif // CEREAL_SERIALIZE_FUNCTION_NAME |
| 80 |
|
| 81 |
#ifndef CEREAL_LOAD_FUNCTION_NAME |
| 82 |
//! The deserialization (load) function name to search for. |
| 83 |
/*! You can define @c CEREAL_LOAD_FUNCTION_NAME to be different assuming you do so |
| 84 |
before this file is included. */ |
| 85 |
#define CEREAL_LOAD_FUNCTION_NAME load |
| 86 |
#endif // CEREAL_LOAD_FUNCTION_NAME |
| 87 |
|
| 88 |
#ifndef CEREAL_SAVE_FUNCTION_NAME |
| 89 |
//! The serialization (save) function name to search for. |
| 90 |
/*! You can define @c CEREAL_SAVE_FUNCTION_NAME to be different assuming you do so |
| 91 |
before this file is included. */ |
| 92 |
#define CEREAL_SAVE_FUNCTION_NAME save |
| 93 |
#endif // CEREAL_SAVE_FUNCTION_NAME |
| 94 |
|
| 95 |
#ifndef CEREAL_LOAD_MINIMAL_FUNCTION_NAME |
| 96 |
//! The deserialization (load_minimal) function name to search for. |
| 97 |
/*! You can define @c CEREAL_LOAD_MINIMAL_FUNCTION_NAME to be different assuming you do so |
| 98 |
before this file is included. */ |
| 99 |
#define CEREAL_LOAD_MINIMAL_FUNCTION_NAME load_minimal |
| 100 |
#endif // CEREAL_LOAD_MINIMAL_FUNCTION_NAME |
| 101 |
|
| 102 |
#ifndef CEREAL_SAVE_MINIMAL_FUNCTION_NAME |
| 103 |
//! The serialization (save_minimal) function name to search for. |
| 104 |
/*! You can define @c CEREAL_SAVE_MINIMAL_FUNCTION_NAME to be different assuming you do so |
| 105 |
before this file is included. */ |
| 106 |
#define CEREAL_SAVE_MINIMAL_FUNCTION_NAME save_minimal |
| 107 |
#endif // CEREAL_SAVE_MINIMAL_FUNCTION_NAME |
| 108 |
|
| 109 |
// ###################################################################### |
| 110 |
//! Defines the CEREAL_NOEXCEPT macro to use instead of noexcept |
| 111 |
/*! If a compiler we support does not support noexcept, this macro |
| 112 |
will detect this and define CEREAL_NOEXCEPT as a no-op |
| 113 |
@internal */ |
| 114 |
#if !defined(CEREAL_HAS_NOEXCEPT) |
| 115 |
#if defined(__clang__) |
| 116 |
#if __has_feature(cxx_noexcept) |
| 117 |
#define CEREAL_HAS_NOEXCEPT |
| 118 |
#endif |
| 119 |
#else // NOT clang |
| 120 |
#if defined(__GXX_EXPERIMENTAL_CXX0X__) && __GNUC__ * 10 + __GNUC_MINOR__ >= 46 || \ |
| 121 |
defined(_MSC_FULL_VER) && _MSC_FULL_VER >= 190023026 |
| 122 |
#define CEREAL_HAS_NOEXCEPT |
| 123 |
#endif // end GCC/MSVC check |
| 124 |
#endif // end NOT clang block |
| 125 |
|
| 126 |
#ifndef CEREAL_NOEXCEPT |
| 127 |
#ifdef CEREAL_HAS_NOEXCEPT |
| 128 |
#define CEREAL_NOEXCEPT noexcept |
| 129 |
#else |
| 130 |
#define CEREAL_NOEXCEPT |
| 131 |
#endif // end CEREAL_HAS_NOEXCEPT |
| 132 |
#endif // end !defined(CEREAL_HAS_NOEXCEPT) |
| 133 |
#endif // ifndef CEREAL_NOEXCEPT |
| 134 |
|
| 135 |
// ###################################################################### |
| 136 |
//! Checks if C++17 is available |
| 137 |
#if __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) |
| 138 |
#define CEREAL_HAS_CPP17 |
| 139 |
#endif |
| 140 |
|
| 141 |
//! Checks if C++14 is available |
| 142 |
#if __cplusplus >= 201402L |
| 143 |
#define CEREAL_HAS_CPP14 |
| 144 |
#endif |
| 145 |
|
| 146 |
// ###################################################################### |
| 147 |
//! Defines the CEREAL_ALIGNOF macro to use instead of alignof |
| 148 |
#if defined(_MSC_VER) && _MSC_VER < 1900 |
| 149 |
#define CEREAL_ALIGNOF __alignof |
| 150 |
#else // not MSVC 2013 or older |
| 151 |
#define CEREAL_ALIGNOF alignof |
| 152 |
#endif // end MSVC check |
| 153 |
|
| 154 |
#endif // CEREAL_MACROS_HPP_ |