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) {}
237 virtual void rtti() {}
249 virtual void rtti() {}
257 static const int32_t msb_32bit = 0x80000000;
258 static const int32_t msb2_32bit = 0x40000000;
276 using Type =
typename std::conditional<std::is_lvalue_reference<T>::value,
278 typename std::decay<T>::type>::type;
283 SizeTag( T && sz ) : size(std::forward<T>(sz)) {}
316 template <
class Key,
class Value>
319 using KeyType =
typename std::conditional<
320 std::is_lvalue_reference<Key>::value,
322 typename std::decay<Key>::type>::type;
324 using ValueType =
typename std::conditional<
325 std::is_lvalue_reference<Value>::value,
327 typename std::decay<Value>::type>::type;
331 MapItem( Key && key_, Value && value_ ) : key(
std::forward<Key>(key_)), value(
std::forward<Value>(value_)) {}
339 template <
class Archive>
inline 342 archive( make_nvp<Archive>(
"key", key),
343 make_nvp<Archive>(
"value", value) );
350 template <
class KeyType,
class ValueType>
inline 353 return {std::forward<KeyType>(key), std::forward<ValueType>(value)};
356 enum class FieldSerialized
375 VersionIdTag(std::uint32_t version_id_) : version_id(version_id_)
380 template<
class Archive>
381 std::uint32_t save_minimal(Archive
const &)
const 386 template<
class Archive>
387 void load_minimal(Archive
const &, std::uint32_t
const &v)
392 std::uint32_t version_id;
404 using Type =
typename std::conditional<std::is_lvalue_reference<T>::value,
406 typename std::decay<T>::type>::type;
407 using SimpleType =
typename std::decay<T>::type;
412 PolymorphicIdTag(T &&polymorphic_id_) : polymorphic_id(std::forward<T>(polymorphic_id_))
417 template<
class Archive>
418 SimpleType save_minimal(Archive
const &)
const 420 return polymorphic_id;
423 template<
class Archive>
424 void load_minimal(Archive
const &, SimpleType
const &v)
434 return {std::forward<T>(polymorphic_id)};
447 using Type =
typename std::conditional<std::is_lvalue_reference<T>::value,
449 typename std::decay<T>::type>::type;
450 using SimpleType =
typename std::decay<T>::type;
455 PolymorphicKeyTag(T &&polymorphic_key_) : polymorphic_key(std::forward<T>(polymorphic_key_))
458 Type polymorphic_key;
460 template<
class Archive>
461 SimpleType save_minimal(Archive
const &)
const 463 return polymorphic_key;
466 template<
class Archive>
467 void load_minimal(Archive
const &, SimpleType
const &v)
477 return {std::forward<T>(polymorphic_key)};
490 using Type =
typename std::conditional<std::is_lvalue_reference<T>::value,
492 typename std::decay<T>::type>::type;
493 using SimpleType =
typename std::decay<T>::type;
498 ObjectIdTag(T &&object_id_) : object_id(std::forward<T>(object_id_))
503 template<
class Archive>
504 SimpleType save_minimal(Archive
const &)
const 509 template<
class Archive>
510 void load_minimal(Archive
const &, SimpleType
const &v)
520 return {std::forward<T>(object_id)};
533 using Type =
typename std::conditional<std::is_lvalue_reference<T>::value,
535 typename std::decay<T>::type>::type;
536 using SimpleType =
typename std::decay<T>::type;
546 template<
class Archive>
547 SimpleType save_minimal(Archive
const &)
const 552 template<
class Archive>
553 void load_minimal(Archive
const &, SimpleType
const &v)
563 return {std::forward<T>(valid)};
574 namespace{
struct version_binding_tag {}; }
580 template <
class T,
class BindingTag = version_binding_tag>
struct Version 582 static const std::uint32_t version = 0;
590 std::unordered_map<std::size_t, std::uint32_t> mapping;
592 std::uint32_t find( std::size_t hash, std::uint32_t version )
594 const auto found = mapping.find(hash);
595 if (mapping.end() != found) {
596 return found->second;
598 return mapping.emplace( hash, version ).first->second;
605 #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:253
A wrapper around size metadata.
Definition: helpers.hpp:271
A wrapper around object id.
Definition: helpers.hpp:485
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:351
A wrapper around a key and value for serializing data into maps.
Definition: helpers.hpp:317
Tag used to indicate that field is ommited from the archive.
Definition: helpers.hpp:292
A wrapper around pointer validity marker.
Definition: helpers.hpp:528
Version information class.
Definition: helpers.hpp:580
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
A wrapper around polymorphic id.
Definition: helpers.hpp:369
uint64_t size_type
The size type used by cereal.
Definition: helpers.hpp:59
Definition: access.hpp:40
A wrapper around polymorphic id.
Definition: helpers.hpp:399
A wrapper around polymorphic key.
Definition: helpers.hpp:442
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
For holding name value pairs.
Definition: helpers.hpp:135
Definition: polymorphic_impl.hpp:573
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:340
#define CEREAL_NOEXCEPT
Defines the CEREAL_NOEXCEPT macro to use instead of noexcept.
Definition: macros.hpp:116
A wrapper around data that can be serialized in a binary fashion.
Definition: helpers.hpp:207
Definition: helpers.hpp:228
uint64_t size
size in bytes
Definition: helpers.hpp:218
Holds all registered version information.
Definition: helpers.hpp:588
MapItem(Key &&key_, Value &&value_)
Construct a MapItem from a key and a value.
Definition: helpers.hpp:331
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