isotree 0.1.1 → 0.2.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 +25 -0
- data/LICENSE.txt +2 -1
- data/README.md +57 -6
- data/ext/isotree/ext.cpp +170 -39
- data/ext/isotree/extconf.rb +3 -3
- data/lib/isotree.rb +2 -0
- data/lib/isotree/dataset.rb +73 -0
- data/lib/isotree/isolation_forest.rb +182 -29
- data/lib/isotree/version.rb +1 -1
- data/vendor/cereal/LICENSE +24 -0
- data/vendor/cereal/README.md +85 -0
- data/vendor/cereal/include/cereal/access.hpp +351 -0
- data/vendor/cereal/include/cereal/archives/adapters.hpp +163 -0
- data/vendor/cereal/include/cereal/archives/binary.hpp +169 -0
- data/vendor/cereal/include/cereal/archives/json.hpp +1019 -0
- data/vendor/cereal/include/cereal/archives/portable_binary.hpp +334 -0
- data/vendor/cereal/include/cereal/archives/xml.hpp +956 -0
- data/vendor/cereal/include/cereal/cereal.hpp +1089 -0
- data/vendor/cereal/include/cereal/details/helpers.hpp +422 -0
- data/vendor/cereal/include/cereal/details/polymorphic_impl.hpp +796 -0
- data/vendor/cereal/include/cereal/details/polymorphic_impl_fwd.hpp +65 -0
- data/vendor/cereal/include/cereal/details/static_object.hpp +127 -0
- data/vendor/cereal/include/cereal/details/traits.hpp +1411 -0
- data/vendor/cereal/include/cereal/details/util.hpp +84 -0
- data/vendor/cereal/include/cereal/external/base64.hpp +134 -0
- data/vendor/cereal/include/cereal/external/rapidjson/allocators.h +284 -0
- data/vendor/cereal/include/cereal/external/rapidjson/cursorstreamwrapper.h +78 -0
- data/vendor/cereal/include/cereal/external/rapidjson/document.h +2652 -0
- data/vendor/cereal/include/cereal/external/rapidjson/encodedstream.h +299 -0
- data/vendor/cereal/include/cereal/external/rapidjson/encodings.h +716 -0
- data/vendor/cereal/include/cereal/external/rapidjson/error/en.h +74 -0
- data/vendor/cereal/include/cereal/external/rapidjson/error/error.h +161 -0
- data/vendor/cereal/include/cereal/external/rapidjson/filereadstream.h +99 -0
- data/vendor/cereal/include/cereal/external/rapidjson/filewritestream.h +104 -0
- data/vendor/cereal/include/cereal/external/rapidjson/fwd.h +151 -0
- data/vendor/cereal/include/cereal/external/rapidjson/internal/biginteger.h +290 -0
- data/vendor/cereal/include/cereal/external/rapidjson/internal/diyfp.h +271 -0
- data/vendor/cereal/include/cereal/external/rapidjson/internal/dtoa.h +245 -0
- data/vendor/cereal/include/cereal/external/rapidjson/internal/ieee754.h +78 -0
- data/vendor/cereal/include/cereal/external/rapidjson/internal/itoa.h +308 -0
- data/vendor/cereal/include/cereal/external/rapidjson/internal/meta.h +186 -0
- data/vendor/cereal/include/cereal/external/rapidjson/internal/pow10.h +55 -0
- data/vendor/cereal/include/cereal/external/rapidjson/internal/regex.h +740 -0
- data/vendor/cereal/include/cereal/external/rapidjson/internal/stack.h +232 -0
- data/vendor/cereal/include/cereal/external/rapidjson/internal/strfunc.h +69 -0
- data/vendor/cereal/include/cereal/external/rapidjson/internal/strtod.h +290 -0
- data/vendor/cereal/include/cereal/external/rapidjson/internal/swap.h +46 -0
- data/vendor/cereal/include/cereal/external/rapidjson/istreamwrapper.h +128 -0
- data/vendor/cereal/include/cereal/external/rapidjson/memorybuffer.h +70 -0
- data/vendor/cereal/include/cereal/external/rapidjson/memorystream.h +71 -0
- data/vendor/cereal/include/cereal/external/rapidjson/msinttypes/inttypes.h +316 -0
- data/vendor/cereal/include/cereal/external/rapidjson/msinttypes/stdint.h +300 -0
- data/vendor/cereal/include/cereal/external/rapidjson/ostreamwrapper.h +81 -0
- data/vendor/cereal/include/cereal/external/rapidjson/pointer.h +1414 -0
- data/vendor/cereal/include/cereal/external/rapidjson/prettywriter.h +277 -0
- data/vendor/cereal/include/cereal/external/rapidjson/rapidjson.h +656 -0
- data/vendor/cereal/include/cereal/external/rapidjson/reader.h +2230 -0
- data/vendor/cereal/include/cereal/external/rapidjson/schema.h +2497 -0
- data/vendor/cereal/include/cereal/external/rapidjson/stream.h +223 -0
- data/vendor/cereal/include/cereal/external/rapidjson/stringbuffer.h +121 -0
- data/vendor/cereal/include/cereal/external/rapidjson/writer.h +709 -0
- data/vendor/cereal/include/cereal/external/rapidxml/license.txt +52 -0
- data/vendor/cereal/include/cereal/external/rapidxml/manual.html +406 -0
- data/vendor/cereal/include/cereal/external/rapidxml/rapidxml.hpp +2624 -0
- data/vendor/cereal/include/cereal/external/rapidxml/rapidxml_iterators.hpp +175 -0
- data/vendor/cereal/include/cereal/external/rapidxml/rapidxml_print.hpp +428 -0
- data/vendor/cereal/include/cereal/external/rapidxml/rapidxml_utils.hpp +123 -0
- data/vendor/cereal/include/cereal/macros.hpp +154 -0
- data/vendor/cereal/include/cereal/specialize.hpp +139 -0
- data/vendor/cereal/include/cereal/types/array.hpp +79 -0
- data/vendor/cereal/include/cereal/types/atomic.hpp +55 -0
- data/vendor/cereal/include/cereal/types/base_class.hpp +203 -0
- data/vendor/cereal/include/cereal/types/bitset.hpp +176 -0
- data/vendor/cereal/include/cereal/types/boost_variant.hpp +164 -0
- data/vendor/cereal/include/cereal/types/chrono.hpp +72 -0
- data/vendor/cereal/include/cereal/types/common.hpp +129 -0
- data/vendor/cereal/include/cereal/types/complex.hpp +56 -0
- data/vendor/cereal/include/cereal/types/concepts/pair_associative_container.hpp +73 -0
- data/vendor/cereal/include/cereal/types/deque.hpp +62 -0
- data/vendor/cereal/include/cereal/types/forward_list.hpp +68 -0
- data/vendor/cereal/include/cereal/types/functional.hpp +43 -0
- data/vendor/cereal/include/cereal/types/list.hpp +62 -0
- data/vendor/cereal/include/cereal/types/map.hpp +36 -0
- data/vendor/cereal/include/cereal/types/memory.hpp +425 -0
- data/vendor/cereal/include/cereal/types/optional.hpp +66 -0
- data/vendor/cereal/include/cereal/types/polymorphic.hpp +483 -0
- data/vendor/cereal/include/cereal/types/queue.hpp +132 -0
- data/vendor/cereal/include/cereal/types/set.hpp +103 -0
- data/vendor/cereal/include/cereal/types/stack.hpp +76 -0
- data/vendor/cereal/include/cereal/types/string.hpp +61 -0
- data/vendor/cereal/include/cereal/types/tuple.hpp +123 -0
- data/vendor/cereal/include/cereal/types/unordered_map.hpp +36 -0
- data/vendor/cereal/include/cereal/types/unordered_set.hpp +99 -0
- data/vendor/cereal/include/cereal/types/utility.hpp +47 -0
- data/vendor/cereal/include/cereal/types/valarray.hpp +89 -0
- data/vendor/cereal/include/cereal/types/variant.hpp +109 -0
- data/vendor/cereal/include/cereal/types/vector.hpp +112 -0
- data/vendor/cereal/include/cereal/version.hpp +52 -0
- data/vendor/isotree/LICENSE +1 -1
- data/vendor/isotree/README.md +7 -2
- data/vendor/isotree/src/RcppExports.cpp +44 -4
- data/vendor/isotree/src/Rwrapper.cpp +141 -51
- data/vendor/isotree/src/crit.cpp +1 -1
- data/vendor/isotree/src/dealloc.cpp +1 -1
- data/vendor/isotree/src/dist.cpp +6 -6
- data/vendor/isotree/src/extended.cpp +5 -5
- data/vendor/isotree/src/fit_model.cpp +27 -5
- data/vendor/isotree/src/helpers_iforest.cpp +26 -11
- data/vendor/isotree/src/impute.cpp +7 -7
- data/vendor/isotree/src/isoforest.cpp +7 -7
- data/vendor/isotree/src/isotree.hpp +27 -5
- data/vendor/isotree/src/merge_models.cpp +1 -1
- data/vendor/isotree/src/mult.cpp +1 -1
- data/vendor/isotree/src/predict.cpp +20 -16
- data/vendor/isotree/src/serialize.cpp +1 -1
- data/vendor/isotree/src/sql.cpp +545 -0
- data/vendor/isotree/src/utils.cpp +36 -44
- metadata +102 -81
@@ -0,0 +1,123 @@
|
|
1
|
+
#ifndef CEREAL_RAPIDXML_UTILS_HPP_INCLUDED
|
2
|
+
#define CEREAL_RAPIDXML_UTILS_HPP_INCLUDED
|
3
|
+
|
4
|
+
// Copyright (C) 2006, 2009 Marcin Kalicinski
|
5
|
+
// Version 1.13
|
6
|
+
// Revision $DateTime: 2009/05/13 01:46:17 $
|
7
|
+
//! in certain simple scenarios. They should probably not be used if maximizing performance is the main objective.
|
8
|
+
|
9
|
+
#include "rapidxml.hpp"
|
10
|
+
#include <vector>
|
11
|
+
#include <string>
|
12
|
+
#include <fstream>
|
13
|
+
#include <stdexcept>
|
14
|
+
|
15
|
+
namespace cereal {
|
16
|
+
namespace rapidxml
|
17
|
+
{
|
18
|
+
|
19
|
+
//! Represents data loaded from a file
|
20
|
+
template<class Ch = char>
|
21
|
+
class file
|
22
|
+
{
|
23
|
+
|
24
|
+
public:
|
25
|
+
|
26
|
+
//! Loads file into the memory. Data will be automatically destroyed by the destructor.
|
27
|
+
//! \param filename Filename to load.
|
28
|
+
file(const char *filename)
|
29
|
+
{
|
30
|
+
using namespace std;
|
31
|
+
|
32
|
+
// Open stream
|
33
|
+
basic_ifstream<Ch> stream(filename, ios::binary);
|
34
|
+
if (!stream)
|
35
|
+
throw runtime_error(string("cannot open file ") + filename);
|
36
|
+
stream.unsetf(ios::skipws);
|
37
|
+
|
38
|
+
// Determine stream size
|
39
|
+
stream.seekg(0, ios::end);
|
40
|
+
size_t size = stream.tellg();
|
41
|
+
stream.seekg(0);
|
42
|
+
|
43
|
+
// Load data and add terminating 0
|
44
|
+
m_data.resize(size + 1);
|
45
|
+
stream.read(&m_data.front(), static_cast<streamsize>(size));
|
46
|
+
m_data[size] = 0;
|
47
|
+
}
|
48
|
+
|
49
|
+
//! Loads file into the memory. Data will be automatically destroyed by the destructor
|
50
|
+
//! \param stream Stream to load from
|
51
|
+
file(std::basic_istream<Ch> &stream)
|
52
|
+
{
|
53
|
+
using namespace std;
|
54
|
+
|
55
|
+
// Load data and add terminating 0
|
56
|
+
stream.unsetf(ios::skipws);
|
57
|
+
m_data.assign(istreambuf_iterator<Ch>(stream), istreambuf_iterator<Ch>());
|
58
|
+
if (stream.fail() || stream.bad())
|
59
|
+
throw runtime_error("error reading stream");
|
60
|
+
m_data.push_back(0);
|
61
|
+
}
|
62
|
+
|
63
|
+
//! Gets file data.
|
64
|
+
//! \return Pointer to data of file.
|
65
|
+
Ch *data()
|
66
|
+
{
|
67
|
+
return &m_data.front();
|
68
|
+
}
|
69
|
+
|
70
|
+
//! Gets file data.
|
71
|
+
//! \return Pointer to data of file.
|
72
|
+
const Ch *data() const
|
73
|
+
{
|
74
|
+
return &m_data.front();
|
75
|
+
}
|
76
|
+
|
77
|
+
//! Gets file data size.
|
78
|
+
//! \return Size of file data, in characters.
|
79
|
+
std::size_t size() const
|
80
|
+
{
|
81
|
+
return m_data.size();
|
82
|
+
}
|
83
|
+
|
84
|
+
private:
|
85
|
+
|
86
|
+
std::vector<Ch> m_data; // File data
|
87
|
+
|
88
|
+
};
|
89
|
+
|
90
|
+
//! Counts children of node. Time complexity is O(n).
|
91
|
+
//! \return Number of children of node
|
92
|
+
template<class Ch>
|
93
|
+
inline std::size_t count_children(xml_node<Ch> *node)
|
94
|
+
{
|
95
|
+
xml_node<Ch> *child = node->first_node();
|
96
|
+
std::size_t count = 0;
|
97
|
+
while (child)
|
98
|
+
{
|
99
|
+
++count;
|
100
|
+
child = child->next_sibling();
|
101
|
+
}
|
102
|
+
return count;
|
103
|
+
}
|
104
|
+
|
105
|
+
//! Counts attributes of node. Time complexity is O(n).
|
106
|
+
//! \return Number of attributes of node
|
107
|
+
template<class Ch>
|
108
|
+
inline std::size_t count_attributes(xml_node<Ch> *node)
|
109
|
+
{
|
110
|
+
xml_attribute<Ch> *attr = node->first_attribute();
|
111
|
+
std::size_t count = 0;
|
112
|
+
while (attr)
|
113
|
+
{
|
114
|
+
++count;
|
115
|
+
attr = attr->next_attribute();
|
116
|
+
}
|
117
|
+
return count;
|
118
|
+
}
|
119
|
+
|
120
|
+
}
|
121
|
+
} // namespace cereal
|
122
|
+
|
123
|
+
#endif
|
@@ -0,0 +1,154 @@
|
|
1
|
+
/*! \file macros.hpp
|
2
|
+
\brief Preprocessor macros that can customise the cereal library
|
3
|
+
|
4
|
+
By default, cereal looks for serialization functions with very
|
5
|
+
specific names, that is: serialize, load, save, load_minimal,
|
6
|
+
or save_minimal.
|
7
|
+
|
8
|
+
This file allows an advanced user to change these names to conform
|
9
|
+
to some other style or preference. This is implemented using
|
10
|
+
preprocessor macros.
|
11
|
+
|
12
|
+
As a result of this, in internal cereal code you will see macros
|
13
|
+
used for these function names. In user code, you should name
|
14
|
+
the functions like you normally would and not use the macros
|
15
|
+
to improve readability.
|
16
|
+
\ingroup utility */
|
17
|
+
/*
|
18
|
+
Copyright (c) 2014, Randolph Voorhies, Shane Grant
|
19
|
+
All rights reserved.
|
20
|
+
|
21
|
+
Redistribution and use in source and binary forms, with or without
|
22
|
+
modification, are permitted provided that the following conditions are met:
|
23
|
+
* Redistributions of source code must retain the above copyright
|
24
|
+
notice, this list of conditions and the following disclaimer.
|
25
|
+
* Redistributions in binary form must reproduce the above copyright
|
26
|
+
notice, this list of conditions and the following disclaimer in the
|
27
|
+
documentation and/or other materials provided with the distribution.
|
28
|
+
* Neither the name of cereal nor the
|
29
|
+
names of its contributors may be used to endorse or promote products
|
30
|
+
derived from this software without specific prior written permission.
|
31
|
+
|
32
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
33
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
34
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
35
|
+
DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY
|
36
|
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
37
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
38
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
39
|
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
40
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
41
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
42
|
+
*/
|
43
|
+
|
44
|
+
#ifndef CEREAL_MACROS_HPP_
|
45
|
+
#define CEREAL_MACROS_HPP_
|
46
|
+
|
47
|
+
#ifndef CEREAL_THREAD_SAFE
|
48
|
+
//! Whether cereal should be compiled for a threaded environment
|
49
|
+
/*! This macro causes cereal to use mutexes to control access to
|
50
|
+
global internal state in a thread safe manner.
|
51
|
+
|
52
|
+
Note that even with this enabled you must still ensure that
|
53
|
+
archives are accessed by only one thread at a time; it is safe
|
54
|
+
to use multiple archives in paralel, but not to access one archive
|
55
|
+
from many places simultaneously. */
|
56
|
+
#define CEREAL_THREAD_SAFE 0
|
57
|
+
#endif // CEREAL_THREAD_SAFE
|
58
|
+
|
59
|
+
#ifndef CEREAL_SIZE_TYPE
|
60
|
+
//! Determines the data type used for size_type
|
61
|
+
/*! cereal uses size_type to ensure that the serialized size of
|
62
|
+
dynamic containers is compatible across different architectures
|
63
|
+
(e.g. 32 vs 64 bit), which may use different underlying types for
|
64
|
+
std::size_t.
|
65
|
+
|
66
|
+
More information can be found in cereal/details/helpers.hpp.
|
67
|
+
|
68
|
+
If you choose to modify this type, ensure that you use a fixed
|
69
|
+
size type (e.g. uint32_t). */
|
70
|
+
#define CEREAL_SIZE_TYPE uint64_t
|
71
|
+
#endif // CEREAL_SIZE_TYPE
|
72
|
+
|
73
|
+
// ######################################################################
|
74
|
+
#ifndef CEREAL_SERIALIZE_FUNCTION_NAME
|
75
|
+
//! The serialization/deserialization function name to search for.
|
76
|
+
/*! You can define @c CEREAL_SERIALIZE_FUNCTION_NAME to be different assuming
|
77
|
+
you do so before this file is included. */
|
78
|
+
#define CEREAL_SERIALIZE_FUNCTION_NAME serialize
|
79
|
+
#endif // CEREAL_SERIALIZE_FUNCTION_NAME
|
80
|
+
|
81
|
+
#ifndef CEREAL_LOAD_FUNCTION_NAME
|
82
|
+
//! The deserialization (load) function name to search for.
|
83
|
+
/*! You can define @c CEREAL_LOAD_FUNCTION_NAME to be different assuming you do so
|
84
|
+
before this file is included. */
|
85
|
+
#define CEREAL_LOAD_FUNCTION_NAME load
|
86
|
+
#endif // CEREAL_LOAD_FUNCTION_NAME
|
87
|
+
|
88
|
+
#ifndef CEREAL_SAVE_FUNCTION_NAME
|
89
|
+
//! The serialization (save) function name to search for.
|
90
|
+
/*! You can define @c CEREAL_SAVE_FUNCTION_NAME to be different assuming you do so
|
91
|
+
before this file is included. */
|
92
|
+
#define CEREAL_SAVE_FUNCTION_NAME save
|
93
|
+
#endif // CEREAL_SAVE_FUNCTION_NAME
|
94
|
+
|
95
|
+
#ifndef CEREAL_LOAD_MINIMAL_FUNCTION_NAME
|
96
|
+
//! The deserialization (load_minimal) function name to search for.
|
97
|
+
/*! You can define @c CEREAL_LOAD_MINIMAL_FUNCTION_NAME to be different assuming you do so
|
98
|
+
before this file is included. */
|
99
|
+
#define CEREAL_LOAD_MINIMAL_FUNCTION_NAME load_minimal
|
100
|
+
#endif // CEREAL_LOAD_MINIMAL_FUNCTION_NAME
|
101
|
+
|
102
|
+
#ifndef CEREAL_SAVE_MINIMAL_FUNCTION_NAME
|
103
|
+
//! The serialization (save_minimal) function name to search for.
|
104
|
+
/*! You can define @c CEREAL_SAVE_MINIMAL_FUNCTION_NAME to be different assuming you do so
|
105
|
+
before this file is included. */
|
106
|
+
#define CEREAL_SAVE_MINIMAL_FUNCTION_NAME save_minimal
|
107
|
+
#endif // CEREAL_SAVE_MINIMAL_FUNCTION_NAME
|
108
|
+
|
109
|
+
// ######################################################################
|
110
|
+
//! Defines the CEREAL_NOEXCEPT macro to use instead of noexcept
|
111
|
+
/*! If a compiler we support does not support noexcept, this macro
|
112
|
+
will detect this and define CEREAL_NOEXCEPT as a no-op
|
113
|
+
@internal */
|
114
|
+
#if !defined(CEREAL_HAS_NOEXCEPT)
|
115
|
+
#if defined(__clang__)
|
116
|
+
#if __has_feature(cxx_noexcept)
|
117
|
+
#define CEREAL_HAS_NOEXCEPT
|
118
|
+
#endif
|
119
|
+
#else // NOT clang
|
120
|
+
#if defined(__GXX_EXPERIMENTAL_CXX0X__) && __GNUC__ * 10 + __GNUC_MINOR__ >= 46 || \
|
121
|
+
defined(_MSC_FULL_VER) && _MSC_FULL_VER >= 190023026
|
122
|
+
#define CEREAL_HAS_NOEXCEPT
|
123
|
+
#endif // end GCC/MSVC check
|
124
|
+
#endif // end NOT clang block
|
125
|
+
|
126
|
+
#ifndef CEREAL_NOEXCEPT
|
127
|
+
#ifdef CEREAL_HAS_NOEXCEPT
|
128
|
+
#define CEREAL_NOEXCEPT noexcept
|
129
|
+
#else
|
130
|
+
#define CEREAL_NOEXCEPT
|
131
|
+
#endif // end CEREAL_HAS_NOEXCEPT
|
132
|
+
#endif // end !defined(CEREAL_HAS_NOEXCEPT)
|
133
|
+
#endif // ifndef CEREAL_NOEXCEPT
|
134
|
+
|
135
|
+
// ######################################################################
|
136
|
+
//! Checks if C++17 is available
|
137
|
+
#if __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
|
138
|
+
#define CEREAL_HAS_CPP17
|
139
|
+
#endif
|
140
|
+
|
141
|
+
//! Checks if C++14 is available
|
142
|
+
#if __cplusplus >= 201402L
|
143
|
+
#define CEREAL_HAS_CPP14
|
144
|
+
#endif
|
145
|
+
|
146
|
+
// ######################################################################
|
147
|
+
//! Defines the CEREAL_ALIGNOF macro to use instead of alignof
|
148
|
+
#if defined(_MSC_VER) && _MSC_VER < 1900
|
149
|
+
#define CEREAL_ALIGNOF __alignof
|
150
|
+
#else // not MSVC 2013 or older
|
151
|
+
#define CEREAL_ALIGNOF alignof
|
152
|
+
#endif // end MSVC check
|
153
|
+
|
154
|
+
#endif // CEREAL_MACROS_HPP_
|
@@ -0,0 +1,139 @@
|
|
1
|
+
/*! \file specialize.hpp
|
2
|
+
\brief Serialization disambiguation */
|
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
|
+
|
30
|
+
#ifndef CEREAL_SPECIALIZE_HPP_
|
31
|
+
#define CEREAL_SPECIALIZE_HPP_
|
32
|
+
|
33
|
+
namespace cereal
|
34
|
+
{
|
35
|
+
// Forward declaration of access class that users can become friends with
|
36
|
+
class access;
|
37
|
+
|
38
|
+
// ######################################################################
|
39
|
+
//! A specifier used in conjunction with cereal::specialize to disambiguate
|
40
|
+
//! serialization in special cases
|
41
|
+
/*! @relates specialize
|
42
|
+
@ingroup Access */
|
43
|
+
enum class specialization
|
44
|
+
{
|
45
|
+
member_serialize, //!< Force the use of a member serialize function
|
46
|
+
member_load_save, //!< Force the use of a member load/save pair
|
47
|
+
member_load_save_minimal, //!< Force the use of a member minimal load/save pair
|
48
|
+
non_member_serialize, //!< Force the use of a non-member serialize function
|
49
|
+
non_member_load_save, //!< Force the use of a non-member load/save pair
|
50
|
+
non_member_load_save_minimal //!< Force the use of a non-member minimal load/save pair
|
51
|
+
};
|
52
|
+
|
53
|
+
//! A class used to disambiguate cases where cereal cannot detect a unique way of serializing a class
|
54
|
+
/*! cereal attempts to figure out which method of serialization (member vs. non-member serialize
|
55
|
+
or load/save pair) at compile time. If for some reason cereal cannot find a non-ambiguous way
|
56
|
+
of serializing a type, it will produce a static assertion complaining about this.
|
57
|
+
|
58
|
+
This can happen because you have both a serialize and load/save pair, or even because a base
|
59
|
+
class has a serialize (public or private with friend access) and a derived class does not
|
60
|
+
overwrite this due to choosing some other serialization type.
|
61
|
+
|
62
|
+
Specializing this class will tell cereal to explicitly use the serialization type you specify
|
63
|
+
and it will not complain about ambiguity in its compile time selection. However, if cereal detects
|
64
|
+
an ambiguity in specializations, it will continue to issue a static assertion.
|
65
|
+
|
66
|
+
@code{.cpp}
|
67
|
+
class MyParent
|
68
|
+
{
|
69
|
+
friend class cereal::access;
|
70
|
+
template <class Archive>
|
71
|
+
void serialize( Archive & ar ) {}
|
72
|
+
};
|
73
|
+
|
74
|
+
// Although serialize is private in MyParent, to cereal::access it will look public,
|
75
|
+
// even through MyDerived
|
76
|
+
class MyDerived : public MyParent
|
77
|
+
{
|
78
|
+
public:
|
79
|
+
template <class Archive>
|
80
|
+
void load( Archive & ar ) {}
|
81
|
+
|
82
|
+
template <class Archive>
|
83
|
+
void save( Archive & ar ) {}
|
84
|
+
};
|
85
|
+
|
86
|
+
// The load/save pair in MyDerived is ambiguous because serialize in MyParent can
|
87
|
+
// be accessed from cereal::access. This looks the same as making serialize public
|
88
|
+
// in MyParent, making it seem as though MyDerived has both a serialize and a load/save pair.
|
89
|
+
// cereal will complain about this at compile time unless we disambiguate:
|
90
|
+
|
91
|
+
namespace cereal
|
92
|
+
{
|
93
|
+
// This struct specialization will tell cereal which is the right way to serialize the ambiguity
|
94
|
+
template <class Archive> struct specialize<Archive, MyDerived, cereal::specialization::member_load_save> {};
|
95
|
+
|
96
|
+
// If we only had a disambiguation for a specific archive type, it would look something like this
|
97
|
+
template <> struct specialize<cereal::BinaryOutputArchive, MyDerived, cereal::specialization::member_load_save> {};
|
98
|
+
}
|
99
|
+
@endcode
|
100
|
+
|
101
|
+
You can also choose to use the macros CEREAL_SPECIALIZE_FOR_ALL_ARCHIVES or
|
102
|
+
CEREAL_SPECIALIZE_FOR_ARCHIVE if you want to type a little bit less.
|
103
|
+
|
104
|
+
@tparam T The type to specialize the serialization for
|
105
|
+
@tparam S The specialization type to use for T
|
106
|
+
@ingroup Access */
|
107
|
+
template <class Archive, class T, specialization S>
|
108
|
+
struct specialize : public std::false_type {};
|
109
|
+
|
110
|
+
//! Convenient macro for performing specialization for all archive types
|
111
|
+
/*! This performs specialization for the specific type for all types of archives.
|
112
|
+
This macro should be placed at the global namespace.
|
113
|
+
|
114
|
+
@code{cpp}
|
115
|
+
struct MyType {};
|
116
|
+
CEREAL_SPECIALIZE_FOR_ALL_ARCHIVES( MyType, cereal::specialization::member_load_save );
|
117
|
+
@endcode
|
118
|
+
|
119
|
+
@relates specialize
|
120
|
+
@ingroup Access */
|
121
|
+
#define CEREAL_SPECIALIZE_FOR_ALL_ARCHIVES( Type, Specialization ) \
|
122
|
+
namespace cereal { template <class Archive> struct specialize<Archive, Type, Specialization> {}; }
|
123
|
+
|
124
|
+
//! Convenient macro for performing specialization for a single archive type
|
125
|
+
/*! This performs specialization for the specific type for a single type of archive.
|
126
|
+
This macro should be placed at the global namespace.
|
127
|
+
|
128
|
+
@code{cpp}
|
129
|
+
struct MyType {};
|
130
|
+
CEREAL_SPECIALIZE_FOR_ARCHIVE( cereal::XMLInputArchive, MyType, cereal::specialization::member_load_save );
|
131
|
+
@endcode
|
132
|
+
|
133
|
+
@relates specialize
|
134
|
+
@ingroup Access */
|
135
|
+
#define CEREAL_SPECIALIZE_FOR_ARCHIVE( Archive, Type, Specialization ) \
|
136
|
+
namespace cereal { template <> struct specialize<Archive, Type, Specialization> {}; }
|
137
|
+
}
|
138
|
+
|
139
|
+
#endif
|
@@ -0,0 +1,79 @@
|
|
1
|
+
/*! \file array.hpp
|
2
|
+
\brief Support for types found in \<array\>
|
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_ARRAY_HPP_
|
31
|
+
#define CEREAL_TYPES_ARRAY_HPP_
|
32
|
+
|
33
|
+
#include "cereal/cereal.hpp"
|
34
|
+
#include <array>
|
35
|
+
|
36
|
+
namespace cereal
|
37
|
+
{
|
38
|
+
//! Saving for std::array primitive types
|
39
|
+
//! using binary serialization, if supported
|
40
|
+
template <class Archive, class T, size_t N> inline
|
41
|
+
typename std::enable_if<traits::is_output_serializable<BinaryData<T>, Archive>::value
|
42
|
+
&& std::is_arithmetic<T>::value, void>::type
|
43
|
+
CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::array<T, N> const & array )
|
44
|
+
{
|
45
|
+
ar( binary_data( array.data(), sizeof(array) ) );
|
46
|
+
}
|
47
|
+
|
48
|
+
//! Loading for std::array primitive types
|
49
|
+
//! using binary serialization, if supported
|
50
|
+
template <class Archive, class T, size_t N> inline
|
51
|
+
typename std::enable_if<traits::is_input_serializable<BinaryData<T>, Archive>::value
|
52
|
+
&& std::is_arithmetic<T>::value, void>::type
|
53
|
+
CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::array<T, N> & array )
|
54
|
+
{
|
55
|
+
ar( binary_data( array.data(), sizeof(array) ) );
|
56
|
+
}
|
57
|
+
|
58
|
+
//! Saving for std::array all other types
|
59
|
+
template <class Archive, class T, size_t N> inline
|
60
|
+
typename std::enable_if<!traits::is_output_serializable<BinaryData<T>, Archive>::value
|
61
|
+
|| !std::is_arithmetic<T>::value, void>::type
|
62
|
+
CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::array<T, N> const & array )
|
63
|
+
{
|
64
|
+
for( auto const & i : array )
|
65
|
+
ar( i );
|
66
|
+
}
|
67
|
+
|
68
|
+
//! Loading for std::array all other types
|
69
|
+
template <class Archive, class T, size_t N> inline
|
70
|
+
typename std::enable_if<!traits::is_input_serializable<BinaryData<T>, Archive>::value
|
71
|
+
|| !std::is_arithmetic<T>::value, void>::type
|
72
|
+
CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::array<T, N> & array )
|
73
|
+
{
|
74
|
+
for( auto & i : array )
|
75
|
+
ar( i );
|
76
|
+
}
|
77
|
+
} // namespace cereal
|
78
|
+
|
79
|
+
#endif // CEREAL_TYPES_ARRAY_HPP_
|