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.
Files changed (185) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +31 -0
  3. data/CMakeLists.txt +0 -4
  4. data/Rakefile +2 -8
  5. data/bin/rice-doc.rb +212 -0
  6. data/bin/rice-rbs.rb +93 -0
  7. data/include/rice/rice.hpp +4972 -4015
  8. data/include/rice/stl.hpp +822 -294
  9. data/lib/rice/doc/cpp_reference.rb +166 -0
  10. data/lib/rice/doc/doxygen.rb +294 -0
  11. data/lib/rice/doc/mkdocs.rb +298 -0
  12. data/lib/rice/doc/rice.rb +29 -0
  13. data/lib/rice/doc/ruby.rb +37 -0
  14. data/lib/rice/doc.rb +5 -0
  15. data/lib/{make_rice_headers.rb → rice/make_rice_headers.rb} +3 -0
  16. data/lib/rice/native.rb +18 -0
  17. data/lib/rice/native_registry.rb +21 -0
  18. data/lib/rice/parameter.rb +7 -0
  19. data/lib/rice/rbs.rb +104 -0
  20. data/lib/rice/version.rb +1 -1
  21. data/lib/rice.rb +4 -0
  22. data/lib/rubygems/cmake_builder.rb +24 -27
  23. data/rice/Arg.hpp +4 -4
  24. data/rice/Arg.ipp +4 -4
  25. data/rice/Buffer.hpp +32 -28
  26. data/rice/Buffer.ipp +306 -178
  27. data/rice/Data_Object.ipp +101 -82
  28. data/rice/Data_Type.hpp +5 -7
  29. data/rice/Data_Type.ipp +48 -29
  30. data/rice/Enum.ipp +15 -21
  31. data/rice/Function.hpp +17 -0
  32. data/rice/Function.ipp +13 -0
  33. data/rice/Pointer.hpp +15 -0
  34. data/rice/Pointer.ipp +49 -0
  35. data/rice/Return.hpp +1 -1
  36. data/rice/Return.ipp +2 -2
  37. data/rice/api.hpp +30 -0
  38. data/rice/cpp_api/Array.hpp +2 -2
  39. data/rice/cpp_api/Array.ipp +50 -5
  40. data/rice/cpp_api/Class.hpp +0 -5
  41. data/rice/cpp_api/Class.ipp +19 -0
  42. data/rice/cpp_api/Hash.ipp +20 -0
  43. data/rice/cpp_api/Module.hpp +6 -3
  44. data/rice/cpp_api/Module.ipp +49 -11
  45. data/rice/cpp_api/Object.ipp +31 -2
  46. data/rice/cpp_api/String.hpp +1 -2
  47. data/rice/cpp_api/String.ipp +21 -1
  48. data/rice/cpp_api/Struct.ipp +5 -0
  49. data/rice/cpp_api/Symbol.ipp +34 -0
  50. data/rice/cpp_api/shared_methods.hpp +12 -12
  51. data/rice/detail/MethodInfo.hpp +4 -2
  52. data/rice/detail/MethodInfo.ipp +19 -3
  53. data/rice/detail/ModuleRegistry.hpp +18 -0
  54. data/rice/detail/ModuleRegistry.ipp +25 -0
  55. data/rice/detail/Native.hpp +45 -2
  56. data/rice/detail/Native.ipp +196 -2
  57. data/rice/detail/NativeAttributeGet.hpp +9 -4
  58. data/rice/detail/NativeAttributeGet.ipp +65 -11
  59. data/rice/detail/NativeAttributeSet.hpp +4 -0
  60. data/rice/detail/NativeAttributeSet.ipp +30 -2
  61. data/rice/detail/NativeCallbackFFI.ipp +2 -2
  62. data/rice/detail/NativeCallbackSimple.ipp +1 -1
  63. data/rice/detail/NativeFunction.hpp +11 -49
  64. data/rice/detail/NativeFunction.ipp +82 -379
  65. data/rice/detail/NativeInvoker.hpp +74 -0
  66. data/rice/detail/NativeInvoker.ipp +197 -0
  67. data/rice/detail/NativeIterator.hpp +4 -0
  68. data/rice/detail/NativeIterator.ipp +19 -0
  69. data/rice/detail/NativeMethod.hpp +97 -0
  70. data/rice/detail/NativeMethod.ipp +332 -0
  71. data/rice/detail/NativeProc.hpp +51 -0
  72. data/rice/detail/NativeProc.ipp +133 -0
  73. data/rice/detail/NativeRegistry.hpp +8 -0
  74. data/rice/detail/NativeRegistry.ipp +27 -0
  75. data/rice/detail/Parameter.hpp +47 -0
  76. data/rice/detail/Parameter.ipp +105 -0
  77. data/rice/detail/Proc.ipp +14 -13
  78. data/rice/detail/Registries.hpp +1 -0
  79. data/rice/detail/RubyType.hpp +0 -2
  80. data/rice/detail/RubyType.ipp +15 -33
  81. data/rice/detail/Type.hpp +44 -8
  82. data/rice/detail/Type.ipp +151 -49
  83. data/rice/detail/TypeRegistry.hpp +3 -0
  84. data/rice/detail/TypeRegistry.ipp +17 -27
  85. data/rice/detail/Types.ipp +430 -0
  86. data/rice/detail/Wrapper.hpp +12 -0
  87. data/rice/detail/Wrapper.ipp +45 -2
  88. data/rice/detail/from_ruby.ipp +567 -1073
  89. data/rice/detail/ruby.hpp +1 -0
  90. data/rice/detail/to_ruby.ipp +4 -635
  91. data/rice/libc/file.ipp +3 -6
  92. data/rice/rice.hpp +22 -12
  93. data/rice/rice_api/Arg.hpp +7 -0
  94. data/rice/rice_api/Arg.ipp +9 -0
  95. data/rice/rice_api/ModuleRegistry.hpp +7 -0
  96. data/rice/rice_api/ModuleRegistry.ipp +10 -0
  97. data/rice/rice_api/Native.hpp +7 -0
  98. data/rice/rice_api/Native.ipp +52 -0
  99. data/rice/rice_api/NativeRegistry.hpp +7 -0
  100. data/rice/rice_api/NativeRegistry.ipp +21 -0
  101. data/rice/rice_api/Parameter.hpp +7 -0
  102. data/rice/rice_api/Parameter.ipp +11 -0
  103. data/rice/rice_api/Registries.hpp +6 -0
  104. data/rice/rice_api/Registries.ipp +12 -0
  105. data/rice/rice_api/TypeRegistry.hpp +7 -0
  106. data/rice/rice_api/TypeRegistry.ipp +10 -0
  107. data/rice/stl/complex.ipp +35 -0
  108. data/rice/stl/exception.ipp +20 -7
  109. data/rice/stl/filesystem.hpp +6 -0
  110. data/rice/stl/filesystem.ipp +34 -0
  111. data/rice/stl/map.ipp +13 -21
  112. data/rice/stl/monostate.ipp +37 -1
  113. data/rice/stl/multimap.ipp +17 -24
  114. data/rice/stl/optional.ipp +47 -2
  115. data/rice/stl/pair.ipp +23 -58
  116. data/rice/stl/reference_wrapper.ipp +22 -1
  117. data/rice/stl/set.ipp +17 -9
  118. data/rice/stl/shared_ptr.ipp +44 -17
  119. data/rice/stl/string.ipp +175 -7
  120. data/rice/stl/string_view.ipp +5 -0
  121. data/rice/stl/tuple.ipp +38 -9
  122. data/rice/stl/unique_ptr.ipp +46 -2
  123. data/rice/stl/unordered_map.ipp +13 -21
  124. data/rice/stl/variant.ipp +47 -11
  125. data/rice/stl/vector.ipp +183 -104
  126. data/rice/stl.hpp +1 -0
  127. data/rice/traits/function_traits.hpp +2 -2
  128. data/rice/traits/method_traits.hpp +5 -16
  129. data/rice/traits/rice_traits.hpp +24 -4
  130. data/rice.gemspec +11 -22
  131. data/test/embed_ruby.cpp +0 -3
  132. data/test/test_Array.cpp +38 -38
  133. data/test/test_Attribute.cpp +187 -2
  134. data/test/test_Buffer.cpp +302 -26
  135. data/test/test_Callback.cpp +2 -3
  136. data/test/test_Class.cpp +5 -5
  137. data/test/test_Data_Object.cpp +0 -55
  138. data/test/test_Data_Type.cpp +19 -30
  139. data/test/test_Enum.cpp +4 -46
  140. data/test/test_From_Ruby.cpp +88 -81
  141. data/test/test_GVL.cpp +109 -0
  142. data/test/test_Iterator.cpp +1 -1
  143. data/test/test_Keep_Alive_No_Wrapper.cpp +5 -3
  144. data/test/test_Module.cpp +8 -9
  145. data/test/test_Object.cpp +1 -1
  146. data/test/test_Overloads.cpp +3 -3
  147. data/test/test_Stl_Map.cpp +8 -8
  148. data/test/test_Stl_Multimap.cpp +4 -4
  149. data/test/test_Stl_Pair.cpp +5 -3
  150. data/test/test_Stl_SharedPtr.cpp +24 -12
  151. data/test/test_Stl_Tuple.cpp +1 -1
  152. data/test/test_Stl_UniquePtr.cpp +8 -0
  153. data/test/test_Stl_Unordered_Map.cpp +9 -9
  154. data/test/test_Stl_Variant.cpp +9 -3
  155. data/test/test_Stl_Vector.cpp +118 -13
  156. data/test/test_To_Ruby.cpp +35 -28
  157. data/test/test_Type.cpp +256 -53
  158. data/test/unittest.hpp +35 -0
  159. metadata +66 -34
  160. data/rice/Init.hpp +0 -8
  161. data/rice/Init.ipp +0 -8
  162. data/rice/detail/RubyFunction.hpp +0 -31
  163. data/rice/detail/RubyFunction.ipp +0 -77
  164. data/sample/callbacks/extconf.rb +0 -5
  165. data/sample/callbacks/sample_callbacks.cpp +0 -35
  166. data/sample/callbacks/test.rb +0 -28
  167. data/sample/enum/extconf.rb +0 -5
  168. data/sample/enum/sample_enum.cpp +0 -40
  169. data/sample/enum/test.rb +0 -8
  170. data/sample/inheritance/animals.cpp +0 -82
  171. data/sample/inheritance/extconf.rb +0 -5
  172. data/sample/inheritance/test.rb +0 -7
  173. data/sample/map/extconf.rb +0 -5
  174. data/sample/map/map.cpp +0 -73
  175. data/sample/map/test.rb +0 -7
  176. data/test/ext/t1/Foo.hpp +0 -10
  177. data/test/ext/t1/extconf.rb +0 -4
  178. data/test/ext/t1/t1.cpp +0 -13
  179. data/test/ext/t2/extconf.rb +0 -4
  180. data/test/ext/t2/t2.cpp +0 -11
  181. data/test/ruby/test_callbacks_sample.rb +0 -28
  182. data/test/ruby/test_multiple_extensions.rb +0 -18
  183. data/test/ruby/test_multiple_extensions_same_class.rb +0 -14
  184. data/test/ruby/test_multiple_extensions_with_inheritance.rb +0 -20
  185. /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. Note that negative indices
42
- // wrap around!
43
- if (index < 0)
41
+ // Negative indices mean count from the right
42
+ if (index < 0 && (-index <= size))
44
43
  {
45
- index = ((-index) % size);
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
- .define_constructor(Constructor<T, Size_T, const Parameter_T>())
61
- .define_constructor(Constructor<T, const T&>());
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,42 +122,85 @@ namespace Rice
120
122
 
121
123
  void define_access_methods()
122
124
  {
123
- // Access methods
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
- if (vector.size() > 0)
127
+ // Access methods
128
+ klass_.define_method("first", [](T& vector) -> std::optional<std::reference_wrapper<Value_T>>
127
129
  {
128
- return vector.front();
129
- }
130
- else
131
- {
132
- return std::nullopt;
133
- }
134
- })
135
- .define_method("last", [](const T& vector) -> std::optional<Value_T>
136
- {
137
- if (vector.size() > 0)
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>>
138
140
  {
139
- return vector.back();
140
- }
141
- else
141
+ if (vector.size() > 0)
142
+ {
143
+ return vector.back();
144
+ }
145
+ else
146
+ {
147
+ return std::nullopt;
148
+ }
149
+ })
150
+ .define_method("[]", [this](T& vector, Difference_T index) -> std::optional<std::reference_wrapper<Value_T>>
142
151
  {
143
- return std::nullopt;
144
- }
145
- })
146
- .define_method("[]", [this](const T& vector, Difference_T index) -> std::optional<Value_T>
152
+ index = normalizeIndex(vector.size(), index);
153
+ if (index < 0 || index >= (Difference_T)vector.size())
154
+ {
155
+ return std::nullopt;
156
+ }
157
+ else
158
+ {
159
+ return vector[index];
160
+ }
161
+ })
162
+ .template define_method<Value_T*(T::*)()>("data", &T::data, Return().setBuffer());
163
+ }
164
+ else
147
165
  {
148
- index = normalizeIndex(vector.size(), index);
149
- if (index < 0 || index >= (Difference_T)vector.size())
166
+ // Access methods
167
+ klass_.define_method("first", [](T& vector) -> std::optional<Value_T>
150
168
  {
151
- return std::nullopt;
152
- }
153
- else
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>
154
179
  {
155
- return vector[index];
156
- }
157
- })
158
- .define_method("[]", [this](const T& vector, Difference_T start, Difference_T length) -> VALUE
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>
190
+ {
191
+ index = normalizeIndex(vector.size(), index);
192
+ if (index < 0 || index >= (Difference_T)vector.size())
193
+ {
194
+ return std::nullopt;
195
+ }
196
+ else
197
+ {
198
+ return vector[index];
199
+ }
200
+ });
201
+ }
202
+
203
+ klass_.define_method("[]", [this](T& vector, Difference_T start, Difference_T length) -> VALUE
159
204
  {
160
205
  start = normalizeIndex(vector.size(), start);
161
206
  if (start < 0 || start >= (Difference_T)vector.size())
@@ -174,25 +219,19 @@ namespace Rice
174
219
  }
175
220
 
176
221
  auto finish = vector.begin() + start + length;
177
- T slice(begin, finish);
178
222
 
179
223
  VALUE result = rb_ary_new();
180
- std::for_each(slice.begin(), slice.end(), [&result](const Reference_T element)
224
+ for (auto iter = begin; iter != finish; iter++)
181
225
  {
182
- VALUE value = detail::To_Ruby<Parameter_T>().convert(element);
226
+ const Reference_T element = *iter;
227
+ VALUE value = detail::To_Ruby<Reference_T>().convert(element);
183
228
  rb_ary_push(result, value);
184
- });
229
+ }
185
230
 
186
231
  return result;
187
232
  }
188
233
  }, Return().setValue());
189
234
 
190
- if constexpr (!std::is_same_v<Value_T, bool>)
191
- {
192
- define_buffer<Value_T>();
193
- klass_.template define_method<Value_T*(T::*)()>("data", &T::data);
194
- }
195
-
196
235
  rb_define_alias(klass_, "at", "[]");
197
236
  }
198
237
 
@@ -202,35 +241,39 @@ namespace Rice
202
241
  if constexpr (detail::is_comparable_v<T>)
203
242
  {
204
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())
205
247
  {
206
- auto iter = std::find(vector.begin(), vector.end(), element);
207
- if (iter == vector.end())
208
- {
209
- return std::nullopt;
210
- }
211
- else
212
- {
213
- Value_T result = *iter;
214
- vector.erase(iter);
215
- return result;
216
- }
217
- })
218
- .define_method("include?", [](T& vector, Parameter_T element)
248
+ return std::nullopt;
249
+ }
250
+ else if constexpr (std::is_copy_assignable_v<Value_T>)
219
251
  {
220
- return std::find(vector.begin(), vector.end(), element) != vector.end();
221
- })
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
+ })
222
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())
223
269
  {
224
- auto iter = std::find(vector.begin(), vector.end(), element);
225
- if (iter == vector.end())
226
- {
227
- return std::nullopt;
228
- }
229
- else
230
- {
231
- return iter - vector.begin();
232
- }
233
- });
270
+ return std::nullopt;
271
+ }
272
+ else
273
+ {
274
+ return iter - vector.begin();
275
+ }
276
+ });
234
277
  }
235
278
  else
236
279
  {
@@ -252,45 +295,65 @@ namespace Rice
252
295
  void define_modify_methods()
253
296
  {
254
297
  klass_.define_method("clear", &T::clear)
255
- .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>)
256
303
  {
257
- auto iter = vector.begin() + pos;
258
304
  Value_T result = *iter;
259
305
  vector.erase(iter);
260
306
  return result;
261
- })
307
+ }
308
+ else
309
+ {
310
+ vector.erase(iter);
311
+ return std::nullopt;
312
+ }
313
+ })
262
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)
263
321
  {
264
- index = normalizeIndex(vector.size(), index, true);
265
- auto iter = vector.begin() + index;
266
- vector.insert(iter, element);
267
- return vector;
268
- })
322
+ normalized++;
323
+ }
324
+ auto iter = vector.begin() + normalized;
325
+ vector.insert(iter, std::move(element));
326
+ return vector;
327
+ })
269
328
  .define_method("pop", [](T& vector) -> std::optional<Value_T>
329
+ {
330
+ if constexpr (!std::is_copy_assignable_v<Value_T>)
270
331
  {
271
- if (vector.size() > 0)
272
- {
273
- Value_T result = vector.back();
274
- vector.pop_back();
275
- return result;
276
- }
277
- else
278
- {
279
- return std::nullopt;
280
- }
281
- })
282
- .define_method("push", [](T& vector, Parameter_T element) -> T&
332
+ vector.pop_back();
333
+ return std::nullopt;
334
+ }
335
+ else if (vector.empty())
283
336
  {
284
- vector.push_back(element);
285
- return vector;
286
- })
287
- .define_method("shrink_to_fit", &T::shrink_to_fit)
288
- .define_method("[]=", [this](T& vector, Difference_T index, Parameter_T element) -> Parameter_T
337
+ return std::nullopt;
338
+ }
339
+ else
289
340
  {
290
- index = normalizeIndex(vector.size(), index, true);
291
- vector[index] = element;
292
- return element;
293
- });
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
+ });
294
357
 
295
358
  rb_define_alias(klass_, "push_back", "push");
296
359
  rb_define_alias(klass_, "<<", "push");
@@ -311,7 +374,7 @@ namespace Rice
311
374
  VALUE result = rb_ary_new();
312
375
  std::for_each(vector.begin(), vector.end(), [&result](const Reference_T element)
313
376
  {
314
- VALUE value = detail::To_Ruby<Parameter_T>().convert(element);
377
+ VALUE value = detail::To_Ruby<Reference_T>().convert(element);
315
378
  rb_ary_push(result, value);
316
379
  });
317
380
 
@@ -369,8 +432,8 @@ namespace Rice
369
432
 
370
433
  if (klassName.empty())
371
434
  {
372
- std::string typeName = detail::typeName(typeid(Vector_T));
373
- klassName = detail::rubyClassName(typeName);
435
+ detail::TypeMapper<Vector_T> typeMapper;
436
+ klassName = typeMapper.rubyName();
374
437
  }
375
438
 
376
439
  Module rb_mStd = define_module("Std");
@@ -522,6 +585,12 @@ namespace Rice
522
585
  class From_Ruby<std::vector<T>*>
523
586
  {
524
587
  public:
588
+ From_Ruby() = default;
589
+
590
+ explicit From_Ruby(Arg* arg) : arg_(arg)
591
+ {
592
+ }
593
+
525
594
  Convertible is_convertible(VALUE value)
526
595
  {
527
596
  switch (rb_type(value))
@@ -569,6 +638,7 @@ namespace Rice
569
638
  }
570
639
 
571
640
  private:
641
+ Arg* arg_;
572
642
  std::vector<T> converted_;
573
643
  };
574
644
  }
@@ -580,10 +650,19 @@ namespace Rice
580
650
  class To_Ruby<std::vector<bool>::reference>
581
651
  {
582
652
  public:
653
+ To_Ruby() = default;
654
+
655
+ explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
656
+ {
657
+ }
658
+
583
659
  VALUE convert(const std::vector<bool>::reference& value)
584
660
  {
585
661
  return value ? Qtrue : Qfalse;
586
662
  }
663
+
664
+ private:
665
+ Return* returnInfo_ = nullptr;
587
666
  };
588
667
  }
589
668
  }
data/rice/stl.hpp CHANGED
@@ -6,6 +6,7 @@
6
6
  #include "stl/string.hpp"
7
7
  #include "stl/string_view.hpp"
8
8
  #include "stl/complex.hpp"
9
+ #include "stl/filesystem.hpp"
9
10
  #include "stl/optional.hpp"
10
11
  #include "stl/reference_wrapper.hpp"
11
12
  #include "stl/pair.hpp"
@@ -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::tuple_element<N, arg_types>::type;
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 - 1;
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, bool IsMethod, typename = void>
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, bool IsMethod>
28
- struct method_traits<Function_T, IsMethod, std::enable_if_t<IsMethod && std::is_same_v<typename function_traits<Function_T>::class_type, std::nullptr_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, bool IsMethod>
39
- struct method_traits<Function_T, IsMethod, std::enable_if_t<IsMethod && !std::is_same_v<typename function_traits<Function_T>::class_type, std::nullptr_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;
@@ -50,11 +50,11 @@ namespace Rice
50
50
  using type = typename remove_cv_recursive<T>::type&;
51
51
  };
52
52
 
53
- /* template<typename T>
53
+ template<typename T>
54
54
  struct remove_cv_recursive<T&&>
55
55
  {
56
56
  using type = typename remove_cv_recursive<T>::type&&;
57
- };*/
57
+ };
58
58
 
59
59
  template<typename T>
60
60
  struct remove_cv_recursive<T*>
@@ -100,6 +100,16 @@ namespace Rice
100
100
  static const bool value = is_comparable_v<T>;
101
101
  };
102
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
+
103
113
  // -- Tuple Helpers ---
104
114
  template<typename T>
105
115
  struct tuple_shift;
@@ -109,16 +119,26 @@ namespace Rice
109
119
  {
110
120
  using type = std::tuple<Arg_Ts...>;
111
121
  };
112
-
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
+
113
132
  template<template<typename, typename...> typename T, typename...Arg_Ts>
114
133
  struct tuple_map;
115
134
 
116
135
  template<template<typename, typename...> typename T, typename...Arg_Ts>
117
136
  struct tuple_map<T, std::tuple<Arg_Ts...>>
118
137
  {
119
- using type = std::tuple<T<remove_cv_recursive_t<Arg_Ts>>...>;
138
+ using type = std::tuple<T<Arg_Ts>...>;
120
139
  };
121
140
 
141
+
122
142
  template<typename...Arg_Ts>
123
143
  struct tuple_to_variant;
124
144
 
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
- # rice.hpp
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
- # Ruby files
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"
data/test/embed_ruby.cpp CHANGED
@@ -25,8 +25,5 @@ void embed_ruby()
25
25
  #endif
26
26
 
27
27
  initialized__ = true;
28
-
29
- // Initialize Rice
30
- Rice::init();
31
28
  }
32
29
  }