rice 4.6.1 → 4.7.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +31 -0
- data/CMakeLists.txt +0 -4
- data/Rakefile +2 -8
- data/bin/rice-doc.rb +212 -0
- data/bin/rice-rbs.rb +93 -0
- data/include/rice/rice.hpp +4972 -4015
- data/include/rice/stl.hpp +822 -294
- data/lib/rice/doc/cpp_reference.rb +166 -0
- data/lib/rice/doc/doxygen.rb +294 -0
- data/lib/rice/doc/mkdocs.rb +298 -0
- data/lib/rice/doc/rice.rb +29 -0
- data/lib/rice/doc/ruby.rb +37 -0
- data/lib/rice/doc.rb +5 -0
- data/lib/{make_rice_headers.rb → rice/make_rice_headers.rb} +3 -0
- data/lib/rice/native.rb +18 -0
- data/lib/rice/native_registry.rb +21 -0
- data/lib/rice/parameter.rb +7 -0
- data/lib/rice/rbs.rb +104 -0
- data/lib/rice/version.rb +1 -1
- data/lib/rice.rb +4 -0
- data/lib/rubygems/cmake_builder.rb +24 -27
- data/rice/Arg.hpp +4 -4
- data/rice/Arg.ipp +4 -4
- data/rice/Buffer.hpp +32 -28
- data/rice/Buffer.ipp +306 -178
- data/rice/Data_Object.ipp +101 -82
- data/rice/Data_Type.hpp +5 -7
- data/rice/Data_Type.ipp +48 -29
- data/rice/Enum.ipp +15 -21
- data/rice/Function.hpp +17 -0
- data/rice/Function.ipp +13 -0
- data/rice/Pointer.hpp +15 -0
- data/rice/Pointer.ipp +49 -0
- data/rice/Return.hpp +1 -1
- data/rice/Return.ipp +2 -2
- data/rice/api.hpp +30 -0
- data/rice/cpp_api/Array.hpp +2 -2
- data/rice/cpp_api/Array.ipp +50 -5
- data/rice/cpp_api/Class.hpp +0 -5
- data/rice/cpp_api/Class.ipp +19 -0
- data/rice/cpp_api/Hash.ipp +20 -0
- data/rice/cpp_api/Module.hpp +6 -3
- data/rice/cpp_api/Module.ipp +49 -11
- data/rice/cpp_api/Object.ipp +31 -2
- data/rice/cpp_api/String.hpp +1 -2
- data/rice/cpp_api/String.ipp +21 -1
- data/rice/cpp_api/Struct.ipp +5 -0
- data/rice/cpp_api/Symbol.ipp +34 -0
- data/rice/cpp_api/shared_methods.hpp +12 -12
- data/rice/detail/MethodInfo.hpp +4 -2
- data/rice/detail/MethodInfo.ipp +19 -3
- data/rice/detail/ModuleRegistry.hpp +18 -0
- data/rice/detail/ModuleRegistry.ipp +25 -0
- data/rice/detail/Native.hpp +45 -2
- data/rice/detail/Native.ipp +196 -2
- data/rice/detail/NativeAttributeGet.hpp +9 -4
- data/rice/detail/NativeAttributeGet.ipp +65 -11
- data/rice/detail/NativeAttributeSet.hpp +4 -0
- data/rice/detail/NativeAttributeSet.ipp +30 -2
- data/rice/detail/NativeCallbackFFI.ipp +2 -2
- data/rice/detail/NativeCallbackSimple.ipp +1 -1
- data/rice/detail/NativeFunction.hpp +11 -49
- data/rice/detail/NativeFunction.ipp +82 -379
- data/rice/detail/NativeInvoker.hpp +74 -0
- data/rice/detail/NativeInvoker.ipp +197 -0
- data/rice/detail/NativeIterator.hpp +4 -0
- data/rice/detail/NativeIterator.ipp +19 -0
- data/rice/detail/NativeMethod.hpp +97 -0
- data/rice/detail/NativeMethod.ipp +332 -0
- data/rice/detail/NativeProc.hpp +51 -0
- data/rice/detail/NativeProc.ipp +133 -0
- data/rice/detail/NativeRegistry.hpp +8 -0
- data/rice/detail/NativeRegistry.ipp +27 -0
- data/rice/detail/Parameter.hpp +47 -0
- data/rice/detail/Parameter.ipp +105 -0
- data/rice/detail/Proc.ipp +14 -13
- data/rice/detail/Registries.hpp +1 -0
- data/rice/detail/RubyType.hpp +0 -2
- data/rice/detail/RubyType.ipp +15 -33
- data/rice/detail/Type.hpp +44 -8
- data/rice/detail/Type.ipp +151 -49
- data/rice/detail/TypeRegistry.hpp +3 -0
- data/rice/detail/TypeRegistry.ipp +17 -27
- data/rice/detail/Types.ipp +430 -0
- data/rice/detail/Wrapper.hpp +12 -0
- data/rice/detail/Wrapper.ipp +45 -2
- data/rice/detail/from_ruby.ipp +567 -1073
- data/rice/detail/ruby.hpp +1 -0
- data/rice/detail/to_ruby.ipp +4 -635
- data/rice/libc/file.ipp +3 -6
- data/rice/rice.hpp +22 -12
- data/rice/rice_api/Arg.hpp +7 -0
- data/rice/rice_api/Arg.ipp +9 -0
- data/rice/rice_api/ModuleRegistry.hpp +7 -0
- data/rice/rice_api/ModuleRegistry.ipp +10 -0
- data/rice/rice_api/Native.hpp +7 -0
- data/rice/rice_api/Native.ipp +52 -0
- data/rice/rice_api/NativeRegistry.hpp +7 -0
- data/rice/rice_api/NativeRegistry.ipp +21 -0
- data/rice/rice_api/Parameter.hpp +7 -0
- data/rice/rice_api/Parameter.ipp +11 -0
- data/rice/rice_api/Registries.hpp +6 -0
- data/rice/rice_api/Registries.ipp +12 -0
- data/rice/rice_api/TypeRegistry.hpp +7 -0
- data/rice/rice_api/TypeRegistry.ipp +10 -0
- data/rice/stl/complex.ipp +35 -0
- data/rice/stl/exception.ipp +20 -7
- data/rice/stl/filesystem.hpp +6 -0
- data/rice/stl/filesystem.ipp +34 -0
- data/rice/stl/map.ipp +13 -21
- data/rice/stl/monostate.ipp +37 -1
- data/rice/stl/multimap.ipp +17 -24
- data/rice/stl/optional.ipp +47 -2
- data/rice/stl/pair.ipp +23 -58
- data/rice/stl/reference_wrapper.ipp +22 -1
- data/rice/stl/set.ipp +17 -9
- data/rice/stl/shared_ptr.ipp +44 -17
- data/rice/stl/string.ipp +175 -7
- data/rice/stl/string_view.ipp +5 -0
- data/rice/stl/tuple.ipp +38 -9
- data/rice/stl/unique_ptr.ipp +46 -2
- data/rice/stl/unordered_map.ipp +13 -21
- data/rice/stl/variant.ipp +47 -11
- data/rice/stl/vector.ipp +183 -104
- data/rice/stl.hpp +1 -0
- data/rice/traits/function_traits.hpp +2 -2
- data/rice/traits/method_traits.hpp +5 -16
- data/rice/traits/rice_traits.hpp +24 -4
- data/rice.gemspec +11 -22
- data/test/embed_ruby.cpp +0 -3
- data/test/test_Array.cpp +38 -38
- data/test/test_Attribute.cpp +187 -2
- data/test/test_Buffer.cpp +302 -26
- data/test/test_Callback.cpp +2 -3
- data/test/test_Class.cpp +5 -5
- data/test/test_Data_Object.cpp +0 -55
- data/test/test_Data_Type.cpp +19 -30
- data/test/test_Enum.cpp +4 -46
- data/test/test_From_Ruby.cpp +88 -81
- data/test/test_GVL.cpp +109 -0
- data/test/test_Iterator.cpp +1 -1
- data/test/test_Keep_Alive_No_Wrapper.cpp +5 -3
- data/test/test_Module.cpp +8 -9
- data/test/test_Object.cpp +1 -1
- data/test/test_Overloads.cpp +3 -3
- data/test/test_Stl_Map.cpp +8 -8
- data/test/test_Stl_Multimap.cpp +4 -4
- data/test/test_Stl_Pair.cpp +5 -3
- data/test/test_Stl_SharedPtr.cpp +24 -12
- data/test/test_Stl_Tuple.cpp +1 -1
- data/test/test_Stl_UniquePtr.cpp +8 -0
- data/test/test_Stl_Unordered_Map.cpp +9 -9
- data/test/test_Stl_Variant.cpp +9 -3
- data/test/test_Stl_Vector.cpp +118 -13
- data/test/test_To_Ruby.cpp +35 -28
- data/test/test_Type.cpp +256 -53
- data/test/unittest.hpp +35 -0
- metadata +66 -34
- data/rice/Init.hpp +0 -8
- data/rice/Init.ipp +0 -8
- data/rice/detail/RubyFunction.hpp +0 -31
- data/rice/detail/RubyFunction.ipp +0 -77
- data/sample/callbacks/extconf.rb +0 -5
- data/sample/callbacks/sample_callbacks.cpp +0 -35
- data/sample/callbacks/test.rb +0 -28
- data/sample/enum/extconf.rb +0 -5
- data/sample/enum/sample_enum.cpp +0 -40
- data/sample/enum/test.rb +0 -8
- data/sample/inheritance/animals.cpp +0 -82
- data/sample/inheritance/extconf.rb +0 -5
- data/sample/inheritance/test.rb +0 -7
- data/sample/map/extconf.rb +0 -5
- data/sample/map/map.cpp +0 -73
- data/sample/map/test.rb +0 -7
- data/test/ext/t1/Foo.hpp +0 -10
- data/test/ext/t1/extconf.rb +0 -4
- data/test/ext/t1/t1.cpp +0 -13
- data/test/ext/t2/extconf.rb +0 -4
- data/test/ext/t2/t2.cpp +0 -11
- data/test/ruby/test_callbacks_sample.rb +0 -28
- data/test/ruby/test_multiple_extensions.rb +0 -18
- data/test/ruby/test_multiple_extensions_same_class.rb +0 -14
- data/test/ruby/test_multiple_extensions_with_inheritance.rb +0 -20
- /data/test/{test_Stl_Type.cpp → test_Stl_Type_Info.cpp} +0 -0
data/rice/detail/Type.ipp
CHANGED
|
@@ -4,35 +4,52 @@
|
|
|
4
4
|
#include <cstring>
|
|
5
5
|
#endif
|
|
6
6
|
|
|
7
|
+
// Rice saves types either as the intrinsic type (MyObject) or pointer (MyObject*).
|
|
8
|
+
// It strips out references, const and volatile to avoid an explosion of template classes.
|
|
9
|
+
// Pointers are used for C function pointers used in callbacks and for the Buffer class.
|
|
7
10
|
namespace Rice::detail
|
|
8
11
|
{
|
|
12
|
+
// ------ Type ----------------
|
|
9
13
|
template<typename T>
|
|
10
|
-
bool Type<T>::verify()
|
|
14
|
+
inline bool Type<T>::verify()
|
|
11
15
|
{
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
return Registries::instance.types.verify<intrinsic_type<T>>();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
template<typename T>
|
|
20
|
+
inline bool Type<T&>::verify()
|
|
21
|
+
{
|
|
22
|
+
return Type<T>::verify();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
template<typename T>
|
|
26
|
+
inline bool Type<T&&>::verify()
|
|
27
|
+
{
|
|
28
|
+
return Type<T>::verify();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
template<typename T>
|
|
32
|
+
inline bool Type<T*>::verify()
|
|
33
|
+
{
|
|
34
|
+
return Type<T>::verify();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
template<typename T>
|
|
38
|
+
inline bool Type<T**>::verify()
|
|
39
|
+
{
|
|
40
|
+
return Type<T>::verify();
|
|
24
41
|
}
|
|
25
42
|
|
|
26
43
|
template<typename T>
|
|
27
44
|
void verifyType()
|
|
28
45
|
{
|
|
29
|
-
Type<
|
|
46
|
+
Type<remove_cv_recursive_t<T>>::verify();
|
|
30
47
|
}
|
|
31
48
|
|
|
32
49
|
template<typename Tuple_T, size_t...Is>
|
|
33
50
|
void verifyTypesImpl(std::index_sequence<Is...> indexes)
|
|
34
51
|
{
|
|
35
|
-
(verifyType<
|
|
52
|
+
(verifyType<std::tuple_element_t<Is, Tuple_T>>(), ...);
|
|
36
53
|
}
|
|
37
54
|
|
|
38
55
|
template<typename Tuple_T>
|
|
@@ -42,7 +59,21 @@ namespace Rice::detail
|
|
|
42
59
|
verifyTypesImpl<Tuple_T>(indexes);
|
|
43
60
|
}
|
|
44
61
|
|
|
45
|
-
|
|
62
|
+
// ---------- RubyKlass ------------
|
|
63
|
+
// Helper template to see if the method rubyKlass is defined on a Type specialization
|
|
64
|
+
template<typename, typename = std::void_t<>>
|
|
65
|
+
struct has_ruby_klass : std::false_type
|
|
66
|
+
{
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
template<typename T>
|
|
70
|
+
struct has_ruby_klass<T, std::void_t<decltype(T::rubyKlass())>> : std::true_type
|
|
71
|
+
{
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
// ---------- TypeMapper ------------
|
|
75
|
+
template<typename T>
|
|
76
|
+
inline std::string TypeMapper<T>::demangle(char const* mangled_name)
|
|
46
77
|
{
|
|
47
78
|
#ifdef __GNUC__
|
|
48
79
|
struct Helper
|
|
@@ -81,12 +112,15 @@ namespace Rice::detail
|
|
|
81
112
|
#endif
|
|
82
113
|
}
|
|
83
114
|
|
|
84
|
-
|
|
115
|
+
template<typename T>
|
|
116
|
+
inline std::string TypeMapper<T>::name()
|
|
85
117
|
{
|
|
86
|
-
|
|
118
|
+
const std::type_index& typeIndex = typeid(T);
|
|
119
|
+
return demangle(typeIndex.name());
|
|
87
120
|
}
|
|
88
121
|
|
|
89
|
-
|
|
122
|
+
template<typename T>
|
|
123
|
+
inline std::string TypeMapper<T>::name(const std::type_index& typeIndex)
|
|
90
124
|
{
|
|
91
125
|
return demangle(typeIndex.name());
|
|
92
126
|
}
|
|
@@ -96,7 +130,8 @@ namespace Rice::detail
|
|
|
96
130
|
// Example:
|
|
97
131
|
//
|
|
98
132
|
// std::vector<std::vector<int>, std::allocator<std::vector, std::allocator<int>>>
|
|
99
|
-
|
|
133
|
+
template<typename T>
|
|
134
|
+
inline std::string TypeMapper<T>::findGroup(std::string& string, size_t offset)
|
|
100
135
|
{
|
|
101
136
|
int depth = 0;
|
|
102
137
|
|
|
@@ -129,7 +164,8 @@ namespace Rice::detail
|
|
|
129
164
|
throw std::runtime_error("Unbalanced Group");
|
|
130
165
|
}
|
|
131
166
|
|
|
132
|
-
|
|
167
|
+
template<typename T>
|
|
168
|
+
inline void TypeMapper<T>::replaceAll(std::string& string, std::regex regex, std::string replacement)
|
|
133
169
|
{
|
|
134
170
|
std::smatch match;
|
|
135
171
|
while (std::regex_search(string, match, regex))
|
|
@@ -138,7 +174,8 @@ namespace Rice::detail
|
|
|
138
174
|
}
|
|
139
175
|
}
|
|
140
176
|
|
|
141
|
-
|
|
177
|
+
template<typename T>
|
|
178
|
+
inline void TypeMapper<T>::removeGroup(std::string& string, std::regex regex)
|
|
142
179
|
{
|
|
143
180
|
std::smatch match;
|
|
144
181
|
while (std::regex_search(string, match, regex))
|
|
@@ -149,7 +186,8 @@ namespace Rice::detail
|
|
|
149
186
|
}
|
|
150
187
|
}
|
|
151
188
|
|
|
152
|
-
|
|
189
|
+
template<typename T>
|
|
190
|
+
inline void TypeMapper<T>::replaceGroup(std::string& string, std::regex regex, std::string replacement)
|
|
153
191
|
{
|
|
154
192
|
std::smatch match;
|
|
155
193
|
while (std::regex_search(string, match, regex))
|
|
@@ -160,20 +198,25 @@ namespace Rice::detail
|
|
|
160
198
|
}
|
|
161
199
|
}
|
|
162
200
|
|
|
163
|
-
|
|
201
|
+
template<typename T>
|
|
202
|
+
inline std::string TypeMapper<T>::simplifiedName()
|
|
164
203
|
{
|
|
165
|
-
std::string base =
|
|
204
|
+
std::string base = this->name();
|
|
205
|
+
|
|
206
|
+
// Remove void from Buffer<T, void> - the void comes from SFINAE
|
|
207
|
+
std::regex fixBuffer = std::regex("(Buffer<.*),\\s?void>");
|
|
208
|
+
base = std::regex_replace(base, fixBuffer, "$1>");
|
|
166
209
|
|
|
167
210
|
// Remove class keyword
|
|
168
|
-
|
|
169
|
-
base = std::regex_replace(
|
|
211
|
+
std::regex classRegex = std::regex("class +");
|
|
212
|
+
base = std::regex_replace(base, classRegex, "");
|
|
170
213
|
|
|
171
214
|
// Remove struct keyword
|
|
172
|
-
|
|
215
|
+
std::regex structRegex = std::regex("struct +");
|
|
173
216
|
base = std::regex_replace(base, structRegex, "");
|
|
174
217
|
|
|
175
218
|
// Remove std::__[^:]*::
|
|
176
|
-
|
|
219
|
+
std::regex stdClangRegex = std::regex("std::__[^:]+::");
|
|
177
220
|
base = std::regex_replace(base, stdClangRegex, "std::");
|
|
178
221
|
|
|
179
222
|
// Remove allocators
|
|
@@ -197,7 +240,7 @@ namespace Rice::detail
|
|
|
197
240
|
removeGroup(base, equalRegex);
|
|
198
241
|
|
|
199
242
|
// Remove spaces before pointers
|
|
200
|
-
|
|
243
|
+
std::regex ptrRegex = std::regex(R"(\s+\*)");
|
|
201
244
|
base = std::regex_replace(base, ptrRegex, "*");
|
|
202
245
|
|
|
203
246
|
// Remove __ptr64
|
|
@@ -205,32 +248,65 @@ namespace Rice::detail
|
|
|
205
248
|
base = std::regex_replace(base, ptr64Regex, "");
|
|
206
249
|
|
|
207
250
|
// Replace " >" with ">"
|
|
208
|
-
|
|
251
|
+
std::regex trailingAngleBracketSpaceRegex = std::regex(R"(\s+>)");
|
|
209
252
|
replaceAll(base, trailingAngleBracketSpaceRegex, ">");
|
|
210
253
|
|
|
211
254
|
// One space after a comma (MSVC has no spaces, GCC one space)
|
|
212
|
-
|
|
255
|
+
std::regex commaSpaceRegex = std::regex(R"(,(\S))");
|
|
213
256
|
replaceAll(base, commaSpaceRegex, ", $1");
|
|
214
257
|
|
|
215
258
|
// Fix strings
|
|
216
|
-
|
|
259
|
+
std::regex stringRegex = std::regex(R"(basic_string<char>)");
|
|
217
260
|
replaceAll(base, stringRegex, "string");
|
|
218
261
|
|
|
219
|
-
|
|
262
|
+
std::regex wstringRegex = std::regex(R"(basic_string<wchar_t>)");
|
|
220
263
|
replaceAll(base, wstringRegex, "wstring");
|
|
221
264
|
|
|
222
265
|
// Normalize Anonymous namespace
|
|
223
|
-
|
|
266
|
+
std::regex anonymousNamespaceGcc = std::regex(R"(\(anonymous namespace\))");
|
|
224
267
|
replaceAll(base, anonymousNamespaceGcc, "AnonymousNamespace");
|
|
225
|
-
|
|
268
|
+
std::regex anonymousNamespaceMsvc = std::regex(R"(`anonymous namespace')");
|
|
226
269
|
replaceAll(base, anonymousNamespaceMsvc, "AnonymousNamespace");
|
|
227
270
|
|
|
228
271
|
return base;
|
|
229
272
|
}
|
|
230
273
|
|
|
231
|
-
|
|
274
|
+
template<typename T>
|
|
275
|
+
inline void TypeMapper<T>::capitalizeHelper(std::string& content, std::regex& regex)
|
|
232
276
|
{
|
|
233
|
-
std::
|
|
277
|
+
std::smatch match;
|
|
278
|
+
while (std::regex_search(content, match, regex))
|
|
279
|
+
{
|
|
280
|
+
std::string replacement = match[1];
|
|
281
|
+
std::transform(replacement.begin(), replacement.end(), replacement.begin(), ::toupper);
|
|
282
|
+
content.replace(match.position(), match.length(), replacement);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
template<typename T>
|
|
287
|
+
inline std::string TypeMapper<T>::rubyTypeName()
|
|
288
|
+
{
|
|
289
|
+
using Intrinsic_T = detail::intrinsic_type<T>;
|
|
290
|
+
|
|
291
|
+
if constexpr (std::is_fundamental_v<T>)
|
|
292
|
+
{
|
|
293
|
+
return RubyType<Intrinsic_T>::name;
|
|
294
|
+
}
|
|
295
|
+
else if constexpr (std::is_same_v<std::remove_cv_t<T>, char*>)
|
|
296
|
+
{
|
|
297
|
+
return "String";
|
|
298
|
+
}
|
|
299
|
+
else
|
|
300
|
+
{
|
|
301
|
+
detail::TypeMapper<Intrinsic_T> typeIntrinsicMapper;
|
|
302
|
+
return typeIntrinsicMapper.simplifiedName();
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
template<typename T>
|
|
307
|
+
inline std::string TypeMapper<T>::rubyName()
|
|
308
|
+
{
|
|
309
|
+
std::string base = this->rubyTypeName();
|
|
234
310
|
|
|
235
311
|
// Remove std:: these could be embedded in template types
|
|
236
312
|
auto stdRegex = std::regex("std::");
|
|
@@ -249,18 +325,21 @@ namespace Rice::detail
|
|
|
249
325
|
replaceAll(base, colonRegex, "\uA789");
|
|
250
326
|
|
|
251
327
|
// Replace _ and capitalize the next letter
|
|
252
|
-
std::regex
|
|
253
|
-
|
|
254
|
-
|
|
328
|
+
std::regex underscoreRegex(R"(_(\w))");
|
|
329
|
+
capitalizeHelper(base, underscoreRegex);
|
|
330
|
+
|
|
331
|
+
if constexpr (std::is_fundamental_v<intrinsic_type<T>>)
|
|
255
332
|
{
|
|
256
|
-
|
|
257
|
-
std::
|
|
258
|
-
base
|
|
333
|
+
// Replace space and capitalize the next letter
|
|
334
|
+
std::regex spaceRegex(R"(\s+(\w))");
|
|
335
|
+
capitalizeHelper(base, spaceRegex);
|
|
336
|
+
}
|
|
337
|
+
else
|
|
338
|
+
{
|
|
339
|
+
// Replace spaces with unicode U+u00A0 (Non breaking Space)
|
|
340
|
+
std::regex spaceRegex = std::regex(R"(\s+)");
|
|
341
|
+
replaceAll(base, spaceRegex, "\u00A0");
|
|
259
342
|
}
|
|
260
|
-
|
|
261
|
-
// Replace spaces with unicode U+u00A0 (Non breaking Space)
|
|
262
|
-
auto spaceRegex = std::regex(R"(\s+)");
|
|
263
|
-
replaceAll(base, spaceRegex, "\u00A0");
|
|
264
343
|
|
|
265
344
|
// Replace < with unicode U+227A (Precedes)
|
|
266
345
|
auto lessThanRegex = std::regex("<");
|
|
@@ -282,4 +361,27 @@ namespace Rice::detail
|
|
|
282
361
|
|
|
283
362
|
return base;
|
|
284
363
|
}
|
|
285
|
-
|
|
364
|
+
|
|
365
|
+
template<typename T>
|
|
366
|
+
inline VALUE TypeMapper<T>::rubyKlass()
|
|
367
|
+
{
|
|
368
|
+
using Type_T = Type<std::remove_reference_t<detail::remove_cv_recursive_t<T>>>;
|
|
369
|
+
using Intrinsic_T = detail::intrinsic_type<T>;
|
|
370
|
+
|
|
371
|
+
if constexpr (has_ruby_klass<Type_T>::value)
|
|
372
|
+
{
|
|
373
|
+
return Type_T::rubyKlass();
|
|
374
|
+
}
|
|
375
|
+
else if constexpr (std::is_fundamental_v<Intrinsic_T> && std::is_pointer_v<T>)
|
|
376
|
+
{
|
|
377
|
+
using Pointer_T = Pointer<std::remove_pointer_t<remove_cv_recursive_t<T>>>;
|
|
378
|
+
std::pair<VALUE, rb_data_type_t*> pair = Registries::instance.types.getType<Pointer_T>();
|
|
379
|
+
return pair.first;
|
|
380
|
+
}
|
|
381
|
+
else
|
|
382
|
+
{
|
|
383
|
+
std::pair<VALUE, rb_data_type_t*> pair = Registries::instance.types.getType<Intrinsic_T>();
|
|
384
|
+
return pair.first;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
}
|
|
@@ -43,6 +43,9 @@ namespace Rice::detail
|
|
|
43
43
|
// Clear unverified types. This is mostly for unit tests
|
|
44
44
|
void clearUnverifiedTypes();
|
|
45
45
|
|
|
46
|
+
// API for access from Ruby
|
|
47
|
+
VALUE klasses();
|
|
48
|
+
|
|
46
49
|
private:
|
|
47
50
|
std::optional<std::pair<VALUE, rb_data_type_t*>> lookup(const std::type_info& typeInfo);
|
|
48
51
|
void raiseUnverifiedType(const std::string& typeName);
|
|
@@ -13,22 +13,6 @@ namespace Rice::detail
|
|
|
13
13
|
registry_[key] = std::pair(klass, rbType);
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
/* Special case void. Rice defines classes using the class name not a pointer to the
|
|
17
|
-
class. Thus define_class<void> is more consistent with Rice then
|
|
18
|
-
define_class<void*>. However, the types of void and void* are different so we need
|
|
19
|
-
this special case.
|
|
20
|
-
|
|
21
|
-
It is possible to support define_class<void*>, but it requires changing the static
|
|
22
|
-
assertions on Data_Type and Data_Object and thus seems less desirable (and less
|
|
23
|
-
consistent as mentioned above).*/
|
|
24
|
-
template <>
|
|
25
|
-
inline void TypeRegistry::add<void>(VALUE klass, rb_data_type_t* rbType)
|
|
26
|
-
{
|
|
27
|
-
// The special case, use void*
|
|
28
|
-
std::type_index key(typeid(void*));
|
|
29
|
-
registry_[key] = std::pair(klass, rbType);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
16
|
template <typename T>
|
|
33
17
|
inline void TypeRegistry::remove()
|
|
34
18
|
{
|
|
@@ -61,15 +45,6 @@ namespace Rice::detail
|
|
|
61
45
|
}
|
|
62
46
|
}
|
|
63
47
|
|
|
64
|
-
// Special case void. See comment for add above.
|
|
65
|
-
template <>
|
|
66
|
-
inline bool TypeRegistry::isDefined<void>()
|
|
67
|
-
{
|
|
68
|
-
std::type_index key(typeid(void*));
|
|
69
|
-
auto iter = registry_.find(key);
|
|
70
|
-
return iter != registry_.end();
|
|
71
|
-
}
|
|
72
|
-
|
|
73
48
|
template <typename T>
|
|
74
49
|
inline bool TypeRegistry::verify()
|
|
75
50
|
{
|
|
@@ -122,7 +97,8 @@ namespace Rice::detail
|
|
|
122
97
|
return result.value();
|
|
123
98
|
}
|
|
124
99
|
|
|
125
|
-
|
|
100
|
+
detail::TypeMapper<T> typeMapper;
|
|
101
|
+
raiseUnverifiedType(typeMapper.name());
|
|
126
102
|
// Make the compiler happy
|
|
127
103
|
return std::pair<VALUE, rb_data_type_t*>(Qnil, nullptr);
|
|
128
104
|
}
|
|
@@ -155,7 +131,8 @@ namespace Rice::detail
|
|
|
155
131
|
|
|
156
132
|
for (const std::type_index& typeIndex : this->unverified_)
|
|
157
133
|
{
|
|
158
|
-
|
|
134
|
+
detail::TypeMapper<int> typeMapper;
|
|
135
|
+
stream << " " << typeMapper.name(typeIndex) << "\n";
|
|
159
136
|
}
|
|
160
137
|
|
|
161
138
|
throw std::invalid_argument(stream.str());
|
|
@@ -171,4 +148,17 @@ namespace Rice::detail
|
|
|
171
148
|
std::string message = "Type is not registered with Rice: " + typeName;
|
|
172
149
|
throw std::invalid_argument(message);
|
|
173
150
|
}
|
|
151
|
+
|
|
152
|
+
inline VALUE TypeRegistry::klasses()
|
|
153
|
+
{
|
|
154
|
+
Array result;
|
|
155
|
+
|
|
156
|
+
for (auto& pair : this->registry_)
|
|
157
|
+
{
|
|
158
|
+
std::pair<VALUE, rb_data_type_t*>& value = pair.second;
|
|
159
|
+
Class klass = value.first;
|
|
160
|
+
result.push(klass, false);
|
|
161
|
+
}
|
|
162
|
+
return result;
|
|
163
|
+
}
|
|
174
164
|
}
|