cereal
A C++11 library for serialization
|
Internal type trait support. More...
#include <type_traits>
#include <typeindex>
#include "cereal/macros.hpp"
#include "cereal/access.hpp"
Go to the source code of this file.
Macros | |
#define | CEREAL_SETUP_ARCHIVE_TRAITS(InputArchive, OutputArchive) |
Sets up traits that relate an input archive to an output archive. More... | |
#define | CEREAL_MAKE_VERSIONED_TEST ,0 |
Used to convert a MAKE_HAS_XXX macro into a versioned variant. | |
#define | CEREAL_MAKE_HAS_MEMBER_TEST(name, test_name, versioned) |
Creates a test for whether a non const member function exists. More... | |
#define | CEREAL_MAKE_HAS_NON_MEMBER_TEST(test_name, func, versioned) |
Creates a test for whether a non const non-member function exists. More... | |
#define | CEREAL_MAKE_HAS_MEMBER_SAVE_IMPL(test_name, versioned) |
Creates a test for whether a member save function exists. More... | |
#define | CEREAL_MAKE_HAS_NON_MEMBER_SAVE_TEST(test_name, versioned) |
Creates a test for whether a non-member save function exists. More... | |
#define | CEREAL_MAKE_HAS_MEMBER_SAVE_MINIMAL_IMPL(test_name, versioned) |
Creates implementation details for whether a member save_minimal function exists. More... | |
#define | CEREAL_MAKE_HAS_MEMBER_SAVE_MINIMAL_HELPERS_IMPL(test_name, versioned) |
Creates helpers for minimal save functions. More... | |
#define | CEREAL_MAKE_HAS_MEMBER_SAVE_MINIMAL_TEST(test_name) |
Creates a test for whether a member save_minimal function exists. More... | |
#define | CEREAL_MAKE_HAS_NON_MEMBER_SAVE_MINIMAL_TEST(test_name, versioned) |
Creates a test for whether a non-member save_minimal function exists. More... | |
#define | CEREAL_MAKE_HAS_MEMBER_LOAD_MINIMAL_IMPL(test_name, versioned) |
Creates a test for whether a member load_minimal function exists. More... | |
#define | CEREAL_MAKE_HAS_MEMBER_LOAD_MINIMAL_HELPERS_IMPL(load_test_name, save_test_name, save_test_prefix, versioned) |
Creates helpers for minimal load functions. More... | |
#define | CEREAL_MAKE_HAS_MEMBER_LOAD_MINIMAL_TEST(load_test_name, load_test_prefix) |
Creates a test for whether a member load_minimal function exists. More... | |
#define | CEREAL_MAKE_HAS_NON_MEMBER_LOAD_MINIMAL_TEST(test_name, save_name, versioned) |
Creates a test for whether a non-member load_minimal function exists. More... | |
#define | CEREAL_MAKE_HAS_NON_MEMBER_LOAD_AND_CONSTRUCT_TEST(test_name, versioned) |
Creates a test for whether a non-member load_and_construct specialization exists. More... | |
#define | CEREAL_MAKE_IS_SPECIALIZED_IMPL(name) |
Create a test for a cereal::specialization entry. More... | |
#define | CEREAL_MAKE_IS_SPECIALIZED_ASSERT(name, versioned_name, print_name, spec_name) |
Create the static assertion for some specialization. More... | |
#define | CEREAL_MAKE_IS_SPECIALIZED(name, versioned_name, spec_name) |
Generates a test for specialization for versioned and unversioned functions. More... | |
#define | CEREAL_ARCHIVE_RESTRICT(INTYPE, OUTTYPE) typename std::enable_if<cereal::traits::is_same_archive<Archive, INTYPE>::value || cereal::traits::is_same_archive<Archive, OUTTYPE>::value, void>::type |
A macro to use to restrict which types of archives your function will work for. More... | |
Typedefs | |
using | cereal::traits::yes = std::true_type |
using | cereal::traits::no = std::false_type |
template<bool ... Conditions> | |
using | EnableIf = typename detail::EnableIfHelper< Conditions... >::type |
Provides a way to enable a function if conditions are met. More... | |
template<bool ... Conditions> | |
using | DisableIf = typename detail::DisableIfHelper< Conditions... >::type |
Provides a way to disable a function if conditions are met. More... | |
template<class A > | |
using | cereal::traits::detail::decay_archive = typename std::decay< typename strip_minimal< A >::type >::type |
Removes all qualifiers and minimal wrappers from an archive. | |
Enumerations | |
enum | cereal::traits::detail::sfinae |
Return type for SFINAE Enablers. | |
Functions | |
cereal::traits::CEREAL_MAKE_HAS_MEMBER_TEST (serialize, serialize,) | |
cereal::traits::CEREAL_MAKE_HAS_MEMBER_TEST (serialize, versioned_serialize, CEREAL_MAKE_VERSIONED_TEST) | |
cereal::traits::CEREAL_MAKE_HAS_NON_MEMBER_TEST (serialize, CEREAL_SERIALIZE_FUNCTION_NAME,) | |
cereal::traits::CEREAL_MAKE_HAS_NON_MEMBER_TEST (versioned_serialize, CEREAL_SERIALIZE_FUNCTION_NAME, CEREAL_MAKE_VERSIONED_TEST) | |
cereal::traits::CEREAL_MAKE_HAS_MEMBER_TEST (load, load,) | |
cereal::traits::CEREAL_MAKE_HAS_MEMBER_TEST (load, versioned_load, CEREAL_MAKE_VERSIONED_TEST) | |
cereal::traits::CEREAL_MAKE_HAS_NON_MEMBER_TEST (load, CEREAL_LOAD_FUNCTION_NAME,) | |
cereal::traits::CEREAL_MAKE_HAS_NON_MEMBER_TEST (versioned_load, CEREAL_LOAD_FUNCTION_NAME, CEREAL_MAKE_VERSIONED_TEST) | |
cereal::traits::detail::CEREAL_MAKE_IS_SPECIALIZED_IMPL (member_serialize) | |
cereal::traits::detail::CEREAL_MAKE_IS_SPECIALIZED_IMPL (member_load_save) | |
cereal::traits::detail::CEREAL_MAKE_IS_SPECIALIZED_IMPL (member_load_save_minimal) | |
cereal::traits::detail::CEREAL_MAKE_IS_SPECIALIZED_IMPL (non_member_serialize) | |
cereal::traits::detail::CEREAL_MAKE_IS_SPECIALIZED_IMPL (non_member_load_save) | |
cereal::traits::detail::CEREAL_MAKE_IS_SPECIALIZED_IMPL (non_member_load_save_minimal) | |
cereal::traits::CEREAL_MAKE_IS_SPECIALIZED (member_serialize, member_versioned_serialize, member_serialize) | |
cereal::traits::CEREAL_MAKE_IS_SPECIALIZED (non_member_serialize, non_member_versioned_serialize, non_member_serialize) | |
cereal::traits::CEREAL_MAKE_IS_SPECIALIZED (member_save, member_versioned_save, member_load_save) | |
cereal::traits::CEREAL_MAKE_IS_SPECIALIZED (non_member_save, non_member_versioned_save, non_member_load_save) | |
cereal::traits::CEREAL_MAKE_IS_SPECIALIZED (member_load, member_versioned_load, member_load_save) | |
cereal::traits::CEREAL_MAKE_IS_SPECIALIZED (non_member_load, non_member_versioned_load, non_member_load_save) | |
cereal::traits::CEREAL_MAKE_IS_SPECIALIZED (member_save_minimal, member_versioned_save_minimal, member_load_save_minimal) | |
cereal::traits::CEREAL_MAKE_IS_SPECIALIZED (non_member_save_minimal, non_member_versioned_save_minimal, non_member_load_save_minimal) | |
cereal::traits::CEREAL_MAKE_IS_SPECIALIZED (member_load_minimal, member_versioned_load_minimal, member_load_save_minimal) | |
cereal::traits::CEREAL_MAKE_IS_SPECIALIZED (non_member_load_minimal, non_member_versioned_load_minimal, non_member_load_save_minimal) | |
Internal type trait support.
#define CEREAL_ARCHIVE_RESTRICT | ( | INTYPE, | |
OUTTYPE | |||
) | typename std::enable_if<cereal::traits::is_same_archive<Archive, INTYPE>::value || cereal::traits::is_same_archive<Archive, OUTTYPE>::value, void>::type |
A macro to use to restrict which types of archives your function will work for.
This requires you to have a template class parameter named Archive and replaces the void return type for your function.
INTYPE refers to the input archive type you wish to restrict on. OUTTYPE refers to the output archive type you wish to restrict on.
For example, if we want to limit a serialize to only work with binary serialization:
If you need to do more restrictions in your enable_if, you will need to do this by hand.
#define CEREAL_MAKE_HAS_MEMBER_LOAD_MINIMAL_HELPERS_IMPL | ( | load_test_name, | |
save_test_name, | |||
save_test_prefix, | |||
versioned | |||
) |
Creates helpers for minimal load functions.
The has_member_*_wrapper structs ensure that the load and save types for the requested function type match appropriately.
load_test_name | The name to give the test (e.g. load_minimal or versioned_load_minimal) |
save_test_name | The name to give the test (e.g. save_minimal or versioned_save_minimal, should match the load name. |
save_test_prefix | The name to give the test (e.g. save_minimal or versioned_save_minimal, should match the load name, without the trailing "_minimal" (e.g. save or versioned_save). Needed because the preprocessor is an abomination. |
versioned | Either blank or the macro CEREAL_MAKE_VERSIONED_TEST |
#define CEREAL_MAKE_HAS_MEMBER_LOAD_MINIMAL_IMPL | ( | test_name, | |
versioned | |||
) |
Creates a test for whether a member load_minimal function exists.
This creates a class derived from std::integral_constant that will be true if the type has the proper member function for the given archive.
Our strategy here is to first check if a function matching the signature more or less exists (allow anything like load_minimal(xxx) using AnyConvert, and then secondly enforce that it has the correct signature using NoConvertConstRef
test_name | The name to give the test (e.g. load_minimal or versioned_load_minimal) |
versioned | Either blank or the macro CEREAL_MAKE_VERSIONED_TEST |
#define CEREAL_MAKE_HAS_MEMBER_LOAD_MINIMAL_TEST | ( | load_test_name, | |
load_test_prefix | |||
) |
Creates a test for whether a member load_minimal function exists.
This creates a class derived from std::integral_constant that will be true if the type has the proper member function for the given archive.
load_test_name | The name to give the test (e.g. load_minimal or versioned_load_minimal) |
load_test_prefix | The above parameter minus the trailing "_minimal" |
#define CEREAL_MAKE_HAS_MEMBER_SAVE_IMPL | ( | test_name, | |
versioned | |||
) |
Creates a test for whether a member save function exists.
This creates a class derived from std::integral_constant that will be true if the type has the proper member function for the given archive.
test_name | The name to give the test (e.g. save or versioned_save) |
versioned | Either blank or the macro CEREAL_MAKE_VERSIONED_TEST |
#define CEREAL_MAKE_HAS_MEMBER_SAVE_MINIMAL_HELPERS_IMPL | ( | test_name, | |
versioned | |||
) |
Creates helpers for minimal save functions.
The get_member_*_type structs allow access to the return type of a save_minimal, assuming that the function actually exists. If the function does not exist, the type will be void.
test_name | The name to give the test (e.g. save_minimal or versioned_save_minimal) |
versioned | Either blank or the macro CEREAL_MAKE_VERSIONED_TEST |
#define CEREAL_MAKE_HAS_MEMBER_SAVE_MINIMAL_IMPL | ( | test_name, | |
versioned | |||
) |
Creates implementation details for whether a member save_minimal function exists.
This creates a class derived from std::integral_constant that will be true if the type has the proper member function for the given archive.
test_name | The name to give the test (e.g. save_minimal or versioned_save_minimal) |
versioned | Either blank or the macro CEREAL_MAKE_VERSIONED_TEST |
#define CEREAL_MAKE_HAS_MEMBER_SAVE_MINIMAL_TEST | ( | test_name | ) |
Creates a test for whether a member save_minimal function exists.
This creates a class derived from std::integral_constant that will be true if the type has the proper member function for the given archive.
test_name | The name to give the test (e.g. save_minimal or versioned_save_minimal) |
#define CEREAL_MAKE_HAS_MEMBER_TEST | ( | name, | |
test_name, | |||
versioned | |||
) |
Creates a test for whether a non const member function exists.
This creates a class derived from std::integral_constant that will be true if the type has the proper member function for the given archive.
name | The name of the function to test for (e.g. serialize, load, save) |
test_name | The name to give the test for the function being tested for (e.g. serialize, versioned_serialize) |
versioned | Either blank or the macro CEREAL_MAKE_VERSIONED_TEST |
#define CEREAL_MAKE_HAS_NON_MEMBER_LOAD_AND_CONSTRUCT_TEST | ( | test_name, | |
versioned | |||
) |
Creates a test for whether a non-member load_and_construct specialization exists.
This creates a class derived from std::integral_constant that will be true if the type has the proper non-member function for the given archive.
#define CEREAL_MAKE_HAS_NON_MEMBER_LOAD_MINIMAL_TEST | ( | test_name, | |
save_name, | |||
versioned | |||
) |
Creates a test for whether a non-member load_minimal function exists.
This creates a class derived from std::integral_constant that will be true if the type has the proper member function for the given archive.
See notes from member load_minimal implementation.
Note that there should be an additional const check on load_minimal after the valid check, but this currently interferes with many valid uses of minimal serialization. It has been removed (see #565 on github) and previously was:
See #132, #436, #263, and #565 on https://github.com/USCiLab/cereal for more details.
test_name | The name to give the test (e.g. load_minimal or versioned_load_minimal) |
save_name | The corresponding name the save test would have (e.g. save_minimal or versioned_save_minimal) |
versioned | Either blank or the macro CEREAL_MAKE_VERSIONED_TEST |
#define CEREAL_MAKE_HAS_NON_MEMBER_SAVE_MINIMAL_TEST | ( | test_name, | |
versioned | |||
) |
Creates a test for whether a non-member save_minimal function exists.
This creates a class derived from std::integral_constant that will be true if the type has the proper member function for the given archive.
test_name | The name to give the test (e.g. save_minimal or versioned_save_minimal) |
versioned | Either blank or the macro CEREAL_MAKE_VERSIONED_TEST |
#define CEREAL_MAKE_HAS_NON_MEMBER_SAVE_TEST | ( | test_name, | |
versioned | |||
) |
Creates a test for whether a non-member save function exists.
This creates a class derived from std::integral_constant that will be true if the type has the proper non-member function for the given archive.
test_name | The name to give the test (e.g. save or versioned_save) |
versioned | Either blank or the macro CEREAL_MAKE_VERSIONED_TEST |
#define CEREAL_MAKE_HAS_NON_MEMBER_TEST | ( | test_name, | |
func, | |||
versioned | |||
) |
Creates a test for whether a non const non-member function exists.
This creates a class derived from std::integral_constant that will be true if the type has the proper non-member function for the given archive.
#define CEREAL_MAKE_IS_SPECIALIZED | ( | name, | |
versioned_name, | |||
spec_name | |||
) |
Generates a test for specialization for versioned and unversioned functions.
This creates checks that can be queried to see if a given type of serialization function has been specialized for this type
#define CEREAL_MAKE_IS_SPECIALIZED_ASSERT | ( | name, | |
versioned_name, | |||
print_name, | |||
spec_name | |||
) |
Create the static assertion for some specialization.
This assertion will fail if the type is indeed specialized and does not have the appropriate type of serialization functions
#define CEREAL_MAKE_IS_SPECIALIZED_IMPL | ( | name | ) |
Create a test for a cereal::specialization entry.
#define CEREAL_SETUP_ARCHIVE_TRAITS | ( | InputArchive, | |
OutputArchive | |||
) |
Sets up traits that relate an input archive to an output archive.
using DisableIf = typename detail::DisableIfHelper<Conditions...>::type |
Provides a way to disable a function if conditions are met.
This is intended to be used in a near identical fashion to std::enable_if while being significantly easier to read at the cost of not allowing for as complicated of a condition.
This will compile (allow the function) if every condition evaluates to false. This should be used with SFINAE to ensure that at least one other candidate function works when one fails due to a DisableIf.
This should be used as the las template parameter to a function as an unnamed parameter with a default value of cereal::traits::sfinae:
This is often used in conjunction with EnableIf to form an enable/disable pair of overloads.
Note that this performs a logical AND of all conditions, so you will need to construct more complicated requirements with this fact in mind. If all conditions hold, the function will be disabled.
Conditions | The conditions which will be logically ANDed to disable the function. |
using EnableIf = typename detail::EnableIfHelper<Conditions...>::type |
Provides a way to enable a function if conditions are met.
This is intended to be used in a near identical fashion to std::enable_if while being significantly easier to read at the cost of not allowing for as complicated of a condition.
This will compile (allow the function) if every condition evaluates to true. at compile time. This should be used with SFINAE to ensure that at least one other candidate function works when one fails due to an EnableIf.
This should be used as the las template parameter to a function as an unnamed parameter with a default value of cereal::traits::sfinae:
Note that this performs a logical AND of all conditions, so you will need to construct more complicated requirements with this fact in mind.
Conditions | The conditions which will be logically ANDed to enable the function. |