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/stl/string.ipp
CHANGED
|
@@ -9,59 +9,186 @@ namespace Rice::detail
|
|
|
9
9
|
{
|
|
10
10
|
return true;
|
|
11
11
|
}
|
|
12
|
+
|
|
13
|
+
static VALUE rubyKlass()
|
|
14
|
+
{
|
|
15
|
+
return rb_cString;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
template<int N>
|
|
20
|
+
struct Type<std::string[N]>
|
|
21
|
+
{
|
|
22
|
+
static bool verify()
|
|
23
|
+
{
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
static VALUE rubyKlass()
|
|
28
|
+
{
|
|
29
|
+
return rb_cString;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
template<>
|
|
34
|
+
struct Type<std::string*>
|
|
35
|
+
{
|
|
36
|
+
static bool verify()
|
|
37
|
+
{
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
static VALUE rubyKlass()
|
|
42
|
+
{
|
|
43
|
+
using Pointer_T = Pointer<std::string>;
|
|
44
|
+
std::pair<VALUE, rb_data_type_t*> pair = Registries::instance.types.getType<Pointer_T>();
|
|
45
|
+
return pair.first;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
template<>
|
|
50
|
+
struct Type<std::string**>
|
|
51
|
+
{
|
|
52
|
+
static bool verify()
|
|
53
|
+
{
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
static VALUE rubyKlass()
|
|
58
|
+
{
|
|
59
|
+
using Pointer_T = Pointer<std::string*>;
|
|
60
|
+
std::pair<VALUE, rb_data_type_t*> pair = Registries::instance.types.getType<Pointer_T>();
|
|
61
|
+
return pair.first;
|
|
62
|
+
}
|
|
12
63
|
};
|
|
13
64
|
|
|
14
65
|
template<>
|
|
15
66
|
class To_Ruby<std::string>
|
|
16
67
|
{
|
|
17
68
|
public:
|
|
69
|
+
To_Ruby() = default;
|
|
70
|
+
|
|
71
|
+
explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
|
|
72
|
+
{
|
|
73
|
+
}
|
|
74
|
+
|
|
18
75
|
VALUE convert(const std::string& x)
|
|
19
76
|
{
|
|
20
77
|
return detail::protect(rb_external_str_new, x.data(), (long)x.size());
|
|
21
78
|
}
|
|
79
|
+
|
|
80
|
+
private:
|
|
81
|
+
Return* returnInfo_ = nullptr;
|
|
22
82
|
};
|
|
23
83
|
|
|
24
84
|
template<>
|
|
25
85
|
class To_Ruby<std::string&>
|
|
26
86
|
{
|
|
27
87
|
public:
|
|
88
|
+
To_Ruby() = default;
|
|
89
|
+
|
|
90
|
+
explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
|
|
91
|
+
{
|
|
92
|
+
}
|
|
93
|
+
|
|
28
94
|
VALUE convert(const std::string& x)
|
|
29
95
|
{
|
|
30
96
|
return detail::protect(rb_external_str_new, x.data(), (long)x.size());
|
|
31
97
|
}
|
|
98
|
+
|
|
99
|
+
private:
|
|
100
|
+
Return* returnInfo_ = nullptr;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
template<int N>
|
|
104
|
+
class To_Ruby<std::string[N]>
|
|
105
|
+
{
|
|
106
|
+
public:
|
|
107
|
+
To_Ruby() = default;
|
|
108
|
+
|
|
109
|
+
explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
|
|
110
|
+
{
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
VALUE convert(std::string data[N])
|
|
114
|
+
{
|
|
115
|
+
Buffer<std::string> buffer(data, N);
|
|
116
|
+
Data_Object<Buffer<std::string>> dataObject(std::move(buffer));
|
|
117
|
+
return dataObject.value();
|
|
118
|
+
}
|
|
119
|
+
private:
|
|
120
|
+
Return* returnInfo_ = nullptr;
|
|
32
121
|
};
|
|
33
122
|
|
|
34
123
|
template<>
|
|
35
124
|
class To_Ruby<std::string*>
|
|
36
125
|
{
|
|
37
126
|
public:
|
|
38
|
-
|
|
127
|
+
To_Ruby() = default;
|
|
128
|
+
|
|
129
|
+
explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
|
|
39
130
|
{
|
|
40
|
-
return detail::protect(rb_external_str_new, x->data(), (long)x->size());
|
|
41
131
|
}
|
|
132
|
+
|
|
133
|
+
VALUE convert(const std::string* value)
|
|
134
|
+
{
|
|
135
|
+
bool isOwner = this->returnInfo_ && this->returnInfo_->isOwner();
|
|
136
|
+
bool isBuffer = this->returnInfo_ && this->returnInfo_->isBuffer();
|
|
137
|
+
|
|
138
|
+
if (isBuffer)
|
|
139
|
+
{
|
|
140
|
+
using Pointer_T = Pointer<std::string>;
|
|
141
|
+
return detail::wrap(Data_Type<Pointer_T>::klass(), Data_Type<Pointer_T>::ruby_data_type(), value, isOwner);
|
|
142
|
+
}
|
|
143
|
+
else
|
|
144
|
+
{
|
|
145
|
+
return detail::protect(rb_external_str_new, value->data(), (long)value->size());
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
private:
|
|
150
|
+
Return* returnInfo_ = nullptr;
|
|
42
151
|
};
|
|
43
152
|
|
|
44
153
|
template<>
|
|
45
154
|
class To_Ruby<std::string*&>
|
|
46
155
|
{
|
|
47
156
|
public:
|
|
157
|
+
To_Ruby() = default;
|
|
158
|
+
|
|
159
|
+
explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
|
|
160
|
+
{
|
|
161
|
+
}
|
|
162
|
+
|
|
48
163
|
VALUE convert(const std::string* x)
|
|
49
164
|
{
|
|
50
165
|
return detail::protect(rb_external_str_new, x->data(), (long)x->size());
|
|
51
166
|
}
|
|
167
|
+
|
|
168
|
+
private:
|
|
169
|
+
Return* returnInfo_ = nullptr;
|
|
52
170
|
};
|
|
53
171
|
|
|
54
|
-
template<>
|
|
172
|
+
/*template<>
|
|
55
173
|
class To_Ruby<std::string**>
|
|
56
174
|
{
|
|
57
175
|
public:
|
|
176
|
+
To_Ruby() = default;
|
|
177
|
+
|
|
178
|
+
explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
|
|
179
|
+
{
|
|
180
|
+
}
|
|
181
|
+
|
|
58
182
|
VALUE convert(std::string** data)
|
|
59
183
|
{
|
|
60
184
|
Buffer<std::string*> buffer(data);
|
|
61
185
|
Data_Object<Buffer<std::string*>> dataObject(std::move(buffer));
|
|
62
186
|
return dataObject.value();
|
|
63
187
|
}
|
|
64
|
-
|
|
188
|
+
|
|
189
|
+
private:
|
|
190
|
+
Return* returnInfo_ = nullptr;
|
|
191
|
+
};*/
|
|
65
192
|
|
|
66
193
|
template<>
|
|
67
194
|
class From_Ruby<std::string>
|
|
@@ -87,7 +214,7 @@ namespace Rice::detail
|
|
|
87
214
|
|
|
88
215
|
std::string convert(VALUE value)
|
|
89
216
|
{
|
|
90
|
-
detail::protect(rb_check_type, value, (int)
|
|
217
|
+
detail::protect(rb_check_type, value, (int)RUBY_T_STRING);
|
|
91
218
|
return std::string(RSTRING_PTR(value), RSTRING_LEN(value));
|
|
92
219
|
}
|
|
93
220
|
|
|
@@ -119,7 +246,7 @@ namespace Rice::detail
|
|
|
119
246
|
|
|
120
247
|
std::string& convert(VALUE value)
|
|
121
248
|
{
|
|
122
|
-
detail::protect(rb_check_type, value, (int)
|
|
249
|
+
detail::protect(rb_check_type, value, (int)RUBY_T_STRING);
|
|
123
250
|
this->converted_ = std::string(RSTRING_PTR(value), RSTRING_LEN(value));
|
|
124
251
|
return this->converted_;
|
|
125
252
|
}
|
|
@@ -129,10 +256,50 @@ namespace Rice::detail
|
|
|
129
256
|
std::string converted_ = "";
|
|
130
257
|
};
|
|
131
258
|
|
|
259
|
+
template<>
|
|
260
|
+
class From_Ruby<std::string&&>
|
|
261
|
+
{
|
|
262
|
+
public:
|
|
263
|
+
From_Ruby() = default;
|
|
264
|
+
|
|
265
|
+
explicit From_Ruby(Arg* arg) : arg_(arg)
|
|
266
|
+
{
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
Convertible is_convertible(VALUE value)
|
|
270
|
+
{
|
|
271
|
+
switch (rb_type(value))
|
|
272
|
+
{
|
|
273
|
+
case RUBY_T_STRING:
|
|
274
|
+
return Convertible::Exact;
|
|
275
|
+
break;
|
|
276
|
+
default:
|
|
277
|
+
return Convertible::None;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
std::string&& convert(VALUE value)
|
|
282
|
+
{
|
|
283
|
+
detail::protect(rb_check_type, value, (int)T_STRING);
|
|
284
|
+
this->converted_ = std::string(RSTRING_PTR(value), RSTRING_LEN(value));
|
|
285
|
+
return std::move(this->converted_);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
private:
|
|
289
|
+
Arg* arg_ = nullptr;
|
|
290
|
+
std::string converted_ = "";
|
|
291
|
+
};
|
|
292
|
+
|
|
132
293
|
template<>
|
|
133
294
|
class From_Ruby<std::string*>
|
|
134
295
|
{
|
|
135
296
|
public:
|
|
297
|
+
From_Ruby() = default;
|
|
298
|
+
|
|
299
|
+
explicit From_Ruby(Arg* arg) : arg_(arg)
|
|
300
|
+
{
|
|
301
|
+
}
|
|
302
|
+
|
|
136
303
|
Convertible is_convertible(VALUE value)
|
|
137
304
|
{
|
|
138
305
|
switch (rb_type(value))
|
|
@@ -147,12 +314,13 @@ namespace Rice::detail
|
|
|
147
314
|
|
|
148
315
|
std::string* convert(VALUE value)
|
|
149
316
|
{
|
|
150
|
-
detail::protect(rb_check_type, value, (int)
|
|
317
|
+
detail::protect(rb_check_type, value, (int)RUBY_T_STRING);
|
|
151
318
|
this->converted_ = std::string(RSTRING_PTR(value), RSTRING_LEN(value));
|
|
152
319
|
return &this->converted_;
|
|
153
320
|
}
|
|
154
321
|
|
|
155
322
|
private:
|
|
323
|
+
Arg* arg_ = nullptr;
|
|
156
324
|
std::string converted_;
|
|
157
325
|
};
|
|
158
326
|
}
|
data/rice/stl/string_view.ipp
CHANGED
data/rice/stl/tuple.ipp
CHANGED
|
@@ -19,42 +19,65 @@ namespace Rice::detail
|
|
|
19
19
|
auto indices = std::make_index_sequence<std::tuple_size_v<std::tuple<Types...>>>{};
|
|
20
20
|
return verifyTypes(indices);
|
|
21
21
|
}
|
|
22
|
+
|
|
23
|
+
static VALUE rubyKlass()
|
|
24
|
+
{
|
|
25
|
+
return rb_cArray;
|
|
26
|
+
}
|
|
22
27
|
};
|
|
23
28
|
|
|
24
29
|
template<typename...Types>
|
|
25
30
|
class To_Ruby<std::tuple<Types...>>
|
|
26
31
|
{
|
|
27
32
|
public:
|
|
28
|
-
|
|
33
|
+
To_Ruby() = default;
|
|
34
|
+
|
|
35
|
+
explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
|
|
36
|
+
{
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
VALUE convert(const std::tuple<Types...>& data)
|
|
29
40
|
{
|
|
30
41
|
Array result;
|
|
31
42
|
|
|
32
43
|
for_each_tuple(data, [&](auto element)
|
|
33
44
|
{
|
|
34
|
-
|
|
35
|
-
result.push<Element_T>((Element_T)element);
|
|
45
|
+
result.push(element, true);
|
|
36
46
|
});
|
|
37
47
|
|
|
38
48
|
return result.value();
|
|
39
49
|
}
|
|
50
|
+
|
|
51
|
+
private:
|
|
52
|
+
Return* returnInfo_ = nullptr;
|
|
40
53
|
};
|
|
41
54
|
|
|
42
55
|
template<typename...Types>
|
|
43
56
|
class To_Ruby<std::tuple<Types...>&>
|
|
44
57
|
{
|
|
45
58
|
public:
|
|
46
|
-
|
|
59
|
+
To_Ruby() = default;
|
|
60
|
+
|
|
61
|
+
explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
|
|
62
|
+
{
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
VALUE convert(const std::tuple<Types...>& data)
|
|
47
66
|
{
|
|
48
67
|
Array result;
|
|
49
68
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
69
|
+
bool isOwner = (this->returnInfo_ && this->returnInfo_->isOwner());
|
|
70
|
+
|
|
71
|
+
for_each_tuple(data, [&](auto& element)
|
|
72
|
+
{
|
|
73
|
+
result.push(element, isOwner);
|
|
74
|
+
});
|
|
55
75
|
|
|
56
76
|
return result.value();
|
|
57
77
|
}
|
|
78
|
+
|
|
79
|
+
private:
|
|
80
|
+
Return* returnInfo_ = nullptr;
|
|
58
81
|
};
|
|
59
82
|
|
|
60
83
|
template<typename...Types>
|
|
@@ -69,6 +92,12 @@ namespace Rice::detail
|
|
|
69
92
|
return (Type<std::tuple_element_t<I, Tuple_T>>::verify() && ...);
|
|
70
93
|
}
|
|
71
94
|
|
|
95
|
+
From_Ruby() = default;
|
|
96
|
+
|
|
97
|
+
explicit From_Ruby(Arg* arg)
|
|
98
|
+
{
|
|
99
|
+
}
|
|
100
|
+
|
|
72
101
|
Convertible is_convertible(VALUE value)
|
|
73
102
|
{
|
|
74
103
|
Convertible result = Convertible::None;
|
data/rice/stl/unique_ptr.ipp
CHANGED
|
@@ -30,6 +30,12 @@ namespace Rice::detail
|
|
|
30
30
|
class To_Ruby<std::unique_ptr<T>>
|
|
31
31
|
{
|
|
32
32
|
public:
|
|
33
|
+
To_Ruby() = default;
|
|
34
|
+
|
|
35
|
+
explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
|
|
36
|
+
{
|
|
37
|
+
}
|
|
38
|
+
|
|
33
39
|
VALUE convert(std::unique_ptr<T>& data)
|
|
34
40
|
{
|
|
35
41
|
std::pair<VALUE, rb_data_type_t*> rubyTypeInfo = detail::Registries::instance.types.figureType<T>(*data);
|
|
@@ -41,17 +47,29 @@ namespace Rice::detail
|
|
|
41
47
|
std::pair<VALUE, rb_data_type_t*> rubyTypeInfo = detail::Registries::instance.types.figureType<T>(*data);
|
|
42
48
|
return detail::wrap<std::unique_ptr<T>>(rubyTypeInfo.first, rubyTypeInfo.second, data, true);
|
|
43
49
|
}
|
|
50
|
+
|
|
51
|
+
private:
|
|
52
|
+
Return* returnInfo_ = nullptr;
|
|
44
53
|
};
|
|
45
54
|
|
|
46
55
|
template <typename T>
|
|
47
56
|
class To_Ruby<std::unique_ptr<T>&>
|
|
48
57
|
{
|
|
49
58
|
public:
|
|
59
|
+
To_Ruby() = default;
|
|
60
|
+
|
|
61
|
+
explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
|
|
62
|
+
{
|
|
63
|
+
}
|
|
64
|
+
|
|
50
65
|
VALUE convert(std::unique_ptr<T>& data)
|
|
51
66
|
{
|
|
52
67
|
std::pair<VALUE, rb_data_type_t*> rubyTypeInfo = detail::Registries::instance.types.figureType<T>(*data);
|
|
53
|
-
return detail::wrap<std::unique_ptr<T>>(rubyTypeInfo.first, rubyTypeInfo.second,
|
|
68
|
+
return detail::wrap<std::unique_ptr<T>>(rubyTypeInfo.first, rubyTypeInfo.second, data, true);
|
|
54
69
|
}
|
|
70
|
+
|
|
71
|
+
private:
|
|
72
|
+
Return* returnInfo_ = nullptr;
|
|
55
73
|
};
|
|
56
74
|
|
|
57
75
|
template <typename T>
|
|
@@ -64,6 +82,12 @@ namespace Rice::detail
|
|
|
64
82
|
return dynamic_cast<Wrapper<std::unique_ptr<T>>*>(wrapper);
|
|
65
83
|
}
|
|
66
84
|
|
|
85
|
+
From_Ruby() = default;
|
|
86
|
+
|
|
87
|
+
explicit From_Ruby(Arg* arg)
|
|
88
|
+
{
|
|
89
|
+
}
|
|
90
|
+
|
|
67
91
|
Convertible is_convertible(VALUE value)
|
|
68
92
|
{
|
|
69
93
|
if (!is_same_smart_ptr(value))
|
|
@@ -101,6 +125,12 @@ namespace Rice::detail
|
|
|
101
125
|
return dynamic_cast<Wrapper<std::unique_ptr<T>>*>(wrapper);
|
|
102
126
|
}
|
|
103
127
|
|
|
128
|
+
From_Ruby() = default;
|
|
129
|
+
|
|
130
|
+
explicit From_Ruby(Arg* arg)
|
|
131
|
+
{
|
|
132
|
+
}
|
|
133
|
+
|
|
104
134
|
Convertible is_convertible(VALUE value)
|
|
105
135
|
{
|
|
106
136
|
if (!is_same_smart_ptr(value))
|
|
@@ -133,7 +163,21 @@ namespace Rice::detail
|
|
|
133
163
|
{
|
|
134
164
|
static bool verify()
|
|
135
165
|
{
|
|
136
|
-
|
|
166
|
+
if constexpr (std::is_fundamental_v<T>)
|
|
167
|
+
{
|
|
168
|
+
return Type<Pointer<T>>::verify();
|
|
169
|
+
return Type<Buffer<T>>::verify();
|
|
170
|
+
}
|
|
171
|
+
else
|
|
172
|
+
{
|
|
173
|
+
return Type<T>::verify();
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
static VALUE rubyKlass()
|
|
178
|
+
{
|
|
179
|
+
TypeMapper<T> typeMapper;
|
|
180
|
+
return typeMapper.rubyKlass();
|
|
137
181
|
}
|
|
138
182
|
};
|
|
139
183
|
}
|
data/rice/stl/unordered_map.ipp
CHANGED
|
@@ -19,8 +19,7 @@ namespace Rice
|
|
|
19
19
|
UnorderedMapHelper(Data_Type<T> klass) : klass_(klass)
|
|
20
20
|
{
|
|
21
21
|
this->register_pair();
|
|
22
|
-
this->
|
|
23
|
-
this->define_copyable_methods();
|
|
22
|
+
this->define_constructors();
|
|
24
23
|
this->define_capacity_methods();
|
|
25
24
|
this->define_access_methods();
|
|
26
25
|
this->define_comparable_methods();
|
|
@@ -37,27 +36,13 @@ namespace Rice
|
|
|
37
36
|
define_pair<const Key_T, T>();
|
|
38
37
|
}
|
|
39
38
|
|
|
40
|
-
void
|
|
39
|
+
void define_constructors()
|
|
41
40
|
{
|
|
42
41
|
klass_.define_constructor(Constructor<T>());
|
|
43
|
-
}
|
|
44
42
|
|
|
45
|
-
|
|
46
|
-
{
|
|
47
|
-
if constexpr (std::is_copy_constructible_v<Value_T>)
|
|
48
|
-
{
|
|
49
|
-
klass_.define_method("copy", [](T& unordered_map) -> T
|
|
50
|
-
{
|
|
51
|
-
return unordered_map;
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
else
|
|
43
|
+
if constexpr (std::is_copy_constructible_v<Key_T> && std::is_copy_constructible_v<Value_T>)
|
|
55
44
|
{
|
|
56
|
-
klass_.
|
|
57
|
-
{
|
|
58
|
-
throw std::runtime_error("Cannot copy unordered_maps with non-copy constructible types");
|
|
59
|
-
return unordered_map;
|
|
60
|
-
});
|
|
45
|
+
klass_.define_constructor(Constructor<T, const T&>());
|
|
61
46
|
}
|
|
62
47
|
}
|
|
63
48
|
|
|
@@ -240,8 +225,8 @@ namespace Rice
|
|
|
240
225
|
|
|
241
226
|
if (klassName.empty())
|
|
242
227
|
{
|
|
243
|
-
|
|
244
|
-
klassName =
|
|
228
|
+
detail::TypeMapper<UnorderedMap_T> typeMapper;
|
|
229
|
+
klassName = typeMapper.rubyName();
|
|
245
230
|
}
|
|
246
231
|
|
|
247
232
|
Module rb_mStd = define_module("Std");
|
|
@@ -418,6 +403,12 @@ namespace Rice
|
|
|
418
403
|
class From_Ruby<std::unordered_map<T, U>*>
|
|
419
404
|
{
|
|
420
405
|
public:
|
|
406
|
+
From_Ruby() = default;
|
|
407
|
+
|
|
408
|
+
explicit From_Ruby(Arg* arg) : arg_(arg)
|
|
409
|
+
{
|
|
410
|
+
}
|
|
411
|
+
|
|
421
412
|
Convertible is_convertible(VALUE value)
|
|
422
413
|
{
|
|
423
414
|
switch (rb_type(value))
|
|
@@ -463,6 +454,7 @@ namespace Rice
|
|
|
463
454
|
}
|
|
464
455
|
|
|
465
456
|
private:
|
|
457
|
+
Arg* arg_;
|
|
466
458
|
std::unordered_map<T, U> converted_;
|
|
467
459
|
};
|
|
468
460
|
}
|
data/rice/stl/variant.ipp
CHANGED
|
@@ -13,27 +13,37 @@ namespace Rice::detail
|
|
|
13
13
|
return (Type<std::tuple_element_t<I, Tuple_T>>::verify() && ...);
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
template<std::size_t... I>
|
|
17
16
|
constexpr static bool verify()
|
|
18
17
|
{
|
|
19
18
|
auto indices = std::make_index_sequence<std::variant_size_v<std::variant<Types...>>>{};
|
|
20
19
|
return verifyTypes(indices);
|
|
21
20
|
}
|
|
21
|
+
|
|
22
|
+
static VALUE rubyKlass()
|
|
23
|
+
{
|
|
24
|
+
// There is no direct mapping to Ruby, so just return Object
|
|
25
|
+
return rb_cObject;
|
|
26
|
+
}
|
|
22
27
|
};
|
|
23
28
|
|
|
24
29
|
template<typename...Types>
|
|
25
30
|
class To_Ruby<std::variant<Types...>>
|
|
26
31
|
{
|
|
27
32
|
public:
|
|
33
|
+
To_Ruby() = default;
|
|
34
|
+
|
|
35
|
+
explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
|
|
36
|
+
{
|
|
37
|
+
}
|
|
28
38
|
|
|
29
39
|
template<typename U, typename V>
|
|
30
|
-
|
|
40
|
+
VALUE convertElement(U& data, bool takeOwnership)
|
|
31
41
|
{
|
|
32
42
|
return To_Ruby<V>().convert(std::forward<V>(std::get<V>(data)));
|
|
33
43
|
}
|
|
34
44
|
|
|
35
45
|
template<typename U, std::size_t... I>
|
|
36
|
-
|
|
46
|
+
VALUE convertIterator(U& data, bool takeOwnership, std::index_sequence<I...>& indices)
|
|
37
47
|
{
|
|
38
48
|
// Create a tuple of the variant types so we can look over the tuple's types
|
|
39
49
|
using Tuple_T = std::tuple<Types...>;
|
|
@@ -76,26 +86,36 @@ namespace Rice::detail
|
|
|
76
86
|
}
|
|
77
87
|
|
|
78
88
|
template<typename U>
|
|
79
|
-
|
|
89
|
+
VALUE convert(U& data)
|
|
80
90
|
{
|
|
81
91
|
auto indices = std::make_index_sequence<std::variant_size_v<std::variant<Types...>>>{};
|
|
82
|
-
return convertIterator(data,
|
|
92
|
+
return convertIterator(data, true, indices);
|
|
83
93
|
}
|
|
84
94
|
|
|
85
95
|
template<typename U>
|
|
86
|
-
|
|
96
|
+
VALUE convert(U&& data)
|
|
87
97
|
{
|
|
98
|
+
bool isOwner = true;
|
|
88
99
|
auto indices = std::make_index_sequence<std::variant_size_v<std::variant<Types...>>>{};
|
|
89
|
-
return convertIterator(data,
|
|
100
|
+
return convertIterator(data, isOwner, indices);
|
|
90
101
|
}
|
|
102
|
+
|
|
103
|
+
private:
|
|
104
|
+
Return* returnInfo_ = nullptr;
|
|
91
105
|
};
|
|
92
106
|
|
|
93
107
|
template<typename...Types>
|
|
94
108
|
class To_Ruby<std::variant<Types...>&>
|
|
95
109
|
{
|
|
96
110
|
public:
|
|
111
|
+
To_Ruby() = default;
|
|
112
|
+
|
|
113
|
+
explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
|
|
114
|
+
{
|
|
115
|
+
}
|
|
116
|
+
|
|
97
117
|
template<typename U, typename V>
|
|
98
|
-
|
|
118
|
+
VALUE convertElement(U& data, bool takeOwnership)
|
|
99
119
|
{
|
|
100
120
|
if constexpr (std::is_const_v<U>)
|
|
101
121
|
{
|
|
@@ -108,7 +128,7 @@ namespace Rice::detail
|
|
|
108
128
|
}
|
|
109
129
|
|
|
110
130
|
template<typename U, std::size_t... I>
|
|
111
|
-
|
|
131
|
+
VALUE convertIterator(U& data, bool takeOwnership, std::index_sequence<I...>& indices)
|
|
112
132
|
{
|
|
113
133
|
// Create a tuple of the variant types so we can look over the tuple's types
|
|
114
134
|
using Tuple_T = std::tuple<Types...>;
|
|
@@ -132,17 +152,27 @@ namespace Rice::detail
|
|
|
132
152
|
}
|
|
133
153
|
|
|
134
154
|
template<typename U>
|
|
135
|
-
|
|
155
|
+
VALUE convert(U& data)
|
|
136
156
|
{
|
|
157
|
+
bool isOwner = (this->returnInfo_ && this->returnInfo_->isOwner());
|
|
137
158
|
auto indices = std::make_index_sequence<std::variant_size_v<std::variant<Types...>>>{};
|
|
138
|
-
return convertIterator(data,
|
|
159
|
+
return convertIterator(data, isOwner, indices);
|
|
139
160
|
}
|
|
161
|
+
|
|
162
|
+
private:
|
|
163
|
+
Return* returnInfo_ = nullptr;
|
|
140
164
|
};
|
|
141
165
|
|
|
142
166
|
template<typename...Types>
|
|
143
167
|
class From_Ruby<std::variant<Types...>>
|
|
144
168
|
{
|
|
145
169
|
public:
|
|
170
|
+
From_Ruby() = default;
|
|
171
|
+
|
|
172
|
+
explicit From_Ruby(Arg* arg)
|
|
173
|
+
{
|
|
174
|
+
}
|
|
175
|
+
|
|
146
176
|
Convertible is_convertible(VALUE value)
|
|
147
177
|
{
|
|
148
178
|
Convertible result = Convertible::None;
|
|
@@ -229,6 +259,12 @@ namespace Rice::detail
|
|
|
229
259
|
class From_Ruby<std::variant<Types...>&> : public From_Ruby<std::variant<Types...>>
|
|
230
260
|
{
|
|
231
261
|
public:
|
|
262
|
+
From_Ruby() = default;
|
|
263
|
+
|
|
264
|
+
explicit From_Ruby(Arg* arg)
|
|
265
|
+
{
|
|
266
|
+
}
|
|
267
|
+
|
|
232
268
|
std::variant<Types...>& convert(VALUE value)
|
|
233
269
|
{
|
|
234
270
|
int index = this->figureIndex(value);
|