git repos / blockattack-game

blame: source/code/Libs/include/cereal/access.hpp

normal view · raw

7a956470 sago007 2016-02-14 17:09 1
/*! \file access.hpp
8f94a7f5 sago007 2020-05-10 10:26 2
    \brief Access control and default construction */
7a956470 sago007 2016-02-14 17:09 3
/*
7a956470 sago007 2016-02-14 17:09 4
  Copyright (c) 2014, Randolph Voorhies, Shane Grant
7a956470 sago007 2016-02-14 17:09 5
  All rights reserved.
7a956470 sago007 2016-02-14 17:09 6
7a956470 sago007 2016-02-14 17:09 7
  Redistribution and use in source and binary forms, with or without
7a956470 sago007 2016-02-14 17:09 8
  modification, are permitted provided that the following conditions are met:
7a956470 sago007 2016-02-14 17:09 9
      * Redistributions of source code must retain the above copyright
7a956470 sago007 2016-02-14 17:09 10
        notice, this list of conditions and the following disclaimer.
7a956470 sago007 2016-02-14 17:09 11
      * Redistributions in binary form must reproduce the above copyright
7a956470 sago007 2016-02-14 17:09 12
        notice, this list of conditions and the following disclaimer in the
7a956470 sago007 2016-02-14 17:09 13
        documentation and/or other materials provided with the distribution.
7a956470 sago007 2016-02-14 17:09 14
      * Neither the name of cereal nor the
7a956470 sago007 2016-02-14 17:09 15
        names of its contributors may be used to endorse or promote products
7a956470 sago007 2016-02-14 17:09 16
        derived from this software without specific prior written permission.
7a956470 sago007 2016-02-14 17:09 17
7a956470 sago007 2016-02-14 17:09 18
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
7a956470 sago007 2016-02-14 17:09 19
  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
7a956470 sago007 2016-02-14 17:09 20
  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
7a956470 sago007 2016-02-14 17:09 21
  DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY
7a956470 sago007 2016-02-14 17:09 22
  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
7a956470 sago007 2016-02-14 17:09 23
  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
7a956470 sago007 2016-02-14 17:09 24
  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
7a956470 sago007 2016-02-14 17:09 25
  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
7a956470 sago007 2016-02-14 17:09 26
  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
7a956470 sago007 2016-02-14 17:09 27
  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
7a956470 sago007 2016-02-14 17:09 28
*/
7a956470 sago007 2016-02-14 17:09 29
#ifndef CEREAL_ACCESS_HPP_
7a956470 sago007 2016-02-14 17:09 30
#define CEREAL_ACCESS_HPP_
7a956470 sago007 2016-02-14 17:09 31
7a956470 sago007 2016-02-14 17:09 32
#include <type_traits>
7a956470 sago007 2016-02-14 17:09 33
#include <iostream>
7a956470 sago007 2016-02-14 17:09 34
#include <cstdint>
6c5f2c01 sago007 2017-03-15 17:56 35
#include <functional>
7a956470 sago007 2016-02-14 17:09 36
6c5f2c01 sago007 2017-03-15 17:56 37
#include "cereal/macros.hpp"
8f94a7f5 sago007 2020-05-10 10:26 38
#include "cereal/specialize.hpp"
6c5f2c01 sago007 2017-03-15 17:56 39
#include "cereal/details/helpers.hpp"
7a956470 sago007 2016-02-14 17:09 40
7a956470 sago007 2016-02-14 17:09 41
namespace cereal
7a956470 sago007 2016-02-14 17:09 42
{
7a956470 sago007 2016-02-14 17:09 43
  // ######################################################################
7a956470 sago007 2016-02-14 17:09 44
  //! A class that allows cereal to load smart pointers to types that have no default constructor
7a956470 sago007 2016-02-14 17:09 45
  /*! If your class does not have a default constructor, cereal will not be able
7a956470 sago007 2016-02-14 17:09 46
      to load any smart pointers to it unless you overload LoadAndConstruct
7a956470 sago007 2016-02-14 17:09 47
      for your class, and provide an appropriate load_and_construct method.  You can also
7a956470 sago007 2016-02-14 17:09 48
      choose to define a member static function instead of specializing this class.
7a956470 sago007 2016-02-14 17:09 49
7a956470 sago007 2016-02-14 17:09 50
      The specialization of LoadAndConstruct must be placed within the cereal namespace:
7a956470 sago007 2016-02-14 17:09 51
7a956470 sago007 2016-02-14 17:09 52
      @code{.cpp}
7a956470 sago007 2016-02-14 17:09 53
      struct MyType
7a956470 sago007 2016-02-14 17:09 54
      {
7a956470 sago007 2016-02-14 17:09 55
        MyType( int x ); // note: no default ctor
7a956470 sago007 2016-02-14 17:09 56
        int myX;
7a956470 sago007 2016-02-14 17:09 57
7a956470 sago007 2016-02-14 17:09 58
        // Define a serialize or load/save pair as you normally would
7a956470 sago007 2016-02-14 17:09 59
        template <class Archive>
7a956470 sago007 2016-02-14 17:09 60
        void serialize( Archive & ar )
7a956470 sago007 2016-02-14 17:09 61
        {
7a956470 sago007 2016-02-14 17:09 62
          ar( myX );
7a956470 sago007 2016-02-14 17:09 63
        }
7a956470 sago007 2016-02-14 17:09 64
      };
7a956470 sago007 2016-02-14 17:09 65
7a956470 sago007 2016-02-14 17:09 66
      // Provide a specialization for LoadAndConstruct for your type
7a956470 sago007 2016-02-14 17:09 67
      namespace cereal
7a956470 sago007 2016-02-14 17:09 68
      {
7a956470 sago007 2016-02-14 17:09 69
        template <> struct LoadAndConstruct<MyType>
7a956470 sago007 2016-02-14 17:09 70
        {
7a956470 sago007 2016-02-14 17:09 71
          // load_and_construct will be passed the archive that you will be loading
7a956470 sago007 2016-02-14 17:09 72
          // from as well as a construct object which you can use as if it were the
7a956470 sago007 2016-02-14 17:09 73
          // constructor for your type.  cereal will handle all memory management for you.
7a956470 sago007 2016-02-14 17:09 74
          template <class Archive>
7a956470 sago007 2016-02-14 17:09 75
          static void load_and_construct( Archive & ar, cereal::construct<MyType> & construct )
7a956470 sago007 2016-02-14 17:09 76
          {
7a956470 sago007 2016-02-14 17:09 77
            int x;
7a956470 sago007 2016-02-14 17:09 78
            ar( x );
7a956470 sago007 2016-02-14 17:09 79
            construct( x );
7a956470 sago007 2016-02-14 17:09 80
          }
6c5f2c01 sago007 2017-03-15 17:56 81
6c5f2c01 sago007 2017-03-15 17:56 82
          // if you require versioning, simply add a const std::uint32_t as the final parameter, e.g.:
6c5f2c01 sago007 2017-03-15 17:56 83
          // load_and_construct( Archive & ar, cereal::construct<MyType> & construct, std::uint32_t const version )
7a956470 sago007 2016-02-14 17:09 84
        };
7a956470 sago007 2016-02-14 17:09 85
      } // end namespace cereal
7a956470 sago007 2016-02-14 17:09 86
      @endcode
7a956470 sago007 2016-02-14 17:09 87
7a956470 sago007 2016-02-14 17:09 88
      Please note that just as in using external serialization functions, you cannot get
7a956470 sago007 2016-02-14 17:09 89
      access to non-public members of your class by befriending cereal::access.  If you
7a956470 sago007 2016-02-14 17:09 90
      have the ability to modify the class you wish to serialize, it is recommended that you
7a956470 sago007 2016-02-14 17:09 91
      use member serialize functions and a static member load_and_construct function.
7a956470 sago007 2016-02-14 17:09 92
6c5f2c01 sago007 2017-03-15 17:56 93
      load_and_construct functions, regardless of whether they are static members of your class or
6c5f2c01 sago007 2017-03-15 17:56 94
      whether you create one in the LoadAndConstruct specialization, have the following signature:
6c5f2c01 sago007 2017-03-15 17:56 95
6c5f2c01 sago007 2017-03-15 17:56 96
      @code{.cpp}
6c5f2c01 sago007 2017-03-15 17:56 97
      // generally Archive will be templated, but it can be specific if desired
6c5f2c01 sago007 2017-03-15 17:56 98
      template <class Archive>
6c5f2c01 sago007 2017-03-15 17:56 99
      static void load_and_construct( Archive & ar, cereal::construct<MyType> & construct );
6c5f2c01 sago007 2017-03-15 17:56 100
      // with an optional last parameter specifying the version: const std::uint32_t version
6c5f2c01 sago007 2017-03-15 17:56 101
      @endcode
6c5f2c01 sago007 2017-03-15 17:56 102
6c5f2c01 sago007 2017-03-15 17:56 103
      Versioning behaves the same way as it does for standard serialization functions.
6c5f2c01 sago007 2017-03-15 17:56 104
7a956470 sago007 2016-02-14 17:09 105
      @tparam T The type to specialize for
7a956470 sago007 2016-02-14 17:09 106
      @ingroup Access */
7a956470 sago007 2016-02-14 17:09 107
  template <class T>
7a956470 sago007 2016-02-14 17:09 108
  struct LoadAndConstruct
6c5f2c01 sago007 2017-03-15 17:56 109
  { };
7a956470 sago007 2016-02-14 17:09 110
7a956470 sago007 2016-02-14 17:09 111
  // forward decl for construct
7a956470 sago007 2016-02-14 17:09 112
  //! @cond PRIVATE_NEVERDEFINED
7a956470 sago007 2016-02-14 17:09 113
  namespace memory_detail{ template <class Ar, class T> struct LoadAndConstructLoadWrapper; }
8f94a7f5 sago007 2020-05-10 10:26 114
  namespace boost_variant_detail{ template <class Ar, class T> struct LoadAndConstructLoadWrapper; }
7a956470 sago007 2016-02-14 17:09 115
  //! @endcond
7a956470 sago007 2016-02-14 17:09 116
7a956470 sago007 2016-02-14 17:09 117
  //! Used to construct types with no default constructor
7a956470 sago007 2016-02-14 17:09 118
  /*! When serializing a type that has no default constructor, cereal
7a956470 sago007 2016-02-14 17:09 119
      will attempt to call either the class static function load_and_construct
7a956470 sago007 2016-02-14 17:09 120
      or the appropriate template specialization of LoadAndConstruct.  cereal
7a956470 sago007 2016-02-14 17:09 121
      will pass that function a reference to the archive as well as a reference
7a956470 sago007 2016-02-14 17:09 122
      to a construct object which should be used to perform the allocation once
7a956470 sago007 2016-02-14 17:09 123
      data has been appropriately loaded.
7a956470 sago007 2016-02-14 17:09 124
7a956470 sago007 2016-02-14 17:09 125
      @code{.cpp}
7a956470 sago007 2016-02-14 17:09 126
      struct MyType
7a956470 sago007 2016-02-14 17:09 127
      {
7a956470 sago007 2016-02-14 17:09 128
        // note the lack of default constructor
7a956470 sago007 2016-02-14 17:09 129
        MyType( int xx, int yy );
7a956470 sago007 2016-02-14 17:09 130
7a956470 sago007 2016-02-14 17:09 131
        int x, y;
7a956470 sago007 2016-02-14 17:09 132
        double notInConstructor;
7a956470 sago007 2016-02-14 17:09 133
7a956470 sago007 2016-02-14 17:09 134
        template <class Archive>
7a956470 sago007 2016-02-14 17:09 135
        void serialize( Archive & ar )
7a956470 sago007 2016-02-14 17:09 136
        {
7a956470 sago007 2016-02-14 17:09 137
          ar( x, y );
7a956470 sago007 2016-02-14 17:09 138
          ar( notInConstructor );
7a956470 sago007 2016-02-14 17:09 139
        }
7a956470 sago007 2016-02-14 17:09 140
7a956470 sago007 2016-02-14 17:09 141
        template <class Archive>
7a956470 sago007 2016-02-14 17:09 142
        static void load_and_construct( Archive & ar, cereal::construct<MyType> & construct )
7a956470 sago007 2016-02-14 17:09 143
        {
7a956470 sago007 2016-02-14 17:09 144
          int x, y;
7a956470 sago007 2016-02-14 17:09 145
          ar( x, y );
7a956470 sago007 2016-02-14 17:09 146
7a956470 sago007 2016-02-14 17:09 147
          // use construct object to initialize with loaded data
7a956470 sago007 2016-02-14 17:09 148
          construct( x, y );
7a956470 sago007 2016-02-14 17:09 149
7a956470 sago007 2016-02-14 17:09 150
          // access to member variables and functions via -> operator
7a956470 sago007 2016-02-14 17:09 151
          ar( construct->notInConstructor );
7a956470 sago007 2016-02-14 17:09 152
7a956470 sago007 2016-02-14 17:09 153
          // could also do the above section by:
7a956470 sago007 2016-02-14 17:09 154
          double z;
7a956470 sago007 2016-02-14 17:09 155
          ar( z );
7a956470 sago007 2016-02-14 17:09 156
          construct->notInConstructor = z;
7a956470 sago007 2016-02-14 17:09 157
        }
7a956470 sago007 2016-02-14 17:09 158
      };
7a956470 sago007 2016-02-14 17:09 159
      @endcode
7a956470 sago007 2016-02-14 17:09 160
7a956470 sago007 2016-02-14 17:09 161
      @tparam T The class type being serialized
7a956470 sago007 2016-02-14 17:09 162
      */
7a956470 sago007 2016-02-14 17:09 163
  template <class T>
7a956470 sago007 2016-02-14 17:09 164
  class construct
7a956470 sago007 2016-02-14 17:09 165
  {
7a956470 sago007 2016-02-14 17:09 166
    public:
7a956470 sago007 2016-02-14 17:09 167
      //! Construct and initialize the type T with the given arguments
7a956470 sago007 2016-02-14 17:09 168
      /*! This will forward all arguments to the underlying type T,
7a956470 sago007 2016-02-14 17:09 169
          calling an appropriate constructor.
7a956470 sago007 2016-02-14 17:09 170
7a956470 sago007 2016-02-14 17:09 171
          Calling this function more than once will result in an exception
7a956470 sago007 2016-02-14 17:09 172
          being thrown.
7a956470 sago007 2016-02-14 17:09 173
7a956470 sago007 2016-02-14 17:09 174
          @param args The arguments to the constructor for T
7a956470 sago007 2016-02-14 17:09 175
          @throw Exception If called more than once */
7a956470 sago007 2016-02-14 17:09 176
      template <class ... Args>
7a956470 sago007 2016-02-14 17:09 177
      void operator()( Args && ... args );
7a956470 sago007 2016-02-14 17:09 178
      // implementation deferred due to reliance on cereal::access
7a956470 sago007 2016-02-14 17:09 179
7a956470 sago007 2016-02-14 17:09 180
      //! Get a reference to the initialized underlying object
7a956470 sago007 2016-02-14 17:09 181
      /*! This must be called after the object has been initialized.
7a956470 sago007 2016-02-14 17:09 182
7a956470 sago007 2016-02-14 17:09 183
          @return A reference to the initialized object
7a956470 sago007 2016-02-14 17:09 184
          @throw Exception If called before initialization */
7a956470 sago007 2016-02-14 17:09 185
      T * operator->()
7a956470 sago007 2016-02-14 17:09 186
      {
7a956470 sago007 2016-02-14 17:09 187
        if( !itsValid )
7a956470 sago007 2016-02-14 17:09 188
          throw Exception("Object must be initialized prior to accessing members");
7a956470 sago007 2016-02-14 17:09 189
7a956470 sago007 2016-02-14 17:09 190
        return itsPtr;
7a956470 sago007 2016-02-14 17:09 191
      }
7a956470 sago007 2016-02-14 17:09 192
7a956470 sago007 2016-02-14 17:09 193
      //! Returns a raw pointer to the initialized underlying object
7a956470 sago007 2016-02-14 17:09 194
      /*! This is mainly intended for use with passing an instance of
7a956470 sago007 2016-02-14 17:09 195
          a constructed object to cereal::base_class.
7a956470 sago007 2016-02-14 17:09 196
7a956470 sago007 2016-02-14 17:09 197
          It is strongly recommended to avoid using this function in
7a956470 sago007 2016-02-14 17:09 198
          any other circumstance.
7a956470 sago007 2016-02-14 17:09 199
7a956470 sago007 2016-02-14 17:09 200
          @return A raw pointer to the initialized type */
7a956470 sago007 2016-02-14 17:09 201
      T * ptr()
7a956470 sago007 2016-02-14 17:09 202
      {
7a956470 sago007 2016-02-14 17:09 203
        return operator->();
7a956470 sago007 2016-02-14 17:09 204
      }
7a956470 sago007 2016-02-14 17:09 205
7a956470 sago007 2016-02-14 17:09 206
    private:
8f94a7f5 sago007 2020-05-10 10:26 207
      template <class Ar, class TT> friend struct ::cereal::memory_detail::LoadAndConstructLoadWrapper;
8f94a7f5 sago007 2020-05-10 10:26 208
      template <class Ar, class TT> friend struct ::cereal::boost_variant_detail::LoadAndConstructLoadWrapper;
7a956470 sago007 2016-02-14 17:09 209
6c5f2c01 sago007 2017-03-15 17:56 210
      construct( T * p ) : itsPtr( p ), itsEnableSharedRestoreFunction( [](){} ), itsValid( false ) {}
6c5f2c01 sago007 2017-03-15 17:56 211
      construct( T * p, std::function<void()> enableSharedFunc ) : // g++4.7 ice with default lambda to std func
6c5f2c01 sago007 2017-03-15 17:56 212
        itsPtr( p ), itsEnableSharedRestoreFunction( enableSharedFunc ), itsValid( false ) {}
7a956470 sago007 2016-02-14 17:09 213
      construct( construct const & ) = delete;
7a956470 sago007 2016-02-14 17:09 214
      construct & operator=( construct const & ) = delete;
7a956470 sago007 2016-02-14 17:09 215
7a956470 sago007 2016-02-14 17:09 216
      T * itsPtr;
6c5f2c01 sago007 2017-03-15 17:56 217
      std::function<void()> itsEnableSharedRestoreFunction;
7a956470 sago007 2016-02-14 17:09 218
      bool itsValid;
7a956470 sago007 2016-02-14 17:09 219
  };
7a956470 sago007 2016-02-14 17:09 220
7a956470 sago007 2016-02-14 17:09 221
  // ######################################################################
7a956470 sago007 2016-02-14 17:09 222
  //! A class that can be made a friend to give cereal access to non public functions
7a956470 sago007 2016-02-14 17:09 223
  /*! If you desire non-public serialization functions within a class, cereal can only
7a956470 sago007 2016-02-14 17:09 224
      access these if you declare cereal::access a friend.
7a956470 sago007 2016-02-14 17:09 225
7a956470 sago007 2016-02-14 17:09 226
      @code{.cpp}
7a956470 sago007 2016-02-14 17:09 227
      class MyClass
7a956470 sago007 2016-02-14 17:09 228
      {
7a956470 sago007 2016-02-14 17:09 229
        private:
7a956470 sago007 2016-02-14 17:09 230
          friend class cereal::access; // gives access to the private serialize
7a956470 sago007 2016-02-14 17:09 231
7a956470 sago007 2016-02-14 17:09 232
          template <class Archive>
7a956470 sago007 2016-02-14 17:09 233
          void serialize( Archive & ar )
7a956470 sago007 2016-02-14 17:09 234
          {
7a956470 sago007 2016-02-14 17:09 235
            // some code
7a956470 sago007 2016-02-14 17:09 236
          }
7a956470 sago007 2016-02-14 17:09 237
      };
7a956470 sago007 2016-02-14 17:09 238
      @endcode
7a956470 sago007 2016-02-14 17:09 239
      @ingroup Access */
7a956470 sago007 2016-02-14 17:09 240
  class access
7a956470 sago007 2016-02-14 17:09 241
  {
7a956470 sago007 2016-02-14 17:09 242
    public:
7a956470 sago007 2016-02-14 17:09 243
      // ####### Standard Serialization ########################################
7a956470 sago007 2016-02-14 17:09 244
      template<class Archive, class T> inline
7a956470 sago007 2016-02-14 17:09 245
      static auto member_serialize(Archive & ar, T & t) -> decltype(t.CEREAL_SERIALIZE_FUNCTION_NAME(ar))
7a956470 sago007 2016-02-14 17:09 246
      { return t.CEREAL_SERIALIZE_FUNCTION_NAME(ar); }
7a956470 sago007 2016-02-14 17:09 247
7a956470 sago007 2016-02-14 17:09 248
      template<class Archive, class T> inline
7a956470 sago007 2016-02-14 17:09 249
      static auto member_save(Archive & ar, T const & t) -> decltype(t.CEREAL_SAVE_FUNCTION_NAME(ar))
7a956470 sago007 2016-02-14 17:09 250
      { return t.CEREAL_SAVE_FUNCTION_NAME(ar); }
7a956470 sago007 2016-02-14 17:09 251
7a956470 sago007 2016-02-14 17:09 252
      template<class Archive, class T> inline
7a956470 sago007 2016-02-14 17:09 253
      static auto member_save_non_const(Archive & ar, T & t) -> decltype(t.CEREAL_SAVE_FUNCTION_NAME(ar))
7a956470 sago007 2016-02-14 17:09 254
      { return t.CEREAL_SAVE_FUNCTION_NAME(ar); }
7a956470 sago007 2016-02-14 17:09 255
7a956470 sago007 2016-02-14 17:09 256
      template<class Archive, class T> inline
7a956470 sago007 2016-02-14 17:09 257
      static auto member_load(Archive & ar, T & t) -> decltype(t.CEREAL_LOAD_FUNCTION_NAME(ar))
7a956470 sago007 2016-02-14 17:09 258
      { return t.CEREAL_LOAD_FUNCTION_NAME(ar); }
7a956470 sago007 2016-02-14 17:09 259
7a956470 sago007 2016-02-14 17:09 260
      template<class Archive, class T> inline
7a956470 sago007 2016-02-14 17:09 261
      static auto member_save_minimal(Archive const & ar, T const & t) -> decltype(t.CEREAL_SAVE_MINIMAL_FUNCTION_NAME(ar))
7a956470 sago007 2016-02-14 17:09 262
      { return t.CEREAL_SAVE_MINIMAL_FUNCTION_NAME(ar); }
7a956470 sago007 2016-02-14 17:09 263
7a956470 sago007 2016-02-14 17:09 264
      template<class Archive, class T> inline
7a956470 sago007 2016-02-14 17:09 265
      static auto member_save_minimal_non_const(Archive const & ar, T & t) -> decltype(t.CEREAL_SAVE_MINIMAL_FUNCTION_NAME(ar))
7a956470 sago007 2016-02-14 17:09 266
      { return t.CEREAL_SAVE_MINIMAL_FUNCTION_NAME(ar); }
7a956470 sago007 2016-02-14 17:09 267
7a956470 sago007 2016-02-14 17:09 268
      template<class Archive, class T, class U> inline
7a956470 sago007 2016-02-14 17:09 269
      static auto member_load_minimal(Archive const & ar, T & t, U && u) -> decltype(t.CEREAL_LOAD_MINIMAL_FUNCTION_NAME(ar, std::forward<U>(u)))
7a956470 sago007 2016-02-14 17:09 270
      { return t.CEREAL_LOAD_MINIMAL_FUNCTION_NAME(ar, std::forward<U>(u)); }
7a956470 sago007 2016-02-14 17:09 271
7a956470 sago007 2016-02-14 17:09 272
      // ####### Versioned Serialization #######################################
7a956470 sago007 2016-02-14 17:09 273
      template<class Archive, class T> inline
7a956470 sago007 2016-02-14 17:09 274
      static auto member_serialize(Archive & ar, T & t, const std::uint32_t version ) -> decltype(t.CEREAL_SERIALIZE_FUNCTION_NAME(ar, version))
7a956470 sago007 2016-02-14 17:09 275
      { return t.CEREAL_SERIALIZE_FUNCTION_NAME(ar, version); }
7a956470 sago007 2016-02-14 17:09 276
7a956470 sago007 2016-02-14 17:09 277
      template<class Archive, class T> inline
7a956470 sago007 2016-02-14 17:09 278
      static auto member_save(Archive & ar, T const & t, const std::uint32_t version ) -> decltype(t.CEREAL_SAVE_FUNCTION_NAME(ar, version))
7a956470 sago007 2016-02-14 17:09 279
      { return t.CEREAL_SAVE_FUNCTION_NAME(ar, version); }
7a956470 sago007 2016-02-14 17:09 280
7a956470 sago007 2016-02-14 17:09 281
      template<class Archive, class T> inline
7a956470 sago007 2016-02-14 17:09 282
      static auto member_save_non_const(Archive & ar, T & t, const std::uint32_t version ) -> decltype(t.CEREAL_SAVE_FUNCTION_NAME(ar, version))
7a956470 sago007 2016-02-14 17:09 283
      { return t.CEREAL_SAVE_FUNCTION_NAME(ar, version); }
7a956470 sago007 2016-02-14 17:09 284
7a956470 sago007 2016-02-14 17:09 285
      template<class Archive, class T> inline
7a956470 sago007 2016-02-14 17:09 286
      static auto member_load(Archive & ar, T & t, const std::uint32_t version ) -> decltype(t.CEREAL_LOAD_FUNCTION_NAME(ar, version))
7a956470 sago007 2016-02-14 17:09 287
      { return t.CEREAL_LOAD_FUNCTION_NAME(ar, version); }
7a956470 sago007 2016-02-14 17:09 288
7a956470 sago007 2016-02-14 17:09 289
      template<class Archive, class T> inline
7a956470 sago007 2016-02-14 17:09 290
      static auto member_save_minimal(Archive const & ar, T const & t, const std::uint32_t version) -> decltype(t.CEREAL_SAVE_MINIMAL_FUNCTION_NAME(ar, version))
7a956470 sago007 2016-02-14 17:09 291
      { return t.CEREAL_SAVE_MINIMAL_FUNCTION_NAME(ar, version); }
7a956470 sago007 2016-02-14 17:09 292
7a956470 sago007 2016-02-14 17:09 293
      template<class Archive, class T> inline
7a956470 sago007 2016-02-14 17:09 294
      static auto member_save_minimal_non_const(Archive const & ar, T & t, const std::uint32_t version) -> decltype(t.CEREAL_SAVE_MINIMAL_FUNCTION_NAME(ar, version))
7a956470 sago007 2016-02-14 17:09 295
      { return t.CEREAL_SAVE_MINIMAL_FUNCTION_NAME(ar, version); }
7a956470 sago007 2016-02-14 17:09 296
7a956470 sago007 2016-02-14 17:09 297
      template<class Archive, class T, class U> inline
7a956470 sago007 2016-02-14 17:09 298
      static auto member_load_minimal(Archive const & ar, T & t, U && u, const std::uint32_t version) -> decltype(t.CEREAL_LOAD_MINIMAL_FUNCTION_NAME(ar, std::forward<U>(u), version))
7a956470 sago007 2016-02-14 17:09 299
      { return t.CEREAL_LOAD_MINIMAL_FUNCTION_NAME(ar, std::forward<U>(u), version); }
7a956470 sago007 2016-02-14 17:09 300
7a956470 sago007 2016-02-14 17:09 301
      // ####### Other Functionality ##########################################
7a956470 sago007 2016-02-14 17:09 302
      // for detecting inheritance from enable_shared_from_this
7a956470 sago007 2016-02-14 17:09 303
      template <class T> inline
7a956470 sago007 2016-02-14 17:09 304
      static auto shared_from_this(T & t) -> decltype(t.shared_from_this());
7a956470 sago007 2016-02-14 17:09 305
7a956470 sago007 2016-02-14 17:09 306
      // for placement new
7a956470 sago007 2016-02-14 17:09 307
      template <class T, class ... Args> inline
7a956470 sago007 2016-02-14 17:09 308
      static void construct( T *& ptr, Args && ... args )
7a956470 sago007 2016-02-14 17:09 309
      {
7a956470 sago007 2016-02-14 17:09 310
        new (ptr) T( std::forward<Args>( args )... );
7a956470 sago007 2016-02-14 17:09 311
      }
7a956470 sago007 2016-02-14 17:09 312
7a956470 sago007 2016-02-14 17:09 313
      // for non-placement new with a default constructor
7a956470 sago007 2016-02-14 17:09 314
      template <class T> inline
7a956470 sago007 2016-02-14 17:09 315
      static T * construct()
7a956470 sago007 2016-02-14 17:09 316
      {
7a956470 sago007 2016-02-14 17:09 317
        return new T();
7a956470 sago007 2016-02-14 17:09 318
      }
7a956470 sago007 2016-02-14 17:09 319
7a956470 sago007 2016-02-14 17:09 320
      template <class T> inline
7a956470 sago007 2016-02-14 17:09 321
      static std::false_type load_and_construct(...)
7a956470 sago007 2016-02-14 17:09 322
      { return std::false_type(); }
7a956470 sago007 2016-02-14 17:09 323
7a956470 sago007 2016-02-14 17:09 324
      template<class T, class Archive> inline
7a956470 sago007 2016-02-14 17:09 325
      static auto load_and_construct(Archive & ar, ::cereal::construct<T> & construct) -> decltype(T::load_and_construct(ar, construct))
7a956470 sago007 2016-02-14 17:09 326
      {
7a956470 sago007 2016-02-14 17:09 327
        T::load_and_construct( ar, construct );
7a956470 sago007 2016-02-14 17:09 328
      }
6c5f2c01 sago007 2017-03-15 17:56 329
6c5f2c01 sago007 2017-03-15 17:56 330
      template<class T, class Archive> inline
6c5f2c01 sago007 2017-03-15 17:56 331
      static auto load_and_construct(Archive & ar, ::cereal::construct<T> & construct, const std::uint32_t version) -> decltype(T::load_and_construct(ar, construct, version))
6c5f2c01 sago007 2017-03-15 17:56 332
      {
6c5f2c01 sago007 2017-03-15 17:56 333
        T::load_and_construct( ar, construct, version );
6c5f2c01 sago007 2017-03-15 17:56 334
      }
7a956470 sago007 2016-02-14 17:09 335
  }; // end class access
7a956470 sago007 2016-02-14 17:09 336
7a956470 sago007 2016-02-14 17:09 337
  // ######################################################################
7a956470 sago007 2016-02-14 17:09 338
  // Deferred Implementation, see construct for more information
7a956470 sago007 2016-02-14 17:09 339
  template <class T> template <class ... Args> inline
7a956470 sago007 2016-02-14 17:09 340
  void construct<T>::operator()( Args && ... args )
7a956470 sago007 2016-02-14 17:09 341
  {
7a956470 sago007 2016-02-14 17:09 342
    if( itsValid )
7a956470 sago007 2016-02-14 17:09 343
      throw Exception("Attempting to construct an already initialized object");
7a956470 sago007 2016-02-14 17:09 344
7a956470 sago007 2016-02-14 17:09 345
    ::cereal::access::construct( itsPtr, std::forward<Args>( args )... );
6c5f2c01 sago007 2017-03-15 17:56 346
    itsEnableSharedRestoreFunction();
7a956470 sago007 2016-02-14 17:09 347
    itsValid = true;
7a956470 sago007 2016-02-14 17:09 348
  }
7a956470 sago007 2016-02-14 17:09 349
} // namespace cereal
7a956470 sago007 2016-02-14 17:09 350
7a956470 sago007 2016-02-14 17:09 351
#endif // CEREAL_ACCESS_HPP_
1970-01-01 00:00 352