isotree 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -1
  3. data/LICENSE.txt +2 -2
  4. data/README.md +32 -14
  5. data/ext/isotree/ext.cpp +144 -31
  6. data/ext/isotree/extconf.rb +7 -7
  7. data/lib/isotree/isolation_forest.rb +110 -30
  8. data/lib/isotree/version.rb +1 -1
  9. data/vendor/isotree/LICENSE +1 -1
  10. data/vendor/isotree/README.md +165 -27
  11. data/vendor/isotree/include/isotree.hpp +2111 -0
  12. data/vendor/isotree/include/isotree_oop.hpp +394 -0
  13. data/vendor/isotree/inst/COPYRIGHTS +62 -0
  14. data/vendor/isotree/src/RcppExports.cpp +525 -52
  15. data/vendor/isotree/src/Rwrapper.cpp +1931 -268
  16. data/vendor/isotree/src/c_interface.cpp +953 -0
  17. data/vendor/isotree/src/crit.hpp +4232 -0
  18. data/vendor/isotree/src/dist.hpp +1886 -0
  19. data/vendor/isotree/src/exp_depth_table.hpp +134 -0
  20. data/vendor/isotree/src/extended.hpp +1444 -0
  21. data/vendor/isotree/src/external_facing_generic.hpp +399 -0
  22. data/vendor/isotree/src/fit_model.hpp +2401 -0
  23. data/vendor/isotree/src/{dealloc.cpp → headers_joined.hpp} +38 -22
  24. data/vendor/isotree/src/helpers_iforest.hpp +813 -0
  25. data/vendor/isotree/src/{impute.cpp → impute.hpp} +353 -122
  26. data/vendor/isotree/src/indexer.cpp +515 -0
  27. data/vendor/isotree/src/instantiate_template_headers.cpp +118 -0
  28. data/vendor/isotree/src/instantiate_template_headers.hpp +240 -0
  29. data/vendor/isotree/src/isoforest.hpp +1659 -0
  30. data/vendor/isotree/src/isotree.hpp +1804 -392
  31. data/vendor/isotree/src/isotree_exportable.hpp +99 -0
  32. data/vendor/isotree/src/merge_models.cpp +159 -16
  33. data/vendor/isotree/src/mult.hpp +1321 -0
  34. data/vendor/isotree/src/oop_interface.cpp +842 -0
  35. data/vendor/isotree/src/oop_interface.hpp +278 -0
  36. data/vendor/isotree/src/other_helpers.hpp +219 -0
  37. data/vendor/isotree/src/predict.hpp +1932 -0
  38. data/vendor/isotree/src/python_helpers.hpp +134 -0
  39. data/vendor/isotree/src/ref_indexer.hpp +154 -0
  40. data/vendor/isotree/src/robinmap/LICENSE +21 -0
  41. data/vendor/isotree/src/robinmap/README.md +483 -0
  42. data/vendor/isotree/src/robinmap/include/tsl/robin_growth_policy.h +406 -0
  43. data/vendor/isotree/src/robinmap/include/tsl/robin_hash.h +1620 -0
  44. data/vendor/isotree/src/robinmap/include/tsl/robin_map.h +807 -0
  45. data/vendor/isotree/src/robinmap/include/tsl/robin_set.h +660 -0
  46. data/vendor/isotree/src/serialize.cpp +4300 -139
  47. data/vendor/isotree/src/sql.cpp +141 -59
  48. data/vendor/isotree/src/subset_models.cpp +174 -0
  49. data/vendor/isotree/src/utils.hpp +3808 -0
  50. data/vendor/isotree/src/xoshiro.hpp +467 -0
  51. data/vendor/isotree/src/ziggurat.hpp +405 -0
  52. metadata +38 -104
  53. data/vendor/cereal/LICENSE +0 -24
  54. data/vendor/cereal/README.md +0 -85
  55. data/vendor/cereal/include/cereal/access.hpp +0 -351
  56. data/vendor/cereal/include/cereal/archives/adapters.hpp +0 -163
  57. data/vendor/cereal/include/cereal/archives/binary.hpp +0 -169
  58. data/vendor/cereal/include/cereal/archives/json.hpp +0 -1019
  59. data/vendor/cereal/include/cereal/archives/portable_binary.hpp +0 -334
  60. data/vendor/cereal/include/cereal/archives/xml.hpp +0 -956
  61. data/vendor/cereal/include/cereal/cereal.hpp +0 -1089
  62. data/vendor/cereal/include/cereal/details/helpers.hpp +0 -422
  63. data/vendor/cereal/include/cereal/details/polymorphic_impl.hpp +0 -796
  64. data/vendor/cereal/include/cereal/details/polymorphic_impl_fwd.hpp +0 -65
  65. data/vendor/cereal/include/cereal/details/static_object.hpp +0 -127
  66. data/vendor/cereal/include/cereal/details/traits.hpp +0 -1411
  67. data/vendor/cereal/include/cereal/details/util.hpp +0 -84
  68. data/vendor/cereal/include/cereal/external/base64.hpp +0 -134
  69. data/vendor/cereal/include/cereal/external/rapidjson/allocators.h +0 -284
  70. data/vendor/cereal/include/cereal/external/rapidjson/cursorstreamwrapper.h +0 -78
  71. data/vendor/cereal/include/cereal/external/rapidjson/document.h +0 -2652
  72. data/vendor/cereal/include/cereal/external/rapidjson/encodedstream.h +0 -299
  73. data/vendor/cereal/include/cereal/external/rapidjson/encodings.h +0 -716
  74. data/vendor/cereal/include/cereal/external/rapidjson/error/en.h +0 -74
  75. data/vendor/cereal/include/cereal/external/rapidjson/error/error.h +0 -161
  76. data/vendor/cereal/include/cereal/external/rapidjson/filereadstream.h +0 -99
  77. data/vendor/cereal/include/cereal/external/rapidjson/filewritestream.h +0 -104
  78. data/vendor/cereal/include/cereal/external/rapidjson/fwd.h +0 -151
  79. data/vendor/cereal/include/cereal/external/rapidjson/internal/biginteger.h +0 -290
  80. data/vendor/cereal/include/cereal/external/rapidjson/internal/diyfp.h +0 -271
  81. data/vendor/cereal/include/cereal/external/rapidjson/internal/dtoa.h +0 -245
  82. data/vendor/cereal/include/cereal/external/rapidjson/internal/ieee754.h +0 -78
  83. data/vendor/cereal/include/cereal/external/rapidjson/internal/itoa.h +0 -308
  84. data/vendor/cereal/include/cereal/external/rapidjson/internal/meta.h +0 -186
  85. data/vendor/cereal/include/cereal/external/rapidjson/internal/pow10.h +0 -55
  86. data/vendor/cereal/include/cereal/external/rapidjson/internal/regex.h +0 -740
  87. data/vendor/cereal/include/cereal/external/rapidjson/internal/stack.h +0 -232
  88. data/vendor/cereal/include/cereal/external/rapidjson/internal/strfunc.h +0 -69
  89. data/vendor/cereal/include/cereal/external/rapidjson/internal/strtod.h +0 -290
  90. data/vendor/cereal/include/cereal/external/rapidjson/internal/swap.h +0 -46
  91. data/vendor/cereal/include/cereal/external/rapidjson/istreamwrapper.h +0 -128
  92. data/vendor/cereal/include/cereal/external/rapidjson/memorybuffer.h +0 -70
  93. data/vendor/cereal/include/cereal/external/rapidjson/memorystream.h +0 -71
  94. data/vendor/cereal/include/cereal/external/rapidjson/msinttypes/inttypes.h +0 -316
  95. data/vendor/cereal/include/cereal/external/rapidjson/msinttypes/stdint.h +0 -300
  96. data/vendor/cereal/include/cereal/external/rapidjson/ostreamwrapper.h +0 -81
  97. data/vendor/cereal/include/cereal/external/rapidjson/pointer.h +0 -1414
  98. data/vendor/cereal/include/cereal/external/rapidjson/prettywriter.h +0 -277
  99. data/vendor/cereal/include/cereal/external/rapidjson/rapidjson.h +0 -656
  100. data/vendor/cereal/include/cereal/external/rapidjson/reader.h +0 -2230
  101. data/vendor/cereal/include/cereal/external/rapidjson/schema.h +0 -2497
  102. data/vendor/cereal/include/cereal/external/rapidjson/stream.h +0 -223
  103. data/vendor/cereal/include/cereal/external/rapidjson/stringbuffer.h +0 -121
  104. data/vendor/cereal/include/cereal/external/rapidjson/writer.h +0 -709
  105. data/vendor/cereal/include/cereal/external/rapidxml/license.txt +0 -52
  106. data/vendor/cereal/include/cereal/external/rapidxml/manual.html +0 -406
  107. data/vendor/cereal/include/cereal/external/rapidxml/rapidxml.hpp +0 -2624
  108. data/vendor/cereal/include/cereal/external/rapidxml/rapidxml_iterators.hpp +0 -175
  109. data/vendor/cereal/include/cereal/external/rapidxml/rapidxml_print.hpp +0 -428
  110. data/vendor/cereal/include/cereal/external/rapidxml/rapidxml_utils.hpp +0 -123
  111. data/vendor/cereal/include/cereal/macros.hpp +0 -154
  112. data/vendor/cereal/include/cereal/specialize.hpp +0 -139
  113. data/vendor/cereal/include/cereal/types/array.hpp +0 -79
  114. data/vendor/cereal/include/cereal/types/atomic.hpp +0 -55
  115. data/vendor/cereal/include/cereal/types/base_class.hpp +0 -203
  116. data/vendor/cereal/include/cereal/types/bitset.hpp +0 -176
  117. data/vendor/cereal/include/cereal/types/boost_variant.hpp +0 -164
  118. data/vendor/cereal/include/cereal/types/chrono.hpp +0 -72
  119. data/vendor/cereal/include/cereal/types/common.hpp +0 -129
  120. data/vendor/cereal/include/cereal/types/complex.hpp +0 -56
  121. data/vendor/cereal/include/cereal/types/concepts/pair_associative_container.hpp +0 -73
  122. data/vendor/cereal/include/cereal/types/deque.hpp +0 -62
  123. data/vendor/cereal/include/cereal/types/forward_list.hpp +0 -68
  124. data/vendor/cereal/include/cereal/types/functional.hpp +0 -43
  125. data/vendor/cereal/include/cereal/types/list.hpp +0 -62
  126. data/vendor/cereal/include/cereal/types/map.hpp +0 -36
  127. data/vendor/cereal/include/cereal/types/memory.hpp +0 -425
  128. data/vendor/cereal/include/cereal/types/optional.hpp +0 -66
  129. data/vendor/cereal/include/cereal/types/polymorphic.hpp +0 -483
  130. data/vendor/cereal/include/cereal/types/queue.hpp +0 -132
  131. data/vendor/cereal/include/cereal/types/set.hpp +0 -103
  132. data/vendor/cereal/include/cereal/types/stack.hpp +0 -76
  133. data/vendor/cereal/include/cereal/types/string.hpp +0 -61
  134. data/vendor/cereal/include/cereal/types/tuple.hpp +0 -123
  135. data/vendor/cereal/include/cereal/types/unordered_map.hpp +0 -36
  136. data/vendor/cereal/include/cereal/types/unordered_set.hpp +0 -99
  137. data/vendor/cereal/include/cereal/types/utility.hpp +0 -47
  138. data/vendor/cereal/include/cereal/types/valarray.hpp +0 -89
  139. data/vendor/cereal/include/cereal/types/variant.hpp +0 -109
  140. data/vendor/cereal/include/cereal/types/vector.hpp +0 -112
  141. data/vendor/cereal/include/cereal/version.hpp +0 -52
  142. data/vendor/isotree/src/Makevars +0 -4
  143. data/vendor/isotree/src/crit.cpp +0 -912
  144. data/vendor/isotree/src/dist.cpp +0 -749
  145. data/vendor/isotree/src/extended.cpp +0 -790
  146. data/vendor/isotree/src/fit_model.cpp +0 -1090
  147. data/vendor/isotree/src/helpers_iforest.cpp +0 -324
  148. data/vendor/isotree/src/isoforest.cpp +0 -771
  149. data/vendor/isotree/src/mult.cpp +0 -607
  150. data/vendor/isotree/src/predict.cpp +0 -853
  151. data/vendor/isotree/src/utils.cpp +0 -1566
@@ -1,422 +0,0 @@
1
- /*! \file helpers.hpp
2
- \brief Internal helper functionality
3
- \ingroup Internal */
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_DETAILS_HELPERS_HPP_
31
- #define CEREAL_DETAILS_HELPERS_HPP_
32
-
33
- #include <type_traits>
34
- #include <cstdint>
35
- #include <utility>
36
- #include <memory>
37
- #include <unordered_map>
38
- #include <stdexcept>
39
-
40
- #include "cereal/macros.hpp"
41
- #include "cereal/details/static_object.hpp"
42
-
43
- namespace cereal
44
- {
45
- // ######################################################################
46
- //! An exception class thrown when things go wrong at runtime
47
- /*! @ingroup Utility */
48
- struct Exception : public std::runtime_error
49
- {
50
- explicit Exception( const std::string & what_ ) : std::runtime_error(what_) {}
51
- explicit Exception( const char * what_ ) : std::runtime_error(what_) {}
52
- };
53
-
54
- // ######################################################################
55
- //! The size type used by cereal
56
- /*! To ensure compatability between 32, 64, etc bit machines, we need to use
57
- a fixed size type instead of size_t, which may vary from machine to
58
- machine.
59
-
60
- The default value for CEREAL_SIZE_TYPE is specified in cereal/macros.hpp */
61
- using size_type = CEREAL_SIZE_TYPE;
62
-
63
- // forward decls
64
- class BinaryOutputArchive;
65
- class BinaryInputArchive;
66
-
67
- // ######################################################################
68
- namespace detail
69
- {
70
- struct NameValuePairCore {}; //!< Traits struct for NVPs
71
- struct DeferredDataCore {}; //!< Traits struct for DeferredData
72
- }
73
-
74
- // ######################################################################
75
- //! For holding name value pairs
76
- /*! This pairs a name (some string) with some value such that an archive
77
- can potentially take advantage of the pairing.
78
-
79
- In serialization functions, NameValuePairs are usually created like so:
80
- @code{.cpp}
81
- struct MyStruct
82
- {
83
- int a, b, c, d, e;
84
-
85
- template<class Archive>
86
- void serialize(Archive & archive)
87
- {
88
- archive( CEREAL_NVP(a),
89
- CEREAL_NVP(b),
90
- CEREAL_NVP(c),
91
- CEREAL_NVP(d),
92
- CEREAL_NVP(e) );
93
- }
94
- };
95
- @endcode
96
-
97
- Alternatively, you can give you data members custom names like so:
98
- @code{.cpp}
99
- struct MyStruct
100
- {
101
- int a, b, my_embarrassing_variable_name, d, e;
102
-
103
- template<class Archive>
104
- void serialize(Archive & archive)
105
- {
106
- archive( CEREAL_NVP(a),
107
- CEREAL_NVP(b),
108
- cereal::make_nvp("var", my_embarrassing_variable_name) );
109
- CEREAL_NVP(d),
110
- CEREAL_NVP(e) );
111
- }
112
- };
113
- @endcode
114
-
115
- There is a slight amount of overhead to creating NameValuePairs, so there
116
- is a third method which will elide the names when they are not used by
117
- the Archive:
118
-
119
- @code{.cpp}
120
- struct MyStruct
121
- {
122
- int a, b;
123
-
124
- template<class Archive>
125
- void serialize(Archive & archive)
126
- {
127
- archive( cereal::make_nvp<Archive>(a),
128
- cereal::make_nvp<Archive>(b) );
129
- }
130
- };
131
- @endcode
132
-
133
- This third method is generally only used when providing generic type
134
- support. Users writing their own serialize functions will normally
135
- explicitly control whether they want to use NVPs or not.
136
-
137
- @internal */
138
- template <class T>
139
- class NameValuePair : detail::NameValuePairCore
140
- {
141
- private:
142
- // If we get passed an array, keep the type as is, otherwise store
143
- // a reference if we were passed an l value reference, else copy the value
144
- using Type = typename std::conditional<std::is_array<typename std::remove_reference<T>::type>::value,
145
- typename std::remove_cv<T>::type,
146
- typename std::conditional<std::is_lvalue_reference<T>::value,
147
- T,
148
- typename std::decay<T>::type>::type>::type;
149
-
150
- // prevent nested nvps
151
- static_assert( !std::is_base_of<detail::NameValuePairCore, T>::value,
152
- "Cannot pair a name to a NameValuePair" );
153
-
154
- NameValuePair & operator=( NameValuePair const & ) = delete;
155
-
156
- public:
157
- //! Constructs a new NameValuePair
158
- /*! @param n The name of the pair
159
- @param v The value to pair. Ideally this should be an l-value reference so that
160
- the value can be both loaded and saved to. If you pass an r-value reference,
161
- the NameValuePair will store a copy of it instead of a reference. Thus you should
162
- only pass r-values in cases where this makes sense, such as the result of some
163
- size() call.
164
- @internal */
165
- NameValuePair( char const * n, T && v ) : name(n), value(std::forward<T>(v)) {}
166
-
167
- char const * name;
168
- Type value;
169
- };
170
-
171
- //! A specialization of make_nvp<> that simply forwards the value for binary archives
172
- /*! @relates NameValuePair
173
- @internal */
174
- template<class Archive, class T> inline
175
- typename
176
- std::enable_if<std::is_same<Archive, ::cereal::BinaryInputArchive>::value ||
177
- std::is_same<Archive, ::cereal::BinaryOutputArchive>::value,
178
- T && >::type
179
- make_nvp( const char *, T && value )
180
- {
181
- return std::forward<T>(value);
182
- }
183
-
184
- //! A specialization of make_nvp<> that actually creates an nvp for non-binary archives
185
- /*! @relates NameValuePair
186
- @internal */
187
- template<class Archive, class T> inline
188
- typename
189
- std::enable_if<!std::is_same<Archive, ::cereal::BinaryInputArchive>::value &&
190
- !std::is_same<Archive, ::cereal::BinaryOutputArchive>::value,
191
- NameValuePair<T> >::type
192
- make_nvp( const char * name, T && value)
193
- {
194
- return {name, std::forward<T>(value)};
195
- }
196
-
197
- //! Convenience for creating a templated NVP
198
- /*! For use in internal generic typing functions which have an
199
- Archive type declared
200
- @internal */
201
- #define CEREAL_NVP_(name, value) ::cereal::make_nvp<Archive>(name, value)
202
-
203
- // ######################################################################
204
- //! A wrapper around data that can be serialized in a binary fashion
205
- /*! This class is used to demarcate data that can safely be serialized
206
- as a binary chunk of data. Individual archives can then choose how
207
- best represent this during serialization.
208
-
209
- @internal */
210
- template <class T>
211
- struct BinaryData
212
- {
213
- //! Internally store the pointer as a void *, keeping const if created with
214
- //! a const pointer
215
- using PT = typename std::conditional<std::is_const<typename std::remove_pointer<typename std::remove_reference<T>::type>::type>::value,
216
- const void *,
217
- void *>::type;
218
-
219
- BinaryData( T && d, uint64_t s ) : data(std::forward<T>(d)), size(s) {}
220
-
221
- PT data; //!< pointer to beginning of data
222
- uint64_t size; //!< size in bytes
223
- };
224
-
225
- // ######################################################################
226
- //! A wrapper around data that should be serialized after all non-deferred data
227
- /*! This class is used to demarcate data that can only be safely serialized after
228
- any data not wrapped in this class.
229
-
230
- @internal */
231
- template <class T>
232
- class DeferredData : detail::DeferredDataCore
233
- {
234
- private:
235
- // If we get passed an array, keep the type as is, otherwise store
236
- // a reference if we were passed an l value reference, else copy the value
237
- using Type = typename std::conditional<std::is_array<typename std::remove_reference<T>::type>::value,
238
- typename std::remove_cv<T>::type,
239
- typename std::conditional<std::is_lvalue_reference<T>::value,
240
- T,
241
- typename std::decay<T>::type>::type>::type;
242
-
243
- // prevent nested nvps
244
- static_assert( !std::is_base_of<detail::DeferredDataCore, T>::value,
245
- "Cannot defer DeferredData" );
246
-
247
- DeferredData & operator=( DeferredData const & ) = delete;
248
-
249
- public:
250
- //! Constructs a new NameValuePair
251
- /*! @param v The value to defer. Ideally this should be an l-value reference so that
252
- the value can be both loaded and saved to. If you pass an r-value reference,
253
- the DeferredData will store a copy of it instead of a reference. Thus you should
254
- only pass r-values in cases where this makes sense, such as the result of some
255
- size() call.
256
- @internal */
257
- DeferredData( T && v ) : value(std::forward<T>(v)) {}
258
-
259
- Type value;
260
- };
261
-
262
- // ######################################################################
263
- namespace detail
264
- {
265
- // base classes for type checking
266
- /* The rtti virtual function only exists to enable an archive to
267
- be used in a polymorphic fashion, if necessary. See the
268
- archive adapters for an example of this */
269
- class OutputArchiveBase
270
- {
271
- public:
272
- OutputArchiveBase() = default;
273
- OutputArchiveBase( OutputArchiveBase && ) CEREAL_NOEXCEPT {}
274
- OutputArchiveBase & operator=( OutputArchiveBase && ) CEREAL_NOEXCEPT { return *this; }
275
- virtual ~OutputArchiveBase() CEREAL_NOEXCEPT = default;
276
-
277
- private:
278
- virtual void rtti() {}
279
- };
280
-
281
- class InputArchiveBase
282
- {
283
- public:
284
- InputArchiveBase() = default;
285
- InputArchiveBase( InputArchiveBase && ) CEREAL_NOEXCEPT {}
286
- InputArchiveBase & operator=( InputArchiveBase && ) CEREAL_NOEXCEPT { return *this; }
287
- virtual ~InputArchiveBase() CEREAL_NOEXCEPT = default;
288
-
289
- private:
290
- virtual void rtti() {}
291
- };
292
-
293
- // forward decls for polymorphic support
294
- template <class Archive, class T> struct polymorphic_serialization_support;
295
- struct adl_tag;
296
-
297
- // used during saving pointers
298
- static const uint32_t msb_32bit = 0x80000000;
299
- static const int32_t msb2_32bit = 0x40000000;
300
- }
301
-
302
- // ######################################################################
303
- //! A wrapper around size metadata
304
- /*! This class provides a way for archives to have more flexibility over how
305
- they choose to serialize size metadata for containers. For some archive
306
- types, the size may be implicitly encoded in the output (e.g. JSON) and
307
- not need an explicit entry. Specializing serialize or load/save for
308
- your archive and SizeTags allows you to choose what happens.
309
-
310
- @internal */
311
- template <class T>
312
- class SizeTag
313
- {
314
- private:
315
- // Store a reference if passed an lvalue reference, otherwise
316
- // make a copy of the data
317
- using Type = typename std::conditional<std::is_lvalue_reference<T>::value,
318
- T,
319
- typename std::decay<T>::type>::type;
320
-
321
- SizeTag & operator=( SizeTag const & ) = delete;
322
-
323
- public:
324
- SizeTag( T && sz ) : size(std::forward<T>(sz)) {}
325
-
326
- Type size;
327
- };
328
-
329
- // ######################################################################
330
- //! A wrapper around a key and value for serializing data into maps.
331
- /*! This class just provides a grouping of keys and values into a struct for
332
- human readable archives. For example, XML archives will use this wrapper
333
- to write maps like so:
334
-
335
- @code{.xml}
336
- <mymap>
337
- <item0>
338
- <key>MyFirstKey</key>
339
- <value>MyFirstValue</value>
340
- </item0>
341
- <item1>
342
- <key>MySecondKey</key>
343
- <value>MySecondValue</value>
344
- </item1>
345
- </mymap>
346
- @endcode
347
-
348
- \sa make_map_item
349
- @internal */
350
- template <class Key, class Value>
351
- struct MapItem
352
- {
353
- using KeyType = typename std::conditional<
354
- std::is_lvalue_reference<Key>::value,
355
- Key,
356
- typename std::decay<Key>::type>::type;
357
-
358
- using ValueType = typename std::conditional<
359
- std::is_lvalue_reference<Value>::value,
360
- Value,
361
- typename std::decay<Value>::type>::type;
362
-
363
- //! Construct a MapItem from a key and a value
364
- /*! @internal */
365
- MapItem( Key && key_, Value && value_ ) : key(std::forward<Key>(key_)), value(std::forward<Value>(value_)) {}
366
-
367
- MapItem & operator=( MapItem const & ) = delete;
368
-
369
- KeyType key;
370
- ValueType value;
371
-
372
- //! Serialize the MapItem with the NVPs "key" and "value"
373
- template <class Archive> inline
374
- void CEREAL_SERIALIZE_FUNCTION_NAME(Archive & archive)
375
- {
376
- archive( make_nvp<Archive>("key", key),
377
- make_nvp<Archive>("value", value) );
378
- }
379
- };
380
-
381
- //! Create a MapItem so that human readable archives will group keys and values together
382
- /*! @internal
383
- @relates MapItem */
384
- template <class KeyType, class ValueType> inline
385
- MapItem<KeyType, ValueType> make_map_item(KeyType && key, ValueType && value)
386
- {
387
- return {std::forward<KeyType>(key), std::forward<ValueType>(value)};
388
- }
389
-
390
- namespace detail
391
- {
392
- //! Tag for Version, which due to its anonymous namespace, becomes a different
393
- //! type in each translation unit
394
- /*! This allows CEREAL_CLASS_VERSION to be safely called in a header file */
395
- namespace{ struct version_binding_tag {}; }
396
-
397
- // ######################################################################
398
- //! Version information class
399
- /*! This is the base case for classes that have not been explicitly
400
- registered */
401
- template <class T, class BindingTag = version_binding_tag> struct Version
402
- {
403
- static const std::uint32_t version = 0;
404
- // we don't need to explicitly register these types since they
405
- // always get a version number of 0
406
- };
407
-
408
- //! Holds all registered version information
409
- struct Versions
410
- {
411
- std::unordered_map<std::size_t, std::uint32_t> mapping;
412
-
413
- std::uint32_t find( std::size_t hash, std::uint32_t version )
414
- {
415
- const auto result = mapping.emplace( hash, version );
416
- return result.first->second;
417
- }
418
- }; // struct Versions
419
- } // namespace detail
420
- } // namespace cereal
421
-
422
- #endif // CEREAL_DETAILS_HELPERS_HPP_