isotree 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -1
- data/LICENSE.txt +2 -2
- data/README.md +41 -23
- data/ext/isotree/ext.cpp +144 -31
- data/ext/isotree/extconf.rb +7 -7
- data/lib/isotree/dataset.rb +0 -1
- data/lib/isotree/isolation_forest.rb +114 -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 +40 -106
- 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
data/vendor/cereal/README.md
DELETED
@@ -1,85 +0,0 @@
|
|
1
|
-
cereal - A C++11 library for serialization
|
2
|
-
==========================================
|
3
|
-
|
4
|
-
<img src="http://uscilab.github.io/cereal/assets/img/cerealboxside.png" align="right"/><p>cereal is a header-only C++11 serialization library. cereal takes arbitrary data types and reversibly turns them into different representations, such as compact binary encodings, XML, or JSON. cereal was designed to be fast, light-weight, and easy to extend - it has no external dependencies and can be easily bundled with other code or used standalone.</p>
|
5
|
-
|
6
|
-
### cereal has great documentation
|
7
|
-
|
8
|
-
Looking for more information on how cereal works and its documentation? Visit [cereal's web page](http://USCiLab.github.com/cereal) to get the latest information.
|
9
|
-
|
10
|
-
### cereal is easy to use
|
11
|
-
|
12
|
-
Installation and use of of cereal is fully documented on the [main web page](http://USCiLab.github.com/cereal), but this is a quick and dirty version:
|
13
|
-
|
14
|
-
* Download cereal and place the headers somewhere your code can see them
|
15
|
-
* Write serialization functions for your custom types or use the built in support for the standard library cereal provides
|
16
|
-
* Use the serialization archives to load and save data
|
17
|
-
|
18
|
-
```cpp
|
19
|
-
#include <cereal/types/unordered_map.hpp>
|
20
|
-
#include <cereal/types/memory.hpp>
|
21
|
-
#include <cereal/archives/binary.hpp>
|
22
|
-
#include <fstream>
|
23
|
-
|
24
|
-
struct MyRecord
|
25
|
-
{
|
26
|
-
uint8_t x, y;
|
27
|
-
float z;
|
28
|
-
|
29
|
-
template <class Archive>
|
30
|
-
void serialize( Archive & ar )
|
31
|
-
{
|
32
|
-
ar( x, y, z );
|
33
|
-
}
|
34
|
-
};
|
35
|
-
|
36
|
-
struct SomeData
|
37
|
-
{
|
38
|
-
int32_t id;
|
39
|
-
std::shared_ptr<std::unordered_map<uint32_t, MyRecord>> data;
|
40
|
-
|
41
|
-
template <class Archive>
|
42
|
-
void save( Archive & ar ) const
|
43
|
-
{
|
44
|
-
ar( data );
|
45
|
-
}
|
46
|
-
|
47
|
-
template <class Archive>
|
48
|
-
void load( Archive & ar )
|
49
|
-
{
|
50
|
-
static int32_t idGen = 0;
|
51
|
-
id = idGen++;
|
52
|
-
ar( data );
|
53
|
-
}
|
54
|
-
};
|
55
|
-
|
56
|
-
int main()
|
57
|
-
{
|
58
|
-
std::ofstream os("out.cereal", std::ios::binary);
|
59
|
-
cereal::BinaryOutputArchive archive( os );
|
60
|
-
|
61
|
-
SomeData myData;
|
62
|
-
archive( myData );
|
63
|
-
|
64
|
-
return 0;
|
65
|
-
}
|
66
|
-
```
|
67
|
-
|
68
|
-
### cereal has a mailing list
|
69
|
-
|
70
|
-
Either get in touch over <a href="mailto:cerealcpp@googlegroups.com">email</a> or [on the web](https://groups.google.com/forum/#!forum/cerealcpp).
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
## cereal has a permissive license
|
75
|
-
|
76
|
-
cereal is licensed under the [BSD license](http://opensource.org/licenses/BSD-3-Clause).
|
77
|
-
|
78
|
-
## cereal build status
|
79
|
-
|
80
|
-
* master : [![Build Status](https://travis-ci.com/USCiLab/cereal.svg?branch=master)](https://travis-ci.com/USCiLab/cereal)
|
81
|
-
[![Build status](https://ci.appveyor.com/api/projects/status/91aou6smj36or0vb/branch/master?svg=true)](https://ci.appveyor.com/project/AzothAmmo/cereal/branch/master)
|
82
|
-
|
83
|
-
---
|
84
|
-
|
85
|
-
Were you looking for the Haskell cereal? Go <a href="https://github.com/GaloisInc/cereal">here</a>.
|
@@ -1,351 +0,0 @@
|
|
1
|
-
/*! \file access.hpp
|
2
|
-
\brief Access control and default construction */
|
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_ACCESS_HPP_
|
30
|
-
#define CEREAL_ACCESS_HPP_
|
31
|
-
|
32
|
-
#include <type_traits>
|
33
|
-
#include <iostream>
|
34
|
-
#include <cstdint>
|
35
|
-
#include <functional>
|
36
|
-
|
37
|
-
#include "cereal/macros.hpp"
|
38
|
-
#include "cereal/specialize.hpp"
|
39
|
-
#include "cereal/details/helpers.hpp"
|
40
|
-
|
41
|
-
namespace cereal
|
42
|
-
{
|
43
|
-
// ######################################################################
|
44
|
-
//! A class that allows cereal to load smart pointers to types that have no default constructor
|
45
|
-
/*! If your class does not have a default constructor, cereal will not be able
|
46
|
-
to load any smart pointers to it unless you overload LoadAndConstruct
|
47
|
-
for your class, and provide an appropriate load_and_construct method. You can also
|
48
|
-
choose to define a member static function instead of specializing this class.
|
49
|
-
|
50
|
-
The specialization of LoadAndConstruct must be placed within the cereal namespace:
|
51
|
-
|
52
|
-
@code{.cpp}
|
53
|
-
struct MyType
|
54
|
-
{
|
55
|
-
MyType( int x ); // note: no default ctor
|
56
|
-
int myX;
|
57
|
-
|
58
|
-
// Define a serialize or load/save pair as you normally would
|
59
|
-
template <class Archive>
|
60
|
-
void serialize( Archive & ar )
|
61
|
-
{
|
62
|
-
ar( myX );
|
63
|
-
}
|
64
|
-
};
|
65
|
-
|
66
|
-
// Provide a specialization for LoadAndConstruct for your type
|
67
|
-
namespace cereal
|
68
|
-
{
|
69
|
-
template <> struct LoadAndConstruct<MyType>
|
70
|
-
{
|
71
|
-
// load_and_construct will be passed the archive that you will be loading
|
72
|
-
// from as well as a construct object which you can use as if it were the
|
73
|
-
// constructor for your type. cereal will handle all memory management for you.
|
74
|
-
template <class Archive>
|
75
|
-
static void load_and_construct( Archive & ar, cereal::construct<MyType> & construct )
|
76
|
-
{
|
77
|
-
int x;
|
78
|
-
ar( x );
|
79
|
-
construct( x );
|
80
|
-
}
|
81
|
-
|
82
|
-
// if you require versioning, simply add a const std::uint32_t as the final parameter, e.g.:
|
83
|
-
// load_and_construct( Archive & ar, cereal::construct<MyType> & construct, std::uint32_t const version )
|
84
|
-
};
|
85
|
-
} // end namespace cereal
|
86
|
-
@endcode
|
87
|
-
|
88
|
-
Please note that just as in using external serialization functions, you cannot get
|
89
|
-
access to non-public members of your class by befriending cereal::access. If you
|
90
|
-
have the ability to modify the class you wish to serialize, it is recommended that you
|
91
|
-
use member serialize functions and a static member load_and_construct function.
|
92
|
-
|
93
|
-
load_and_construct functions, regardless of whether they are static members of your class or
|
94
|
-
whether you create one in the LoadAndConstruct specialization, have the following signature:
|
95
|
-
|
96
|
-
@code{.cpp}
|
97
|
-
// generally Archive will be templated, but it can be specific if desired
|
98
|
-
template <class Archive>
|
99
|
-
static void load_and_construct( Archive & ar, cereal::construct<MyType> & construct );
|
100
|
-
// with an optional last parameter specifying the version: const std::uint32_t version
|
101
|
-
@endcode
|
102
|
-
|
103
|
-
Versioning behaves the same way as it does for standard serialization functions.
|
104
|
-
|
105
|
-
@tparam T The type to specialize for
|
106
|
-
@ingroup Access */
|
107
|
-
template <class T>
|
108
|
-
struct LoadAndConstruct
|
109
|
-
{ };
|
110
|
-
|
111
|
-
// forward decl for construct
|
112
|
-
//! @cond PRIVATE_NEVERDEFINED
|
113
|
-
namespace memory_detail{ template <class Ar, class T> struct LoadAndConstructLoadWrapper; }
|
114
|
-
namespace boost_variant_detail{ template <class Ar, class T> struct LoadAndConstructLoadWrapper; }
|
115
|
-
//! @endcond
|
116
|
-
|
117
|
-
//! Used to construct types with no default constructor
|
118
|
-
/*! When serializing a type that has no default constructor, cereal
|
119
|
-
will attempt to call either the class static function load_and_construct
|
120
|
-
or the appropriate template specialization of LoadAndConstruct. cereal
|
121
|
-
will pass that function a reference to the archive as well as a reference
|
122
|
-
to a construct object which should be used to perform the allocation once
|
123
|
-
data has been appropriately loaded.
|
124
|
-
|
125
|
-
@code{.cpp}
|
126
|
-
struct MyType
|
127
|
-
{
|
128
|
-
// note the lack of default constructor
|
129
|
-
MyType( int xx, int yy );
|
130
|
-
|
131
|
-
int x, y;
|
132
|
-
double notInConstructor;
|
133
|
-
|
134
|
-
template <class Archive>
|
135
|
-
void serialize( Archive & ar )
|
136
|
-
{
|
137
|
-
ar( x, y );
|
138
|
-
ar( notInConstructor );
|
139
|
-
}
|
140
|
-
|
141
|
-
template <class Archive>
|
142
|
-
static void load_and_construct( Archive & ar, cereal::construct<MyType> & construct )
|
143
|
-
{
|
144
|
-
int x, y;
|
145
|
-
ar( x, y );
|
146
|
-
|
147
|
-
// use construct object to initialize with loaded data
|
148
|
-
construct( x, y );
|
149
|
-
|
150
|
-
// access to member variables and functions via -> operator
|
151
|
-
ar( construct->notInConstructor );
|
152
|
-
|
153
|
-
// could also do the above section by:
|
154
|
-
double z;
|
155
|
-
ar( z );
|
156
|
-
construct->notInConstructor = z;
|
157
|
-
}
|
158
|
-
};
|
159
|
-
@endcode
|
160
|
-
|
161
|
-
@tparam T The class type being serialized
|
162
|
-
*/
|
163
|
-
template <class T>
|
164
|
-
class construct
|
165
|
-
{
|
166
|
-
public:
|
167
|
-
//! Construct and initialize the type T with the given arguments
|
168
|
-
/*! This will forward all arguments to the underlying type T,
|
169
|
-
calling an appropriate constructor.
|
170
|
-
|
171
|
-
Calling this function more than once will result in an exception
|
172
|
-
being thrown.
|
173
|
-
|
174
|
-
@param args The arguments to the constructor for T
|
175
|
-
@throw Exception If called more than once */
|
176
|
-
template <class ... Args>
|
177
|
-
void operator()( Args && ... args );
|
178
|
-
// implementation deferred due to reliance on cereal::access
|
179
|
-
|
180
|
-
//! Get a reference to the initialized underlying object
|
181
|
-
/*! This must be called after the object has been initialized.
|
182
|
-
|
183
|
-
@return A reference to the initialized object
|
184
|
-
@throw Exception If called before initialization */
|
185
|
-
T * operator->()
|
186
|
-
{
|
187
|
-
if( !itsValid )
|
188
|
-
throw Exception("Object must be initialized prior to accessing members");
|
189
|
-
|
190
|
-
return itsPtr;
|
191
|
-
}
|
192
|
-
|
193
|
-
//! Returns a raw pointer to the initialized underlying object
|
194
|
-
/*! This is mainly intended for use with passing an instance of
|
195
|
-
a constructed object to cereal::base_class.
|
196
|
-
|
197
|
-
It is strongly recommended to avoid using this function in
|
198
|
-
any other circumstance.
|
199
|
-
|
200
|
-
@return A raw pointer to the initialized type */
|
201
|
-
T * ptr()
|
202
|
-
{
|
203
|
-
return operator->();
|
204
|
-
}
|
205
|
-
|
206
|
-
private:
|
207
|
-
template <class Ar, class TT> friend struct ::cereal::memory_detail::LoadAndConstructLoadWrapper;
|
208
|
-
template <class Ar, class TT> friend struct ::cereal::boost_variant_detail::LoadAndConstructLoadWrapper;
|
209
|
-
|
210
|
-
construct( T * p ) : itsPtr( p ), itsEnableSharedRestoreFunction( [](){} ), itsValid( false ) {}
|
211
|
-
construct( T * p, std::function<void()> enableSharedFunc ) : // g++4.7 ice with default lambda to std func
|
212
|
-
itsPtr( p ), itsEnableSharedRestoreFunction( enableSharedFunc ), itsValid( false ) {}
|
213
|
-
construct( construct const & ) = delete;
|
214
|
-
construct & operator=( construct const & ) = delete;
|
215
|
-
|
216
|
-
T * itsPtr;
|
217
|
-
std::function<void()> itsEnableSharedRestoreFunction;
|
218
|
-
bool itsValid;
|
219
|
-
};
|
220
|
-
|
221
|
-
// ######################################################################
|
222
|
-
//! A class that can be made a friend to give cereal access to non public functions
|
223
|
-
/*! If you desire non-public serialization functions within a class, cereal can only
|
224
|
-
access these if you declare cereal::access a friend.
|
225
|
-
|
226
|
-
@code{.cpp}
|
227
|
-
class MyClass
|
228
|
-
{
|
229
|
-
private:
|
230
|
-
friend class cereal::access; // gives access to the private serialize
|
231
|
-
|
232
|
-
template <class Archive>
|
233
|
-
void serialize( Archive & ar )
|
234
|
-
{
|
235
|
-
// some code
|
236
|
-
}
|
237
|
-
};
|
238
|
-
@endcode
|
239
|
-
@ingroup Access */
|
240
|
-
class access
|
241
|
-
{
|
242
|
-
public:
|
243
|
-
// ####### Standard Serialization ########################################
|
244
|
-
template<class Archive, class T> inline
|
245
|
-
static auto member_serialize(Archive & ar, T & t) -> decltype(t.CEREAL_SERIALIZE_FUNCTION_NAME(ar))
|
246
|
-
{ return t.CEREAL_SERIALIZE_FUNCTION_NAME(ar); }
|
247
|
-
|
248
|
-
template<class Archive, class T> inline
|
249
|
-
static auto member_save(Archive & ar, T const & t) -> decltype(t.CEREAL_SAVE_FUNCTION_NAME(ar))
|
250
|
-
{ return t.CEREAL_SAVE_FUNCTION_NAME(ar); }
|
251
|
-
|
252
|
-
template<class Archive, class T> inline
|
253
|
-
static auto member_save_non_const(Archive & ar, T & t) -> decltype(t.CEREAL_SAVE_FUNCTION_NAME(ar))
|
254
|
-
{ return t.CEREAL_SAVE_FUNCTION_NAME(ar); }
|
255
|
-
|
256
|
-
template<class Archive, class T> inline
|
257
|
-
static auto member_load(Archive & ar, T & t) -> decltype(t.CEREAL_LOAD_FUNCTION_NAME(ar))
|
258
|
-
{ return t.CEREAL_LOAD_FUNCTION_NAME(ar); }
|
259
|
-
|
260
|
-
template<class Archive, class T> inline
|
261
|
-
static auto member_save_minimal(Archive const & ar, T const & t) -> decltype(t.CEREAL_SAVE_MINIMAL_FUNCTION_NAME(ar))
|
262
|
-
{ return t.CEREAL_SAVE_MINIMAL_FUNCTION_NAME(ar); }
|
263
|
-
|
264
|
-
template<class Archive, class T> inline
|
265
|
-
static auto member_save_minimal_non_const(Archive const & ar, T & t) -> decltype(t.CEREAL_SAVE_MINIMAL_FUNCTION_NAME(ar))
|
266
|
-
{ return t.CEREAL_SAVE_MINIMAL_FUNCTION_NAME(ar); }
|
267
|
-
|
268
|
-
template<class Archive, class T, class U> inline
|
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)))
|
270
|
-
{ return t.CEREAL_LOAD_MINIMAL_FUNCTION_NAME(ar, std::forward<U>(u)); }
|
271
|
-
|
272
|
-
// ####### Versioned Serialization #######################################
|
273
|
-
template<class Archive, class T> inline
|
274
|
-
static auto member_serialize(Archive & ar, T & t, const std::uint32_t version ) -> decltype(t.CEREAL_SERIALIZE_FUNCTION_NAME(ar, version))
|
275
|
-
{ return t.CEREAL_SERIALIZE_FUNCTION_NAME(ar, version); }
|
276
|
-
|
277
|
-
template<class Archive, class T> inline
|
278
|
-
static auto member_save(Archive & ar, T const & t, const std::uint32_t version ) -> decltype(t.CEREAL_SAVE_FUNCTION_NAME(ar, version))
|
279
|
-
{ return t.CEREAL_SAVE_FUNCTION_NAME(ar, version); }
|
280
|
-
|
281
|
-
template<class Archive, class T> inline
|
282
|
-
static auto member_save_non_const(Archive & ar, T & t, const std::uint32_t version ) -> decltype(t.CEREAL_SAVE_FUNCTION_NAME(ar, version))
|
283
|
-
{ return t.CEREAL_SAVE_FUNCTION_NAME(ar, version); }
|
284
|
-
|
285
|
-
template<class Archive, class T> inline
|
286
|
-
static auto member_load(Archive & ar, T & t, const std::uint32_t version ) -> decltype(t.CEREAL_LOAD_FUNCTION_NAME(ar, version))
|
287
|
-
{ return t.CEREAL_LOAD_FUNCTION_NAME(ar, version); }
|
288
|
-
|
289
|
-
template<class Archive, class T> inline
|
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))
|
291
|
-
{ return t.CEREAL_SAVE_MINIMAL_FUNCTION_NAME(ar, version); }
|
292
|
-
|
293
|
-
template<class Archive, class T> inline
|
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))
|
295
|
-
{ return t.CEREAL_SAVE_MINIMAL_FUNCTION_NAME(ar, version); }
|
296
|
-
|
297
|
-
template<class Archive, class T, class U> inline
|
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))
|
299
|
-
{ return t.CEREAL_LOAD_MINIMAL_FUNCTION_NAME(ar, std::forward<U>(u), version); }
|
300
|
-
|
301
|
-
// ####### Other Functionality ##########################################
|
302
|
-
// for detecting inheritance from enable_shared_from_this
|
303
|
-
template <class T> inline
|
304
|
-
static auto shared_from_this(T & t) -> decltype(t.shared_from_this());
|
305
|
-
|
306
|
-
// for placement new
|
307
|
-
template <class T, class ... Args> inline
|
308
|
-
static void construct( T *& ptr, Args && ... args )
|
309
|
-
{
|
310
|
-
new (ptr) T( std::forward<Args>( args )... );
|
311
|
-
}
|
312
|
-
|
313
|
-
// for non-placement new with a default constructor
|
314
|
-
template <class T> inline
|
315
|
-
static T * construct()
|
316
|
-
{
|
317
|
-
return new T();
|
318
|
-
}
|
319
|
-
|
320
|
-
template <class T> inline
|
321
|
-
static std::false_type load_and_construct(...)
|
322
|
-
{ return std::false_type(); }
|
323
|
-
|
324
|
-
template<class T, class Archive> inline
|
325
|
-
static auto load_and_construct(Archive & ar, ::cereal::construct<T> & construct) -> decltype(T::load_and_construct(ar, construct))
|
326
|
-
{
|
327
|
-
T::load_and_construct( ar, construct );
|
328
|
-
}
|
329
|
-
|
330
|
-
template<class T, class Archive> inline
|
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))
|
332
|
-
{
|
333
|
-
T::load_and_construct( ar, construct, version );
|
334
|
-
}
|
335
|
-
}; // end class access
|
336
|
-
|
337
|
-
// ######################################################################
|
338
|
-
// Deferred Implementation, see construct for more information
|
339
|
-
template <class T> template <class ... Args> inline
|
340
|
-
void construct<T>::operator()( Args && ... args )
|
341
|
-
{
|
342
|
-
if( itsValid )
|
343
|
-
throw Exception("Attempting to construct an already initialized object");
|
344
|
-
|
345
|
-
::cereal::access::construct( itsPtr, std::forward<Args>( args )... );
|
346
|
-
itsEnableSharedRestoreFunction();
|
347
|
-
itsValid = true;
|
348
|
-
}
|
349
|
-
} // namespace cereal
|
350
|
-
|
351
|
-
#endif // CEREAL_ACCESS_HPP_
|
@@ -1,163 +0,0 @@
|
|
1
|
-
/*! \file adapters.hpp
|
2
|
-
\brief Archive adapters that provide additional functionality
|
3
|
-
on top of an existing archive */
|
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_ARCHIVES_ADAPTERS_HPP_
|
31
|
-
#define CEREAL_ARCHIVES_ADAPTERS_HPP_
|
32
|
-
|
33
|
-
#include "cereal/details/helpers.hpp"
|
34
|
-
#include <utility>
|
35
|
-
|
36
|
-
namespace cereal
|
37
|
-
{
|
38
|
-
#ifdef CEREAL_FUTURE_EXPERIMENTAL
|
39
|
-
|
40
|
-
// Forward declaration for friend access
|
41
|
-
template <class U, class A> U & get_user_data( A & );
|
42
|
-
|
43
|
-
//! Wraps an archive and gives access to user data
|
44
|
-
/*! This adapter is useful if you require access to
|
45
|
-
either raw pointers or references within your
|
46
|
-
serialization functions.
|
47
|
-
|
48
|
-
While cereal does not directly support serialization
|
49
|
-
raw pointers or references, it is sometimes the case
|
50
|
-
that you may want to supply something such as a raw
|
51
|
-
pointer or global reference to some constructor.
|
52
|
-
In this situation this adapter would likely be used
|
53
|
-
with the construct class to allow for non-default
|
54
|
-
constructors.
|
55
|
-
|
56
|
-
@note This feature is experimental and may be altered or removed in a future release. See issue #46.
|
57
|
-
|
58
|
-
@code{.cpp}
|
59
|
-
struct MyUserData
|
60
|
-
{
|
61
|
-
int * myRawPointer;
|
62
|
-
std::reference_wrapper<MyOtherType> myReference;
|
63
|
-
};
|
64
|
-
|
65
|
-
struct MyClass
|
66
|
-
{
|
67
|
-
// Note the raw pointer parameter
|
68
|
-
MyClass( int xx, int * rawP );
|
69
|
-
|
70
|
-
int x;
|
71
|
-
|
72
|
-
template <class Archive>
|
73
|
-
void serialize( Archive & ar )
|
74
|
-
{ ar( x ); }
|
75
|
-
|
76
|
-
template <class Archive>
|
77
|
-
static void load_and_construct( Archive & ar, cereal::construct<MyClass> & construct )
|
78
|
-
{
|
79
|
-
int xx;
|
80
|
-
ar( xx );
|
81
|
-
// note the need to use get_user_data to retrieve user data from the archive
|
82
|
-
construct( xx, cereal::get_user_data<MyUserData>( ar ).myRawPointer );
|
83
|
-
}
|
84
|
-
};
|
85
|
-
|
86
|
-
int main()
|
87
|
-
{
|
88
|
-
{
|
89
|
-
MyUserData md;
|
90
|
-
md.myRawPointer = &something;
|
91
|
-
md.myReference = someInstanceOfType;
|
92
|
-
|
93
|
-
std::ifstream is( "data.xml" );
|
94
|
-
cereal::UserDataAdapter<MyUserData, cereal::XMLInputArchive> ar( md, is );
|
95
|
-
|
96
|
-
std::unique_ptr<MyClass> sc;
|
97
|
-
ar( sc ); // use as normal
|
98
|
-
}
|
99
|
-
|
100
|
-
return 0;
|
101
|
-
}
|
102
|
-
@endcode
|
103
|
-
|
104
|
-
@relates get_user_data
|
105
|
-
|
106
|
-
@tparam UserData The type to give the archive access to
|
107
|
-
@tparam Archive The archive to wrap */
|
108
|
-
template <class UserData, class Archive>
|
109
|
-
class UserDataAdapter : public Archive
|
110
|
-
{
|
111
|
-
public:
|
112
|
-
//! Construct the archive with some user data struct
|
113
|
-
/*! This will forward all arguments (other than the user
|
114
|
-
data) to the wrapped archive type. The UserDataAdapter
|
115
|
-
can then be used identically to the wrapped archive type
|
116
|
-
|
117
|
-
@tparam Args The arguments to pass to the constructor of
|
118
|
-
the archive. */
|
119
|
-
template <class ... Args>
|
120
|
-
UserDataAdapter( UserData & ud, Args && ... args ) :
|
121
|
-
Archive( std::forward<Args>( args )... ),
|
122
|
-
userdata( ud )
|
123
|
-
{ }
|
124
|
-
|
125
|
-
private:
|
126
|
-
//! Overload the rtti function to enable dynamic_cast
|
127
|
-
void rtti() {}
|
128
|
-
friend UserData & get_user_data<UserData>( Archive & ar );
|
129
|
-
UserData & userdata; //!< The actual user data
|
130
|
-
};
|
131
|
-
|
132
|
-
//! Retrieves user data from an archive wrapped by UserDataAdapter
|
133
|
-
/*! This will attempt to retrieve the user data associated with
|
134
|
-
some archive wrapped by UserDataAdapter. If this is used on
|
135
|
-
an archive that is not wrapped, a run-time exception will occur.
|
136
|
-
|
137
|
-
@note This feature is experimental and may be altered or removed in a future release. See issue #46.
|
138
|
-
|
139
|
-
@note The correct use of this function cannot be enforced at compile
|
140
|
-
time.
|
141
|
-
|
142
|
-
@relates UserDataAdapter
|
143
|
-
@tparam UserData The data struct contained in the archive
|
144
|
-
@tparam Archive The archive, which should be wrapped by UserDataAdapter
|
145
|
-
@param ar The archive
|
146
|
-
@throws Exception if the archive this is used upon is not wrapped with
|
147
|
-
UserDataAdapter. */
|
148
|
-
template <class UserData, class Archive>
|
149
|
-
UserData & get_user_data( Archive & ar )
|
150
|
-
{
|
151
|
-
try
|
152
|
-
{
|
153
|
-
return dynamic_cast<UserDataAdapter<UserData, Archive> &>( ar ).userdata;
|
154
|
-
}
|
155
|
-
catch( std::bad_cast const & )
|
156
|
-
{
|
157
|
-
throw ::cereal::Exception("Attempting to get user data from archive not wrapped in UserDataAdapter");
|
158
|
-
}
|
159
|
-
}
|
160
|
-
#endif // CEREAL_FUTURE_EXPERIMENTAL
|
161
|
-
} // namespace cereal
|
162
|
-
|
163
|
-
#endif // CEREAL_ARCHIVES_ADAPTERS_HPP_
|