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/Pointer.ipp ADDED
@@ -0,0 +1,49 @@
1
+ namespace Rice
2
+ {
3
+ template<typename T>
4
+ inline Data_Type<Pointer<T>> define_pointer(std::string klassName)
5
+ {
6
+ using Pointer_T = Pointer<T>;
7
+ using Data_Type_T = Data_Type<Pointer_T>;
8
+
9
+ if (klassName.empty())
10
+ {
11
+ detail::TypeMapper<Pointer_T> typeMapper;
12
+ klassName = typeMapper.rubyName();
13
+ }
14
+
15
+ Module rb_mRice = define_module("Rice");
16
+
17
+ if (Data_Type_T::check_defined(klassName, rb_mRice))
18
+ {
19
+ return Data_Type_T();
20
+ }
21
+
22
+ Data_Type<Pointer<T>> result = define_class_under<Pointer_T>(rb_mRice, klassName).
23
+ define_method("buffer", [](VALUE self) -> Buffer<T>
24
+ {
25
+ T* ptr = detail::unwrap<T>(self, Data_Type<Pointer<T>>::ruby_data_type(), false);
26
+ Buffer<T> buffer(ptr);
27
+ return buffer;
28
+ }, Arg("self").setValue());
29
+
30
+ // Define a buffer to read the pointer's data
31
+ define_buffer<T>();
32
+
33
+ return result;
34
+ }
35
+ }
36
+
37
+ namespace Rice::detail
38
+ {
39
+ template<typename T>
40
+ struct Type<Pointer<T>>
41
+ {
42
+ static bool verify()
43
+ {
44
+ detail::verifyType<T>();
45
+ define_pointer<T>();
46
+ return true;
47
+ }
48
+ };
49
+ }
data/rice/Return.hpp CHANGED
@@ -13,7 +13,7 @@ namespace Rice
13
13
  Return& setValue() override;
14
14
  Return& setOpaque() override;
15
15
  Return& takeOwnership() override;
16
- Return& setArray() override;
16
+ Return& setBuffer() override;
17
17
  };
18
18
  } // Rice
19
19
 
data/rice/Return.ipp CHANGED
@@ -30,9 +30,9 @@ namespace Rice
30
30
  return *this;
31
31
  }
32
32
 
33
- inline Return& Return::setArray()
33
+ inline Return& Return::setBuffer()
34
34
  {
35
- Arg::setArray();
35
+ Arg::setBuffer();
36
36
  return *this;
37
37
  }
38
38
  } // Rice
data/rice/api.hpp ADDED
@@ -0,0 +1,30 @@
1
+ #ifndef Rice__Api_hpp_
2
+ #define Rice__Api_hpp_
3
+
4
+ #include "rice_api/ModuleRegistry.hpp"
5
+ #include "rice_api/ModuleRegistry.ipp"
6
+ #include "rice_api/NativeRegistry.hpp"
7
+ #include "rice_api/NativeRegistry.ipp"
8
+ #include "rice_api/TypeRegistry.hpp"
9
+ #include "rice_api/TypeRegistry.ipp"
10
+ #include "rice_api/Registries.hpp"
11
+ #include "rice_api/Registries.ipp"
12
+ #include "rice_api/Arg.hpp"
13
+ #include "rice_api/Arg.ipp"
14
+ #include "rice_api/Parameter.hpp"
15
+ #include "rice_api/Parameter.ipp"
16
+ #include "rice_api/Native.hpp"
17
+ #include "rice_api/Native.ipp"
18
+
19
+ extern "C"
20
+ inline void Init_Rice_Api()
21
+ {
22
+ Init_Registries();
23
+ Init_Module_Registry();
24
+ Init_Native_Registry();
25
+ Init_Type_Registry();
26
+ Init_Arg();
27
+ Init_Parameter();
28
+ Init_Native();
29
+ }
30
+ #endif
@@ -47,7 +47,7 @@ namespace Rice
47
47
  /*! \param a a C array of type T and size n.
48
48
  */
49
49
  template<typename T, long n>
50
- Array(T const (&a)[n]);
50
+ Array(T (&a)[n]);
51
51
 
52
52
  public:
53
53
  //! Return the size of the array.
@@ -92,7 +92,7 @@ namespace Rice
92
92
  * \return the object which was pushed onto the array.
93
93
  */
94
94
  template<typename T>
95
- Object push(T obj);
95
+ Object push(T&& obj, bool takeOwnership);
96
96
 
97
97
  //! Pop an element from the end of the array
98
98
  /*! \return the object which was popped from the array, or Qnil if
@@ -24,16 +24,16 @@ namespace Rice
24
24
  {
25
25
  for (; it != end; ++it)
26
26
  {
27
- push(*it);
27
+ push(*it, false);
28
28
  }
29
29
  }
30
30
 
31
31
  template<typename T, long n>
32
- inline Array::Array(T const (&a)[n]) : Builtin_Object<T_ARRAY>(detail::protect(rb_ary_new))
32
+ inline Array::Array(T (&a)[n]) : Builtin_Object<T_ARRAY>(detail::protect(rb_ary_new))
33
33
  {
34
34
  for (long j = 0; j < n; ++j)
35
35
  {
36
- push(a[j]);
36
+ push(a[j], false);
37
37
  }
38
38
  }
39
39
 
@@ -65,9 +65,16 @@ namespace Rice
65
65
  }
66
66
 
67
67
  template<typename T>
68
- inline Object Array::push(T obj)
68
+ inline Object Array::push(T&& obj, bool takeOwnership)
69
69
  {
70
- return detail::protect(rb_ary_push, value(), detail::To_Ruby<T>().convert(std::forward<T>(obj)));
70
+ Return returnInfo;
71
+ if (takeOwnership)
72
+ {
73
+ returnInfo.takeOwnership();
74
+ }
75
+
76
+ detail::To_Ruby<detail::remove_cv_recursive_t<T>> toRuby(&returnInfo);
77
+ return detail::protect(rb_ary_push, value(), toRuby.convert(std::forward<T>(obj)));
71
78
  }
72
79
 
73
80
  inline Object Array::pop()
@@ -247,42 +254,80 @@ namespace Rice::detail
247
254
  {
248
255
  return true;
249
256
  }
257
+
258
+ static VALUE rubyKlass()
259
+ {
260
+ return rb_cArray;
261
+ }
250
262
  };
251
263
 
252
264
  template<>
253
265
  class To_Ruby<Array>
254
266
  {
255
267
  public:
268
+ To_Ruby() = default;
269
+
270
+ explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
271
+ {
272
+ }
273
+
256
274
  VALUE convert(Array const& x)
257
275
  {
258
276
  return x.value();
259
277
  }
278
+
279
+ private:
280
+ Return* returnInfo_ = nullptr;
260
281
  };
261
282
 
262
283
  template<>
263
284
  class To_Ruby<Array&>
264
285
  {
265
286
  public:
287
+ To_Ruby() = default;
288
+
289
+ explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
290
+ {
291
+ }
292
+
266
293
  VALUE convert(Array const& x)
267
294
  {
268
295
  return x.value();
269
296
  }
297
+
298
+ private:
299
+ Return* returnInfo_ = nullptr;
270
300
  };
271
301
 
272
302
  template<>
273
303
  class To_Ruby<Array*>
274
304
  {
275
305
  public:
306
+ To_Ruby() = default;
307
+
308
+ explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
309
+ {
310
+ }
311
+
276
312
  VALUE convert(Array const* x)
277
313
  {
278
314
  return x->value();
279
315
  }
316
+
317
+ private:
318
+ Return* returnInfo_ = nullptr;
280
319
  };
281
320
 
282
321
  template<>
283
322
  class From_Ruby<Array>
284
323
  {
285
324
  public:
325
+ From_Ruby() = default;
326
+
327
+ explicit From_Ruby(Arg* arg)
328
+ {
329
+ }
330
+
286
331
  Convertible is_convertible(VALUE value)
287
332
  {
288
333
  switch (rb_type(value))
@@ -1,11 +1,6 @@
1
1
  #ifndef Rice__Class__hpp_
2
2
  #define Rice__Class__hpp_
3
3
 
4
- /*!
5
- * \example inheritance/animals.cpp
6
- * \example callbacks/sample_callbacks.cpp
7
- */
8
-
9
4
  namespace Rice
10
5
  {
11
6
  //! A helper for defining a Class and its methods.
@@ -85,6 +85,25 @@ namespace Rice::detail
85
85
  }
86
86
  };
87
87
 
88
+ template<>
89
+ class To_Ruby<Class&>
90
+ {
91
+ public:
92
+ To_Ruby() = default;
93
+
94
+ explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
95
+ {
96
+ }
97
+
98
+ VALUE convert(Class const& x)
99
+ {
100
+ return x.value();
101
+ }
102
+
103
+ private:
104
+ Return* returnInfo_ = nullptr;
105
+ };
106
+
88
107
  template<>
89
108
  class From_Ruby<Class>
90
109
  {
@@ -221,22 +221,42 @@ namespace Rice::detail
221
221
  {
222
222
  return true;
223
223
  }
224
+
225
+ static VALUE rubyKlass()
226
+ {
227
+ return rb_cHash;
228
+ }
224
229
  };
225
230
 
226
231
  template<>
227
232
  class To_Ruby<Hash>
228
233
  {
229
234
  public:
235
+ To_Ruby() = default;
236
+
237
+ explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
238
+ {
239
+ }
240
+
230
241
  VALUE convert(Hash const& x)
231
242
  {
232
243
  return x.value();
233
244
  }
245
+
246
+ private:
247
+ Return* returnInfo_ = nullptr;
234
248
  };
235
249
 
236
250
  template<>
237
251
  class From_Ruby<Hash>
238
252
  {
239
253
  public:
254
+ From_Ruby() = default;
255
+
256
+ explicit From_Ruby(Arg* arg)
257
+ {
258
+ }
259
+
240
260
  Convertible is_convertible(VALUE value)
241
261
  {
242
262
  switch (rb_type(value))
@@ -49,15 +49,18 @@ namespace Rice
49
49
 
50
50
  #include "shared_methods.hpp"
51
51
  protected:
52
- template<bool IsMethod, typename Function_T>
53
- void wrap_native_call(VALUE klass, std::string name, Function_T&& function, MethodInfo* methodInfo);
52
+ template<typename Function_T>
53
+ void wrap_native_function(VALUE klass, std::string name, Function_T&& function, MethodInfo* methodInfo);
54
+
55
+ template<typename Class_T = VALUE, typename Method_T>
56
+ void wrap_native_method(VALUE klass, std::string name, Method_T&& method, MethodInfo* methodInfo);
54
57
  };
55
58
 
56
59
  //! Define a new module in the namespace given by module.
57
60
  /*! \param module the module in which to define the new module.
58
61
  * \param name the name of the new module.
59
62
  */
60
- Module define_module_under(Object module, char const * name);
63
+ Module define_module_under(Object parent, char const * name);
61
64
 
62
65
  //! Define a new module in the default namespace.
63
66
  /*! \param name the name of the new module.
@@ -32,26 +32,30 @@ namespace Rice
32
32
  this->set_value(result);
33
33
  }
34
34
 
35
- template<bool IsMethod, typename Function_T>
36
- inline void Module::wrap_native_call(VALUE klass, std::string name, Function_T&& function, MethodInfo* methodInfo)
35
+ template<typename Function_T>
36
+ inline void Module::wrap_native_function(VALUE klass, std::string name, Function_T&& function, MethodInfo* methodInfo)
37
37
  {
38
- // Make sure the return type and arguments have been previously seen by Rice
39
- using traits = detail::method_traits<Function_T, IsMethod>;
40
- detail::verifyType<typename traits::Return_T>();
41
- detail::verifyTypes<typename traits::Arg_Ts>();
38
+ detail::NativeFunction<Function_T>::define(klass, name, std::forward<Function_T>(function), methodInfo);
39
+ }
42
40
 
43
- // Define a NativeFunction to bridge Ruby to C++
44
- detail::NativeFunction<VALUE, Function_T, IsMethod>::define(klass, name, std::forward<Function_T>(function), methodInfo);
41
+ template<typename Class_T, typename Method_T>
42
+ inline void Module::wrap_native_method(VALUE klass, std::string name, Method_T&& method, MethodInfo* methodInfo)
43
+ {
44
+ detail::NativeMethod<Class_T, Method_T>::define(klass, name, std::forward<Method_T>(method), methodInfo);
45
45
  }
46
46
 
47
- inline Module define_module_under(Object module, char const* name)
47
+ inline Module define_module_under(Object parent, char const* name)
48
48
  {
49
- return detail::protect(rb_define_module_under, module.value(), name);
49
+ VALUE module = detail::protect(rb_define_module_under, parent.value(), name);
50
+ detail::Registries::instance.modules.add(module);
51
+ return module;
50
52
  }
51
53
 
52
54
  inline Module define_module(char const* name)
53
55
  {
54
- return detail::protect(rb_define_module, name);
56
+ VALUE module = detail::protect(rb_define_module, name);
57
+ detail::Registries::instance.modules.add(module);
58
+ return module;
55
59
  }
56
60
 
57
61
  inline Module anonymous_module()
@@ -77,16 +81,50 @@ namespace Rice::detail
77
81
  {
78
82
  return true;
79
83
  }
84
+
85
+ static VALUE rubyKlass()
86
+ {
87
+ return rb_cModule;
88
+ }
80
89
  };
81
90
 
82
91
  template<>
83
92
  class To_Ruby<Module>
84
93
  {
85
94
  public:
95
+ To_Ruby() = default;
96
+
97
+ explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
98
+ {
99
+ }
100
+
86
101
  VALUE convert(Module const& x)
87
102
  {
88
103
  return x.value();
89
104
  }
105
+
106
+ private:
107
+ Return* returnInfo_ = nullptr;
108
+ };
109
+
110
+
111
+ template<>
112
+ class To_Ruby<Module&>
113
+ {
114
+ public:
115
+ To_Ruby() = default;
116
+
117
+ explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
118
+ {
119
+ }
120
+
121
+ VALUE convert(Module const& x)
122
+ {
123
+ return x.value();
124
+ }
125
+
126
+ private:
127
+ Return* returnInfo_ = nullptr;
90
128
  };
91
129
 
92
130
  template<>
@@ -189,32 +189,61 @@ namespace Rice::detail
189
189
  {
190
190
  return true;
191
191
  }
192
+
193
+ static VALUE rubyKlass()
194
+ {
195
+ return rb_cObject;
196
+ }
192
197
  };
193
198
 
194
199
  template<>
195
200
  class To_Ruby<Object>
196
201
  {
197
202
  public:
198
- static VALUE convert(Object const& x)
203
+ To_Ruby() = default;
204
+
205
+ explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
206
+ {
207
+ }
208
+
209
+ VALUE convert(Object const& x)
199
210
  {
200
211
  return x.value();
201
212
  }
213
+
214
+ private:
215
+ Return* returnInfo_ = nullptr;
202
216
  };
203
217
 
204
218
  template<>
205
219
  class To_Ruby<Object&>
206
220
  {
207
221
  public:
208
- static VALUE convert(Object const& x)
222
+ To_Ruby() = default;
223
+
224
+ explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
225
+ {
226
+ }
227
+
228
+ VALUE convert(Object const& x)
209
229
  {
210
230
  return x.value();
211
231
  }
232
+
233
+ private:
234
+ Return* returnInfo_ = nullptr;
212
235
  };
213
236
 
214
237
  template<>
215
238
  class From_Ruby<Object>
216
239
  {
217
240
  public:
241
+ From_Ruby() = default;
242
+
243
+ explicit From_Ruby(Arg* arg)
244
+ {
245
+ }
246
+
218
247
  Convertible is_convertible(VALUE value)
219
248
  {
220
249
  switch (rb_type(value))
@@ -13,8 +13,7 @@ namespace Rice
13
13
  * std::cout << s.length() << std::endl;
14
14
  * \endcode
15
15
  */
16
- class String
17
- : public Builtin_Object<T_STRING>
16
+ class String : public Builtin_Object<T_STRING>
18
17
  {
19
18
  public:
20
19
  //! Construct a new string.
@@ -66,7 +66,7 @@ namespace Rice
66
66
  template<typename T>
67
67
  inline Array String::unpack() const
68
68
  {
69
- return this->call("unpack", detail::RubyType<T>::packTemplate.c_str());
69
+ return this->call("unpack", detail::RubyType<detail::remove_cv_recursive_t<T>>::packTemplate.c_str());
70
70
  }
71
71
 
72
72
  inline Identifier String::intern() const
@@ -84,22 +84,42 @@ namespace Rice::detail
84
84
  {
85
85
  return true;
86
86
  }
87
+
88
+ static VALUE rubyKlass()
89
+ {
90
+ return rb_cString;
91
+ }
87
92
  };
88
93
 
89
94
  template<>
90
95
  class To_Ruby<String>
91
96
  {
92
97
  public:
98
+ To_Ruby() = default;
99
+
100
+ explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
101
+ {
102
+ }
103
+
93
104
  VALUE convert(String const& x)
94
105
  {
95
106
  return x.value();
96
107
  }
108
+
109
+ private:
110
+ Return* returnInfo_ = nullptr;
97
111
  };
98
112
 
99
113
  template<>
100
114
  class From_Ruby<String>
101
115
  {
102
116
  public:
117
+ From_Ruby() = default;
118
+
119
+ explicit From_Ruby(Arg* arg)
120
+ {
121
+ }
122
+
103
123
  Convertible is_convertible(VALUE value)
104
124
  {
105
125
  switch (rb_type(value))
@@ -88,5 +88,10 @@ namespace Rice::detail
88
88
  {
89
89
  return true;
90
90
  }
91
+
92
+ static VALUE rubyKlass()
93
+ {
94
+ return rb_cStruct;
95
+ }
91
96
  };
92
97
  }
@@ -54,16 +54,50 @@ namespace Rice::detail
54
54
  {
55
55
  return true;
56
56
  }
57
+
58
+ static VALUE rubyKlass()
59
+ {
60
+ return rb_cSymbol;
61
+ }
57
62
  };
58
63
 
59
64
  template<>
60
65
  class To_Ruby<Symbol>
61
66
  {
62
67
  public:
68
+ To_Ruby() = default;
69
+
70
+ explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
71
+ {
72
+ }
73
+
63
74
  VALUE convert(Symbol const& x)
64
75
  {
65
76
  return x.value();
66
77
  }
78
+
79
+ private:
80
+ Return* returnInfo_ = nullptr;
81
+ };
82
+
83
+
84
+ template<>
85
+ class To_Ruby<Symbol&>
86
+ {
87
+ public:
88
+ To_Ruby() = default;
89
+
90
+ explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
91
+ {
92
+ }
93
+
94
+ VALUE convert(Symbol const& x)
95
+ {
96
+ return x.value();
97
+ }
98
+
99
+ private:
100
+ Return* returnInfo_ = nullptr;
67
101
  };
68
102
 
69
103
  template<>
@@ -30,11 +30,11 @@ inline auto& include_module(Module const& inc)
30
30
  * \param args a list of Arg instance used to define default parameters.
31
31
  * \return *this
32
32
  */
33
- template<typename Function_T, typename...Arg_Ts>
34
- inline auto& define_method(std::string name, Function_T&& func, const Arg_Ts&...args)
33
+ template<typename Method_T, typename...Arg_Ts>
34
+ inline auto& define_method(std::string name, Method_T&& method, const Arg_Ts&...args)
35
35
  {
36
- MethodInfo* methodInfo = new MethodInfo(detail::method_traits<Function_T, true>::arity, args...);
37
- this->wrap_native_call<true>(this->value(), name, std::forward<Function_T>(func), methodInfo);
36
+ MethodInfo* methodInfo = new MethodInfo(detail::method_traits<Method_T>::arity, args...);
37
+ this->wrap_native_method(this->value(), name, std::forward<Method_T>(method), methodInfo);
38
38
  return *this;
39
39
  }
40
40
 
@@ -52,8 +52,8 @@ inline auto& define_method(std::string name, Function_T&& func, const Arg_Ts&...
52
52
  template<typename Function_T, typename...Arg_Ts>
53
53
  inline auto& define_function(std::string name, Function_T&& func, const Arg_Ts&...args)
54
54
  {
55
- MethodInfo* methodInfo = new MethodInfo(detail::method_traits<Function_T, false>::arity, args...);
56
- this->wrap_native_call<false>(this->value(), name, std::forward<Function_T>(func), methodInfo);
55
+ MethodInfo* methodInfo = new MethodInfo(detail::function_traits<Function_T>::arity, args...);
56
+ this->wrap_native_function(this->value(), name, std::forward<Function_T>(func), methodInfo);
57
57
  return *this;
58
58
  }
59
59
 
@@ -72,11 +72,11 @@ inline auto& define_function(std::string name, Function_T&& func, const Arg_Ts&.
72
72
  * \param args a list of Arg instance used to define default parameters (optional)
73
73
  * \return *this
74
74
  */
75
- template<typename Function_T, typename...Arg_Ts>
76
- inline auto& define_singleton_method(std::string name, Function_T&& func, const Arg_Ts&...args)
75
+ template<typename Method_T, typename...Arg_Ts>
76
+ inline auto& define_singleton_method(std::string name, Method_T&& method, const Arg_Ts&...args)
77
77
  {
78
- MethodInfo* methodInfo = new MethodInfo(detail::method_traits<Function_T, true>::arity, args...);
79
- this->wrap_native_call<true>(rb_singleton_class(*this), name, std::forward<Function_T>(func), methodInfo);
78
+ MethodInfo* methodInfo = new MethodInfo(detail::method_traits<Method_T>::arity, args...);
79
+ this->wrap_native_method(rb_singleton_class(*this), name, std::forward<Method_T>(method), methodInfo);
80
80
  return *this;
81
81
  }
82
82
 
@@ -94,8 +94,8 @@ inline auto& define_singleton_method(std::string name, Function_T&& func, const
94
94
  template<typename Function_T, typename...Arg_Ts>
95
95
  inline auto& define_singleton_function(std::string name, Function_T&& func, const Arg_Ts& ...args)
96
96
  {
97
- MethodInfo* methodInfo = new MethodInfo(detail::method_traits<Function_T, false>::arity, args...);
98
- this->wrap_native_call<false>(rb_singleton_class(*this), name, std::forward<Function_T>(func), methodInfo);
97
+ MethodInfo* methodInfo = new MethodInfo(detail::function_traits<Function_T>::arity, args...);
98
+ this->wrap_native_function(rb_singleton_class(*this), name, std::forward<Function_T>(func), methodInfo);
99
99
  return *this;
100
100
  }
101
101