cereal
A C++11 library for serialization
cereal.hpp
Go to the documentation of this file.
1 
3 /*
4  Copyright (c) 2014, Randolph Voorhies, Shane Grant
5  All rights reserved.
6 
7  Redistribution and use in source and binary forms, with or without
8  modification, are permitted provided that the following conditions are met:
9  * Redistributions of source code must retain the above copyright
10  notice, this list of conditions and the following disclaimer.
11  * Redistributions in binary form must reproduce the above copyright
12  notice, this list of conditions and the following disclaimer in the
13  documentation and/or other materials provided with the distribution.
14  * Neither the name of cereal nor the
15  names of its contributors may be used to endorse or promote products
16  derived from this software without specific prior written permission.
17 
18  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21  DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY
22  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29 #ifndef CEREAL_CEREAL_HPP_
30 #define CEREAL_CEREAL_HPP_
31 
32 #include <type_traits>
33 #include <string>
34 #include <memory>
35 #include <unordered_map>
36 #include <unordered_set>
37 #include <vector>
38 #include <cstddef>
39 #include <cstdint>
40 #include <functional>
41 
42 #include <cereal/macros.hpp>
46 
47 namespace cereal
48 {
49  // ######################################################################
51 
53  template <class T> inline
54  NameValuePair<T> make_nvp( std::string const & name, T && value )
55  {
56  return {name.c_str(), std::forward<T>(value)};
57  }
58 
60 
62  template <class T> inline
63  NameValuePair<T> make_nvp( const char * name, T && value )
64  {
65  return {name, std::forward<T>(value)};
66  }
67 
69 
71  #define CEREAL_NVP(T) ::cereal::make_nvp(#T, T)
72 
73  // ######################################################################
75 
79  template <class T> inline
80  BinaryData<T> binary_data( T && data, size_t size )
81  {
82  return {std::forward<T>(data), size};
83  }
84 
85  // ######################################################################
87 
94  template <class T> inline
96  {
97  return {std::forward<T>(sz)};
98  }
99 
100  // ######################################################################
103 
107  template <class Archive, class T> inline
108  void prologue( Archive & /* archive */, T const & /* data */)
109  { }
110 
113 
114  template <class Archive, class T> inline
115  void epilogue( Archive & /* archive */, T const & /* data */)
116  { }
117 
118  // ######################################################################
120 
131  enum Flags { AllowEmptyClassElision = 1 };
132 
133  // ######################################################################
135 
141  #define CEREAL_REGISTER_ARCHIVE(Archive) \
142  namespace cereal { namespace detail { \
143  template <class T, class BindingTag> \
144  typename polymorphic_serialization_support<Archive, T>::type \
145  instantiate_polymorphic_binding( T*, Archive*, BindingTag, adl_tag ); \
146  } } /* end namespaces */
147 
148  // ######################################################################
150 
199  #define CEREAL_CLASS_VERSION(TYPE, VERSION_NUMBER) \
200  namespace cereal { namespace detail { \
201  template <> struct Version<TYPE> \
202  { \
203  static const std::uint32_t version; \
204  static std::uint32_t registerVersion() \
205  { \
206  ::cereal::detail::StaticObject<Versions>::getInstance().mapping.emplace( \
207  std::type_index(typeid(TYPE)).hash_code(), VERSION_NUMBER ); \
208  return VERSION_NUMBER; \
209  } \
210  static void unused() { (void)version; } \
211  }; /* end Version */ \
212  const std::uint32_t Version<TYPE>::version = \
213  Version<TYPE>::registerVersion(); \
214  } } // end namespaces
215 
216  // ######################################################################
218 
233  template<class ArchiveType, std::uint32_t Flags = 0>
235  {
236  public:
238 
239  OutputArchive(ArchiveType * const derived) : self(derived), itsCurrentPointerId(1), itsCurrentPolymorphicTypeId(1)
240  { }
241 
242  OutputArchive & operator=( OutputArchive const & ) = delete;
243 
245 
246  template <class ... Types> inline
247  ArchiveType & operator()( Types && ... args )
248  {
249  self->process( std::forward<Types>( args )... );
250  return *self;
251  }
252 
256 
259 
262  template <class T> inline
263  ArchiveType & operator&( T && arg )
264  {
265  self->process( std::forward<T>( arg ) );
266  return *self;
267  }
268 
270 
273  template <class T> inline
274  ArchiveType & operator<<( T && arg )
275  {
276  self->process( std::forward<T>( arg ) );
277  return *self;
278  }
279 
281 
283 
290  inline std::uint32_t registerSharedPointer( void const * addr )
291  {
292  // Handle null pointers by just returning 0
293  if(addr == 0) return 0;
294 
295  auto id = itsSharedPointerMap.find( addr );
296  if( id == itsSharedPointerMap.end() )
297  {
298  auto ptrId = itsCurrentPointerId++;
299  itsSharedPointerMap.insert( {addr, ptrId} );
300  return ptrId | detail::msb_32bit; // mask MSB to be 1
301  }
302  else
303  return id->second;
304  }
305 
307 
314  inline std::uint32_t registerPolymorphicType( char const * name )
315  {
316  auto id = itsPolymorphicTypeMap.find( name );
317  if( id == itsPolymorphicTypeMap.end() )
318  {
319  auto polyId = itsCurrentPolymorphicTypeId++;
320  itsPolymorphicTypeMap.insert( {name, polyId} );
321  return polyId | detail::msb_32bit; // mask MSB to be 1
322  }
323  else
324  return id->second;
325  }
326 
327  private:
329  template <class T> inline
330  void process( T && head )
331  {
332  prologue( *self, head );
333  self->processImpl( head );
334  epilogue( *self, head );
335  }
336 
338  template <class T, class ... Other> inline
339  void process( T && head, Other && ... tail )
340  {
341  self->process( std::forward<T>( head ) );
342  self->process( std::forward<Other>( tail )... );
343  }
344 
346 
347  template <class T> inline
348  ArchiveType & processImpl(virtual_base_class<T> const & b)
349  {
350  traits::detail::base_class_id id(b.base_ptr);
351  if(itsBaseClassSet.count(id) == 0)
352  {
353  itsBaseClassSet.insert(id);
354  self->processImpl( *b.base_ptr );
355  }
356  return *self;
357  }
358 
360 
361  template <class T> inline
362  ArchiveType & processImpl(base_class<T> const & b)
363  {
364  self->processImpl( *b.base_ptr );
365  return *self;
366  }
367 
369 
375  #define PROCESS_IF(name) \
376  traits::EnableIf<traits::has_##name<T, ArchiveType>::value, \
377  !traits::has_invalid_output_versioning<T, ArchiveType>::value, \
378  (traits::is_output_serializable<T, ArchiveType>::value && \
379  (traits::is_specialized_##name<T, ArchiveType>::value || \
380  !traits::is_specialized<T, ArchiveType>::value))> = traits::sfinae
381 
383  template <class T, PROCESS_IF(member_serialize)> inline
384  ArchiveType & processImpl(T const & t)
385  {
386  access::member_serialize(*self, const_cast<T &>(t));
387  return *self;
388  }
389 
391  template <class T, PROCESS_IF(non_member_serialize)> inline
392  ArchiveType & processImpl(T const & t)
393  {
394  CEREAL_SERIALIZE_FUNCTION_NAME(*self, const_cast<T &>(t));
395  return *self;
396  }
397 
399  template <class T, PROCESS_IF(member_save)> inline
400  ArchiveType & processImpl(T const & t)
401  {
402  access::member_save(*self, t);
403  return *self;
404  }
405 
407  template <class T, PROCESS_IF(non_member_save)> inline
408  ArchiveType & processImpl(T const & t)
409  {
410  CEREAL_SAVE_FUNCTION_NAME(*self, t);
411  return *self;
412  }
413 
415  template <class T, PROCESS_IF(member_save_minimal)> inline
416  ArchiveType & processImpl(T const & t)
417  {
418  self->process( access::member_save_minimal(*self, t) );
419  return *self;
420  }
421 
423  template <class T, PROCESS_IF(non_member_save_minimal)> inline
424  ArchiveType & processImpl(T const & t)
425  {
426  self->process( CEREAL_SAVE_MINIMAL_FUNCTION_NAME(*self, t) );
427  return *self;
428  }
429 
431  template <class T, traits::EnableIf<(Flags & AllowEmptyClassElision),
433  std::is_empty<T>::value> = traits::sfinae> inline
434  ArchiveType & processImpl(T const &)
435  {
436  return *self;
437  }
438 
440 
443  template <class T, traits::EnableIf<traits::has_invalid_output_versioning<T, ArchiveType>::value ||
445  (!(Flags & AllowEmptyClassElision) || ((Flags & AllowEmptyClassElision) && !std::is_empty<T>::value)))> = traits::sfinae> inline
446  ArchiveType & processImpl(T const &)
447  {
449  "cereal could not find any output serialization functions for the provided type and archive combination. \n\n "
450  "Types must either have a serialize function, load/save pair, or load_minimal/save_minimal pair (you may not mix these). \n "
451  "Serialize functions generally have the following signature: \n\n "
452  "template<class Archive> \n "
453  " void serialize(Archive & ar) \n "
454  " { \n "
455  " ar( member1, member2, member3 ); \n "
456  " } \n\n " );
457 
459  "cereal found more than one compatible output serialization function for the provided type and archive combination. \n\n "
460  "Types must either have a serialize function, load/save pair, or load_minimal/save_minimal pair (you may not mix these). \n "
461  "Use specialization (see access.hpp) if you need to disambiguate between serialize vs load/save functions. \n "
462  "Note that serialization functions can be inherited which may lead to the aforementioned ambiguities. \n "
463  "In addition, you may not mix versioned with non-versioned serialization functions. \n\n ");
464 
465  return *self;
466  }
467 
469 
474  template <class T> inline
475  std::uint32_t registerClassVersion()
476  {
477  static const auto hash = std::type_index(typeid(T)).hash_code();
478  const auto insertResult = itsVersionedTypes.insert( hash );
480  const auto version =
482 
483  if( insertResult.second ) // insertion took place, serialize the version number
484  process( make_nvp<ArchiveType>("cereal_class_version", version) );
485 
486  return version;
487  }
488 
490 
491  template <class T, PROCESS_IF(member_versioned_serialize)> inline
492  ArchiveType & processImpl(T const & t)
493  {
494  access::member_serialize(*self, const_cast<T &>(t), registerClassVersion<T>());
495  return *self;
496  }
497 
499 
500  template <class T, PROCESS_IF(non_member_versioned_serialize)> inline
501  ArchiveType & processImpl(T const & t)
502  {
503  CEREAL_SERIALIZE_FUNCTION_NAME(*self, const_cast<T &>(t), registerClassVersion<T>());
504  return *self;
505  }
506 
508 
509  template <class T, PROCESS_IF(member_versioned_save)> inline
510  ArchiveType & processImpl(T const & t)
511  {
512  access::member_save(*self, t, registerClassVersion<T>());
513  return *self;
514  }
515 
517 
518  template <class T, PROCESS_IF(non_member_versioned_save)> inline
519  ArchiveType & processImpl(T const & t)
520  {
521  CEREAL_SAVE_FUNCTION_NAME(*self, t, registerClassVersion<T>());
522  return *self;
523  }
524 
526 
527  template <class T, PROCESS_IF(member_versioned_save_minimal)> inline
528  ArchiveType & processImpl(T const & t)
529  {
530  self->process( access::member_save_minimal(*self, t, registerClassVersion<T>()) );
531  return *self;
532  }
533 
535 
536  template <class T, PROCESS_IF(non_member_versioned_save_minimal)> inline
537  ArchiveType & processImpl(T const & t)
538  {
539  self->process( CEREAL_SAVE_MINIMAL_FUNCTION_NAME(*self, t, registerClassVersion<T>()) );
540  return *self;
541  }
542 
543  #undef PROCESS_IF
544 
545  private:
546  ArchiveType * const self;
547 
549  std::unordered_set<traits::detail::base_class_id, traits::detail::base_class_id_hash> itsBaseClassSet;
550 
552  std::unordered_map<void const *, std::uint32_t> itsSharedPointerMap;
553 
555  std::uint32_t itsCurrentPointerId;
556 
558  std::unordered_map<char const *, std::uint32_t> itsPolymorphicTypeMap;
559 
561  std::uint32_t itsCurrentPolymorphicTypeId;
562 
564  std::unordered_set<size_type> itsVersionedTypes;
565  }; // class OutputArchive
566 
567  // ######################################################################
569 
584  template<class ArchiveType, std::uint32_t Flags = 0>
586  {
587  public:
589 
590  InputArchive(ArchiveType * const derived) :
591  self(derived),
592  itsBaseClassSet(),
593  itsSharedPointerMap(),
594  itsPolymorphicTypeMap(),
595  itsVersionedTypes()
596  { }
597 
598  InputArchive & operator=( InputArchive const & ) = delete;
599 
601 
602  template <class ... Types> inline
603  ArchiveType & operator()( Types && ... args )
604  {
605  process( std::forward<Types>( args )... );
606  return *self;
607  }
608 
612 
615 
618  template <class T> inline
619  ArchiveType & operator&( T && arg )
620  {
621  self->process( std::forward<T>( arg ) );
622  return *self;
623  }
624 
626 
629  template <class T> inline
630  ArchiveType & operator>>( T && arg )
631  {
632  self->process( std::forward<T>( arg ) );
633  return *self;
634  }
635 
637 
639 
645  inline std::shared_ptr<void> getSharedPointer(std::uint32_t const id)
646  {
647  if(id == 0) return std::shared_ptr<void>(nullptr);
648 
649  auto iter = itsSharedPointerMap.find( id );
650  if(iter == itsSharedPointerMap.end())
651  throw Exception("Error while trying to deserialize a smart pointer. Could not find id " + std::to_string(id));
652 
653  return iter->second;
654  }
655 
657 
662  inline void registerSharedPointer(std::uint32_t const id, std::shared_ptr<void> ptr)
663  {
664  std::uint32_t const stripped_id = id & ~detail::msb_32bit;
665  itsSharedPointerMap[stripped_id] = ptr;
666  }
667 
669 
674  inline std::string getPolymorphicName(std::uint32_t const id)
675  {
676  auto name = itsPolymorphicTypeMap.find( id );
677  if(name == itsPolymorphicTypeMap.end())
678  {
679  throw Exception("Error while trying to deserialize a polymorphic pointer. Could not find type id " + std::to_string(id));
680  }
681  return name->second;
682  }
683 
685 
690  inline void registerPolymorphicName(std::uint32_t const id, std::string const & name)
691  {
692  std::uint32_t const stripped_id = id & ~detail::msb_32bit;
693  itsPolymorphicTypeMap.insert( {stripped_id, name} );
694  }
695 
696  private:
698  template <class T> inline
699  void process( T && head )
700  {
701  prologue( *self, head );
702  self->processImpl( head );
703  epilogue( *self, head );
704  }
705 
707  template <class T, class ... Other> inline
708  void process( T && head, Other && ... tail )
709  {
710  process( std::forward<T>( head ) );
711  process( std::forward<Other>( tail )... );
712  }
713 
715 
716  template <class T> inline
717  ArchiveType & processImpl(virtual_base_class<T> & b)
718  {
719  traits::detail::base_class_id id(b.base_ptr);
720  if(itsBaseClassSet.count(id) == 0)
721  {
722  itsBaseClassSet.insert(id);
723  self->processImpl( *b.base_ptr );
724  }
725  return *self;
726  }
727 
729 
730  template <class T> inline
731  ArchiveType & processImpl(base_class<T> & b)
732  {
733  self->processImpl( *b.base_ptr );
734  return *self;
735  }
736 
738 
744  #define PROCESS_IF(name) \
745  traits::EnableIf<traits::has_##name<T, ArchiveType>::value, \
746  !traits::has_invalid_input_versioning<T, ArchiveType>::value, \
747  (traits::is_input_serializable<T, ArchiveType>::value && \
748  (traits::is_specialized_##name<T, ArchiveType>::value || \
749  !traits::is_specialized<T, ArchiveType>::value))> = traits::sfinae
750 
752  template <class T, PROCESS_IF(member_serialize)> inline
753  ArchiveType & processImpl(T & t)
754  {
755  access::member_serialize(*self, t);
756  return *self;
757  }
758 
760  template <class T, PROCESS_IF(non_member_serialize)> inline
761  ArchiveType & processImpl(T & t)
762  {
764  return *self;
765  }
766 
768  template <class T, PROCESS_IF(member_load)> inline
769  ArchiveType & processImpl(T & t)
770  {
771  access::member_load(*self, t);
772  return *self;
773  }
774 
776  template <class T, PROCESS_IF(non_member_load)> inline
777  ArchiveType & processImpl(T & t)
778  {
779  CEREAL_LOAD_FUNCTION_NAME(*self, t);
780  return *self;
781  }
782 
784  template <class T, PROCESS_IF(member_load_minimal)> inline
785  ArchiveType & processImpl(T & t)
786  {
787  using OutArchiveType = typename traits::detail::get_output_from_input<ArchiveType>::type;
788  typename traits::has_member_save_minimal<T, OutArchiveType>::type value;
789  self->process( value );
790  access::member_load_minimal(*self, t, value);
791  return *self;
792  }
793 
795  template <class T, PROCESS_IF(non_member_load_minimal)> inline
796  ArchiveType & processImpl(T & t)
797  {
798  using OutArchiveType = typename traits::detail::get_output_from_input<ArchiveType>::type;
799  typename traits::has_non_member_save_minimal<T, OutArchiveType>::type value;
800  self->process( value );
801  CEREAL_LOAD_MINIMAL_FUNCTION_NAME(*self, t, value);
802  return *self;
803  }
804 
806  template <class T, traits::EnableIf<(Flags & AllowEmptyClassElision),
807  !traits::is_input_serializable<T, ArchiveType>::value,
808  std::is_empty<T>::value> = traits::sfinae> inline
809  ArchiveType & processImpl(T const &)
810  {
811  return *self;
812  }
813 
815 
818  template <class T, traits::EnableIf<traits::has_invalid_input_versioning<T, ArchiveType>::value ||
819  (!traits::is_input_serializable<T, ArchiveType>::value &&
820  (!(Flags & AllowEmptyClassElision) || ((Flags & AllowEmptyClassElision) && !std::is_empty<T>::value)))> = traits::sfinae> inline
821  ArchiveType & processImpl(T const &)
822  {
823  static_assert(traits::detail::count_input_serializers<T, ArchiveType>::value != 0,
824  "cereal could not find any input serialization functions for the provided type and archive combination. \n\n "
825  "Types must either have a serialize function, load/save pair, or load_minimal/save_minimal pair (you may not mix these). \n "
826  "Serialize functions generally have the following signature: \n\n "
827  "template<class Archive> \n "
828  " void serialize(Archive & ar) \n "
829  " { \n "
830  " ar( member1, member2, member3 ); \n "
831  " } \n\n " );
832 
833  static_assert(traits::detail::count_input_serializers<T, ArchiveType>::value < 2,
834  "cereal found more than one compatible input serialization function for the provided type and archive combination. \n\n "
835  "Types must either have a serialize function, load/save pair, or load_minimal/save_minimal pair (you may not mix these). \n "
836  "Use specialization (see access.hpp) if you need to disambiguate between serialize vs load/save functions. \n "
837  "Note that serialization functions can be inherited which may lead to the aforementioned ambiguities. \n "
838  "In addition, you may not mix versioned with non-versioned serialization functions. \n\n ");
839 
840  return *self;
841  }
842 
844  template <class A, class B, bool C, bool D, bool E, bool F> friend struct detail::Construct;
845 
847 
852  template <class T> inline
853  std::uint32_t loadClassVersion()
854  {
855  static const auto hash = std::type_index(typeid(T)).hash_code();
856  auto lookupResult = itsVersionedTypes.find( hash );
857 
858  if( lookupResult != itsVersionedTypes.end() ) // already exists
859  return lookupResult->second;
860  else // need to load
861  {
862  std::uint32_t version;
863 
864  process( make_nvp<ArchiveType>("cereal_class_version", version) );
865  itsVersionedTypes.emplace_hint( lookupResult, hash, version );
866 
867  return version;
868  }
869  }
870 
872 
873  template <class T, PROCESS_IF(member_versioned_serialize)> inline
874  ArchiveType & processImpl(T & t)
875  {
876  const auto version = loadClassVersion<T>();
877  access::member_serialize(*self, t, version);
878  return *self;
879  }
880 
882 
883  template <class T, PROCESS_IF(non_member_versioned_serialize)> inline
884  ArchiveType & processImpl(T & t)
885  {
886  const auto version = loadClassVersion<T>();
887  CEREAL_SERIALIZE_FUNCTION_NAME(*self, t, version);
888  return *self;
889  }
890 
892 
893  template <class T, PROCESS_IF(member_versioned_load)> inline
894  ArchiveType & processImpl(T & t)
895  {
896  const auto version = loadClassVersion<T>();
897  access::member_load(*self, t, version);
898  return *self;
899  }
900 
902 
903  template <class T, PROCESS_IF(non_member_versioned_load)> inline
904  ArchiveType & processImpl(T & t)
905  {
906  const auto version = loadClassVersion<T>();
907  CEREAL_LOAD_FUNCTION_NAME(*self, t, version);
908  return *self;
909  }
910 
912 
913  template <class T, PROCESS_IF(member_versioned_load_minimal)> inline
914  ArchiveType & processImpl(T & t)
915  {
916  using OutArchiveType = typename traits::detail::get_output_from_input<ArchiveType>::type;
917  const auto version = loadClassVersion<T>();
918  typename traits::has_member_versioned_save_minimal<T, OutArchiveType>::type value;
919  self->process(value);
920  access::member_load_minimal(*self, t, value, version);
921  return *self;
922  }
923 
925 
926  template <class T, PROCESS_IF(non_member_versioned_load_minimal)> inline
927  ArchiveType & processImpl(T & t)
928  {
929  using OutArchiveType = typename traits::detail::get_output_from_input<ArchiveType>::type;
930  const auto version = loadClassVersion<T>();
931  typename traits::has_non_member_versioned_save_minimal<T, OutArchiveType>::type value;
932  self->process(value);
933  CEREAL_LOAD_MINIMAL_FUNCTION_NAME(*self, t, value, version);
934  return *self;
935  }
936 
937  #undef PROCESS_IF
938 
939  private:
940  ArchiveType * const self;
941 
943  std::unordered_set<traits::detail::base_class_id, traits::detail::base_class_id_hash> itsBaseClassSet;
944 
946  std::unordered_map<std::uint32_t, std::shared_ptr<void>> itsSharedPointerMap;
947 
949  std::unordered_map<std::uint32_t, std::string> itsPolymorphicTypeMap;
950 
952  std::unordered_map<std::size_t, std::uint32_t> itsVersionedTypes;
953  }; // class InputArchive
954 } // namespace cereal
955 
956 // This include needs to come after things such as binary_data, make_nvp, etc
957 #include <cereal/types/common.hpp>
958 
959 #endif // CEREAL_CEREAL_HPP_
ArchiveType & operator()(Types &&...args)
Serializes all passed in data.
Definition: cereal.hpp:603
The number of output serialization functions available.
Definition: traits.hpp:1071
A wrapper around size metadata.
Definition: helpers.hpp:271
Casts a derived class to its virtual base class in a way that allows cereal to track inheritance...
Definition: base_class.hpp:186
Support for base classes (virtual and non-virtual)
std::shared_ptr< void > getSharedPointer(std::uint32_t const id)
Retrieves a shared pointer given a unique key for it.
Definition: cereal.hpp:645
typename detail::EnableIfHelper< Conditions... >::type EnableIf
Provides a way to enable a function if conditions are met.
Definition: traits.hpp:116
Version information class.
Definition: helpers.hpp:360
NameValuePair< T > make_nvp(std::string const &name, T &&value)
Creates a name value pair.
Definition: cereal.hpp:54
Internal type trait support.
std::string getPolymorphicName(std::uint32_t const id)
Retrieves the string for a polymorphic type given a unique key for it.
Definition: cereal.hpp:674
Casts a derived class to its non-virtual base class in a way that safely supports abstract classes...
Definition: base_class.hpp:99
The base input archive class.
Definition: cereal.hpp:585
#define CEREAL_SERIALIZE_FUNCTION_NAME
The serialization/deserialization function name to search for.
Definition: macros.hpp:64
InputArchive(ArchiveType *const derived)
Construct the output archive.
Definition: cereal.hpp:590
#define CEREAL_SAVE_MINIMAL_FUNCTION_NAME
The serialization (save_minimal) function name to search for.
Definition: macros.hpp:92
void prologue(Archive &, T const &)
Definition: cereal.hpp:108
SizeTag< T > make_size_tag(T &&sz)
Creates a size tag from some variable.
Definition: cereal.hpp:95
std::uint32_t registerPolymorphicType(char const *name)
Registers a polymorphic type name with the archive.
Definition: cereal.hpp:314
Support common types - always included automatically.
Internal helper functionality.
Flags
Special flags for archives.
Definition: cereal.hpp:131
static LockGuard lock()
Attempts to lock this static object for the current scope.
Definition: static_object.hpp:109
Definition: access.hpp:40
NameValuePair< T > make_nvp(const char *name, T &&value)
Creates a name value pair.
Definition: cereal.hpp:63
ArchiveType & operator&(T &&arg)
Serializes passed in data.
Definition: cereal.hpp:263
For holding name value pairs.
Definition: helpers.hpp:135
Definition: traits.hpp:1089
Preprocessor macros that can customise the cereal library.
void registerSharedPointer(std::uint32_t const id, std::shared_ptr< void > ptr)
Registers a shared pointer to its unique identifier.
Definition: cereal.hpp:662
#define CEREAL_LOAD_FUNCTION_NAME
The deserialization (load) function name to search for.
Definition: macros.hpp:71
#define CEREAL_LOAD_MINIMAL_FUNCTION_NAME
The deserialization (load_minimal) function name to search for.
Definition: macros.hpp:85
std::uint32_t registerSharedPointer(void const *addr)
Registers a shared pointer with the archive.
Definition: cereal.hpp:290
void registerPolymorphicName(std::uint32_t const id, std::string const &name)
Registers a polymorphic name string to its unique identifier.
Definition: cereal.hpp:690
A wrapper around data that can be serialized in a binary fashion.
Definition: helpers.hpp:207
OutputArchive(ArchiveType *const derived)
Construct the output archive.
Definition: cereal.hpp:239
ArchiveType & operator>>(T &&arg)
Serializes passed in data.
Definition: cereal.hpp:630
Definition: helpers.hpp:228
ArchiveType & operator()(Types &&...args)
Serializes all passed in data.
Definition: cereal.hpp:247
The base output archive class.
Definition: cereal.hpp:234
#define CEREAL_SAVE_FUNCTION_NAME
The serialization (save) function name to search for.
Definition: macros.hpp:78
ArchiveType & operator&(T &&arg)
Serializes passed in data.
Definition: cereal.hpp:619
Definition: traits.hpp:1316
Definition: helpers.hpp:240
ArchiveType & operator<<(T &&arg)
Serializes passed in data.
Definition: cereal.hpp:274
Definition: traits.hpp:1123
A static, pre-execution object.
Definition: static_object.hpp:67
An exception class thrown when things go wrong at runtime.
Definition: helpers.hpp:48
BinaryData< T > binary_data(T &&data, size_t size)
Convenience function to create binary data for both const and non const pointers. ...
Definition: cereal.hpp:80
void epilogue(Archive &, T const &)
Definition: cereal.hpp:115