isotree 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -1
- data/LICENSE.txt +2 -2
- data/README.md +32 -14
- data/ext/isotree/ext.cpp +144 -31
- data/ext/isotree/extconf.rb +7 -7
- data/lib/isotree/isolation_forest.rb +110 -30
- data/lib/isotree/version.rb +1 -1
- data/vendor/isotree/LICENSE +1 -1
- data/vendor/isotree/README.md +165 -27
- data/vendor/isotree/include/isotree.hpp +2111 -0
- data/vendor/isotree/include/isotree_oop.hpp +394 -0
- data/vendor/isotree/inst/COPYRIGHTS +62 -0
- data/vendor/isotree/src/RcppExports.cpp +525 -52
- data/vendor/isotree/src/Rwrapper.cpp +1931 -268
- data/vendor/isotree/src/c_interface.cpp +953 -0
- data/vendor/isotree/src/crit.hpp +4232 -0
- data/vendor/isotree/src/dist.hpp +1886 -0
- data/vendor/isotree/src/exp_depth_table.hpp +134 -0
- data/vendor/isotree/src/extended.hpp +1444 -0
- data/vendor/isotree/src/external_facing_generic.hpp +399 -0
- data/vendor/isotree/src/fit_model.hpp +2401 -0
- data/vendor/isotree/src/{dealloc.cpp → headers_joined.hpp} +38 -22
- data/vendor/isotree/src/helpers_iforest.hpp +813 -0
- data/vendor/isotree/src/{impute.cpp → impute.hpp} +353 -122
- data/vendor/isotree/src/indexer.cpp +515 -0
- data/vendor/isotree/src/instantiate_template_headers.cpp +118 -0
- data/vendor/isotree/src/instantiate_template_headers.hpp +240 -0
- data/vendor/isotree/src/isoforest.hpp +1659 -0
- data/vendor/isotree/src/isotree.hpp +1804 -392
- data/vendor/isotree/src/isotree_exportable.hpp +99 -0
- data/vendor/isotree/src/merge_models.cpp +159 -16
- data/vendor/isotree/src/mult.hpp +1321 -0
- data/vendor/isotree/src/oop_interface.cpp +842 -0
- data/vendor/isotree/src/oop_interface.hpp +278 -0
- data/vendor/isotree/src/other_helpers.hpp +219 -0
- data/vendor/isotree/src/predict.hpp +1932 -0
- data/vendor/isotree/src/python_helpers.hpp +134 -0
- data/vendor/isotree/src/ref_indexer.hpp +154 -0
- data/vendor/isotree/src/robinmap/LICENSE +21 -0
- data/vendor/isotree/src/robinmap/README.md +483 -0
- data/vendor/isotree/src/robinmap/include/tsl/robin_growth_policy.h +406 -0
- data/vendor/isotree/src/robinmap/include/tsl/robin_hash.h +1620 -0
- data/vendor/isotree/src/robinmap/include/tsl/robin_map.h +807 -0
- data/vendor/isotree/src/robinmap/include/tsl/robin_set.h +660 -0
- data/vendor/isotree/src/serialize.cpp +4300 -139
- data/vendor/isotree/src/sql.cpp +141 -59
- data/vendor/isotree/src/subset_models.cpp +174 -0
- data/vendor/isotree/src/utils.hpp +3808 -0
- data/vendor/isotree/src/xoshiro.hpp +467 -0
- data/vendor/isotree/src/ziggurat.hpp +405 -0
- metadata +38 -104
- data/vendor/cereal/LICENSE +0 -24
- data/vendor/cereal/README.md +0 -85
- data/vendor/cereal/include/cereal/access.hpp +0 -351
- data/vendor/cereal/include/cereal/archives/adapters.hpp +0 -163
- data/vendor/cereal/include/cereal/archives/binary.hpp +0 -169
- data/vendor/cereal/include/cereal/archives/json.hpp +0 -1019
- data/vendor/cereal/include/cereal/archives/portable_binary.hpp +0 -334
- data/vendor/cereal/include/cereal/archives/xml.hpp +0 -956
- data/vendor/cereal/include/cereal/cereal.hpp +0 -1089
- data/vendor/cereal/include/cereal/details/helpers.hpp +0 -422
- data/vendor/cereal/include/cereal/details/polymorphic_impl.hpp +0 -796
- data/vendor/cereal/include/cereal/details/polymorphic_impl_fwd.hpp +0 -65
- data/vendor/cereal/include/cereal/details/static_object.hpp +0 -127
- data/vendor/cereal/include/cereal/details/traits.hpp +0 -1411
- data/vendor/cereal/include/cereal/details/util.hpp +0 -84
- data/vendor/cereal/include/cereal/external/base64.hpp +0 -134
- data/vendor/cereal/include/cereal/external/rapidjson/allocators.h +0 -284
- data/vendor/cereal/include/cereal/external/rapidjson/cursorstreamwrapper.h +0 -78
- data/vendor/cereal/include/cereal/external/rapidjson/document.h +0 -2652
- data/vendor/cereal/include/cereal/external/rapidjson/encodedstream.h +0 -299
- data/vendor/cereal/include/cereal/external/rapidjson/encodings.h +0 -716
- data/vendor/cereal/include/cereal/external/rapidjson/error/en.h +0 -74
- data/vendor/cereal/include/cereal/external/rapidjson/error/error.h +0 -161
- data/vendor/cereal/include/cereal/external/rapidjson/filereadstream.h +0 -99
- data/vendor/cereal/include/cereal/external/rapidjson/filewritestream.h +0 -104
- data/vendor/cereal/include/cereal/external/rapidjson/fwd.h +0 -151
- data/vendor/cereal/include/cereal/external/rapidjson/internal/biginteger.h +0 -290
- data/vendor/cereal/include/cereal/external/rapidjson/internal/diyfp.h +0 -271
- data/vendor/cereal/include/cereal/external/rapidjson/internal/dtoa.h +0 -245
- data/vendor/cereal/include/cereal/external/rapidjson/internal/ieee754.h +0 -78
- data/vendor/cereal/include/cereal/external/rapidjson/internal/itoa.h +0 -308
- data/vendor/cereal/include/cereal/external/rapidjson/internal/meta.h +0 -186
- data/vendor/cereal/include/cereal/external/rapidjson/internal/pow10.h +0 -55
- data/vendor/cereal/include/cereal/external/rapidjson/internal/regex.h +0 -740
- data/vendor/cereal/include/cereal/external/rapidjson/internal/stack.h +0 -232
- data/vendor/cereal/include/cereal/external/rapidjson/internal/strfunc.h +0 -69
- data/vendor/cereal/include/cereal/external/rapidjson/internal/strtod.h +0 -290
- data/vendor/cereal/include/cereal/external/rapidjson/internal/swap.h +0 -46
- data/vendor/cereal/include/cereal/external/rapidjson/istreamwrapper.h +0 -128
- data/vendor/cereal/include/cereal/external/rapidjson/memorybuffer.h +0 -70
- data/vendor/cereal/include/cereal/external/rapidjson/memorystream.h +0 -71
- data/vendor/cereal/include/cereal/external/rapidjson/msinttypes/inttypes.h +0 -316
- data/vendor/cereal/include/cereal/external/rapidjson/msinttypes/stdint.h +0 -300
- data/vendor/cereal/include/cereal/external/rapidjson/ostreamwrapper.h +0 -81
- data/vendor/cereal/include/cereal/external/rapidjson/pointer.h +0 -1414
- data/vendor/cereal/include/cereal/external/rapidjson/prettywriter.h +0 -277
- data/vendor/cereal/include/cereal/external/rapidjson/rapidjson.h +0 -656
- data/vendor/cereal/include/cereal/external/rapidjson/reader.h +0 -2230
- data/vendor/cereal/include/cereal/external/rapidjson/schema.h +0 -2497
- data/vendor/cereal/include/cereal/external/rapidjson/stream.h +0 -223
- data/vendor/cereal/include/cereal/external/rapidjson/stringbuffer.h +0 -121
- data/vendor/cereal/include/cereal/external/rapidjson/writer.h +0 -709
- data/vendor/cereal/include/cereal/external/rapidxml/license.txt +0 -52
- data/vendor/cereal/include/cereal/external/rapidxml/manual.html +0 -406
- data/vendor/cereal/include/cereal/external/rapidxml/rapidxml.hpp +0 -2624
- data/vendor/cereal/include/cereal/external/rapidxml/rapidxml_iterators.hpp +0 -175
- data/vendor/cereal/include/cereal/external/rapidxml/rapidxml_print.hpp +0 -428
- data/vendor/cereal/include/cereal/external/rapidxml/rapidxml_utils.hpp +0 -123
- data/vendor/cereal/include/cereal/macros.hpp +0 -154
- data/vendor/cereal/include/cereal/specialize.hpp +0 -139
- data/vendor/cereal/include/cereal/types/array.hpp +0 -79
- data/vendor/cereal/include/cereal/types/atomic.hpp +0 -55
- data/vendor/cereal/include/cereal/types/base_class.hpp +0 -203
- data/vendor/cereal/include/cereal/types/bitset.hpp +0 -176
- data/vendor/cereal/include/cereal/types/boost_variant.hpp +0 -164
- data/vendor/cereal/include/cereal/types/chrono.hpp +0 -72
- data/vendor/cereal/include/cereal/types/common.hpp +0 -129
- data/vendor/cereal/include/cereal/types/complex.hpp +0 -56
- data/vendor/cereal/include/cereal/types/concepts/pair_associative_container.hpp +0 -73
- data/vendor/cereal/include/cereal/types/deque.hpp +0 -62
- data/vendor/cereal/include/cereal/types/forward_list.hpp +0 -68
- data/vendor/cereal/include/cereal/types/functional.hpp +0 -43
- data/vendor/cereal/include/cereal/types/list.hpp +0 -62
- data/vendor/cereal/include/cereal/types/map.hpp +0 -36
- data/vendor/cereal/include/cereal/types/memory.hpp +0 -425
- data/vendor/cereal/include/cereal/types/optional.hpp +0 -66
- data/vendor/cereal/include/cereal/types/polymorphic.hpp +0 -483
- data/vendor/cereal/include/cereal/types/queue.hpp +0 -132
- data/vendor/cereal/include/cereal/types/set.hpp +0 -103
- data/vendor/cereal/include/cereal/types/stack.hpp +0 -76
- data/vendor/cereal/include/cereal/types/string.hpp +0 -61
- data/vendor/cereal/include/cereal/types/tuple.hpp +0 -123
- data/vendor/cereal/include/cereal/types/unordered_map.hpp +0 -36
- data/vendor/cereal/include/cereal/types/unordered_set.hpp +0 -99
- data/vendor/cereal/include/cereal/types/utility.hpp +0 -47
- data/vendor/cereal/include/cereal/types/valarray.hpp +0 -89
- data/vendor/cereal/include/cereal/types/variant.hpp +0 -109
- data/vendor/cereal/include/cereal/types/vector.hpp +0 -112
- data/vendor/cereal/include/cereal/version.hpp +0 -52
- data/vendor/isotree/src/Makevars +0 -4
- data/vendor/isotree/src/crit.cpp +0 -912
- data/vendor/isotree/src/dist.cpp +0 -749
- data/vendor/isotree/src/extended.cpp +0 -790
- data/vendor/isotree/src/fit_model.cpp +0 -1090
- data/vendor/isotree/src/helpers_iforest.cpp +0 -324
- data/vendor/isotree/src/isoforest.cpp +0 -771
- data/vendor/isotree/src/mult.cpp +0 -607
- data/vendor/isotree/src/predict.cpp +0 -853
- data/vendor/isotree/src/utils.cpp +0 -1566
|
@@ -1,425 +0,0 @@
|
|
|
1
|
-
/*! \file memory.hpp
|
|
2
|
-
\brief Support for types found in \<memory\>
|
|
3
|
-
\ingroup STLSupport */
|
|
4
|
-
/*
|
|
5
|
-
Copyright (c) 2014, Randolph Voorhies, Shane Grant
|
|
6
|
-
All rights reserved.
|
|
7
|
-
|
|
8
|
-
Redistribution and use in source and binary forms, with or without
|
|
9
|
-
modification, are permitted provided that the following conditions are met:
|
|
10
|
-
* Redistributions of source code must retain the above copyright
|
|
11
|
-
notice, this list of conditions and the following disclaimer.
|
|
12
|
-
* Redistributions in binary form must reproduce the above copyright
|
|
13
|
-
notice, this list of conditions and the following disclaimer in the
|
|
14
|
-
documentation and/or other materials provided with the distribution.
|
|
15
|
-
* Neither the name of cereal nor the
|
|
16
|
-
names of its contributors may be used to endorse or promote products
|
|
17
|
-
derived from this software without specific prior written permission.
|
|
18
|
-
|
|
19
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
20
|
-
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
21
|
-
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
22
|
-
DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY
|
|
23
|
-
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
24
|
-
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
25
|
-
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
26
|
-
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
27
|
-
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
28
|
-
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
29
|
-
*/
|
|
30
|
-
#ifndef CEREAL_TYPES_SHARED_PTR_HPP_
|
|
31
|
-
#define CEREAL_TYPES_SHARED_PTR_HPP_
|
|
32
|
-
|
|
33
|
-
#include "cereal/cereal.hpp"
|
|
34
|
-
#include <memory>
|
|
35
|
-
#include <cstring>
|
|
36
|
-
|
|
37
|
-
namespace cereal
|
|
38
|
-
{
|
|
39
|
-
namespace memory_detail
|
|
40
|
-
{
|
|
41
|
-
//! A wrapper class to notify cereal that it is ok to serialize the contained pointer
|
|
42
|
-
/*! This mechanism allows us to intercept and properly handle polymorphic pointers
|
|
43
|
-
@internal */
|
|
44
|
-
template<class T>
|
|
45
|
-
struct PtrWrapper
|
|
46
|
-
{
|
|
47
|
-
PtrWrapper(T && p) : ptr(std::forward<T>(p)) {}
|
|
48
|
-
T & ptr;
|
|
49
|
-
|
|
50
|
-
PtrWrapper( PtrWrapper const & ) = default;
|
|
51
|
-
PtrWrapper & operator=( PtrWrapper const & ) = delete;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
//! Make a PtrWrapper
|
|
55
|
-
/*! @internal */
|
|
56
|
-
template<class T> inline
|
|
57
|
-
PtrWrapper<T> make_ptr_wrapper(T && t)
|
|
58
|
-
{
|
|
59
|
-
return {std::forward<T>(t)};
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
//! A struct that acts as a wrapper around calling load_andor_construct
|
|
63
|
-
/*! The purpose of this is to allow a load_and_construct call to properly enter into the
|
|
64
|
-
'data' NVP of the ptr_wrapper
|
|
65
|
-
@internal */
|
|
66
|
-
template <class Archive, class T>
|
|
67
|
-
struct LoadAndConstructLoadWrapper
|
|
68
|
-
{
|
|
69
|
-
LoadAndConstructLoadWrapper( T * ptr ) :
|
|
70
|
-
construct( ptr )
|
|
71
|
-
{ }
|
|
72
|
-
|
|
73
|
-
//! Constructor for embedding an early call for restoring shared_from_this
|
|
74
|
-
template <class F>
|
|
75
|
-
LoadAndConstructLoadWrapper( T * ptr, F && sharedFromThisFunc ) :
|
|
76
|
-
construct( ptr, sharedFromThisFunc )
|
|
77
|
-
{ }
|
|
78
|
-
|
|
79
|
-
inline void CEREAL_SERIALIZE_FUNCTION_NAME( Archive & ar )
|
|
80
|
-
{
|
|
81
|
-
::cereal::detail::Construct<T, Archive>::load_andor_construct( ar, construct );
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
::cereal::construct<T> construct;
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
//! A helper struct for saving and restoring the state of types that derive from
|
|
88
|
-
//! std::enable_shared_from_this
|
|
89
|
-
/*! This special struct is necessary because when a user uses load_and_construct,
|
|
90
|
-
the weak_ptr (or whatever implementation defined variant) that allows
|
|
91
|
-
enable_shared_from_this to function correctly will not be initialized properly.
|
|
92
|
-
|
|
93
|
-
This internal weak_ptr can also be modified by the shared_ptr that is created
|
|
94
|
-
during the serialization of a polymorphic pointer, where cereal creates a
|
|
95
|
-
wrapper shared_ptr out of a void pointer to the real data.
|
|
96
|
-
|
|
97
|
-
In the case of load_and_construct, this happens because it is the allocation
|
|
98
|
-
of shared_ptr that perform this initialization, which we let happen on a buffer
|
|
99
|
-
of memory (aligned_storage). This buffer is then used for placement new
|
|
100
|
-
later on, effectively overwriting any initialized weak_ptr with a default
|
|
101
|
-
initialized one, eventually leading to issues when the user calls shared_from_this.
|
|
102
|
-
|
|
103
|
-
To get around these issues, we will store the memory for the enable_shared_from_this
|
|
104
|
-
portion of the class and replace it after whatever happens to modify it (e.g. the
|
|
105
|
-
user performing construction or the wrapper shared_ptr in saving).
|
|
106
|
-
|
|
107
|
-
Note that this goes into undefined behavior territory, but as of the initial writing
|
|
108
|
-
of this, all standard library implementations of std::enable_shared_from_this are
|
|
109
|
-
compatible with this memory manipulation. It is entirely possible that this may someday
|
|
110
|
-
break or may not work with convoluted use cases.
|
|
111
|
-
|
|
112
|
-
Example usage:
|
|
113
|
-
|
|
114
|
-
@code{.cpp}
|
|
115
|
-
T * myActualPointer;
|
|
116
|
-
{
|
|
117
|
-
EnableSharedStateHelper<T> helper( myActualPointer ); // save the state
|
|
118
|
-
std::shared_ptr<T> myPtr( myActualPointer ); // modifies the internal weak_ptr
|
|
119
|
-
// helper restores state when it goes out of scope
|
|
120
|
-
}
|
|
121
|
-
@endcode
|
|
122
|
-
|
|
123
|
-
When possible, this is designed to be used in an RAII fashion - it will save state on
|
|
124
|
-
construction and restore it on destruction. The restore can be done at an earlier time
|
|
125
|
-
(e.g. after construct() is called in load_and_construct) in which case the destructor will
|
|
126
|
-
do nothing. Performing the restore immediately following construct() allows a user to call
|
|
127
|
-
shared_from_this within their load_and_construct function.
|
|
128
|
-
|
|
129
|
-
@tparam T Type pointed to by shared_ptr
|
|
130
|
-
@internal */
|
|
131
|
-
template <class T>
|
|
132
|
-
class EnableSharedStateHelper
|
|
133
|
-
{
|
|
134
|
-
// typedefs for parent type and storage type
|
|
135
|
-
using BaseType = typename ::cereal::traits::get_shared_from_this_base<T>::type;
|
|
136
|
-
using ParentType = std::enable_shared_from_this<BaseType>;
|
|
137
|
-
using StorageType = typename std::aligned_storage<sizeof(ParentType), CEREAL_ALIGNOF(ParentType)>::type;
|
|
138
|
-
|
|
139
|
-
public:
|
|
140
|
-
//! Saves the state of some type inheriting from enable_shared_from_this
|
|
141
|
-
/*! @param ptr The raw pointer held by the shared_ptr */
|
|
142
|
-
inline EnableSharedStateHelper( T * ptr ) :
|
|
143
|
-
itsPtr( static_cast<ParentType *>( ptr ) ),
|
|
144
|
-
itsState(),
|
|
145
|
-
itsRestored( false )
|
|
146
|
-
{
|
|
147
|
-
std::memcpy( &itsState, itsPtr, sizeof(ParentType) );
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
//! Restores the state of the held pointer (can only be done once)
|
|
151
|
-
inline void restore()
|
|
152
|
-
{
|
|
153
|
-
if( !itsRestored )
|
|
154
|
-
{
|
|
155
|
-
// void * cast needed when type has no trivial copy-assignment
|
|
156
|
-
std::memcpy( static_cast<void *>(itsPtr), &itsState, sizeof(ParentType) );
|
|
157
|
-
itsRestored = true;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
//! Restores the state of the held pointer if not done previously
|
|
162
|
-
inline ~EnableSharedStateHelper()
|
|
163
|
-
{
|
|
164
|
-
restore();
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
private:
|
|
168
|
-
ParentType * itsPtr;
|
|
169
|
-
StorageType itsState;
|
|
170
|
-
bool itsRestored;
|
|
171
|
-
}; // end EnableSharedStateHelper
|
|
172
|
-
|
|
173
|
-
//! Performs loading and construction for a shared pointer that is derived from
|
|
174
|
-
//! std::enable_shared_from_this
|
|
175
|
-
/*! @param ar The archive
|
|
176
|
-
@param ptr Raw pointer held by the shared_ptr
|
|
177
|
-
@internal */
|
|
178
|
-
template <class Archive, class T> inline
|
|
179
|
-
void loadAndConstructSharedPtr( Archive & ar, T * ptr, std::true_type /* has_shared_from_this */ )
|
|
180
|
-
{
|
|
181
|
-
memory_detail::EnableSharedStateHelper<T> state( ptr );
|
|
182
|
-
memory_detail::LoadAndConstructLoadWrapper<Archive, T> loadWrapper( ptr, [&](){ state.restore(); } );
|
|
183
|
-
|
|
184
|
-
// let the user perform their initialization, shared state will be restored as soon as construct()
|
|
185
|
-
// is called
|
|
186
|
-
ar( CEREAL_NVP_("data", loadWrapper) );
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
//! Performs loading and construction for a shared pointer that is NOT derived from
|
|
190
|
-
//! std::enable_shared_from_this
|
|
191
|
-
/*! This is the typical case, where we simply pass the load wrapper to the
|
|
192
|
-
archive.
|
|
193
|
-
|
|
194
|
-
@param ar The archive
|
|
195
|
-
@param ptr Raw pointer held by the shared_ptr
|
|
196
|
-
@internal */
|
|
197
|
-
template <class Archive, class T> inline
|
|
198
|
-
void loadAndConstructSharedPtr( Archive & ar, T * ptr, std::false_type /* has_shared_from_this */ )
|
|
199
|
-
{
|
|
200
|
-
memory_detail::LoadAndConstructLoadWrapper<Archive, T> loadWrapper( ptr );
|
|
201
|
-
ar( CEREAL_NVP_("data", loadWrapper) );
|
|
202
|
-
}
|
|
203
|
-
} // end namespace memory_detail
|
|
204
|
-
|
|
205
|
-
//! Saving std::shared_ptr for non polymorphic types
|
|
206
|
-
template <class Archive, class T> inline
|
|
207
|
-
typename std::enable_if<!std::is_polymorphic<T>::value, void>::type
|
|
208
|
-
CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::shared_ptr<T> const & ptr )
|
|
209
|
-
{
|
|
210
|
-
ar( CEREAL_NVP_("ptr_wrapper", memory_detail::make_ptr_wrapper( ptr )) );
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
//! Loading std::shared_ptr, case when no user load and construct for non polymorphic types
|
|
214
|
-
template <class Archive, class T> inline
|
|
215
|
-
typename std::enable_if<!std::is_polymorphic<T>::value, void>::type
|
|
216
|
-
CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::shared_ptr<T> & ptr )
|
|
217
|
-
{
|
|
218
|
-
ar( CEREAL_NVP_("ptr_wrapper", memory_detail::make_ptr_wrapper( ptr )) );
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
//! Saving std::weak_ptr for non polymorphic types
|
|
222
|
-
template <class Archive, class T> inline
|
|
223
|
-
typename std::enable_if<!std::is_polymorphic<T>::value, void>::type
|
|
224
|
-
CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::weak_ptr<T> const & ptr )
|
|
225
|
-
{
|
|
226
|
-
auto const sptr = ptr.lock();
|
|
227
|
-
ar( CEREAL_NVP_("ptr_wrapper", memory_detail::make_ptr_wrapper( sptr )) );
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
//! Loading std::weak_ptr for non polymorphic types
|
|
231
|
-
template <class Archive, class T> inline
|
|
232
|
-
typename std::enable_if<!std::is_polymorphic<T>::value, void>::type
|
|
233
|
-
CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::weak_ptr<T> & ptr )
|
|
234
|
-
{
|
|
235
|
-
std::shared_ptr<T> sptr;
|
|
236
|
-
ar( CEREAL_NVP_("ptr_wrapper", memory_detail::make_ptr_wrapper( sptr )) );
|
|
237
|
-
ptr = sptr;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
//! Saving std::unique_ptr for non polymorphic types
|
|
241
|
-
template <class Archive, class T, class D> inline
|
|
242
|
-
typename std::enable_if<!std::is_polymorphic<T>::value, void>::type
|
|
243
|
-
CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::unique_ptr<T, D> const & ptr )
|
|
244
|
-
{
|
|
245
|
-
ar( CEREAL_NVP_("ptr_wrapper", memory_detail::make_ptr_wrapper( ptr )) );
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
//! Loading std::unique_ptr, case when user provides load_and_construct for non polymorphic types
|
|
249
|
-
template <class Archive, class T, class D> inline
|
|
250
|
-
typename std::enable_if<!std::is_polymorphic<T>::value, void>::type
|
|
251
|
-
CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::unique_ptr<T, D> & ptr )
|
|
252
|
-
{
|
|
253
|
-
ar( CEREAL_NVP_("ptr_wrapper", memory_detail::make_ptr_wrapper( ptr )) );
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
// ######################################################################
|
|
257
|
-
// Pointer wrapper implementations follow below
|
|
258
|
-
|
|
259
|
-
//! Saving std::shared_ptr (wrapper implementation)
|
|
260
|
-
/*! @internal */
|
|
261
|
-
template <class Archive, class T> inline
|
|
262
|
-
void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, memory_detail::PtrWrapper<std::shared_ptr<T> const &> const & wrapper )
|
|
263
|
-
{
|
|
264
|
-
auto & ptr = wrapper.ptr;
|
|
265
|
-
|
|
266
|
-
uint32_t id = ar.registerSharedPointer( ptr.get() );
|
|
267
|
-
ar( CEREAL_NVP_("id", id) );
|
|
268
|
-
|
|
269
|
-
if( id & detail::msb_32bit )
|
|
270
|
-
{
|
|
271
|
-
ar( CEREAL_NVP_("data", *ptr) );
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
//! Loading std::shared_ptr, case when user load and construct (wrapper implementation)
|
|
276
|
-
/*! @internal */
|
|
277
|
-
template <class Archive, class T> inline
|
|
278
|
-
typename std::enable_if<traits::has_load_and_construct<T, Archive>::value, void>::type
|
|
279
|
-
CEREAL_LOAD_FUNCTION_NAME( Archive & ar, memory_detail::PtrWrapper<std::shared_ptr<T> &> & wrapper )
|
|
280
|
-
{
|
|
281
|
-
uint32_t id;
|
|
282
|
-
|
|
283
|
-
ar( CEREAL_NVP_("id", id) );
|
|
284
|
-
|
|
285
|
-
if( id & detail::msb_32bit )
|
|
286
|
-
{
|
|
287
|
-
// Storage type for the pointer - since we can't default construct this type,
|
|
288
|
-
// we'll allocate it using std::aligned_storage and use a custom deleter
|
|
289
|
-
using ST = typename std::aligned_storage<sizeof(T), CEREAL_ALIGNOF(T)>::type;
|
|
290
|
-
|
|
291
|
-
// Valid flag - set to true once construction finishes
|
|
292
|
-
// This prevents us from calling the destructor on
|
|
293
|
-
// uninitialized data.
|
|
294
|
-
auto valid = std::make_shared<bool>( false );
|
|
295
|
-
|
|
296
|
-
// Allocate our storage, which we will treat as
|
|
297
|
-
// uninitialized until initialized with placement new
|
|
298
|
-
using NonConstT = typename std::remove_const<T>::type;
|
|
299
|
-
std::shared_ptr<NonConstT> ptr(reinterpret_cast<NonConstT *>(new ST()),
|
|
300
|
-
[=]( NonConstT * t )
|
|
301
|
-
{
|
|
302
|
-
if( *valid )
|
|
303
|
-
t->~T();
|
|
304
|
-
|
|
305
|
-
delete reinterpret_cast<ST *>( t );
|
|
306
|
-
} );
|
|
307
|
-
|
|
308
|
-
// Register the pointer
|
|
309
|
-
ar.registerSharedPointer( id, ptr );
|
|
310
|
-
|
|
311
|
-
// Perform the actual loading and allocation
|
|
312
|
-
memory_detail::loadAndConstructSharedPtr( ar, ptr.get(), typename ::cereal::traits::has_shared_from_this<NonConstT>::type() );
|
|
313
|
-
|
|
314
|
-
// Mark pointer as valid (initialized)
|
|
315
|
-
*valid = true;
|
|
316
|
-
wrapper.ptr = std::move(ptr);
|
|
317
|
-
}
|
|
318
|
-
else
|
|
319
|
-
wrapper.ptr = std::static_pointer_cast<T>(ar.getSharedPointer(id));
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
//! Loading std::shared_ptr, case when no user load and construct (wrapper implementation)
|
|
323
|
-
/*! @internal */
|
|
324
|
-
template <class Archive, class T> inline
|
|
325
|
-
typename std::enable_if<!traits::has_load_and_construct<T, Archive>::value, void>::type
|
|
326
|
-
CEREAL_LOAD_FUNCTION_NAME( Archive & ar, memory_detail::PtrWrapper<std::shared_ptr<T> &> & wrapper )
|
|
327
|
-
{
|
|
328
|
-
uint32_t id;
|
|
329
|
-
|
|
330
|
-
ar( CEREAL_NVP_("id", id) );
|
|
331
|
-
|
|
332
|
-
if( id & detail::msb_32bit )
|
|
333
|
-
{
|
|
334
|
-
using NonConstT = typename std::remove_const<T>::type;
|
|
335
|
-
std::shared_ptr<NonConstT> ptr( detail::Construct<NonConstT, Archive>::load_andor_construct() );
|
|
336
|
-
ar.registerSharedPointer( id, ptr );
|
|
337
|
-
ar( CEREAL_NVP_("data", *ptr) );
|
|
338
|
-
wrapper.ptr = std::move(ptr);
|
|
339
|
-
}
|
|
340
|
-
else
|
|
341
|
-
wrapper.ptr = std::static_pointer_cast<T>(ar.getSharedPointer(id));
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
//! Saving std::unique_ptr (wrapper implementation)
|
|
345
|
-
/*! @internal */
|
|
346
|
-
template <class Archive, class T, class D> inline
|
|
347
|
-
void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, memory_detail::PtrWrapper<std::unique_ptr<T, D> const &> const & wrapper )
|
|
348
|
-
{
|
|
349
|
-
auto & ptr = wrapper.ptr;
|
|
350
|
-
|
|
351
|
-
// unique_ptr get one byte of metadata which signifies whether they were a nullptr
|
|
352
|
-
// 0 == nullptr
|
|
353
|
-
// 1 == not null
|
|
354
|
-
|
|
355
|
-
if( !ptr )
|
|
356
|
-
ar( CEREAL_NVP_("valid", uint8_t(0)) );
|
|
357
|
-
else
|
|
358
|
-
{
|
|
359
|
-
ar( CEREAL_NVP_("valid", uint8_t(1)) );
|
|
360
|
-
ar( CEREAL_NVP_("data", *ptr) );
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
//! Loading std::unique_ptr, case when user provides load_and_construct (wrapper implementation)
|
|
365
|
-
/*! @internal */
|
|
366
|
-
template <class Archive, class T, class D> inline
|
|
367
|
-
typename std::enable_if<traits::has_load_and_construct<T, Archive>::value, void>::type
|
|
368
|
-
CEREAL_LOAD_FUNCTION_NAME( Archive & ar, memory_detail::PtrWrapper<std::unique_ptr<T, D> &> & wrapper )
|
|
369
|
-
{
|
|
370
|
-
uint8_t isValid;
|
|
371
|
-
ar( CEREAL_NVP_("valid", isValid) );
|
|
372
|
-
|
|
373
|
-
auto & ptr = wrapper.ptr;
|
|
374
|
-
|
|
375
|
-
if( isValid )
|
|
376
|
-
{
|
|
377
|
-
using NonConstT = typename std::remove_const<T>::type;
|
|
378
|
-
// Storage type for the pointer - since we can't default construct this type,
|
|
379
|
-
// we'll allocate it using std::aligned_storage
|
|
380
|
-
using ST = typename std::aligned_storage<sizeof(NonConstT), CEREAL_ALIGNOF(NonConstT)>::type;
|
|
381
|
-
|
|
382
|
-
// Allocate storage - note the ST type so that deleter is correct if
|
|
383
|
-
// an exception is thrown before we are initialized
|
|
384
|
-
std::unique_ptr<ST> stPtr( new ST() );
|
|
385
|
-
|
|
386
|
-
// Use wrapper to enter into "data" nvp of ptr_wrapper
|
|
387
|
-
memory_detail::LoadAndConstructLoadWrapper<Archive, NonConstT> loadWrapper( reinterpret_cast<NonConstT *>( stPtr.get() ) );
|
|
388
|
-
|
|
389
|
-
// Initialize storage
|
|
390
|
-
ar( CEREAL_NVP_("data", loadWrapper) );
|
|
391
|
-
|
|
392
|
-
// Transfer ownership to correct unique_ptr type
|
|
393
|
-
ptr.reset( reinterpret_cast<T *>( stPtr.release() ) );
|
|
394
|
-
}
|
|
395
|
-
else
|
|
396
|
-
ptr.reset( nullptr );
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
//! Loading std::unique_ptr, case when no load_and_construct (wrapper implementation)
|
|
400
|
-
/*! @internal */
|
|
401
|
-
template <class Archive, class T, class D> inline
|
|
402
|
-
typename std::enable_if<!traits::has_load_and_construct<T, Archive>::value, void>::type
|
|
403
|
-
CEREAL_LOAD_FUNCTION_NAME( Archive & ar, memory_detail::PtrWrapper<std::unique_ptr<T, D> &> & wrapper )
|
|
404
|
-
{
|
|
405
|
-
uint8_t isValid;
|
|
406
|
-
ar( CEREAL_NVP_("valid", isValid) );
|
|
407
|
-
|
|
408
|
-
if( isValid )
|
|
409
|
-
{
|
|
410
|
-
using NonConstT = typename std::remove_const<T>::type;
|
|
411
|
-
std::unique_ptr<NonConstT, D> ptr( detail::Construct<NonConstT, Archive>::load_andor_construct() );
|
|
412
|
-
ar( CEREAL_NVP_( "data", *ptr ) );
|
|
413
|
-
wrapper.ptr = std::move(ptr);
|
|
414
|
-
}
|
|
415
|
-
else
|
|
416
|
-
{
|
|
417
|
-
wrapper.ptr.reset( nullptr );
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
} // namespace cereal
|
|
421
|
-
|
|
422
|
-
// automatically include polymorphic support
|
|
423
|
-
#include "cereal/types/polymorphic.hpp"
|
|
424
|
-
|
|
425
|
-
#endif // CEREAL_TYPES_SHARED_PTR_HPP_
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
/*! \file optional.hpp
|
|
2
|
-
\brief Support for std::optional
|
|
3
|
-
\ingroup STLSupport */
|
|
4
|
-
/*
|
|
5
|
-
Copyright (c) 2017, Juan Pedro Bolivar Puente
|
|
6
|
-
All rights reserved.
|
|
7
|
-
|
|
8
|
-
Redistribution and use in source and binary forms, with or without
|
|
9
|
-
modification, are permitted provided that the following conditions are met:
|
|
10
|
-
* Redistributions of source code must retain the above copyright
|
|
11
|
-
notice, this list of conditions and the following disclaimer.
|
|
12
|
-
* Redistributions in binary form must reproduce the above copyright
|
|
13
|
-
notice, this list of conditions and the following disclaimer in the
|
|
14
|
-
documentation and/or other materials provided with the distribution.
|
|
15
|
-
* Neither the name of cereal nor the
|
|
16
|
-
names of its contributors may be used to endorse or promote products
|
|
17
|
-
derived from this software without specific prior written permission.
|
|
18
|
-
|
|
19
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
20
|
-
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
21
|
-
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
22
|
-
DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY
|
|
23
|
-
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
24
|
-
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
25
|
-
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
26
|
-
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
27
|
-
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
28
|
-
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
29
|
-
*/
|
|
30
|
-
#ifndef CEREAL_TYPES_STD_OPTIONAL_
|
|
31
|
-
#define CEREAL_TYPES_STD_OPTIONAL_
|
|
32
|
-
|
|
33
|
-
#include "cereal/cereal.hpp"
|
|
34
|
-
#include <optional>
|
|
35
|
-
|
|
36
|
-
namespace cereal {
|
|
37
|
-
//! Saving for std::optional
|
|
38
|
-
template <class Archive, typename T> inline
|
|
39
|
-
void CEREAL_SAVE_FUNCTION_NAME(Archive& ar, const std::optional<T>& optional)
|
|
40
|
-
{
|
|
41
|
-
if(!optional) {
|
|
42
|
-
ar(CEREAL_NVP_("nullopt", true));
|
|
43
|
-
} else {
|
|
44
|
-
ar(CEREAL_NVP_("nullopt", false),
|
|
45
|
-
CEREAL_NVP_("data", *optional));
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
//! Loading for std::optional
|
|
50
|
-
template <class Archive, typename T> inline
|
|
51
|
-
void CEREAL_LOAD_FUNCTION_NAME(Archive& ar, std::optional<T>& optional)
|
|
52
|
-
{
|
|
53
|
-
bool nullopt;
|
|
54
|
-
ar(CEREAL_NVP_("nullopt", nullopt));
|
|
55
|
-
|
|
56
|
-
if (nullopt) {
|
|
57
|
-
optional = std::nullopt;
|
|
58
|
-
} else {
|
|
59
|
-
T value;
|
|
60
|
-
ar(CEREAL_NVP_("data", value));
|
|
61
|
-
optional = std::move(value);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
} // namespace cereal
|
|
65
|
-
|
|
66
|
-
#endif // CEREAL_TYPES_STD_OPTIONAL_
|