30 #ifndef CEREAL_DETAILS_HELPERS_HPP_ 31 #define CEREAL_DETAILS_HELPERS_HPP_ 33 #include <type_traits> 37 #include <unordered_map> 50 explicit Exception(
const std::string & what_ ) : std::runtime_error(what_) {}
51 explicit Exception(
const char * what_ ) : std::runtime_error(what_) {}
140 using Type =
typename std::conditional<std::is_array<typename std::remove_reference<T>::type>::value,
141 typename std::remove_cv<T>::type,
142 typename std::conditional<std::is_lvalue_reference<T>::value,
144 typename std::decay<T>::type>::type>::type;
147 static_assert( !std::is_base_of<detail::NameValuePairCore, T>::value,
148 "Cannot pair a name to a NameValuePair" );
170 template<
class Archive,
class T>
inline 172 std::enable_if<std::is_same<Archive, ::cereal::BinaryInputArchive>::value ||
173 std::is_same<Archive, ::cereal::BinaryOutputArchive>::value,
177 return std::forward<T>(value);
183 template<
class Archive,
class T>
inline 185 std::enable_if<!std::is_same<Archive, ::cereal::BinaryInputArchive>::value &&
186 !std::is_same<Archive, ::cereal::BinaryOutputArchive>::value,
190 return {name, std::forward<T>(value)};
197 #define CEREAL_NVP_(name, value) ::cereal::make_nvp<Archive>(name, value) 211 using PT =
typename std::conditional<std::is_const<typename std::remove_pointer<T>::type>::value,
215 BinaryData( T && d, uint64_t s ) : data(
std::forward<T>(d)), size(s) {}
236 static const int32_t msb_32bit = 0x80000000;
237 static const int32_t msb2_32bit = 0x40000000;
255 using Type =
typename std::conditional<std::is_lvalue_reference<T>::value,
257 typename std::decay<T>::type>::type;
262 SizeTag( T && sz ) : size(std::forward<T>(sz)) {}
288 template <
class Key,
class Value>
291 using KeyType =
typename std::conditional<
292 std::is_lvalue_reference<Key>::value,
294 typename std::decay<Key>::type>::type;
296 using ValueType =
typename std::conditional<
297 std::is_lvalue_reference<Value>::value,
299 typename std::decay<Value>::type>::type;
303 MapItem( Key && key_, Value && value_ ) : key(
std::forward<Key>(key_)), value(
std::forward<Value>(value_)) {}
311 template <
class Archive>
inline 314 archive( make_nvp<Archive>(
"key", key),
315 make_nvp<Archive>(
"value", value) );
322 template <
class KeyType,
class ValueType>
inline 325 return {std::forward<KeyType>(key), std::forward<ValueType>(value)};
333 namespace{
struct version_binding_tag {}; }
339 template <
class T,
class BindingTag = version_binding_tag>
struct Version 341 static const std::uint32_t version = 0;
349 std::unordered_map<std::size_t, std::uint32_t> mapping;
351 std::uint32_t find( std::size_t hash, std::uint32_t version )
353 const auto result = mapping.emplace( hash, version );
354 return result.first->second;
360 #endif // CEREAL_DETAILS_HELPERS_HPP_ std::enable_if<!std::is_same< Archive,::cereal::BinaryInputArchive >::value &&!std::is_same< Archive,::cereal::BinaryOutputArchive >::value, NameValuePair< T > >::type make_nvp(const char *name, T &&value)
A specialization of make_nvp<> that actually creates an nvp for non-binary archives.
Definition: helpers.hpp:188
PT data
pointer to beginning of data
Definition: helpers.hpp:217
Definition: helpers.hpp:232
A wrapper around size metadata.
Definition: helpers.hpp:250
Traits struct for NVPs.
Definition: helpers.hpp:68
MapItem< KeyType, ValueType > make_map_item(KeyType &&key, ValueType &&value)
Create a MapItem so that human readable archives will group keys and values together.
Definition: helpers.hpp:323
A wrapper around a key and value for serializing data into maps.
Definition: helpers.hpp:289
Version information class.
Definition: helpers.hpp:339
typename std::conditional< std::is_const< typename std::remove_pointer< T >::type >::value, const void *, void * >::type PT
Definition: helpers.hpp:213
NameValuePair(char const *n, T &&v)
Constructs a new NameValuePair.
Definition: helpers.hpp:161
uint64_t size_type
The size type used by cereal.
Definition: helpers.hpp:59
Definition: access.hpp:39
For holding name value pairs.
Definition: helpers.hpp:135
Definition: polymorphic_impl.hpp:322
Preprocessor macros that can customise the cereal library.
void CEREAL_SERIALIZE_FUNCTION_NAME(Archive &archive)
Serialize the MapItem with the NVPs "key" and "value".
Definition: helpers.hpp:312
A wrapper around data that can be serialized in a binary fashion.
Definition: helpers.hpp:207
Definition: helpers.hpp:228
std::enable_if< std::is_same< Archive,::cereal::BinaryInputArchive >::value||std::is_same< Archive,::cereal::BinaryOutputArchive >::value, T && >::type make_nvp(const char *, T &&value)
A specialization of make_nvp<> that simply forwards the value for binary archives.
Definition: helpers.hpp:175
uint64_t size
size in bytes
Definition: helpers.hpp:218
Holds all registered version information.
Definition: helpers.hpp:347
MapItem(Key &&key_, Value &&value_)
Construct a MapItem from a key and a value.
Definition: helpers.hpp:303
Internal polymorphism static object support.
An exception class thrown when things go wrong at runtime.
Definition: helpers.hpp:48
An output archive designed to save data in a compact binary representation.
Definition: binary.hpp:51