rice 4.6.0 → 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 +41 -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 +5221 -4009
- data/include/rice/stl.hpp +822 -295
- 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 +77 -28
- data/rice/Buffer.ipp +500 -183
- data/rice/Data_Object.ipp +101 -82
- data/rice/Data_Type.hpp +7 -6
- data/rice/Data_Type.ipp +77 -47
- 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 +73 -8
- data/rice/detail/NativeAttributeSet.hpp +4 -0
- data/rice/detail/NativeAttributeSet.ipp +33 -23
- data/rice/detail/NativeCallbackFFI.ipp +3 -2
- data/rice/detail/NativeCallbackSimple.ipp +1 -1
- data/rice/detail/NativeFunction.hpp +11 -49
- data/rice/detail/NativeFunction.ipp +83 -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 +150 -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 +182 -104
- data/rice/stl.hpp +1 -0
- data/rice/traits/attribute_traits.hpp +6 -6
- data/rice/traits/function_traits.hpp +2 -2
- data/rice/traits/method_traits.hpp +5 -16
- data/rice/traits/rice_traits.hpp +36 -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 +244 -10
- data/test/test_Buffer.cpp +344 -13
- 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 +89 -82
- 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 -76
- 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/vector.ipp
CHANGED
|
@@ -38,12 +38,10 @@ namespace Rice
|
|
|
38
38
|
// Helper method to translate Ruby indices to vector indices
|
|
39
39
|
Difference_T normalizeIndex(Size_T size, Difference_T index, bool enforceBounds = false)
|
|
40
40
|
{
|
|
41
|
-
// Negative indices mean count from the right
|
|
42
|
-
|
|
43
|
-
if (index < 0)
|
|
41
|
+
// Negative indices mean count from the right
|
|
42
|
+
if (index < 0 && (-index <= size))
|
|
44
43
|
{
|
|
45
|
-
index =
|
|
46
|
-
index = index > 0 ? size - index : index;
|
|
44
|
+
index = size + index;
|
|
47
45
|
}
|
|
48
46
|
|
|
49
47
|
if (enforceBounds && (index < 0 || index >= (Difference_T)size))
|
|
@@ -56,9 +54,13 @@ namespace Rice
|
|
|
56
54
|
|
|
57
55
|
void define_constructors()
|
|
58
56
|
{
|
|
59
|
-
klass_.define_constructor(Constructor<T>())
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
klass_.define_constructor(Constructor<T>());
|
|
58
|
+
|
|
59
|
+
if constexpr (std::is_copy_constructible_v<Value_T>)
|
|
60
|
+
{
|
|
61
|
+
klass_.define_constructor(Constructor<T, const T&>())
|
|
62
|
+
.define_constructor(Constructor<T, Size_T, const Parameter_T>());
|
|
63
|
+
}
|
|
62
64
|
|
|
63
65
|
if constexpr (std::is_default_constructible_v<Value_T>)
|
|
64
66
|
{
|
|
@@ -120,19 +122,21 @@ namespace Rice
|
|
|
120
122
|
|
|
121
123
|
void define_access_methods()
|
|
122
124
|
{
|
|
123
|
-
|
|
124
|
-
klass_.define_method("first", [](const T& vector) -> std::optional<Value_T>
|
|
125
|
+
if constexpr (!std::is_same_v<Value_T, bool>)
|
|
125
126
|
{
|
|
126
|
-
|
|
127
|
+
// Access methods
|
|
128
|
+
klass_.define_method("first", [](T& vector) -> std::optional<std::reference_wrapper<Value_T>>
|
|
127
129
|
{
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
130
|
+
if (vector.size() > 0)
|
|
131
|
+
{
|
|
132
|
+
return vector.front();
|
|
133
|
+
}
|
|
134
|
+
else
|
|
135
|
+
{
|
|
136
|
+
return std::nullopt;
|
|
137
|
+
}
|
|
138
|
+
})
|
|
139
|
+
.define_method("last", [](T& vector) -> std::optional<std::reference_wrapper<Value_T>>
|
|
136
140
|
{
|
|
137
141
|
if (vector.size() > 0)
|
|
138
142
|
{
|
|
@@ -143,7 +147,7 @@ namespace Rice
|
|
|
143
147
|
return std::nullopt;
|
|
144
148
|
}
|
|
145
149
|
})
|
|
146
|
-
|
|
150
|
+
.define_method("[]", [this](T& vector, Difference_T index) -> std::optional<std::reference_wrapper<Value_T>>
|
|
147
151
|
{
|
|
148
152
|
index = normalizeIndex(vector.size(), index);
|
|
149
153
|
if (index < 0 || index >= (Difference_T)vector.size())
|
|
@@ -155,46 +159,80 @@ namespace Rice
|
|
|
155
159
|
return vector[index];
|
|
156
160
|
}
|
|
157
161
|
})
|
|
158
|
-
|
|
162
|
+
.template define_method<Value_T*(T::*)()>("data", &T::data, Return().setBuffer());
|
|
163
|
+
}
|
|
164
|
+
else
|
|
165
|
+
{
|
|
166
|
+
// Access methods
|
|
167
|
+
klass_.define_method("first", [](T& vector) -> std::optional<Value_T>
|
|
168
|
+
{
|
|
169
|
+
if (vector.size() > 0)
|
|
170
|
+
{
|
|
171
|
+
return vector.front();
|
|
172
|
+
}
|
|
173
|
+
else
|
|
174
|
+
{
|
|
175
|
+
return std::nullopt;
|
|
176
|
+
}
|
|
177
|
+
})
|
|
178
|
+
.define_method("last", [](T& vector) -> std::optional<Value_T>
|
|
179
|
+
{
|
|
180
|
+
if (vector.size() > 0)
|
|
181
|
+
{
|
|
182
|
+
return vector.back();
|
|
183
|
+
}
|
|
184
|
+
else
|
|
185
|
+
{
|
|
186
|
+
return std::nullopt;
|
|
187
|
+
}
|
|
188
|
+
})
|
|
189
|
+
.define_method("[]", [this](T& vector, Difference_T index) -> std::optional<Value_T>
|
|
159
190
|
{
|
|
160
|
-
|
|
161
|
-
if (
|
|
191
|
+
index = normalizeIndex(vector.size(), index);
|
|
192
|
+
if (index < 0 || index >= (Difference_T)vector.size())
|
|
162
193
|
{
|
|
163
|
-
return
|
|
194
|
+
return std::nullopt;
|
|
164
195
|
}
|
|
165
196
|
else
|
|
166
197
|
{
|
|
167
|
-
|
|
198
|
+
return vector[index];
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
}
|
|
168
202
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
203
|
+
klass_.define_method("[]", [this](T& vector, Difference_T start, Difference_T length) -> VALUE
|
|
204
|
+
{
|
|
205
|
+
start = normalizeIndex(vector.size(), start);
|
|
206
|
+
if (start < 0 || start >= (Difference_T)vector.size())
|
|
207
|
+
{
|
|
208
|
+
return rb_ary_new();
|
|
209
|
+
}
|
|
210
|
+
else
|
|
211
|
+
{
|
|
212
|
+
auto begin = vector.begin() + start;
|
|
175
213
|
|
|
176
|
-
|
|
177
|
-
|
|
214
|
+
// Ruby does not throw an exception when the length is too long
|
|
215
|
+
Difference_T size = (Difference_T)vector.size();
|
|
216
|
+
if (start + length > size)
|
|
217
|
+
{
|
|
218
|
+
length = size - start;
|
|
219
|
+
}
|
|
178
220
|
|
|
179
|
-
|
|
180
|
-
std::for_each(slice.begin(), slice.end(), [&result](const Reference_T element)
|
|
181
|
-
{
|
|
182
|
-
VALUE value = detail::To_Ruby<Parameter_T>().convert(element);
|
|
183
|
-
rb_ary_push(result, value);
|
|
184
|
-
});
|
|
221
|
+
auto finish = vector.begin() + start + length;
|
|
185
222
|
|
|
186
|
-
|
|
223
|
+
VALUE result = rb_ary_new();
|
|
224
|
+
for (auto iter = begin; iter != finish; iter++)
|
|
225
|
+
{
|
|
226
|
+
const Reference_T element = *iter;
|
|
227
|
+
VALUE value = detail::To_Ruby<Reference_T>().convert(element);
|
|
228
|
+
rb_ary_push(result, value);
|
|
187
229
|
}
|
|
188
|
-
}, Return().setValue());
|
|
189
230
|
|
|
190
|
-
|
|
191
|
-
{
|
|
192
|
-
define_buffer<Value_T>();
|
|
193
|
-
define_buffer<Value_T*>();
|
|
194
|
-
klass_.template define_method<Value_T*(T::*)()>("data", &T::data);
|
|
231
|
+
return result;
|
|
195
232
|
}
|
|
233
|
+
}, Return().setValue());
|
|
196
234
|
|
|
197
|
-
|
|
235
|
+
rb_define_alias(klass_, "at", "[]");
|
|
198
236
|
}
|
|
199
237
|
|
|
200
238
|
// Methods that require Value_T to support operator==
|
|
@@ -203,35 +241,39 @@ namespace Rice
|
|
|
203
241
|
if constexpr (detail::is_comparable_v<T>)
|
|
204
242
|
{
|
|
205
243
|
klass_.define_method("delete", [](T& vector, Parameter_T element) -> std::optional<Value_T>
|
|
244
|
+
{
|
|
245
|
+
auto iter = std::find(vector.begin(), vector.end(), element);
|
|
246
|
+
if (iter == vector.end())
|
|
206
247
|
{
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
return std::nullopt;
|
|
211
|
-
}
|
|
212
|
-
else
|
|
213
|
-
{
|
|
214
|
-
Value_T result = *iter;
|
|
215
|
-
vector.erase(iter);
|
|
216
|
-
return result;
|
|
217
|
-
}
|
|
218
|
-
})
|
|
219
|
-
.define_method("include?", [](T& vector, Parameter_T element)
|
|
248
|
+
return std::nullopt;
|
|
249
|
+
}
|
|
250
|
+
else if constexpr (std::is_copy_assignable_v<Value_T>)
|
|
220
251
|
{
|
|
221
|
-
|
|
222
|
-
|
|
252
|
+
Value_T result = *iter;
|
|
253
|
+
vector.erase(iter);
|
|
254
|
+
return result;
|
|
255
|
+
}
|
|
256
|
+
else
|
|
257
|
+
{
|
|
258
|
+
return std::nullopt;
|
|
259
|
+
}
|
|
260
|
+
})
|
|
261
|
+
.define_method("include?", [](T& vector, Parameter_T element)
|
|
262
|
+
{
|
|
263
|
+
return std::find(vector.begin(), vector.end(), element) != vector.end();
|
|
264
|
+
})
|
|
223
265
|
.define_method("index", [](T& vector, Parameter_T element) -> std::optional<Difference_T>
|
|
266
|
+
{
|
|
267
|
+
auto iter = std::find(vector.begin(), vector.end(), element);
|
|
268
|
+
if (iter == vector.end())
|
|
224
269
|
{
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
return iter - vector.begin();
|
|
233
|
-
}
|
|
234
|
-
});
|
|
270
|
+
return std::nullopt;
|
|
271
|
+
}
|
|
272
|
+
else
|
|
273
|
+
{
|
|
274
|
+
return iter - vector.begin();
|
|
275
|
+
}
|
|
276
|
+
});
|
|
235
277
|
}
|
|
236
278
|
else
|
|
237
279
|
{
|
|
@@ -253,45 +295,65 @@ namespace Rice
|
|
|
253
295
|
void define_modify_methods()
|
|
254
296
|
{
|
|
255
297
|
klass_.define_method("clear", &T::clear)
|
|
256
|
-
.define_method("delete_at", [](T& vector, const size_t& pos)
|
|
298
|
+
.define_method("delete_at", [](T& vector, const size_t& pos) -> std::optional<Value_T>
|
|
299
|
+
{
|
|
300
|
+
auto iter = vector.begin() + pos;
|
|
301
|
+
|
|
302
|
+
if constexpr (std::is_copy_assignable_v<Value_T>)
|
|
257
303
|
{
|
|
258
|
-
auto iter = vector.begin() + pos;
|
|
259
304
|
Value_T result = *iter;
|
|
260
305
|
vector.erase(iter);
|
|
261
306
|
return result;
|
|
262
|
-
}
|
|
307
|
+
}
|
|
308
|
+
else
|
|
309
|
+
{
|
|
310
|
+
vector.erase(iter);
|
|
311
|
+
return std::nullopt;
|
|
312
|
+
}
|
|
313
|
+
})
|
|
263
314
|
.define_method("insert", [this](T& vector, Difference_T index, Parameter_T element) -> T&
|
|
315
|
+
{
|
|
316
|
+
int normalized = normalizeIndex(vector.size(), index, true);
|
|
317
|
+
// For a Ruby array a positive index means insert the element before the index. But
|
|
318
|
+
// a negative index means insert the element *after* the index. std::vector
|
|
319
|
+
// inserts *before* the index. So add 1 if this is a negative index.
|
|
320
|
+
if (index < 0)
|
|
264
321
|
{
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
322
|
+
normalized++;
|
|
323
|
+
}
|
|
324
|
+
auto iter = vector.begin() + normalized;
|
|
325
|
+
vector.insert(iter, std::move(element));
|
|
326
|
+
return vector;
|
|
327
|
+
})
|
|
270
328
|
.define_method("pop", [](T& vector) -> std::optional<Value_T>
|
|
329
|
+
{
|
|
330
|
+
if constexpr (!std::is_copy_assignable_v<Value_T>)
|
|
271
331
|
{
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
return result;
|
|
277
|
-
}
|
|
278
|
-
else
|
|
279
|
-
{
|
|
280
|
-
return std::nullopt;
|
|
281
|
-
}
|
|
282
|
-
})
|
|
283
|
-
.define_method("push", [](T& vector, Parameter_T element) -> T&
|
|
332
|
+
vector.pop_back();
|
|
333
|
+
return std::nullopt;
|
|
334
|
+
}
|
|
335
|
+
else if (vector.empty())
|
|
284
336
|
{
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
.define_method("shrink_to_fit", &T::shrink_to_fit)
|
|
289
|
-
.define_method("[]=", [this](T& vector, Difference_T index, Parameter_T element) -> Parameter_T
|
|
337
|
+
return std::nullopt;
|
|
338
|
+
}
|
|
339
|
+
else
|
|
290
340
|
{
|
|
291
|
-
|
|
292
|
-
vector
|
|
293
|
-
return
|
|
294
|
-
}
|
|
341
|
+
Value_T result = vector.back();
|
|
342
|
+
vector.pop_back();
|
|
343
|
+
return result;
|
|
344
|
+
}
|
|
345
|
+
})
|
|
346
|
+
.define_method("push", [](T& vector, Parameter_T element) -> T&
|
|
347
|
+
{
|
|
348
|
+
vector.push_back(std::move(element));
|
|
349
|
+
return vector;
|
|
350
|
+
})
|
|
351
|
+
.define_method("shrink_to_fit", &T::shrink_to_fit)
|
|
352
|
+
.define_method("[]=", [this](T& vector, Difference_T index, Parameter_T element) -> void
|
|
353
|
+
{
|
|
354
|
+
index = normalizeIndex(vector.size(), index, true);
|
|
355
|
+
vector[index] = std::move(element);
|
|
356
|
+
});
|
|
295
357
|
|
|
296
358
|
rb_define_alias(klass_, "push_back", "push");
|
|
297
359
|
rb_define_alias(klass_, "<<", "push");
|
|
@@ -312,7 +374,7 @@ namespace Rice
|
|
|
312
374
|
VALUE result = rb_ary_new();
|
|
313
375
|
std::for_each(vector.begin(), vector.end(), [&result](const Reference_T element)
|
|
314
376
|
{
|
|
315
|
-
VALUE value = detail::To_Ruby<
|
|
377
|
+
VALUE value = detail::To_Ruby<Reference_T>().convert(element);
|
|
316
378
|
rb_ary_push(result, value);
|
|
317
379
|
});
|
|
318
380
|
|
|
@@ -370,8 +432,8 @@ namespace Rice
|
|
|
370
432
|
|
|
371
433
|
if (klassName.empty())
|
|
372
434
|
{
|
|
373
|
-
|
|
374
|
-
klassName =
|
|
435
|
+
detail::TypeMapper<Vector_T> typeMapper;
|
|
436
|
+
klassName = typeMapper.rubyName();
|
|
375
437
|
}
|
|
376
438
|
|
|
377
439
|
Module rb_mStd = define_module("Std");
|
|
@@ -523,6 +585,12 @@ namespace Rice
|
|
|
523
585
|
class From_Ruby<std::vector<T>*>
|
|
524
586
|
{
|
|
525
587
|
public:
|
|
588
|
+
From_Ruby() = default;
|
|
589
|
+
|
|
590
|
+
explicit From_Ruby(Arg* arg) : arg_(arg)
|
|
591
|
+
{
|
|
592
|
+
}
|
|
593
|
+
|
|
526
594
|
Convertible is_convertible(VALUE value)
|
|
527
595
|
{
|
|
528
596
|
switch (rb_type(value))
|
|
@@ -570,6 +638,7 @@ namespace Rice
|
|
|
570
638
|
}
|
|
571
639
|
|
|
572
640
|
private:
|
|
641
|
+
Arg* arg_;
|
|
573
642
|
std::vector<T> converted_;
|
|
574
643
|
};
|
|
575
644
|
}
|
|
@@ -581,10 +650,19 @@ namespace Rice
|
|
|
581
650
|
class To_Ruby<std::vector<bool>::reference>
|
|
582
651
|
{
|
|
583
652
|
public:
|
|
653
|
+
To_Ruby() = default;
|
|
654
|
+
|
|
655
|
+
explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
|
|
656
|
+
{
|
|
657
|
+
}
|
|
658
|
+
|
|
584
659
|
VALUE convert(const std::vector<bool>::reference& value)
|
|
585
660
|
{
|
|
586
661
|
return value ? Qtrue : Qfalse;
|
|
587
662
|
}
|
|
663
|
+
|
|
664
|
+
private:
|
|
665
|
+
Return* returnInfo_ = nullptr;
|
|
588
666
|
};
|
|
589
667
|
}
|
|
590
668
|
}
|
data/rice/stl.hpp
CHANGED
|
@@ -9,17 +9,17 @@ namespace Rice::detail
|
|
|
9
9
|
template<typename Attribute_T>
|
|
10
10
|
struct attribute_traits;
|
|
11
11
|
|
|
12
|
-
template<typename
|
|
13
|
-
struct attribute_traits<
|
|
12
|
+
template<typename Attribute_T>
|
|
13
|
+
struct attribute_traits<Attribute_T*>
|
|
14
14
|
{
|
|
15
|
-
using attr_type =
|
|
15
|
+
using attr_type = Attribute_T;
|
|
16
16
|
using class_type = std::nullptr_t;
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
-
template<typename
|
|
20
|
-
struct attribute_traits<
|
|
19
|
+
template<typename Attribute_T, typename Class_T>
|
|
20
|
+
struct attribute_traits<Attribute_T(Class_T::*)>
|
|
21
21
|
{
|
|
22
|
-
using attr_type =
|
|
22
|
+
using attr_type = Attribute_T;
|
|
23
23
|
using class_type = Class_T;
|
|
24
24
|
};
|
|
25
25
|
}
|
|
@@ -17,7 +17,7 @@ namespace Rice::detail
|
|
|
17
17
|
static constexpr std::size_t arity = sizeof...(Arg_Ts);
|
|
18
18
|
|
|
19
19
|
template<std::size_t N>
|
|
20
|
-
using nth_arg = typename std::
|
|
20
|
+
using nth_arg = typename std::tuple_element_t<N, arg_types>;
|
|
21
21
|
|
|
22
22
|
using return_type = Return_T;
|
|
23
23
|
using class_type = Class_T;
|
|
@@ -32,7 +32,7 @@ namespace Rice::detail
|
|
|
32
32
|
|
|
33
33
|
public:
|
|
34
34
|
using arg_types = typename functor_t::arg_types;
|
|
35
|
-
static constexpr std::size_t arity = functor_t::arity
|
|
35
|
+
static constexpr std::size_t arity = functor_t::arity;
|
|
36
36
|
using class_type = std::nullptr_t;
|
|
37
37
|
};
|
|
38
38
|
|
|
@@ -6,26 +6,15 @@
|
|
|
6
6
|
namespace Rice::detail
|
|
7
7
|
{
|
|
8
8
|
// Declare struct
|
|
9
|
-
template<typename Function_T,
|
|
9
|
+
template<typename Function_T, typename = void>
|
|
10
10
|
struct method_traits;
|
|
11
11
|
|
|
12
|
-
// Functions that do not have a self parameter:
|
|
13
|
-
// doSomething(int a)
|
|
14
|
-
template<typename Function_T, bool IsMethod>
|
|
15
|
-
struct method_traits<Function_T, IsMethod, std::enable_if_t<!IsMethod>>
|
|
16
|
-
{
|
|
17
|
-
using Return_T = typename function_traits<Function_T>::return_type;
|
|
18
|
-
using Class_T = std::nullptr_t;
|
|
19
|
-
using Arg_Ts = typename function_traits<Function_T>::arg_types;
|
|
20
|
-
static constexpr std::size_t arity = std::tuple_size_v<Arg_Ts>;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
12
|
/* Functions that have a self parameter and thus we treat them as free standing
|
|
24
13
|
"methods" versus member functions.
|
|
25
14
|
|
|
26
15
|
doSomething(VALUE self, int a) */
|
|
27
|
-
template<typename Function_T
|
|
28
|
-
struct method_traits<Function_T,
|
|
16
|
+
template<typename Function_T>
|
|
17
|
+
struct method_traits<Function_T, std::enable_if_t<std::is_same_v<typename function_traits<Function_T>::class_type, std::nullptr_t>>>
|
|
29
18
|
{
|
|
30
19
|
using Return_T = typename function_traits<Function_T>::return_type;
|
|
31
20
|
using Class_T = typename function_traits<Function_T>::template nth_arg<0>;
|
|
@@ -35,8 +24,8 @@ namespace Rice::detail
|
|
|
35
24
|
|
|
36
25
|
// Member functions that have an implied self parameter of an object instance
|
|
37
26
|
// foo.doSomething(int a)
|
|
38
|
-
template<typename Function_T
|
|
39
|
-
struct method_traits<Function_T,
|
|
27
|
+
template<typename Function_T>
|
|
28
|
+
struct method_traits<Function_T, std::enable_if_t<!std::is_same_v<typename function_traits<Function_T>::class_type, std::nullptr_t>>>
|
|
40
29
|
{
|
|
41
30
|
using Return_T = typename function_traits<Function_T>::return_type;
|
|
42
31
|
using Class_T = typename function_traits<Function_T>::class_type;
|
data/rice/traits/rice_traits.hpp
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
#define Rice__detail__traits__hpp_
|
|
3
3
|
|
|
4
4
|
#include <ostream>
|
|
5
|
+
#include <tuple>
|
|
5
6
|
#include <type_traits>
|
|
6
7
|
#include <variant>
|
|
7
8
|
#include <vector>
|
|
@@ -49,11 +50,11 @@ namespace Rice
|
|
|
49
50
|
using type = typename remove_cv_recursive<T>::type&;
|
|
50
51
|
};
|
|
51
52
|
|
|
52
|
-
|
|
53
|
+
template<typename T>
|
|
53
54
|
struct remove_cv_recursive<T&&>
|
|
54
55
|
{
|
|
55
56
|
using type = typename remove_cv_recursive<T>::type&&;
|
|
56
|
-
}
|
|
57
|
+
};
|
|
57
58
|
|
|
58
59
|
template<typename T>
|
|
59
60
|
struct remove_cv_recursive<T*>
|
|
@@ -99,6 +100,16 @@ namespace Rice
|
|
|
99
100
|
static const bool value = is_comparable_v<T>;
|
|
100
101
|
};
|
|
101
102
|
|
|
103
|
+
template<typename>
|
|
104
|
+
struct is_std_vector : std::false_type {};
|
|
105
|
+
|
|
106
|
+
template<typename T, typename A>
|
|
107
|
+
struct is_std_vector<std::vector<T, A>> : std::true_type {};
|
|
108
|
+
|
|
109
|
+
template <typename T>
|
|
110
|
+
constexpr bool is_std_vector_v = is_std_vector<T>::value;
|
|
111
|
+
|
|
112
|
+
|
|
102
113
|
// -- Tuple Helpers ---
|
|
103
114
|
template<typename T>
|
|
104
115
|
struct tuple_shift;
|
|
@@ -108,16 +119,26 @@ namespace Rice
|
|
|
108
119
|
{
|
|
109
120
|
using type = std::tuple<Arg_Ts...>;
|
|
110
121
|
};
|
|
111
|
-
|
|
122
|
+
|
|
123
|
+
template<typename T, typename...Arg_Ts>
|
|
124
|
+
struct tuple_unshift;
|
|
125
|
+
|
|
126
|
+
template<typename T, typename...Arg_Ts>
|
|
127
|
+
struct tuple_unshift<T, std::tuple<Arg_Ts...>>
|
|
128
|
+
{
|
|
129
|
+
using type = std::tuple<T, Arg_Ts...>;
|
|
130
|
+
};
|
|
131
|
+
|
|
112
132
|
template<template<typename, typename...> typename T, typename...Arg_Ts>
|
|
113
133
|
struct tuple_map;
|
|
114
134
|
|
|
115
135
|
template<template<typename, typename...> typename T, typename...Arg_Ts>
|
|
116
136
|
struct tuple_map<T, std::tuple<Arg_Ts...>>
|
|
117
137
|
{
|
|
118
|
-
using type = std::tuple<T<
|
|
138
|
+
using type = std::tuple<T<Arg_Ts>...>;
|
|
119
139
|
};
|
|
120
140
|
|
|
141
|
+
|
|
121
142
|
template<typename...Arg_Ts>
|
|
122
143
|
struct tuple_to_variant;
|
|
123
144
|
|
|
@@ -154,6 +175,17 @@ namespace Rice
|
|
|
154
175
|
(callable(std::forward<decltype(args)>(args)), ...);
|
|
155
176
|
}, std::forward<Tuple_T>(tuple));
|
|
156
177
|
}
|
|
178
|
+
|
|
179
|
+
template<typename T, typename = void>
|
|
180
|
+
struct is_wrapped : std::true_type {};
|
|
181
|
+
|
|
182
|
+
template<typename T>
|
|
183
|
+
struct is_wrapped<T, std::enable_if_t<std::is_fundamental_v<detail::intrinsic_type<T>> ||
|
|
184
|
+
std::is_same_v<detail::intrinsic_type<T>, std::string>>
|
|
185
|
+
>: std::false_type {};
|
|
186
|
+
|
|
187
|
+
template<typename T>
|
|
188
|
+
constexpr bool is_wrapped_v = is_wrapped<T>::value;
|
|
157
189
|
} // detail
|
|
158
190
|
} // Rice
|
|
159
191
|
|
data/rice.gemspec
CHANGED
|
@@ -23,6 +23,9 @@ Ruby extensions with C++ easier.
|
|
|
23
23
|
"source_code_uri" => "https://github.com/ruby-rice/rice",
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
s.bindir = "bin"
|
|
27
|
+
s.executables = ["rice-doc.rb", "rice-rbs.rb"]
|
|
28
|
+
|
|
26
29
|
s.test_files = Dir['test/ruby/*.rb']
|
|
27
30
|
s.extra_rdoc_files = ['README.md']
|
|
28
31
|
s.require_paths = ['lib']
|
|
@@ -44,41 +47,27 @@ Ruby extensions with C++ easier.
|
|
|
44
47
|
'CMakePresets.json',
|
|
45
48
|
'FindRuby.cmake',
|
|
46
49
|
|
|
47
|
-
#
|
|
50
|
+
# Include files
|
|
48
51
|
'include/rice/rice.hpp',
|
|
49
52
|
'include/rice/stl.hpp',
|
|
53
|
+
'include/rice/ruby-api.hpp',
|
|
54
|
+
|
|
55
|
+
# Bin files
|
|
56
|
+
'bin/rice-rbs.rb',
|
|
50
57
|
|
|
51
58
|
# Source files
|
|
52
59
|
'rice/**/*.?pp',
|
|
53
60
|
|
|
54
|
-
#
|
|
61
|
+
# Library files
|
|
55
62
|
'lib/**/*.rb',
|
|
56
63
|
|
|
57
|
-
# Samples
|
|
58
|
-
'sample/enum/extconf.rb',
|
|
59
|
-
'sample/enum/*.?pp',
|
|
60
|
-
'sample/enum/*.rb',
|
|
61
|
-
'sample/map/extconf.rb',
|
|
62
|
-
'sample/map/*.?pp',
|
|
63
|
-
'sample/map/*.rb',
|
|
64
|
-
'sample/inheritance/extconf.rb',
|
|
65
|
-
'sample/inheritance/*.?pp',
|
|
66
|
-
'sample/inheritance/*.rb',
|
|
67
|
-
'sample/callbacks/extconf.rb',
|
|
68
|
-
'sample/callbacks/*.?pp',
|
|
69
|
-
'sample/callbacks/*.rb',
|
|
70
|
-
|
|
71
64
|
# Test source files
|
|
72
65
|
'test/*.?pp',
|
|
73
|
-
'test/extconf.rb'
|
|
74
|
-
'test/ext/t1/extconf.rb',
|
|
75
|
-
'test/ext/t1/*.*pp',
|
|
76
|
-
'test/ext/t2/extconf.rb',
|
|
77
|
-
'test/ext/t2/*.*pp'
|
|
66
|
+
'test/extconf.rb'
|
|
78
67
|
]
|
|
79
68
|
|
|
80
69
|
s.required_ruby_version = ">= 3.1"
|
|
81
|
-
|
|
70
|
+
s.add_dependency "ostruct"
|
|
82
71
|
s.add_development_dependency "bundler"
|
|
83
72
|
s.add_development_dependency "rake"
|
|
84
73
|
s.add_development_dependency "minitest"
|