rice 4.3.3 → 4.6.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 (237) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +86 -26
  3. data/CMakeLists.txt +31 -0
  4. data/CMakePresets.json +75 -0
  5. data/COPYING +3 -2
  6. data/FindRuby.cmake +437 -0
  7. data/README.md +7 -2
  8. data/Rakefile +12 -5
  9. data/include/rice/rice.hpp +9522 -4426
  10. data/include/rice/stl.hpp +2831 -1198
  11. data/lib/make_rice_headers.rb +79 -0
  12. data/lib/mkmf-rice.rb +40 -94
  13. data/lib/rice/version.rb +3 -0
  14. data/lib/rice.rb +1 -0
  15. data/lib/rubygems/builder.rb +11 -0
  16. data/lib/rubygems/cmake_builder.rb +113 -0
  17. data/lib/rubygems_plugin.rb +9 -0
  18. data/rice/Address_Registration_Guard.hpp +72 -3
  19. data/rice/Arg.hpp +26 -6
  20. data/rice/Arg.ipp +35 -2
  21. data/rice/Buffer.hpp +123 -0
  22. data/rice/Buffer.ipp +599 -0
  23. data/rice/Callback.hpp +21 -0
  24. data/rice/Callback.ipp +13 -0
  25. data/rice/Constructor.hpp +4 -27
  26. data/rice/Constructor.ipp +79 -0
  27. data/rice/Data_Object.hpp +73 -3
  28. data/rice/Data_Object.ipp +388 -96
  29. data/rice/Data_Type.hpp +214 -3
  30. data/rice/Data_Type.ipp +144 -67
  31. data/rice/Director.hpp +0 -2
  32. data/rice/Enum.hpp +4 -7
  33. data/rice/Enum.ipp +102 -55
  34. data/rice/Exception.hpp +62 -2
  35. data/rice/Exception.ipp +7 -12
  36. data/rice/Init.hpp +8 -0
  37. data/rice/Init.ipp +8 -0
  38. data/rice/JumpException.hpp +44 -0
  39. data/rice/JumpException.ipp +48 -0
  40. data/rice/MemoryView.hpp +11 -0
  41. data/rice/MemoryView.ipp +3 -0
  42. data/rice/Return.hpp +7 -27
  43. data/rice/Return.ipp +13 -13
  44. data/rice/cpp_api/Array.hpp +209 -0
  45. data/rice/cpp_api/Array.ipp +304 -0
  46. data/rice/cpp_api/Builtin_Object.hpp +31 -0
  47. data/rice/cpp_api/Builtin_Object.ipp +37 -0
  48. data/rice/cpp_api/Class.hpp +70 -0
  49. data/rice/cpp_api/Class.ipp +97 -0
  50. data/rice/cpp_api/Encoding.hpp +32 -0
  51. data/rice/cpp_api/Encoding.ipp +59 -0
  52. data/rice/cpp_api/Hash.hpp +194 -0
  53. data/rice/cpp_api/Hash.ipp +257 -0
  54. data/rice/{Identifier.hpp → cpp_api/Identifier.hpp} +2 -6
  55. data/rice/{Identifier.ipp → cpp_api/Identifier.ipp} +4 -2
  56. data/rice/cpp_api/Module.hpp +72 -0
  57. data/rice/cpp_api/Module.ipp +101 -0
  58. data/rice/cpp_api/Object.hpp +272 -0
  59. data/rice/cpp_api/Object.ipp +235 -0
  60. data/rice/cpp_api/String.hpp +74 -0
  61. data/rice/cpp_api/String.ipp +120 -0
  62. data/rice/cpp_api/Struct.hpp +113 -0
  63. data/rice/cpp_api/Struct.ipp +92 -0
  64. data/rice/cpp_api/Symbol.hpp +46 -0
  65. data/rice/cpp_api/Symbol.ipp +93 -0
  66. data/rice/cpp_api/shared_methods.hpp +134 -0
  67. data/rice/detail/DefaultHandler.hpp +12 -0
  68. data/rice/detail/DefaultHandler.ipp +8 -0
  69. data/rice/detail/HandlerRegistry.hpp +5 -35
  70. data/rice/detail/HandlerRegistry.ipp +7 -11
  71. data/rice/detail/InstanceRegistry.hpp +1 -4
  72. data/rice/detail/MethodInfo.hpp +12 -10
  73. data/rice/detail/MethodInfo.ipp +26 -21
  74. data/rice/detail/Native.hpp +33 -0
  75. data/rice/detail/Native.ipp +157 -0
  76. data/rice/detail/NativeAttributeGet.hpp +52 -0
  77. data/rice/detail/NativeAttributeGet.ipp +57 -0
  78. data/rice/detail/NativeAttributeSet.hpp +44 -0
  79. data/rice/detail/NativeAttributeSet.ipp +88 -0
  80. data/rice/detail/NativeCallbackFFI.hpp +55 -0
  81. data/rice/detail/NativeCallbackFFI.ipp +151 -0
  82. data/rice/detail/NativeCallbackSimple.hpp +30 -0
  83. data/rice/detail/NativeCallbackSimple.ipp +29 -0
  84. data/rice/detail/NativeFunction.hpp +33 -23
  85. data/rice/detail/NativeFunction.ipp +309 -70
  86. data/rice/detail/NativeIterator.hpp +9 -11
  87. data/rice/detail/NativeIterator.ipp +33 -31
  88. data/rice/detail/NativeRegistry.hpp +24 -15
  89. data/rice/detail/NativeRegistry.ipp +23 -48
  90. data/rice/detail/Proc.hpp +4 -0
  91. data/rice/detail/Proc.ipp +85 -0
  92. data/rice/detail/Registries.hpp +0 -7
  93. data/rice/detail/Registries.ipp +0 -18
  94. data/rice/detail/RubyFunction.hpp +0 -3
  95. data/rice/detail/RubyFunction.ipp +4 -8
  96. data/rice/detail/RubyType.hpp +16 -0
  97. data/rice/detail/RubyType.ipp +232 -0
  98. data/rice/detail/Type.hpp +7 -6
  99. data/rice/detail/Type.ipp +192 -45
  100. data/rice/detail/TypeRegistry.hpp +15 -7
  101. data/rice/detail/TypeRegistry.ipp +105 -12
  102. data/rice/detail/Wrapper.hpp +68 -32
  103. data/rice/detail/Wrapper.ipp +121 -109
  104. data/rice/detail/cpp_protect.hpp +5 -6
  105. data/rice/detail/default_allocation_func.ipp +0 -2
  106. data/rice/detail/from_ruby.hpp +38 -3
  107. data/rice/detail/from_ruby.ipp +1321 -492
  108. data/rice/detail/ruby.hpp +18 -0
  109. data/rice/detail/to_ruby.hpp +41 -3
  110. data/rice/detail/to_ruby.ipp +1424 -194
  111. data/rice/global_function.hpp +0 -4
  112. data/rice/global_function.ipp +0 -1
  113. data/rice/libc/file.hpp +11 -0
  114. data/rice/libc/file.ipp +32 -0
  115. data/rice/rice.hpp +116 -26
  116. data/rice/ruby_mark.hpp +4 -3
  117. data/rice/stl/complex.hpp +6 -0
  118. data/rice/stl/complex.ipp +93 -0
  119. data/rice/stl/exception.hpp +11 -0
  120. data/rice/stl/exception.ipp +29 -0
  121. data/rice/stl/exception_ptr.hpp +6 -0
  122. data/rice/stl/exception_ptr.ipp +27 -0
  123. data/rice/stl/map.hpp +12 -0
  124. data/rice/stl/map.ipp +469 -0
  125. data/rice/stl/monostate.hpp +6 -0
  126. data/rice/stl/monostate.ipp +80 -0
  127. data/rice/stl/multimap.hpp +14 -0
  128. data/rice/stl/multimap.ipp +448 -0
  129. data/rice/stl/optional.hpp +6 -0
  130. data/rice/stl/optional.ipp +118 -0
  131. data/rice/stl/pair.hpp +13 -0
  132. data/rice/stl/pair.ipp +155 -0
  133. data/rice/stl/reference_wrapper.hpp +6 -0
  134. data/rice/stl/reference_wrapper.ipp +41 -0
  135. data/rice/stl/set.hpp +12 -0
  136. data/rice/stl/set.ipp +495 -0
  137. data/rice/stl/shared_ptr.hpp +28 -0
  138. data/rice/stl/shared_ptr.ipp +224 -0
  139. data/rice/stl/string.hpp +6 -0
  140. data/rice/stl/string.ipp +158 -0
  141. data/rice/stl/string_view.hpp +6 -0
  142. data/rice/stl/string_view.ipp +65 -0
  143. data/rice/stl/tuple.hpp +6 -0
  144. data/rice/stl/tuple.ipp +128 -0
  145. data/rice/stl/type_index.hpp +6 -0
  146. data/rice/stl/type_index.ipp +30 -0
  147. data/rice/stl/type_info.hpp +6 -0
  148. data/rice/stl/type_info.ipp +29 -0
  149. data/rice/stl/unique_ptr.hpp +22 -0
  150. data/rice/stl/unique_ptr.ipp +139 -0
  151. data/rice/stl/unordered_map.hpp +12 -0
  152. data/rice/stl/unordered_map.ipp +469 -0
  153. data/rice/stl/variant.hpp +6 -0
  154. data/rice/stl/variant.ipp +242 -0
  155. data/rice/stl/vector.hpp +12 -0
  156. data/rice/stl/vector.ipp +590 -0
  157. data/rice/stl.hpp +11 -3
  158. data/rice/traits/attribute_traits.hpp +26 -0
  159. data/rice/traits/function_traits.hpp +95 -0
  160. data/rice/traits/method_traits.hpp +47 -0
  161. data/rice/traits/rice_traits.hpp +160 -0
  162. data/rice.gemspec +85 -0
  163. data/test/embed_ruby.cpp +7 -1
  164. data/test/extconf.rb +2 -0
  165. data/test/test_Address_Registration_Guard.cpp +5 -0
  166. data/test/test_Array.cpp +18 -4
  167. data/test/test_Attribute.cpp +136 -21
  168. data/test/test_Buffer.cpp +285 -0
  169. data/test/test_Builtin_Object.cpp +5 -0
  170. data/test/test_Callback.cpp +230 -0
  171. data/test/test_Class.cpp +5 -31
  172. data/test/test_Constructor.cpp +69 -6
  173. data/test/test_Data_Object.cpp +97 -38
  174. data/test/test_Data_Type.cpp +470 -65
  175. data/test/test_Director.cpp +17 -8
  176. data/test/test_Enum.cpp +155 -40
  177. data/test/test_Exception.cpp +235 -0
  178. data/test/test_File.cpp +70 -0
  179. data/test/test_From_Ruby.cpp +609 -0
  180. data/test/test_Hash.cpp +5 -0
  181. data/test/test_Identifier.cpp +5 -0
  182. data/test/test_Inheritance.cpp +6 -1
  183. data/test/test_Iterator.cpp +6 -1
  184. data/test/test_Jump_Exception.cpp +23 -0
  185. data/test/test_Keep_Alive.cpp +13 -19
  186. data/test/test_Keep_Alive_No_Wrapper.cpp +5 -1
  187. data/test/test_Memory_Management.cpp +5 -0
  188. data/test/test_Module.cpp +128 -67
  189. data/test/test_Native_Registry.cpp +2 -34
  190. data/test/test_Object.cpp +5 -0
  191. data/test/test_Overloads.cpp +806 -0
  192. data/test/test_Ownership.cpp +160 -54
  193. data/test/test_Proc.cpp +44 -0
  194. data/test/test_Self.cpp +9 -4
  195. data/test/test_Stl_Exception.cpp +109 -0
  196. data/test/test_Stl_Map.cpp +54 -42
  197. data/test/test_Stl_Multimap.cpp +693 -0
  198. data/test/test_Stl_Optional.cpp +5 -0
  199. data/test/test_Stl_Pair.cpp +14 -9
  200. data/test/test_Stl_Reference_Wrapper.cpp +9 -2
  201. data/test/test_Stl_Set.cpp +790 -0
  202. data/test/test_Stl_SharedPtr.cpp +458 -0
  203. data/test/test_Stl_String.cpp +5 -0
  204. data/test/test_Stl_String_View.cpp +5 -0
  205. data/test/test_Stl_Tuple.cpp +116 -0
  206. data/test/test_Stl_Type.cpp +147 -0
  207. data/test/test_Stl_UniquePtr.cpp +202 -0
  208. data/test/test_Stl_Unordered_Map.cpp +43 -38
  209. data/test/test_Stl_Variant.cpp +217 -84
  210. data/test/test_Stl_Vector.cpp +306 -58
  211. data/test/test_String.cpp +5 -0
  212. data/test/test_Struct.cpp +5 -0
  213. data/test/test_Symbol.cpp +5 -0
  214. data/test/test_Template.cpp +192 -0
  215. data/test/test_To_Ruby.cpp +524 -0
  216. data/test/test_Tracking.cpp +1 -0
  217. data/test/test_Type.cpp +171 -0
  218. data/test/test_global_functions.cpp +67 -7
  219. data/test/unittest.cpp +8 -0
  220. metadata +127 -26
  221. data/lib/version.rb +0 -3
  222. data/rice/Address_Registration_Guard_defn.hpp +0 -79
  223. data/rice/Data_Object_defn.hpp +0 -84
  224. data/rice/Data_Type_defn.hpp +0 -190
  225. data/rice/Exception_defn.hpp +0 -68
  226. data/rice/HandlerRegistration.hpp +0 -15
  227. data/rice/detail/ExceptionHandler.hpp +0 -8
  228. data/rice/detail/ExceptionHandler.ipp +0 -28
  229. data/rice/detail/ExceptionHandler_defn.hpp +0 -77
  230. data/rice/detail/Jump_Tag.hpp +0 -21
  231. data/rice/detail/NativeAttribute.hpp +0 -64
  232. data/rice/detail/NativeAttribute.ipp +0 -112
  233. data/rice/detail/from_ruby_defn.hpp +0 -38
  234. data/rice/detail/to_ruby_defn.hpp +0 -48
  235. data/test/test_Jump_Tag.cpp +0 -17
  236. data/test/test_Stl_SmartPointer.cpp +0 -283
  237. data/test/test_To_From_Ruby.cpp +0 -399
@@ -1,448 +1,1678 @@
1
- #include "RubyFunction.hpp"
2
- #include "../Return.hpp"
3
1
 
4
2
  namespace Rice
5
3
  {
6
4
  namespace detail
7
5
  {
6
+ // =========== bool ============
8
7
  template<>
9
- class To_Ruby<void>
8
+ class To_Ruby<bool>
10
9
  {
11
10
  public:
12
- VALUE convert(void const*)
11
+ To_Ruby() = default;
12
+
13
+ explicit To_Ruby(Arg* arg) : arg_(arg)
13
14
  {
14
- return Qnil;
15
15
  }
16
+
17
+ VALUE convert(const bool& native)
18
+ {
19
+ return native ? Qtrue : Qfalse;
20
+ }
21
+
22
+ private:
23
+ Arg* arg_ = nullptr;
16
24
  };
17
25
 
18
26
  template<>
19
- class To_Ruby<std::nullptr_t>
27
+ class To_Ruby<bool&>
20
28
  {
21
29
  public:
22
- VALUE convert(std::nullptr_t const)
30
+ To_Ruby() = default;
31
+
32
+ explicit To_Ruby(Arg* arg) : arg_(arg)
23
33
  {
24
- return Qnil;
25
34
  }
35
+
36
+ VALUE convert(const bool& native)
37
+ {
38
+ return native ? Qtrue : Qfalse;
39
+ }
40
+
41
+ private:
42
+ Arg* arg_ = nullptr;
26
43
  };
27
44
 
28
45
  template<>
29
- class To_Ruby<short>
46
+ class To_Ruby<bool*>
30
47
  {
31
48
  public:
32
- VALUE convert(short const& x)
49
+ To_Ruby() = default;
50
+
51
+ explicit To_Ruby(Arg* arg) : arg_(arg)
33
52
  {
34
- #ifdef rb_int2num_inline
35
- return protect(rb_int2num_inline, (int)x);
36
- #else
37
- return RB_INT2NUM(x);
38
- #endif
39
53
  }
54
+
55
+ VALUE convert(bool* data)
56
+ {
57
+ Buffer<bool> buffer(data);
58
+ Data_Object<Buffer<bool>> dataObject(std::move(buffer));
59
+ return dataObject.value();
60
+ }
61
+
62
+ VALUE convert(const bool* data)
63
+ {
64
+ return this->convert((bool*)data);
65
+ }
66
+
67
+ private:
68
+ Arg* arg_ = nullptr;
40
69
  };
41
70
 
42
- template<>
43
- class To_Ruby<short&>
71
+ template<bool N>
72
+ class To_Ruby<bool[N]>
44
73
  {
45
74
  public:
46
- VALUE convert(short const& x)
75
+ To_Ruby() = default;
76
+
77
+ explicit To_Ruby(Arg* arg) : arg_(arg)
47
78
  {
48
- #ifdef rb_int2num_inline
49
- return protect(rb_int2num_inline, (int)x);
50
- #else
51
- return RB_INT2NUM(x);
52
- #endif
53
79
  }
80
+
81
+ VALUE convert(bool data[N])
82
+ {
83
+ Buffer<bool> buffer(data, N);
84
+ Data_Object<Buffer<bool>> dataObject(std::move(buffer));
85
+ return dataObject.value();
86
+ }
87
+ private:
88
+ Arg* arg_ = nullptr;
54
89
  };
55
90
 
91
+ // =========== int ============
56
92
  template<>
57
93
  class To_Ruby<int>
58
94
  {
59
95
  public:
60
- VALUE convert(int const& x)
96
+ To_Ruby() = default;
97
+
98
+ explicit To_Ruby(Arg* arg) : arg_(arg)
99
+ {
100
+ }
101
+
102
+ VALUE convert(const int& native)
103
+ {
104
+ #ifdef rb_int2num_inline
105
+ return protect(rb_int2num_inline, (int)native);
106
+ #else
107
+ return RB_INT2NUM(native);
108
+ #endif
109
+ }
110
+
111
+ VALUE convert(const volatile int& native)
61
112
  {
62
113
  #ifdef rb_int2num_inline
63
- return protect(rb_int2num_inline, (int)x);
114
+ return protect(rb_int2num_inline, (int)native);
64
115
  #else
65
- return RB_INT2NUM(x);
116
+ return RB_INT2NUM(native);
66
117
  #endif
67
118
  }
119
+
120
+ private:
121
+ Arg* arg_ = nullptr;
68
122
  };
69
123
 
70
124
  template<>
71
125
  class To_Ruby<int&>
72
126
  {
73
127
  public:
74
- VALUE convert(int const& x)
128
+ To_Ruby() = default;
129
+
130
+ explicit To_Ruby(Arg* arg) : arg_(arg)
131
+ {
132
+ }
133
+
134
+ VALUE convert(const int& native)
75
135
  {
76
136
  #ifdef rb_int2num_inline
77
- return protect(rb_int2num_inline, (int)x);
137
+ return protect(rb_int2num_inline, (int)native);
78
138
  #else
79
- return RB_INT2NUM(x);
139
+ return RB_INT2NUM(native);
80
140
  #endif
81
141
  }
142
+
143
+ private:
144
+ Arg* arg_ = nullptr;
82
145
  };
83
146
 
84
147
  template<>
85
- class To_Ruby<long>
148
+ class To_Ruby<int*>
86
149
  {
87
150
  public:
88
- VALUE convert(long const& x)
151
+ To_Ruby() = default;
152
+
153
+ explicit To_Ruby(Arg* arg) : arg_(arg)
89
154
  {
90
- return protect(rb_long2num_inline, x);
91
155
  }
92
- };
93
156
 
94
- template<>
95
- class To_Ruby<long&>
96
- {
97
- public:
98
- VALUE convert(long const& x)
157
+ VALUE convert(int* data)
158
+ {
159
+ Buffer<int> buffer(data);
160
+ Data_Object<Buffer<int>> dataObject(std::move(buffer));
161
+ return dataObject.value();
162
+ }
163
+
164
+ VALUE convert(const int* data)
99
165
  {
100
- return protect(rb_long2num_inline, x);
166
+ return this->convert((int*)data);
101
167
  }
168
+
169
+ private:
170
+ Arg* arg_ = nullptr;
102
171
  };
103
172
 
104
- template<>
105
- class To_Ruby<long long>
173
+ template<int N>
174
+ class To_Ruby<int[N]>
106
175
  {
107
176
  public:
108
- VALUE convert(long long const& x)
177
+ To_Ruby() = default;
178
+
179
+ explicit To_Ruby(Arg* arg) : arg_(arg)
109
180
  {
110
- return protect(rb_ll2inum, x);
111
181
  }
182
+
183
+ VALUE convert(int data[N])
184
+ {
185
+ Buffer<int> buffer(data, N);
186
+ Data_Object<Buffer<int>> dataObject(std::move(buffer));
187
+ return dataObject.value();
188
+ }
189
+ private:
190
+ Arg* arg_ = nullptr;
112
191
  };
113
192
 
114
193
  template<>
115
- class To_Ruby<long long&>
194
+ class To_Ruby<int**>
116
195
  {
117
196
  public:
118
- VALUE convert(long long const& x)
197
+ To_Ruby() = default;
198
+
199
+ explicit To_Ruby(Arg* arg) : arg_(arg)
200
+ {
201
+ }
202
+
203
+ VALUE convert(int** data)
204
+ {
205
+ Buffer<int*> buffer(data);
206
+ Data_Object<Buffer<int*>> dataObject(std::move(buffer));
207
+ return dataObject.value();
208
+ }
209
+
210
+ VALUE convert(const int** data)
119
211
  {
120
- return protect(rb_ll2inum, x);
212
+ return this->convert((int**)data);
121
213
  }
214
+
215
+ private:
216
+ Arg* arg_ = nullptr;
122
217
  };
123
218
 
219
+ // =========== unsigned int ============
124
220
  template<>
125
- class To_Ruby<unsigned short>
221
+ class To_Ruby<unsigned int>
126
222
  {
127
223
  public:
128
- VALUE convert(unsigned short const& x)
224
+ To_Ruby() = default;
225
+
226
+ explicit To_Ruby(Arg* arg) : arg_(arg)
227
+ {
228
+ }
229
+
230
+ VALUE convert(const unsigned int& native)
129
231
  {
130
232
  #ifdef rb_int2num_inline
131
- return protect(rb_uint2num_inline, (unsigned int)x);
233
+ return protect(rb_uint2num_inline, (unsigned int)native);
132
234
  #else
133
- return RB_UINT2NUM(x);
235
+ return RB_UINT2NUM(native);
134
236
  #endif
135
237
  }
238
+
239
+ private:
240
+ Arg* arg_ = nullptr;
136
241
  };
137
242
 
138
243
  template<>
139
- class To_Ruby<unsigned short&>
244
+ class To_Ruby<unsigned int&>
140
245
  {
141
246
  public:
142
- VALUE convert(unsigned short const& x)
247
+ To_Ruby() = default;
248
+
249
+ explicit To_Ruby(Arg* arg) : arg_(arg)
250
+ {
251
+ }
252
+
253
+ VALUE convert(const unsigned int& native)
143
254
  {
144
255
  #ifdef rb_int2num_inline
145
- return protect(rb_uint2num_inline, (unsigned int)x);
256
+ return protect(rb_uint2num_inline, (unsigned int)native);
146
257
  #else
147
- return RB_UINT2NUM(x);
258
+ return RB_UINT2NUM(native);
148
259
  #endif
149
260
  }
261
+
262
+ private:
263
+ Arg* arg_ = nullptr;
150
264
  };
151
265
 
152
266
  template<>
153
- class To_Ruby<unsigned int>
267
+ class To_Ruby<unsigned int*>
154
268
  {
155
269
  public:
156
- VALUE convert(unsigned int const& x)
270
+ To_Ruby() = default;
271
+
272
+ explicit To_Ruby(Arg* arg) : arg_(arg)
273
+ {
274
+ }
275
+
276
+ VALUE convert(unsigned int* data)
277
+ {
278
+ Buffer<unsigned int> buffer(data);
279
+ Data_Object<Buffer<unsigned int>> dataObject(std::move(buffer));
280
+ return dataObject.value();
281
+ }
282
+
283
+ VALUE convert(const unsigned int* data)
284
+ {
285
+ return this->convert((unsigned int*)data);
286
+ }
287
+
288
+ private:
289
+ Arg* arg_ = nullptr;
290
+ };
291
+
292
+ template<int N>
293
+ class To_Ruby<unsigned int[N]>
294
+ {
295
+ public:
296
+ To_Ruby() = default;
297
+
298
+ explicit To_Ruby(Arg* arg) : arg_(arg)
157
299
  {
158
- #ifdef rb_int2num_inline
159
- return protect(rb_uint2num_inline, (unsigned int)x);
160
- #else
161
- return RB_UINT2NUM(x);
162
- #endif
163
300
  }
301
+
302
+ VALUE convert(unsigned int data[N])
303
+ {
304
+ Buffer<unsigned int> buffer(data, N);
305
+ Data_Object<Buffer<unsigned int>> dataObject(std::move(buffer));
306
+ return dataObject.value();
307
+ }
308
+ private:
309
+ Arg* arg_ = nullptr;
164
310
  };
165
311
 
166
312
  template<>
167
- class To_Ruby<unsigned int&>
313
+ class To_Ruby<unsigned int**>
168
314
  {
169
315
  public:
170
- VALUE convert(unsigned int const& x)
316
+ To_Ruby() = default;
317
+
318
+ explicit To_Ruby(Arg* arg) : arg_(arg)
171
319
  {
172
- #ifdef rb_int2num_inline
173
- return protect(rb_uint2num_inline, (unsigned int)x);
174
- #else
175
- return RB_UINT2NUM(x);
176
- #endif
177
320
  }
321
+
322
+ VALUE convert(unsigned int** data)
323
+ {
324
+ Buffer<unsigned int*> buffer(data);
325
+ Data_Object<Buffer<unsigned int*>> dataObject(std::move(buffer));
326
+ return dataObject.value();
327
+ }
328
+
329
+ VALUE convert(const unsigned int** data)
330
+ {
331
+ return this->convert((unsigned int**)data);
332
+ }
333
+
334
+ private:
335
+ Arg* arg_ = nullptr;
178
336
  };
179
337
 
338
+ // =========== char ============
180
339
  template<>
181
- class To_Ruby<unsigned long>
340
+ class To_Ruby<char>
182
341
  {
183
342
  public:
184
343
  To_Ruby() = default;
185
344
 
186
- explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
345
+ explicit To_Ruby(Arg* arg) : arg_(arg)
187
346
  {
188
347
  }
189
348
 
190
- VALUE convert(unsigned long const& x)
349
+ VALUE convert(const char& native)
191
350
  {
192
- if (this->returnInfo_ && this->returnInfo_->isValue())
193
- {
194
- return x;
195
- }
196
- else
197
- {
198
- return protect(rb_ulong2num_inline, x);
199
- }
351
+ return To_Ruby<int>().convert(native);
200
352
  }
201
353
 
202
354
  private:
203
- Return* returnInfo_ = nullptr;
355
+ Arg* arg_ = nullptr;
204
356
  };
205
357
 
206
358
  template<>
207
- class To_Ruby<unsigned long&>
359
+ class To_Ruby<char&>
208
360
  {
209
361
  public:
210
362
  To_Ruby() = default;
211
363
 
212
- explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
364
+ explicit To_Ruby(Arg* arg) : arg_(arg)
213
365
  {
214
366
  }
215
367
 
216
- VALUE convert(unsigned long const& x)
368
+ VALUE convert(const char& native)
217
369
  {
218
- if (this->returnInfo_ && this->returnInfo_->isValue())
219
- {
220
- return x;
221
- }
222
- else
223
- {
224
- return protect(rb_ulong2num_inline, x);
225
- }
370
+ return To_Ruby<int>().convert(native);
226
371
  }
227
372
 
228
373
  private:
229
- Return* returnInfo_ = nullptr;
374
+ Arg* arg_ = nullptr;
230
375
  };
231
376
 
232
377
  template<>
233
- class To_Ruby<unsigned long long>
378
+ class To_Ruby<char*>
234
379
  {
235
380
  public:
236
381
  To_Ruby() = default;
237
382
 
238
- explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
383
+ explicit To_Ruby(Arg* arg) : arg_(arg)
239
384
  {
240
385
  }
241
386
 
242
- VALUE convert(unsigned long long const& x)
387
+ VALUE convert(const char* data)
243
388
  {
244
- if (this->returnInfo_ && this->returnInfo_->isValue())
389
+ if (!data)
390
+ {
391
+ return Qnil;
392
+ }
393
+ else if (strlen(data) > 0 && data[0] == ':')
245
394
  {
246
- return x;
395
+ size_t symbolLength = strlen(data) - 1;
396
+ char* symbol = new char[symbolLength];
397
+ strncpy(symbol, data + 1, symbolLength);
398
+ ID id = protect(rb_intern2, symbol, (long)symbolLength);
399
+ delete[] symbol;
400
+ return protect(rb_id2sym, id);
401
+ }
402
+ else if (this->arg_ && this->arg_->isOwner())
403
+ {
404
+ // This copies the buffer but does not free it. So Ruby is not really
405
+ // taking ownership of it. But there isn't a Ruby API for creating a string
406
+ // from an existing buffer and later freeing it.
407
+ return protect(rb_usascii_str_new_cstr, data);
247
408
  }
248
409
  else
249
410
  {
250
- return protect(rb_ull2inum, (unsigned long long)x);
411
+ // Does NOT copy the passed in buffer and does NOT free it when the string is GCed
412
+ long size = (long)strlen(data);
413
+ VALUE result = protect(rb_str_new_static, data, size);
414
+ // Freeze the object so Ruby can't modify the C string
415
+ return rb_obj_freeze(result);
251
416
  }
252
417
  }
253
418
 
254
419
  private:
255
- Return* returnInfo_ = nullptr;
420
+ Arg* arg_ = nullptr;
256
421
  };
257
422
 
258
- template<>
259
- class To_Ruby<unsigned long long&>
423
+ template<int N>
424
+ class To_Ruby<char[N]>
260
425
  {
261
426
  public:
262
427
  To_Ruby() = default;
263
428
 
264
- explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
429
+ explicit To_Ruby(Arg* arg) : arg_(arg)
265
430
  {
266
431
  }
267
432
 
268
- VALUE convert(unsigned long long const& x)
433
+ VALUE convert(const char buffer[])
269
434
  {
270
- if (this->returnInfo_ && this->returnInfo_->isValue())
435
+ if (N > 0 && buffer[0] == ':')
271
436
  {
272
- return x;
437
+ // N count includes a NULL character at the end of the string
438
+ constexpr size_t symbolLength = N - 1;
439
+ char symbol[symbolLength];
440
+ strncpy(symbol, buffer + 1, symbolLength);
441
+ ID id = protect(rb_intern, symbol);
442
+ return protect(rb_id2sym, id);
273
443
  }
274
444
  else
275
445
  {
276
- return protect(rb_ull2inum, (unsigned long long)x);
446
+ long size = (long)strlen(buffer);
447
+ return protect(rb_usascii_str_new_static, buffer, size);
277
448
  }
278
449
  }
279
450
 
280
451
  private:
281
- Return* returnInfo_ = nullptr;
452
+ Arg* arg_ = nullptr;
282
453
  };
283
454
 
284
455
  template<>
285
- class To_Ruby<float>
456
+ class To_Ruby<char**>
286
457
  {
287
458
  public:
288
- VALUE convert(float const& x)
459
+ To_Ruby() = default;
460
+
461
+ explicit To_Ruby(Arg* arg) : arg_(arg)
289
462
  {
290
- return protect(rb_float_new, (double)x);
291
463
  }
292
- };
293
464
 
294
- template<>
295
- class To_Ruby<float&>
296
- {
297
- public:
298
- VALUE convert(float const& x)
465
+ VALUE convert(char** data)
299
466
  {
300
- return protect(rb_float_new, (double)x);
467
+ Buffer<char*> buffer(data);
468
+ Data_Object<Buffer<char*>> dataObject(std::move(buffer));
469
+ return dataObject.value();
301
470
  }
302
- };
303
471
 
304
- template<>
305
- class To_Ruby<double>
306
- {
307
- public:
308
- VALUE convert(double const& x)
472
+ VALUE convert(const char** data)
309
473
  {
310
- return protect(rb_float_new, x);
474
+ return this->convert((char**)data);
311
475
  }
476
+
477
+ private:
478
+ Arg* arg_ = nullptr;
312
479
  };
313
480
 
481
+ // =========== unsigned char ============
314
482
  template<>
315
- class To_Ruby<double&>
483
+ class To_Ruby<unsigned char>
316
484
  {
317
485
  public:
318
- VALUE convert(double const& x)
486
+ To_Ruby() = default;
487
+
488
+ explicit To_Ruby(Arg* arg) : arg_(arg)
319
489
  {
320
- return protect(rb_float_new, x);
321
490
  }
322
- };
323
491
 
324
- template<>
325
- class To_Ruby<bool>
326
- {
327
- public:
328
- VALUE convert(bool const& x)
492
+ VALUE convert(const unsigned char& native)
329
493
  {
330
- return x ? Qtrue : Qfalse;
494
+ return To_Ruby<unsigned int>().convert(native);
331
495
  }
496
+
497
+ private:
498
+ Arg* arg_ = nullptr;
332
499
  };
333
500
 
334
501
  template<>
335
- class To_Ruby<bool&>
502
+ class To_Ruby<unsigned char&>
336
503
  {
337
504
  public:
338
- VALUE convert(bool const& x)
505
+ To_Ruby() = default;
506
+
507
+ explicit To_Ruby(Arg* arg) : arg_(arg)
339
508
  {
340
- return x ? Qtrue : Qfalse;
341
509
  }
342
- };
343
510
 
344
- template<>
345
- class To_Ruby<char>
346
- {
347
- public:
348
- VALUE convert(char const& x)
511
+ VALUE convert(const unsigned char& native)
349
512
  {
350
- return To_Ruby<int>().convert(x);
513
+ return To_Ruby<unsigned int>().convert(native);
351
514
  }
515
+
516
+ private:
517
+ Arg* arg_ = nullptr;
352
518
  };
353
519
 
354
520
  template<>
355
- class To_Ruby<char&>
521
+ class To_Ruby<unsigned char*>
356
522
  {
357
523
  public:
358
- VALUE convert(char const& x)
524
+ To_Ruby() = default;
525
+
526
+ explicit To_Ruby(Arg* arg) : arg_(arg)
359
527
  {
360
- return To_Ruby<int>().convert(x);
361
528
  }
362
- };
363
529
 
364
- template<>
365
- class To_Ruby<unsigned char>
366
- {
367
- public:
368
- VALUE convert(unsigned char const& x)
530
+ VALUE convert(unsigned char* data)
369
531
  {
370
- return To_Ruby<unsigned int>().convert(x);
532
+ Buffer<unsigned char> buffer(data);
533
+ Data_Object<Buffer<unsigned char>> dataObject(std::move(buffer));
534
+ return dataObject.value();
371
535
  }
372
- };
373
536
 
374
- template<>
375
- class To_Ruby<unsigned char&>
376
- {
377
- public:
378
- VALUE convert(unsigned char const& x)
537
+ VALUE convert(const unsigned char* data)
379
538
  {
380
- return To_Ruby<unsigned int>().convert(x);
539
+ return this->convert((unsigned char*)data);
381
540
  }
541
+
542
+ private:
543
+ Arg* arg_ = nullptr;
382
544
  };
383
545
 
384
- template<>
385
- class To_Ruby<signed char>
546
+ template<int N>
547
+ class To_Ruby<unsigned char[N]>
386
548
  {
387
549
  public:
388
- VALUE convert(signed char const& x)
550
+ VALUE convert(unsigned char data[N])
389
551
  {
390
- return To_Ruby<signed int>().convert(x);
552
+ Buffer<unsigned char> buffer(data, N);
553
+ Data_Object<Buffer<unsigned char>> dataObject(std::move(buffer));
554
+ return dataObject.value();
391
555
  }
556
+ private:
557
+ Arg* arg_ = nullptr;
392
558
  };
393
559
 
394
560
  template<>
395
- class To_Ruby<signed char&>
561
+ class To_Ruby<unsigned char**>
396
562
  {
397
563
  public:
398
- VALUE convert(signed char const& x)
564
+ To_Ruby() = default;
565
+
566
+ explicit To_Ruby(Arg* arg) : arg_(arg)
399
567
  {
400
- return To_Ruby<signed int>().convert(x);
401
568
  }
402
- };
403
569
 
404
- template<>
405
- class To_Ruby<char*>
406
- {
407
- public:
408
- VALUE convert(char const* x)
570
+ VALUE convert(unsigned char** data)
409
571
  {
410
- if (strlen(x) > 0 && x[0] == ':')
411
- {
412
- size_t symbolLength = strlen(x) - 1;
413
- char* symbol = new char[symbolLength];
414
- strncpy(symbol, x + 1, symbolLength);
415
- ID id = protect(rb_intern2, symbol, (long)symbolLength);
416
- delete[] symbol;
417
- return protect(rb_id2sym, id);
572
+ Buffer<unsigned char*> buffer(data);
573
+ Data_Object<Buffer<unsigned char*>> dataObject(std::move(buffer));
574
+ return dataObject.value();
575
+ }
576
+
577
+ VALUE convert(const unsigned char** data)
578
+ {
579
+ return this->convert((unsigned char**)data);
580
+ }
581
+
582
+ private:
583
+ Arg* arg_ = nullptr;
584
+ };
585
+
586
+ // =========== signed char ============
587
+ template<>
588
+ class To_Ruby<signed char>
589
+ {
590
+ public:
591
+ To_Ruby() = default;
592
+
593
+ explicit To_Ruby(Arg* arg) : arg_(arg)
594
+ {
595
+ }
596
+
597
+ VALUE convert(const signed char& native)
598
+ {
599
+ return To_Ruby<signed int>().convert(native);
600
+ }
601
+
602
+ private:
603
+ Arg* arg_ = nullptr;
604
+ };
605
+
606
+ template<>
607
+ class To_Ruby<signed char&>
608
+ {
609
+ public:
610
+ To_Ruby() = default;
611
+
612
+ explicit To_Ruby(Arg* arg) : arg_(arg)
613
+ {
614
+ }
615
+
616
+ VALUE convert(const signed char& native)
617
+ {
618
+ return To_Ruby<signed int>().convert(native);
619
+ }
620
+
621
+ private:
622
+ Arg* arg_ = nullptr;
623
+ };
624
+
625
+ template<>
626
+ class To_Ruby<signed char*>
627
+ {
628
+ public:
629
+ To_Ruby() = default;
630
+
631
+ explicit To_Ruby(Arg* arg) : arg_(arg)
632
+ {
633
+ }
634
+
635
+ VALUE convert(signed char* data)
636
+ {
637
+ Buffer<signed char> buffer(data);
638
+ Data_Object<Buffer<signed char>> dataObject(std::move(buffer));
639
+ return dataObject.value();
640
+ }
641
+
642
+ VALUE convert(const signed char* data)
643
+ {
644
+ return this->convert((signed char*)data);
645
+ }
646
+
647
+ private:
648
+ Arg* arg_ = nullptr;
649
+ };
650
+
651
+ template<int N>
652
+ class To_Ruby<signed char[N]>
653
+ {
654
+ public:
655
+ To_Ruby() = default;
656
+
657
+ explicit To_Ruby(Arg* arg) : arg_(arg)
658
+ {
659
+ }
660
+
661
+ VALUE convert(signed char data[N])
662
+ {
663
+ Buffer<signed char> buffer(data, N);
664
+ Data_Object<Buffer<signed char>> dataObject(std::move(buffer));
665
+ return dataObject.value();
666
+ }
667
+ private:
668
+ Arg* arg_ = nullptr;
669
+ };
670
+
671
+ template<>
672
+ class To_Ruby<signed char**>
673
+ {
674
+ public:
675
+ To_Ruby() = default;
676
+
677
+ explicit To_Ruby(Arg* arg) : arg_(arg)
678
+ {
679
+ }
680
+
681
+ VALUE convert(signed char** data)
682
+ {
683
+ Buffer<signed char*> buffer(data);
684
+ Data_Object<Buffer<signed char*>> dataObject(std::move(buffer));
685
+ return dataObject.value();
686
+ }
687
+
688
+ VALUE convert(const signed char** data)
689
+ {
690
+ return this->convert((signed char**)data);
691
+ }
692
+
693
+ private:
694
+ Arg* arg_ = nullptr;
695
+ };
696
+
697
+ // =========== double ============
698
+ template<>
699
+ class To_Ruby<double>
700
+ {
701
+ public:
702
+ To_Ruby() = default;
703
+
704
+ explicit To_Ruby(Arg* arg) : arg_(arg)
705
+ {
706
+ }
707
+
708
+ VALUE convert(const double& native)
709
+ {
710
+ return protect(rb_float_new, native);
711
+ }
712
+
713
+ private:
714
+ Arg* arg_ = nullptr;
715
+ };
716
+
717
+ template<>
718
+ class To_Ruby<double&>
719
+ {
720
+ public:
721
+ To_Ruby() = default;
722
+
723
+ explicit To_Ruby(Arg* arg) : arg_(arg)
724
+ {
725
+ }
726
+
727
+ VALUE convert(const double& native)
728
+ {
729
+ return protect(rb_float_new, native);
730
+ }
731
+
732
+ private:
733
+ Arg* arg_ = nullptr;
734
+ };
735
+
736
+ template<>
737
+ class To_Ruby<double*>
738
+ {
739
+ public:
740
+ To_Ruby() = default;
741
+
742
+ explicit To_Ruby(Arg* arg) : arg_(arg)
743
+ {
744
+ }
745
+
746
+ VALUE convert(double* data)
747
+ {
748
+ Buffer<double> buffer(data);
749
+ Data_Object<Buffer<double>> dataObject(std::move(buffer));
750
+ return dataObject.value();
751
+ }
752
+
753
+ private:
754
+ Arg* arg_ = nullptr;
755
+ };
756
+
757
+ template<int N>
758
+ class To_Ruby<double[N]>
759
+ {
760
+ public:
761
+ To_Ruby() = default;
762
+
763
+ explicit To_Ruby(Arg* arg) : arg_(arg)
764
+ {
765
+ }
766
+
767
+ VALUE convert(double data[N])
768
+ {
769
+ Buffer<double> buffer(data, N);
770
+ Data_Object<Buffer<double>> dataObject(std::move(buffer));
771
+ return dataObject.value();
772
+ }
773
+ private:
774
+ Arg* arg_ = nullptr;
775
+ };
776
+
777
+ template<>
778
+ class To_Ruby<double**>
779
+ {
780
+ public:
781
+ To_Ruby() = default;
782
+
783
+ explicit To_Ruby(Arg* arg) : arg_(arg)
784
+ {
785
+ }
786
+
787
+ VALUE convert(double** data)
788
+ {
789
+ Buffer<double*> buffer(data);
790
+ Data_Object<Buffer<double*>> dataObject(std::move(buffer));
791
+ return dataObject.value();
792
+ }
793
+
794
+ VALUE convert(const double** data)
795
+ {
796
+ return this->convert((double**)data);
797
+ }
798
+
799
+ private:
800
+ Arg* arg_ = nullptr;
801
+ };
802
+
803
+ // =========== float ============
804
+ template<>
805
+ class To_Ruby<float>
806
+ {
807
+ public:
808
+ To_Ruby() = default;
809
+
810
+ explicit To_Ruby(Arg* arg) : arg_(arg)
811
+ {
812
+ }
813
+
814
+ VALUE convert(const float& native)
815
+ {
816
+ return protect(rb_float_new, (double)native);
817
+ }
818
+
819
+ private:
820
+ Arg* arg_ = nullptr;
821
+ };
822
+
823
+ template<>
824
+ class To_Ruby<float&>
825
+ {
826
+ public:
827
+ To_Ruby() = default;
828
+
829
+ explicit To_Ruby(Arg* arg) : arg_(arg)
830
+ {
831
+ }
832
+
833
+ VALUE convert(const float& native)
834
+ {
835
+ return protect(rb_float_new, (double)native);
836
+ }
837
+
838
+ private:
839
+ Arg* arg_ = nullptr;
840
+ };
841
+
842
+ template<>
843
+ class To_Ruby<float*>
844
+ {
845
+ public:
846
+ To_Ruby() = default;
847
+
848
+ explicit To_Ruby(Arg* arg) : arg_(arg)
849
+ {
850
+ }
851
+
852
+ VALUE convert(float* data)
853
+ {
854
+ Buffer<float> buffer(data);
855
+ Data_Object<Buffer<float>> dataObject(std::move(buffer));
856
+ return dataObject.value();
857
+ }
858
+
859
+ private:
860
+ Arg* arg_ = nullptr;
861
+ };
862
+
863
+ template<int N>
864
+ class To_Ruby<float[N]>
865
+ {
866
+ public:
867
+ To_Ruby() = default;
868
+
869
+ explicit To_Ruby(Arg* arg) : arg_(arg)
870
+ {
871
+ }
872
+
873
+ VALUE convert(float data[N])
874
+ {
875
+ Buffer<float> buffer(data, N);
876
+ Data_Object<Buffer<float>> dataObject(std::move(buffer));
877
+ return dataObject.value();
878
+ }
879
+ private:
880
+ Arg* arg_ = nullptr;
881
+ };
882
+
883
+ template<>
884
+ class To_Ruby<float**>
885
+ {
886
+ public:
887
+ To_Ruby() = default;
888
+
889
+ explicit To_Ruby(Arg* arg) : arg_(arg)
890
+ {
891
+ }
892
+
893
+ VALUE convert(float** data)
894
+ {
895
+ Buffer<float*> buffer(data);
896
+ Data_Object<Buffer<float*>> dataObject(std::move(buffer));
897
+ return dataObject.value();
898
+ }
899
+
900
+ VALUE convert(const float** data)
901
+ {
902
+ return this->convert((float**)data);
903
+ }
904
+
905
+ private:
906
+ Arg* arg_ = nullptr;
907
+ };
908
+
909
+ // =========== long ============
910
+ template<>
911
+ class To_Ruby<long>
912
+ {
913
+ public:
914
+ To_Ruby() = default;
915
+
916
+ explicit To_Ruby(Arg* arg) : arg_(arg)
917
+ {
918
+ }
919
+
920
+ VALUE convert(const long& native)
921
+ {
922
+ return protect(rb_long2num_inline, native);
923
+ }
924
+
925
+ private:
926
+ Arg* arg_ = nullptr;
927
+ };
928
+
929
+ template<>
930
+ class To_Ruby<long&>
931
+ {
932
+ public:
933
+ To_Ruby() = default;
934
+
935
+ explicit To_Ruby(Arg* arg) : arg_(arg)
936
+ {
937
+ }
938
+
939
+ VALUE convert(const long& native)
940
+ {
941
+ return protect(rb_long2num_inline, native);
942
+ }
943
+
944
+ private:
945
+ Arg* arg_ = nullptr;
946
+ };
947
+
948
+ template<>
949
+ class To_Ruby<long*>
950
+ {
951
+ public:
952
+ To_Ruby() = default;
953
+
954
+ explicit To_Ruby(Arg* arg) : arg_(arg)
955
+ {
956
+ }
957
+
958
+ VALUE convert(long* data)
959
+ {
960
+ Buffer<long> buffer(data);
961
+ Data_Object<Buffer<long>> dataObject(std::move(buffer));
962
+ return dataObject.value();
963
+ }
964
+
965
+ private:
966
+ Arg* arg_ = nullptr;
967
+ };
968
+
969
+ template<int N>
970
+ class To_Ruby<long[N]>
971
+ {
972
+ public:
973
+ To_Ruby() = default;
974
+
975
+ explicit To_Ruby(Arg* arg) : arg_(arg)
976
+ {
977
+ }
978
+
979
+ VALUE convert(long data[N])
980
+ {
981
+ Buffer<long> buffer(data, N);
982
+ Data_Object<Buffer<long>> dataObject(std::move(buffer));
983
+ return dataObject.value();
984
+ }
985
+ private:
986
+ Arg* arg_ = nullptr;
987
+ };
988
+
989
+ template<>
990
+ class To_Ruby<long**>
991
+ {
992
+ public:
993
+ To_Ruby() = default;
994
+
995
+ explicit To_Ruby(Arg* arg) : arg_(arg)
996
+ {
997
+ }
998
+
999
+ VALUE convert(long** data)
1000
+ {
1001
+ Buffer<long*> buffer(data);
1002
+ Data_Object<Buffer<long*>> dataObject(std::move(buffer));
1003
+ return dataObject.value();
1004
+ }
1005
+
1006
+ VALUE convert(const long** data)
1007
+ {
1008
+ return this->convert((long**)data);
1009
+ }
1010
+
1011
+ private:
1012
+ Arg* arg_ = nullptr;
1013
+ };
1014
+
1015
+ // =========== unsigned long ============
1016
+ template<>
1017
+ class To_Ruby<unsigned long>
1018
+ {
1019
+ public:
1020
+ To_Ruby() = default;
1021
+
1022
+ explicit To_Ruby(Arg* arg) : arg_(arg)
1023
+ {
1024
+ }
1025
+
1026
+ VALUE convert(const unsigned long& native)
1027
+ {
1028
+ if (this->arg_ && this->arg_->isValue())
1029
+ {
1030
+ return native;
1031
+ }
1032
+ else
1033
+ {
1034
+ return protect(rb_ulong2num_inline, native);
1035
+ }
1036
+ }
1037
+
1038
+ private:
1039
+ Arg* arg_ = nullptr;
1040
+ };
1041
+
1042
+ template<>
1043
+ class To_Ruby<unsigned long&>
1044
+ {
1045
+ public:
1046
+ To_Ruby() = default;
1047
+
1048
+ explicit To_Ruby(Arg* arg) : arg_(arg)
1049
+ {
1050
+ }
1051
+
1052
+ VALUE convert(const unsigned long& native)
1053
+ {
1054
+ if (this->arg_ && this->arg_->isValue())
1055
+ {
1056
+ return native;
1057
+ }
1058
+ else
1059
+ {
1060
+ return protect(rb_ulong2num_inline, native);
1061
+ }
1062
+ }
1063
+
1064
+ private:
1065
+ Arg* arg_ = nullptr;
1066
+ };
1067
+
1068
+ template<>
1069
+ class To_Ruby<unsigned long*>
1070
+ {
1071
+ public:
1072
+ To_Ruby() = default;
1073
+
1074
+ explicit To_Ruby(Arg* arg) : arg_(arg)
1075
+ {
1076
+ }
1077
+
1078
+ VALUE convert(unsigned long* data)
1079
+ {
1080
+ Buffer<unsigned long> buffer(data);
1081
+ Data_Object<Buffer<unsigned long>> dataObject(std::move(buffer));
1082
+ return dataObject.value();
1083
+ }
1084
+
1085
+ private:
1086
+ Arg* arg_ = nullptr;
1087
+ };
1088
+
1089
+ template<int N>
1090
+ class To_Ruby<unsigned long[N]>
1091
+ {
1092
+ public:
1093
+ To_Ruby() = default;
1094
+
1095
+ explicit To_Ruby(Arg* arg) : arg_(arg)
1096
+ {
1097
+ }
1098
+
1099
+ VALUE convert(unsigned long data[N])
1100
+ {
1101
+ Buffer<unsigned long> buffer(data, N);
1102
+ Data_Object<Buffer<unsigned long>> dataObject(std::move(buffer));
1103
+ return dataObject.value();
1104
+ }
1105
+ private:
1106
+ Arg* arg_ = nullptr;
1107
+ };
1108
+
1109
+ template<>
1110
+ class To_Ruby<unsigned long**>
1111
+ {
1112
+ public:
1113
+ To_Ruby() = default;
1114
+
1115
+ explicit To_Ruby(Arg* arg) : arg_(arg)
1116
+ {
1117
+ }
1118
+
1119
+ VALUE convert(unsigned long** data)
1120
+ {
1121
+ Buffer<unsigned long*> buffer(data);
1122
+ Data_Object<Buffer<unsigned long*>> dataObject(std::move(buffer));
1123
+ return dataObject.value();
1124
+ }
1125
+
1126
+ VALUE convert(const unsigned long** data)
1127
+ {
1128
+ return this->convert((unsigned long**)data);
1129
+ }
1130
+
1131
+ private:
1132
+ Arg* arg_ = nullptr;
1133
+ };
1134
+
1135
+ // =========== long long ============
1136
+ template<>
1137
+ class To_Ruby<long long>
1138
+ {
1139
+ public:
1140
+ To_Ruby() = default;
1141
+
1142
+ explicit To_Ruby(Arg* arg) : arg_(arg)
1143
+ {
1144
+ }
1145
+
1146
+ VALUE convert(const long long& native)
1147
+ {
1148
+ return protect(rb_ll2inum, native);
1149
+ }
1150
+
1151
+ private:
1152
+ Arg* arg_ = nullptr;
1153
+ };
1154
+
1155
+ template<>
1156
+ class To_Ruby<long long&>
1157
+ {
1158
+ public:
1159
+ To_Ruby() = default;
1160
+
1161
+ explicit To_Ruby(Arg* arg) : arg_(arg)
1162
+ {
1163
+ }
1164
+
1165
+ VALUE convert(const long long& native)
1166
+ {
1167
+ return protect(rb_ll2inum, native);
1168
+ }
1169
+
1170
+ private:
1171
+ Arg* arg_ = nullptr;
1172
+ };
1173
+
1174
+ template<>
1175
+ class To_Ruby<long long*>
1176
+ {
1177
+ public:
1178
+ To_Ruby() = default;
1179
+
1180
+ explicit To_Ruby(Arg* arg) : arg_(arg)
1181
+ {
1182
+ }
1183
+
1184
+ VALUE convert(long long* data)
1185
+ {
1186
+ Buffer<long long> buffer(data);
1187
+ Data_Object<Buffer<long long>> dataObject(std::move(buffer));
1188
+ return dataObject.value();
1189
+ }
1190
+
1191
+ private:
1192
+ Arg* arg_ = nullptr;
1193
+ };
1194
+
1195
+ template<int N>
1196
+ class To_Ruby<long long[N]>
1197
+ {
1198
+ public:
1199
+ To_Ruby() = default;
1200
+
1201
+ explicit To_Ruby(Arg* arg) : arg_(arg)
1202
+ {
1203
+ }
1204
+
1205
+ VALUE convert(long long data[N])
1206
+ {
1207
+ Buffer<long long> buffer(data, N);
1208
+ Data_Object<Buffer<long long>> dataObject(std::move(buffer));
1209
+ return dataObject.value();
1210
+ }
1211
+ private:
1212
+ Arg* arg_ = nullptr;
1213
+ };
1214
+
1215
+ template<>
1216
+ class To_Ruby<long long**>
1217
+ {
1218
+ public:
1219
+ To_Ruby() = default;
1220
+
1221
+ explicit To_Ruby(Arg* arg) : arg_(arg)
1222
+ {
1223
+ }
1224
+
1225
+ VALUE convert(long long** data)
1226
+ {
1227
+ Buffer<long long*> buffer(data);
1228
+ Data_Object<Buffer<long long*>> dataObject(std::move(buffer));
1229
+ return dataObject.value();
1230
+ }
1231
+
1232
+ VALUE convert(const long long** data)
1233
+ {
1234
+ return this->convert((long long**)data);
1235
+ }
1236
+
1237
+ private:
1238
+ Arg* arg_ = nullptr;
1239
+ };
1240
+
1241
+ // =========== unsigned long long ============
1242
+ template<>
1243
+ class To_Ruby<unsigned long long>
1244
+ {
1245
+ public:
1246
+ To_Ruby() = default;
1247
+
1248
+ explicit To_Ruby(Arg* arg) : arg_(arg)
1249
+ {
1250
+ }
1251
+
1252
+ VALUE convert(const unsigned long long& native)
1253
+ {
1254
+ if (this->arg_ && this->arg_->isValue())
1255
+ {
1256
+ return native;
1257
+ }
1258
+ else
1259
+ {
1260
+ return protect(rb_ull2inum, (unsigned long long)native);
1261
+ }
1262
+ }
1263
+
1264
+ VALUE convert(const volatile unsigned long long& native)
1265
+ {
1266
+ if (this->arg_ && this->arg_->isValue())
1267
+ {
1268
+ return native;
1269
+ }
1270
+ else
1271
+ {
1272
+ return protect(rb_ull2inum, (unsigned long long)native);
1273
+ }
1274
+ }
1275
+ private:
1276
+ Arg* arg_ = nullptr;
1277
+ };
1278
+
1279
+ template<>
1280
+ class To_Ruby<unsigned long long&>
1281
+ {
1282
+ public:
1283
+ To_Ruby() = default;
1284
+
1285
+ explicit To_Ruby(Arg* arg) : arg_(arg)
1286
+ {
1287
+ }
1288
+
1289
+ VALUE convert(const unsigned long long& native)
1290
+ {
1291
+ if (this->arg_ && this->arg_->isValue())
1292
+ {
1293
+ return native;
418
1294
  }
419
1295
  else
420
1296
  {
421
- return protect(rb_str_new2, x);
1297
+ return protect(rb_ull2inum, (unsigned long long)native);
422
1298
  }
423
1299
  }
1300
+
1301
+ private:
1302
+ Arg* arg_ = nullptr;
1303
+ };
1304
+
1305
+ template<>
1306
+ class To_Ruby<unsigned long long*>
1307
+ {
1308
+ public:
1309
+ To_Ruby() = default;
1310
+
1311
+ explicit To_Ruby(Arg* arg) : arg_(arg)
1312
+ {
1313
+ }
1314
+
1315
+ VALUE convert(unsigned long long* data)
1316
+ {
1317
+ Buffer<unsigned long long> buffer(data);
1318
+ Data_Object<Buffer<unsigned long long>> dataObject(std::move(buffer));
1319
+ return dataObject.value();
1320
+ }
1321
+
1322
+ private:
1323
+ Arg* arg_ = nullptr;
424
1324
  };
425
1325
 
426
1326
  template<int N>
427
- class To_Ruby<char[N]>
1327
+ class To_Ruby<unsigned long long[N]>
1328
+ {
1329
+ public:
1330
+ To_Ruby() = default;
1331
+
1332
+ explicit To_Ruby(Arg* arg) : arg_(arg)
1333
+ {
1334
+ }
1335
+
1336
+ VALUE convert(unsigned long long data[N])
1337
+ {
1338
+ Buffer<unsigned long long> buffer(data, N);
1339
+ Data_Object<Buffer<unsigned long long>> dataObject(std::move(buffer));
1340
+ return dataObject.value();
1341
+ }
1342
+ private:
1343
+ Arg* arg_ = nullptr;
1344
+ };
1345
+
1346
+ template<>
1347
+ class To_Ruby<unsigned long long**>
1348
+ {
1349
+ public:
1350
+ To_Ruby() = default;
1351
+
1352
+ explicit To_Ruby(Arg* arg) : arg_(arg)
1353
+ {
1354
+ }
1355
+
1356
+ VALUE convert(unsigned long long** data)
1357
+ {
1358
+ Buffer<unsigned long long*> buffer(data);
1359
+ Data_Object<Buffer<unsigned long long*>> dataObject(std::move(buffer));
1360
+ return dataObject.value();
1361
+ }
1362
+
1363
+ VALUE convert(const unsigned long long** data)
1364
+ {
1365
+ return this->convert((unsigned long long**)data);
1366
+ }
1367
+
1368
+ private:
1369
+ Arg* arg_ = nullptr;
1370
+ };
1371
+
1372
+ // =========== short ============
1373
+ template<>
1374
+ class To_Ruby<short>
1375
+ {
1376
+ public:
1377
+ To_Ruby() = default;
1378
+
1379
+ explicit To_Ruby(Arg* arg) : arg_(arg)
1380
+ {
1381
+ }
1382
+
1383
+ VALUE convert(const short& native)
1384
+ {
1385
+ #ifdef rb_int2num_inline
1386
+ return protect(rb_int2num_inline, (int)native);
1387
+ #else
1388
+ return RB_INT2NUM(native);
1389
+ #endif
1390
+ }
1391
+
1392
+ private:
1393
+ Arg* arg_ = nullptr;
1394
+ };
1395
+
1396
+ template<>
1397
+ class To_Ruby<short&>
1398
+ {
1399
+ public:
1400
+ To_Ruby() = default;
1401
+
1402
+ explicit To_Ruby(Arg* arg) : arg_(arg)
1403
+ {
1404
+ }
1405
+
1406
+ VALUE convert(const short& native)
1407
+ {
1408
+ #ifdef rb_int2num_inline
1409
+ return protect(rb_int2num_inline, (int)native);
1410
+ #else
1411
+ return RB_INT2NUM(native);
1412
+ #endif
1413
+ }
1414
+
1415
+ private:
1416
+ Arg* arg_ = nullptr;
1417
+ };
1418
+
1419
+ template<>
1420
+ class To_Ruby<short*>
1421
+ {
1422
+ public:
1423
+ To_Ruby() = default;
1424
+
1425
+ explicit To_Ruby(Arg* arg) : arg_(arg)
1426
+ {
1427
+ }
1428
+
1429
+ VALUE convert(short* data)
1430
+ {
1431
+ Buffer<short> buffer(data);
1432
+ Data_Object<Buffer<short>> dataObject(std::move(buffer));
1433
+ return dataObject.value();
1434
+ }
1435
+
1436
+ private:
1437
+ Arg* arg_ = nullptr;
1438
+ };
1439
+
1440
+ template<int N>
1441
+ class To_Ruby<short[N]>
1442
+ {
1443
+ public:
1444
+ To_Ruby() = default;
1445
+
1446
+ explicit To_Ruby(Arg* arg) : arg_(arg)
1447
+ {
1448
+ }
1449
+
1450
+ VALUE convert(short data[N])
1451
+ {
1452
+ Buffer<short> buffer(data, N);
1453
+ Data_Object<Buffer<short>> dataObject(std::move(buffer));
1454
+ return dataObject.value();
1455
+ }
1456
+ private:
1457
+ Arg* arg_ = nullptr;
1458
+ };
1459
+
1460
+ template<>
1461
+ class To_Ruby<short**>
1462
+ {
1463
+ public:
1464
+ To_Ruby() = default;
1465
+
1466
+ explicit To_Ruby(Arg* arg) : arg_(arg)
1467
+ {
1468
+ }
1469
+
1470
+ VALUE convert(short** data)
1471
+ {
1472
+ Buffer<short*> buffer(data);
1473
+ Data_Object<Buffer<short*>> dataObject(std::move(buffer));
1474
+ return dataObject.value();
1475
+ }
1476
+
1477
+ VALUE convert(const short** data)
1478
+ {
1479
+ return this->convert((short**)data);
1480
+ }
1481
+
1482
+ private:
1483
+ Arg* arg_ = nullptr;
1484
+ };
1485
+
1486
+ // =========== unsigned short ============
1487
+ template<>
1488
+ class To_Ruby<unsigned short>
1489
+ {
1490
+ public:
1491
+ To_Ruby() = default;
1492
+
1493
+ explicit To_Ruby(Arg* arg) : arg_(arg)
1494
+ {
1495
+ }
1496
+
1497
+ VALUE convert(const unsigned short& native)
1498
+ {
1499
+ #ifdef rb_int2num_inline
1500
+ return protect(rb_uint2num_inline, (unsigned int)native);
1501
+ #else
1502
+ return RB_UINT2NUM(native);
1503
+ #endif
1504
+ }
1505
+
1506
+ private:
1507
+ Arg* arg_ = nullptr;
1508
+ };
1509
+
1510
+ template<>
1511
+ class To_Ruby<unsigned short&>
1512
+ {
1513
+ public:
1514
+ To_Ruby() = default;
1515
+
1516
+ explicit To_Ruby(Arg* arg) : arg_(arg)
1517
+ {
1518
+ }
1519
+
1520
+ VALUE convert(const unsigned short& native)
1521
+ {
1522
+ #ifdef rb_int2num_inline
1523
+ return protect(rb_uint2num_inline, (unsigned int)native);
1524
+ #else
1525
+ return RB_UINT2NUM(native);
1526
+ #endif
1527
+ }
1528
+
1529
+ private:
1530
+ Arg* arg_ = nullptr;
1531
+ };
1532
+
1533
+ template<>
1534
+ class To_Ruby<unsigned short*>
1535
+ {
1536
+ public:
1537
+ To_Ruby() = default;
1538
+
1539
+ explicit To_Ruby(Arg* arg) : arg_(arg)
1540
+ {
1541
+ }
1542
+
1543
+ VALUE convert(unsigned short* data)
1544
+ {
1545
+ Buffer<unsigned short> buffer(data);
1546
+ Data_Object<Buffer<unsigned short>> dataObject(std::move(buffer));
1547
+ return dataObject.value();
1548
+ }
1549
+
1550
+ private:
1551
+ Arg* arg_ = nullptr;
1552
+ };
1553
+
1554
+ template<int N>
1555
+ class To_Ruby<unsigned short[N]>
1556
+ {
1557
+ public:
1558
+ To_Ruby() = default;
1559
+
1560
+ explicit To_Ruby(Arg* arg) : arg_(arg)
1561
+ {
1562
+ }
1563
+
1564
+ VALUE convert(unsigned short data[N])
1565
+ {
1566
+ Buffer<unsigned short> buffer(data, N);
1567
+ Data_Object<Buffer<unsigned short>> dataObject(std::move(buffer));
1568
+ return dataObject.value();
1569
+ }
1570
+ private:
1571
+ Arg* arg_ = nullptr;
1572
+ };
1573
+
1574
+ template<>
1575
+ class To_Ruby<unsigned short**>
1576
+ {
1577
+ public:
1578
+ To_Ruby() = default;
1579
+
1580
+ explicit To_Ruby(Arg* arg) : arg_(arg)
1581
+ {
1582
+ }
1583
+
1584
+ VALUE convert(unsigned short** data)
1585
+ {
1586
+ Buffer<unsigned short*> buffer(data);
1587
+ Data_Object<Buffer<unsigned short*>> dataObject(std::move(buffer));
1588
+ return dataObject.value();
1589
+ }
1590
+
1591
+ VALUE convert(const unsigned short** data)
1592
+ {
1593
+ return this->convert((unsigned short**)data);
1594
+ }
1595
+
1596
+ private:
1597
+ Arg* arg_ = nullptr;
1598
+ };
1599
+
1600
+ // =========== std::nullptr_t ============
1601
+ template<>
1602
+ class To_Ruby<std::nullptr_t>
1603
+ {
1604
+ public:
1605
+ To_Ruby() = default;
1606
+
1607
+ explicit To_Ruby(Arg* arg) : arg_(arg)
1608
+ {
1609
+ }
1610
+
1611
+ VALUE convert(std::nullptr_t const)
1612
+ {
1613
+ return Qnil;
1614
+ }
1615
+
1616
+ private:
1617
+ Arg* arg_ = nullptr;
1618
+ };
1619
+
1620
+ // =========== void ============
1621
+ template<>
1622
+ class To_Ruby<void>
1623
+ {
1624
+ public:
1625
+ To_Ruby() = default;
1626
+
1627
+ explicit To_Ruby(Arg* arg) : arg_(arg)
1628
+ {
1629
+ }
1630
+
1631
+ VALUE convert(const void*)
1632
+ {
1633
+ throw std::runtime_error("Converting from void pointer is not implemented");
1634
+ return Qnil;
1635
+ }
1636
+
1637
+ private:
1638
+ Arg* arg_ = nullptr;
1639
+ };
1640
+
1641
+ template <>
1642
+ class To_Ruby<void*>
428
1643
  {
429
1644
  public:
430
- VALUE convert(char const x[])
1645
+ To_Ruby() = default;
1646
+
1647
+ explicit To_Ruby(Arg* arg) : arg_(arg)
1648
+ {
1649
+ }
1650
+
1651
+ VALUE convert(void* data)
431
1652
  {
432
- if (N > 0 && x[0] == ':')
1653
+ if (data == nullptr)
433
1654
  {
434
- // N count includes a NULL character at the end of the string
435
- constexpr size_t symbolLength = N - 1;
436
- char symbol[symbolLength];
437
- strncpy(symbol, x + 1, symbolLength);
438
- ID id = protect(rb_intern, symbol);
439
- return protect(rb_id2sym, id);
1655
+ return Qnil;
1656
+ }
1657
+ else if (this->arg_ && this->arg_->isOpaque())
1658
+ {
1659
+ return VALUE(data);
440
1660
  }
441
1661
  else
442
1662
  {
443
- return protect(rb_str_new2, x);
1663
+ Buffer<void> buffer(data);
1664
+ Data_Object<Buffer<void>> dataObject(std::move(buffer));
1665
+ return dataObject.value();
444
1666
  }
445
1667
  }
1668
+
1669
+ VALUE convert(const void* data)
1670
+ {
1671
+ return convert((void*)data);
1672
+ }
1673
+
1674
+ private:
1675
+ Arg* arg_ = nullptr;
446
1676
  };
447
- }
1677
+ }
448
1678
  }