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,175 +0,0 @@
1
- #ifndef CEREAL_RAPIDXML_ITERATORS_HPP_INCLUDED
2
- #define CEREAL_RAPIDXML_ITERATORS_HPP_INCLUDED
3
-
4
- // Copyright (C) 2006, 2009 Marcin Kalicinski
5
- // Version 1.13
6
- // Revision $DateTime: 2009/05/13 01:46:17 $
7
-
8
- #include "rapidxml.hpp"
9
-
10
- namespace cereal {
11
- namespace rapidxml
12
- {
13
-
14
- //! Iterator of child nodes of xml_node
15
- template<class Ch>
16
- class node_iterator
17
- {
18
-
19
- public:
20
-
21
- typedef typename xml_node<Ch> value_type;
22
- typedef typename xml_node<Ch> &reference;
23
- typedef typename xml_node<Ch> *pointer;
24
- typedef std::ptrdiff_t difference_type;
25
- typedef std::bidirectional_iterator_tag iterator_category;
26
-
27
- node_iterator()
28
- : m_node(0)
29
- {
30
- }
31
-
32
- node_iterator(xml_node<Ch> *node)
33
- : m_node(node->first_node())
34
- {
35
- }
36
-
37
- reference operator *() const
38
- {
39
- assert(m_node);
40
- return *m_node;
41
- }
42
-
43
- pointer operator->() const
44
- {
45
- assert(m_node);
46
- return m_node;
47
- }
48
-
49
- node_iterator& operator++()
50
- {
51
- assert(m_node);
52
- m_node = m_node->next_sibling();
53
- return *this;
54
- }
55
-
56
- node_iterator operator++(int)
57
- {
58
- node_iterator tmp = *this;
59
- ++this;
60
- return tmp;
61
- }
62
-
63
- node_iterator& operator--()
64
- {
65
- assert(m_node && m_node->previous_sibling());
66
- m_node = m_node->previous_sibling();
67
- return *this;
68
- }
69
-
70
- node_iterator operator--(int)
71
- {
72
- node_iterator tmp = *this;
73
- ++this;
74
- return tmp;
75
- }
76
-
77
- bool operator ==(const node_iterator<Ch> &rhs)
78
- {
79
- return m_node == rhs.m_node;
80
- }
81
-
82
- bool operator !=(const node_iterator<Ch> &rhs)
83
- {
84
- return m_node != rhs.m_node;
85
- }
86
-
87
- private:
88
-
89
- xml_node<Ch> *m_node;
90
-
91
- };
92
-
93
- //! Iterator of child attributes of xml_node
94
- template<class Ch>
95
- class attribute_iterator
96
- {
97
-
98
- public:
99
-
100
- typedef typename xml_attribute<Ch> value_type;
101
- typedef typename xml_attribute<Ch> &reference;
102
- typedef typename xml_attribute<Ch> *pointer;
103
- typedef std::ptrdiff_t difference_type;
104
- typedef std::bidirectional_iterator_tag iterator_category;
105
-
106
- attribute_iterator()
107
- : m_attribute(0)
108
- {
109
- }
110
-
111
- attribute_iterator(xml_node<Ch> *node)
112
- : m_attribute(node->first_attribute())
113
- {
114
- }
115
-
116
- reference operator *() const
117
- {
118
- assert(m_attribute);
119
- return *m_attribute;
120
- }
121
-
122
- pointer operator->() const
123
- {
124
- assert(m_attribute);
125
- return m_attribute;
126
- }
127
-
128
- attribute_iterator& operator++()
129
- {
130
- assert(m_attribute);
131
- m_attribute = m_attribute->next_attribute();
132
- return *this;
133
- }
134
-
135
- attribute_iterator operator++(int)
136
- {
137
- attribute_iterator tmp = *this;
138
- ++this;
139
- return tmp;
140
- }
141
-
142
- attribute_iterator& operator--()
143
- {
144
- assert(m_attribute && m_attribute->previous_attribute());
145
- m_attribute = m_attribute->previous_attribute();
146
- return *this;
147
- }
148
-
149
- attribute_iterator operator--(int)
150
- {
151
- attribute_iterator tmp = *this;
152
- ++this;
153
- return tmp;
154
- }
155
-
156
- bool operator ==(const attribute_iterator<Ch> &rhs)
157
- {
158
- return m_attribute == rhs.m_attribute;
159
- }
160
-
161
- bool operator !=(const attribute_iterator<Ch> &rhs)
162
- {
163
- return m_attribute != rhs.m_attribute;
164
- }
165
-
166
- private:
167
-
168
- xml_attribute<Ch> *m_attribute;
169
-
170
- };
171
-
172
- }
173
- } // namespace cereal
174
-
175
- #endif
@@ -1,428 +0,0 @@
1
- #ifndef CEREAL_RAPIDXML_PRINT_HPP_INCLUDED
2
- #define CEREAL_RAPIDXML_PRINT_HPP_INCLUDED
3
-
4
- // Copyright (C) 2006, 2009 Marcin Kalicinski
5
- // Version 1.13
6
- // Revision $DateTime: 2009/05/13 01:46:17 $
7
-
8
- #include "rapidxml.hpp"
9
-
10
- // Only include streams if not disabled
11
- #ifndef CEREAL_RAPIDXML_NO_STREAMS
12
- #include <ostream>
13
- #include <iterator>
14
- #endif
15
-
16
- namespace cereal {
17
- namespace rapidxml
18
- {
19
-
20
- ///////////////////////////////////////////////////////////////////////
21
- // Printing flags
22
-
23
- const int print_no_indenting = 0x1; //!< Printer flag instructing the printer to suppress indenting of XML. See print() function.
24
-
25
- ///////////////////////////////////////////////////////////////////////
26
- // Internal
27
-
28
- //! \cond internal
29
- namespace internal
30
- {
31
-
32
- ///////////////////////////////////////////////////////////////////////////
33
- // Internal character operations
34
-
35
- // Copy characters from given range to given output iterator
36
- template<class OutIt, class Ch>
37
- inline OutIt copy_chars(const Ch *begin, const Ch *end, OutIt out)
38
- {
39
- while (begin != end)
40
- *out++ = *begin++;
41
- return out;
42
- }
43
-
44
- // Copy characters from given range to given output iterator and expand
45
- // characters into references (&lt; &gt; &apos; &quot; &amp;)
46
- template<class OutIt, class Ch>
47
- inline OutIt copy_and_expand_chars(const Ch *begin, const Ch *end, Ch noexpand, OutIt out)
48
- {
49
- while (begin != end)
50
- {
51
- if (*begin == noexpand)
52
- {
53
- *out++ = *begin; // No expansion, copy character
54
- }
55
- else
56
- {
57
- switch (*begin)
58
- {
59
- case Ch('<'):
60
- *out++ = Ch('&'); *out++ = Ch('l'); *out++ = Ch('t'); *out++ = Ch(';');
61
- break;
62
- case Ch('>'):
63
- *out++ = Ch('&'); *out++ = Ch('g'); *out++ = Ch('t'); *out++ = Ch(';');
64
- break;
65
- case Ch('\''):
66
- *out++ = Ch('&'); *out++ = Ch('a'); *out++ = Ch('p'); *out++ = Ch('o'); *out++ = Ch('s'); *out++ = Ch(';');
67
- break;
68
- case Ch('"'):
69
- *out++ = Ch('&'); *out++ = Ch('q'); *out++ = Ch('u'); *out++ = Ch('o'); *out++ = Ch('t'); *out++ = Ch(';');
70
- break;
71
- case Ch('&'):
72
- *out++ = Ch('&'); *out++ = Ch('a'); *out++ = Ch('m'); *out++ = Ch('p'); *out++ = Ch(';');
73
- break;
74
- default:
75
- *out++ = *begin; // No expansion, copy character
76
- }
77
- }
78
- ++begin; // Step to next character
79
- }
80
- return out;
81
- }
82
-
83
- // Fill given output iterator with repetitions of the same character
84
- template<class OutIt, class Ch>
85
- inline OutIt fill_chars(OutIt out, int n, Ch ch)
86
- {
87
- for (int i = 0; i < n; ++i)
88
- *out++ = ch;
89
- return out;
90
- }
91
-
92
- // Find character
93
- template<class Ch, Ch ch>
94
- inline bool find_char(const Ch *begin, const Ch *end)
95
- {
96
- while (begin != end)
97
- if (*begin++ == ch)
98
- return true;
99
- return false;
100
- }
101
-
102
- ///////////////////////////////////////////////////////////////////////////
103
- // Internal printing operations
104
-
105
- // Print node
106
- template<class OutIt, class Ch>
107
- inline OutIt print_node(OutIt out, const xml_node<Ch> *node, int flags, int indent);
108
-
109
- // Print children of the node
110
- template<class OutIt, class Ch>
111
- inline OutIt print_children(OutIt out, const xml_node<Ch> *node, int flags, int indent)
112
- {
113
- for (xml_node<Ch> *child = node->first_node(); child; child = child->next_sibling())
114
- out = print_node(out, child, flags, indent);
115
- return out;
116
- }
117
-
118
- // Print attributes of the node
119
- template<class OutIt, class Ch>
120
- inline OutIt print_attributes(OutIt out, const xml_node<Ch> *node, int /*flags*/)
121
- {
122
- for (xml_attribute<Ch> *attribute = node->first_attribute(); attribute; attribute = attribute->next_attribute())
123
- {
124
- if (attribute->name() && attribute->value())
125
- {
126
- // Print attribute name
127
- *out = Ch(' '), ++out;
128
- out = copy_chars(attribute->name(), attribute->name() + attribute->name_size(), out);
129
- *out = Ch('='), ++out;
130
- // Print attribute value using appropriate quote type
131
- if (find_char<Ch, Ch('"')>(attribute->value(), attribute->value() + attribute->value_size()))
132
- {
133
- *out = Ch('\''), ++out;
134
- out = copy_and_expand_chars(attribute->value(), attribute->value() + attribute->value_size(), Ch('"'), out);
135
- *out = Ch('\''), ++out;
136
- }
137
- else
138
- {
139
- *out = Ch('"'), ++out;
140
- out = copy_and_expand_chars(attribute->value(), attribute->value() + attribute->value_size(), Ch('\''), out);
141
- *out = Ch('"'), ++out;
142
- }
143
- }
144
- }
145
- return out;
146
- }
147
-
148
- // Print data node
149
- template<class OutIt, class Ch>
150
- inline OutIt print_data_node(OutIt out, const xml_node<Ch> *node, int flags, int indent)
151
- {
152
- assert(node->type() == node_data);
153
- if (!(flags & print_no_indenting))
154
- out = fill_chars(out, indent, Ch('\t'));
155
- out = copy_and_expand_chars(node->value(), node->value() + node->value_size(), Ch(0), out);
156
- return out;
157
- }
158
-
159
- // Print data node
160
- template<class OutIt, class Ch>
161
- inline OutIt print_cdata_node(OutIt out, const xml_node<Ch> *node, int flags, int indent)
162
- {
163
- assert(node->type() == node_cdata);
164
- if (!(flags & print_no_indenting))
165
- out = fill_chars(out, indent, Ch('\t'));
166
- *out = Ch('<'); ++out;
167
- *out = Ch('!'); ++out;
168
- *out = Ch('['); ++out;
169
- *out = Ch('C'); ++out;
170
- *out = Ch('D'); ++out;
171
- *out = Ch('A'); ++out;
172
- *out = Ch('T'); ++out;
173
- *out = Ch('A'); ++out;
174
- *out = Ch('['); ++out;
175
- out = copy_chars(node->value(), node->value() + node->value_size(), out);
176
- *out = Ch(']'); ++out;
177
- *out = Ch(']'); ++out;
178
- *out = Ch('>'); ++out;
179
- return out;
180
- }
181
-
182
- // Print element node
183
- template<class OutIt, class Ch>
184
- inline OutIt print_element_node(OutIt out, const xml_node<Ch> *node, int flags, int indent)
185
- {
186
- assert(node->type() == node_element);
187
-
188
- // Print element name and attributes, if any
189
- if (!(flags & print_no_indenting))
190
- out = fill_chars(out, indent, Ch('\t'));
191
- *out = Ch('<'), ++out;
192
- out = copy_chars(node->name(), node->name() + node->name_size(), out);
193
- out = print_attributes(out, node, flags);
194
-
195
- // If node is childless
196
- if (node->value_size() == 0 && !node->first_node())
197
- {
198
- // Print childless node tag ending
199
- *out = Ch('/'), ++out;
200
- *out = Ch('>'), ++out;
201
- }
202
- else
203
- {
204
- // Print normal node tag ending
205
- *out = Ch('>'), ++out;
206
-
207
- // Test if node contains a single data node only (and no other nodes)
208
- xml_node<Ch> *child = node->first_node();
209
- if (!child)
210
- {
211
- // If node has no children, only print its value without indenting
212
- out = copy_and_expand_chars(node->value(), node->value() + node->value_size(), Ch(0), out);
213
- }
214
- else if (child->next_sibling() == 0 && child->type() == node_data)
215
- {
216
- // If node has a sole data child, only print its value without indenting
217
- out = copy_and_expand_chars(child->value(), child->value() + child->value_size(), Ch(0), out);
218
- }
219
- else
220
- {
221
- // Print all children with full indenting
222
- if (!(flags & print_no_indenting))
223
- *out = Ch('\n'), ++out;
224
- out = print_children(out, node, flags, indent + 1);
225
- if (!(flags & print_no_indenting))
226
- out = fill_chars(out, indent, Ch('\t'));
227
- }
228
-
229
- // Print node end
230
- *out = Ch('<'), ++out;
231
- *out = Ch('/'), ++out;
232
- out = copy_chars(node->name(), node->name() + node->name_size(), out);
233
- *out = Ch('>'), ++out;
234
- }
235
- return out;
236
- }
237
-
238
- // Print declaration node
239
- template<class OutIt, class Ch>
240
- inline OutIt print_declaration_node(OutIt out, const xml_node<Ch> *node, int flags, int indent)
241
- {
242
- // Print declaration start
243
- if (!(flags & print_no_indenting))
244
- out = fill_chars(out, indent, Ch('\t'));
245
- *out = Ch('<'), ++out;
246
- *out = Ch('?'), ++out;
247
- *out = Ch('x'), ++out;
248
- *out = Ch('m'), ++out;
249
- *out = Ch('l'), ++out;
250
-
251
- // Print attributes
252
- out = print_attributes(out, node, flags);
253
-
254
- // Print declaration end
255
- *out = Ch('?'), ++out;
256
- *out = Ch('>'), ++out;
257
-
258
- return out;
259
- }
260
-
261
- // Print comment node
262
- template<class OutIt, class Ch>
263
- inline OutIt print_comment_node(OutIt out, const xml_node<Ch> *node, int flags, int indent)
264
- {
265
- assert(node->type() == node_comment);
266
- if (!(flags & print_no_indenting))
267
- out = fill_chars(out, indent, Ch('\t'));
268
- *out = Ch('<'), ++out;
269
- *out = Ch('!'), ++out;
270
- *out = Ch('-'), ++out;
271
- *out = Ch('-'), ++out;
272
- out = copy_chars(node->value(), node->value() + node->value_size(), out);
273
- *out = Ch('-'), ++out;
274
- *out = Ch('-'), ++out;
275
- *out = Ch('>'), ++out;
276
- return out;
277
- }
278
-
279
- // Print doctype node
280
- template<class OutIt, class Ch>
281
- inline OutIt print_doctype_node(OutIt out, const xml_node<Ch> *node, int flags, int indent)
282
- {
283
- assert(node->type() == node_doctype);
284
- if (!(flags & print_no_indenting))
285
- out = fill_chars(out, indent, Ch('\t'));
286
- *out = Ch('<'), ++out;
287
- *out = Ch('!'), ++out;
288
- *out = Ch('D'), ++out;
289
- *out = Ch('O'), ++out;
290
- *out = Ch('C'), ++out;
291
- *out = Ch('T'), ++out;
292
- *out = Ch('Y'), ++out;
293
- *out = Ch('P'), ++out;
294
- *out = Ch('E'), ++out;
295
- *out = Ch(' '), ++out;
296
- out = copy_chars(node->value(), node->value() + node->value_size(), out);
297
- *out = Ch('>'), ++out;
298
- return out;
299
- }
300
-
301
- // Print pi node
302
- template<class OutIt, class Ch>
303
- inline OutIt print_pi_node(OutIt out, const xml_node<Ch> *node, int flags, int indent)
304
- {
305
- assert(node->type() == node_pi);
306
- if (!(flags & print_no_indenting))
307
- out = fill_chars(out, indent, Ch('\t'));
308
- *out = Ch('<'), ++out;
309
- *out = Ch('?'), ++out;
310
- out = copy_chars(node->name(), node->name() + node->name_size(), out);
311
- *out = Ch(' '), ++out;
312
- out = copy_chars(node->value(), node->value() + node->value_size(), out);
313
- *out = Ch('?'), ++out;
314
- *out = Ch('>'), ++out;
315
- return out;
316
- }
317
-
318
- // Print node
319
- template<class OutIt, class Ch>
320
- inline OutIt print_node(OutIt out, const xml_node<Ch> *node, int flags, int indent)
321
- {
322
- // Print proper node type
323
- switch (node->type())
324
- {
325
-
326
- // Document
327
- case node_document:
328
- out = print_children(out, node, flags, indent);
329
- break;
330
-
331
- // Element
332
- case node_element:
333
- out = print_element_node(out, node, flags, indent);
334
- break;
335
-
336
- // Data
337
- case node_data:
338
- out = print_data_node(out, node, flags, indent);
339
- break;
340
-
341
- // CDATA
342
- case node_cdata:
343
- out = print_cdata_node(out, node, flags, indent);
344
- break;
345
-
346
- // Declaration
347
- case node_declaration:
348
- out = print_declaration_node(out, node, flags, indent);
349
- break;
350
-
351
- // Comment
352
- case node_comment:
353
- out = print_comment_node(out, node, flags, indent);
354
- break;
355
-
356
- // Doctype
357
- case node_doctype:
358
- out = print_doctype_node(out, node, flags, indent);
359
- break;
360
-
361
- // Pi
362
- case node_pi:
363
- out = print_pi_node(out, node, flags, indent);
364
- break;
365
-
366
- #ifndef __GNUC__
367
- // Unknown
368
- default:
369
- assert(0);
370
- break;
371
- #endif
372
- }
373
-
374
- // If indenting not disabled, add line break after node
375
- if (!(flags & print_no_indenting))
376
- *out = Ch('\n'), ++out;
377
-
378
- // Return modified iterator
379
- return out;
380
- }
381
-
382
- }
383
- //! \endcond
384
-
385
- ///////////////////////////////////////////////////////////////////////////
386
- // Printing
387
-
388
- //! Prints XML to given output iterator.
389
- //! \param out Output iterator to print to.
390
- //! \param node Node to be printed. Pass xml_document to print entire document.
391
- //! \param flags Flags controlling how XML is printed.
392
- //! \return Output iterator pointing to position immediately after last character of printed text.
393
- template<class OutIt, class Ch>
394
- inline OutIt print(OutIt out, const xml_node<Ch> &node, int flags = 0)
395
- {
396
- return internal::print_node(out, &node, flags, 0);
397
- }
398
-
399
- #ifndef CEREAL_RAPIDXML_NO_STREAMS
400
-
401
- //! Prints XML to given output stream.
402
- //! \param out Output stream to print to.
403
- //! \param node Node to be printed. Pass xml_document to print entire document.
404
- //! \param flags Flags controlling how XML is printed.
405
- //! \return Output stream.
406
- template<class Ch>
407
- inline std::basic_ostream<Ch> &print(std::basic_ostream<Ch> &out, const xml_node<Ch> &node, int flags = 0)
408
- {
409
- print(std::ostream_iterator<Ch>(out), node, flags);
410
- return out;
411
- }
412
-
413
- //! Prints formatted XML to given output stream. Uses default printing flags. Use print() function to customize printing process.
414
- //! \param out Output stream to print to.
415
- //! \param node Node to be printed.
416
- //! \return Output stream.
417
- template<class Ch>
418
- inline std::basic_ostream<Ch> &operator <<(std::basic_ostream<Ch> &out, const xml_node<Ch> &node)
419
- {
420
- return print(out, node);
421
- }
422
-
423
- #endif
424
-
425
- }
426
- } // namespace cereal
427
-
428
- #endif