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.
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,299 +0,0 @@
1
- // Tencent is pleased to support the open source community by making RapidJSON available.
2
- //
3
- // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
4
- //
5
- // Licensed under the MIT License (the "License"); you may not use this file except
6
- // in compliance with the License. You may obtain a copy of the License at
7
- //
8
- // http://opensource.org/licenses/MIT
9
- //
10
- // Unless required by applicable law or agreed to in writing, software distributed
11
- // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12
- // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13
- // specific language governing permissions and limitations under the License.
14
-
15
- #ifndef CEREAL_RAPIDJSON_ENCODEDSTREAM_H_
16
- #define CEREAL_RAPIDJSON_ENCODEDSTREAM_H_
17
-
18
- #include "stream.h"
19
- #include "memorystream.h"
20
-
21
- #ifdef __GNUC__
22
- CEREAL_RAPIDJSON_DIAG_PUSH
23
- CEREAL_RAPIDJSON_DIAG_OFF(effc++)
24
- #endif
25
-
26
- #ifdef __clang__
27
- CEREAL_RAPIDJSON_DIAG_PUSH
28
- CEREAL_RAPIDJSON_DIAG_OFF(padded)
29
- #endif
30
-
31
- CEREAL_RAPIDJSON_NAMESPACE_BEGIN
32
-
33
- //! Input byte stream wrapper with a statically bound encoding.
34
- /*!
35
- \tparam Encoding The interpretation of encoding of the stream. Either UTF8, UTF16LE, UTF16BE, UTF32LE, UTF32BE.
36
- \tparam InputByteStream Type of input byte stream. For example, FileReadStream.
37
- */
38
- template <typename Encoding, typename InputByteStream>
39
- class EncodedInputStream {
40
- CEREAL_RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1);
41
- public:
42
- typedef typename Encoding::Ch Ch;
43
-
44
- EncodedInputStream(InputByteStream& is) : is_(is) {
45
- current_ = Encoding::TakeBOM(is_);
46
- }
47
-
48
- Ch Peek() const { return current_; }
49
- Ch Take() { Ch c = current_; current_ = Encoding::Take(is_); return c; }
50
- size_t Tell() const { return is_.Tell(); }
51
-
52
- // Not implemented
53
- void Put(Ch) { CEREAL_RAPIDJSON_ASSERT(false); }
54
- void Flush() { CEREAL_RAPIDJSON_ASSERT(false); }
55
- Ch* PutBegin() { CEREAL_RAPIDJSON_ASSERT(false); return 0; }
56
- size_t PutEnd(Ch*) { CEREAL_RAPIDJSON_ASSERT(false); return 0; }
57
-
58
- private:
59
- EncodedInputStream(const EncodedInputStream&);
60
- EncodedInputStream& operator=(const EncodedInputStream&);
61
-
62
- InputByteStream& is_;
63
- Ch current_;
64
- };
65
-
66
- //! Specialized for UTF8 MemoryStream.
67
- template <>
68
- class EncodedInputStream<UTF8<>, MemoryStream> {
69
- public:
70
- typedef UTF8<>::Ch Ch;
71
-
72
- EncodedInputStream(MemoryStream& is) : is_(is) {
73
- if (static_cast<unsigned char>(is_.Peek()) == 0xEFu) is_.Take();
74
- if (static_cast<unsigned char>(is_.Peek()) == 0xBBu) is_.Take();
75
- if (static_cast<unsigned char>(is_.Peek()) == 0xBFu) is_.Take();
76
- }
77
- Ch Peek() const { return is_.Peek(); }
78
- Ch Take() { return is_.Take(); }
79
- size_t Tell() const { return is_.Tell(); }
80
-
81
- // Not implemented
82
- void Put(Ch) {}
83
- void Flush() {}
84
- Ch* PutBegin() { return 0; }
85
- size_t PutEnd(Ch*) { return 0; }
86
-
87
- MemoryStream& is_;
88
-
89
- private:
90
- EncodedInputStream(const EncodedInputStream&);
91
- EncodedInputStream& operator=(const EncodedInputStream&);
92
- };
93
-
94
- //! Output byte stream wrapper with statically bound encoding.
95
- /*!
96
- \tparam Encoding The interpretation of encoding of the stream. Either UTF8, UTF16LE, UTF16BE, UTF32LE, UTF32BE.
97
- \tparam OutputByteStream Type of input byte stream. For example, FileWriteStream.
98
- */
99
- template <typename Encoding, typename OutputByteStream>
100
- class EncodedOutputStream {
101
- CEREAL_RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1);
102
- public:
103
- typedef typename Encoding::Ch Ch;
104
-
105
- EncodedOutputStream(OutputByteStream& os, bool putBOM = true) : os_(os) {
106
- if (putBOM)
107
- Encoding::PutBOM(os_);
108
- }
109
-
110
- void Put(Ch c) { Encoding::Put(os_, c); }
111
- void Flush() { os_.Flush(); }
112
-
113
- // Not implemented
114
- Ch Peek() const { CEREAL_RAPIDJSON_ASSERT(false); return 0;}
115
- Ch Take() { CEREAL_RAPIDJSON_ASSERT(false); return 0;}
116
- size_t Tell() const { CEREAL_RAPIDJSON_ASSERT(false); return 0; }
117
- Ch* PutBegin() { CEREAL_RAPIDJSON_ASSERT(false); return 0; }
118
- size_t PutEnd(Ch*) { CEREAL_RAPIDJSON_ASSERT(false); return 0; }
119
-
120
- private:
121
- EncodedOutputStream(const EncodedOutputStream&);
122
- EncodedOutputStream& operator=(const EncodedOutputStream&);
123
-
124
- OutputByteStream& os_;
125
- };
126
-
127
- #define CEREAL_RAPIDJSON_ENCODINGS_FUNC(x) UTF8<Ch>::x, UTF16LE<Ch>::x, UTF16BE<Ch>::x, UTF32LE<Ch>::x, UTF32BE<Ch>::x
128
-
129
- //! Input stream wrapper with dynamically bound encoding and automatic encoding detection.
130
- /*!
131
- \tparam CharType Type of character for reading.
132
- \tparam InputByteStream type of input byte stream to be wrapped.
133
- */
134
- template <typename CharType, typename InputByteStream>
135
- class AutoUTFInputStream {
136
- CEREAL_RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1);
137
- public:
138
- typedef CharType Ch;
139
-
140
- //! Constructor.
141
- /*!
142
- \param is input stream to be wrapped.
143
- \param type UTF encoding type if it is not detected from the stream.
144
- */
145
- AutoUTFInputStream(InputByteStream& is, UTFType type = kUTF8) : is_(&is), type_(type), hasBOM_(false) {
146
- CEREAL_RAPIDJSON_ASSERT(type >= kUTF8 && type <= kUTF32BE);
147
- DetectType();
148
- static const TakeFunc f[] = { CEREAL_RAPIDJSON_ENCODINGS_FUNC(Take) };
149
- takeFunc_ = f[type_];
150
- current_ = takeFunc_(*is_);
151
- }
152
-
153
- UTFType GetType() const { return type_; }
154
- bool HasBOM() const { return hasBOM_; }
155
-
156
- Ch Peek() const { return current_; }
157
- Ch Take() { Ch c = current_; current_ = takeFunc_(*is_); return c; }
158
- size_t Tell() const { return is_->Tell(); }
159
-
160
- // Not implemented
161
- void Put(Ch) { CEREAL_RAPIDJSON_ASSERT(false); }
162
- void Flush() { CEREAL_RAPIDJSON_ASSERT(false); }
163
- Ch* PutBegin() { CEREAL_RAPIDJSON_ASSERT(false); return 0; }
164
- size_t PutEnd(Ch*) { CEREAL_RAPIDJSON_ASSERT(false); return 0; }
165
-
166
- private:
167
- AutoUTFInputStream(const AutoUTFInputStream&);
168
- AutoUTFInputStream& operator=(const AutoUTFInputStream&);
169
-
170
- // Detect encoding type with BOM or RFC 4627
171
- void DetectType() {
172
- // BOM (Byte Order Mark):
173
- // 00 00 FE FF UTF-32BE
174
- // FF FE 00 00 UTF-32LE
175
- // FE FF UTF-16BE
176
- // FF FE UTF-16LE
177
- // EF BB BF UTF-8
178
-
179
- const unsigned char* c = reinterpret_cast<const unsigned char *>(is_->Peek4());
180
- if (!c)
181
- return;
182
-
183
- unsigned bom = static_cast<unsigned>(c[0] | (c[1] << 8) | (c[2] << 16) | (c[3] << 24));
184
- hasBOM_ = false;
185
- if (bom == 0xFFFE0000) { type_ = kUTF32BE; hasBOM_ = true; is_->Take(); is_->Take(); is_->Take(); is_->Take(); }
186
- else if (bom == 0x0000FEFF) { type_ = kUTF32LE; hasBOM_ = true; is_->Take(); is_->Take(); is_->Take(); is_->Take(); }
187
- else if ((bom & 0xFFFF) == 0xFFFE) { type_ = kUTF16BE; hasBOM_ = true; is_->Take(); is_->Take(); }
188
- else if ((bom & 0xFFFF) == 0xFEFF) { type_ = kUTF16LE; hasBOM_ = true; is_->Take(); is_->Take(); }
189
- else if ((bom & 0xFFFFFF) == 0xBFBBEF) { type_ = kUTF8; hasBOM_ = true; is_->Take(); is_->Take(); is_->Take(); }
190
-
191
- // RFC 4627: Section 3
192
- // "Since the first two characters of a JSON text will always be ASCII
193
- // characters [RFC0020], it is possible to determine whether an octet
194
- // stream is UTF-8, UTF-16 (BE or LE), or UTF-32 (BE or LE) by looking
195
- // at the pattern of nulls in the first four octets."
196
- // 00 00 00 xx UTF-32BE
197
- // 00 xx 00 xx UTF-16BE
198
- // xx 00 00 00 UTF-32LE
199
- // xx 00 xx 00 UTF-16LE
200
- // xx xx xx xx UTF-8
201
-
202
- if (!hasBOM_) {
203
- int pattern = (c[0] ? 1 : 0) | (c[1] ? 2 : 0) | (c[2] ? 4 : 0) | (c[3] ? 8 : 0);
204
- switch (pattern) {
205
- case 0x08: type_ = kUTF32BE; break;
206
- case 0x0A: type_ = kUTF16BE; break;
207
- case 0x01: type_ = kUTF32LE; break;
208
- case 0x05: type_ = kUTF16LE; break;
209
- case 0x0F: type_ = kUTF8; break;
210
- default: break; // Use type defined by user.
211
- }
212
- }
213
-
214
- // Runtime check whether the size of character type is sufficient. It only perform checks with assertion.
215
- if (type_ == kUTF16LE || type_ == kUTF16BE) CEREAL_RAPIDJSON_ASSERT(sizeof(Ch) >= 2);
216
- if (type_ == kUTF32LE || type_ == kUTF32BE) CEREAL_RAPIDJSON_ASSERT(sizeof(Ch) >= 4);
217
- }
218
-
219
- typedef Ch (*TakeFunc)(InputByteStream& is);
220
- InputByteStream* is_;
221
- UTFType type_;
222
- Ch current_;
223
- TakeFunc takeFunc_;
224
- bool hasBOM_;
225
- };
226
-
227
- //! Output stream wrapper with dynamically bound encoding and automatic encoding detection.
228
- /*!
229
- \tparam CharType Type of character for writing.
230
- \tparam OutputByteStream type of output byte stream to be wrapped.
231
- */
232
- template <typename CharType, typename OutputByteStream>
233
- class AutoUTFOutputStream {
234
- CEREAL_RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1);
235
- public:
236
- typedef CharType Ch;
237
-
238
- //! Constructor.
239
- /*!
240
- \param os output stream to be wrapped.
241
- \param type UTF encoding type.
242
- \param putBOM Whether to write BOM at the beginning of the stream.
243
- */
244
- AutoUTFOutputStream(OutputByteStream& os, UTFType type, bool putBOM) : os_(&os), type_(type) {
245
- CEREAL_RAPIDJSON_ASSERT(type >= kUTF8 && type <= kUTF32BE);
246
-
247
- // Runtime check whether the size of character type is sufficient. It only perform checks with assertion.
248
- if (type_ == kUTF16LE || type_ == kUTF16BE) CEREAL_RAPIDJSON_ASSERT(sizeof(Ch) >= 2);
249
- if (type_ == kUTF32LE || type_ == kUTF32BE) CEREAL_RAPIDJSON_ASSERT(sizeof(Ch) >= 4);
250
-
251
- static const PutFunc f[] = { CEREAL_RAPIDJSON_ENCODINGS_FUNC(Put) };
252
- putFunc_ = f[type_];
253
-
254
- if (putBOM)
255
- PutBOM();
256
- }
257
-
258
- UTFType GetType() const { return type_; }
259
-
260
- void Put(Ch c) { putFunc_(*os_, c); }
261
- void Flush() { os_->Flush(); }
262
-
263
- // Not implemented
264
- Ch Peek() const { CEREAL_RAPIDJSON_ASSERT(false); return 0;}
265
- Ch Take() { CEREAL_RAPIDJSON_ASSERT(false); return 0;}
266
- size_t Tell() const { CEREAL_RAPIDJSON_ASSERT(false); return 0; }
267
- Ch* PutBegin() { CEREAL_RAPIDJSON_ASSERT(false); return 0; }
268
- size_t PutEnd(Ch*) { CEREAL_RAPIDJSON_ASSERT(false); return 0; }
269
-
270
- private:
271
- AutoUTFOutputStream(const AutoUTFOutputStream&);
272
- AutoUTFOutputStream& operator=(const AutoUTFOutputStream&);
273
-
274
- void PutBOM() {
275
- typedef void (*PutBOMFunc)(OutputByteStream&);
276
- static const PutBOMFunc f[] = { CEREAL_RAPIDJSON_ENCODINGS_FUNC(PutBOM) };
277
- f[type_](*os_);
278
- }
279
-
280
- typedef void (*PutFunc)(OutputByteStream&, Ch);
281
-
282
- OutputByteStream* os_;
283
- UTFType type_;
284
- PutFunc putFunc_;
285
- };
286
-
287
- #undef CEREAL_RAPIDJSON_ENCODINGS_FUNC
288
-
289
- CEREAL_RAPIDJSON_NAMESPACE_END
290
-
291
- #ifdef __clang__
292
- CEREAL_RAPIDJSON_DIAG_POP
293
- #endif
294
-
295
- #ifdef __GNUC__
296
- CEREAL_RAPIDJSON_DIAG_POP
297
- #endif
298
-
299
- #endif // CEREAL_RAPIDJSON_FILESTREAM_H_