rice 4.5.0 → 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 (166) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +23 -0
  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/Rakefile +5 -4
  8. data/include/rice/rice.hpp +5436 -3201
  9. data/include/rice/stl.hpp +2355 -1269
  10. data/lib/make_rice_headers.rb +79 -0
  11. data/lib/mkmf-rice.rb +4 -0
  12. data/lib/rice/version.rb +3 -0
  13. data/lib/rice.rb +1 -0
  14. data/lib/rubygems/builder.rb +11 -0
  15. data/lib/rubygems/cmake_builder.rb +113 -0
  16. data/lib/rubygems_plugin.rb +9 -0
  17. data/rice/Arg.hpp +7 -1
  18. data/rice/Arg.ipp +11 -2
  19. data/rice/Buffer.hpp +123 -0
  20. data/rice/Buffer.ipp +599 -0
  21. data/rice/Constructor.ipp +3 -3
  22. data/rice/Data_Object.hpp +2 -3
  23. data/rice/Data_Object.ipp +188 -188
  24. data/rice/Data_Type.hpp +4 -5
  25. data/rice/Data_Type.ipp +42 -26
  26. data/rice/Enum.hpp +0 -1
  27. data/rice/Enum.ipp +26 -23
  28. data/rice/Init.hpp +8 -0
  29. data/rice/Init.ipp +8 -0
  30. data/rice/MemoryView.ipp +1 -41
  31. data/rice/Return.hpp +1 -1
  32. data/rice/Return.ipp +6 -0
  33. data/rice/cpp_api/Array.hpp +209 -0
  34. data/rice/cpp_api/Array.ipp +304 -0
  35. data/rice/cpp_api/Builtin_Object.hpp +31 -0
  36. data/rice/cpp_api/Builtin_Object.ipp +37 -0
  37. data/rice/cpp_api/Class.hpp +70 -0
  38. data/rice/cpp_api/Class.ipp +97 -0
  39. data/rice/cpp_api/Encoding.hpp +32 -0
  40. data/rice/cpp_api/Encoding.ipp +59 -0
  41. data/rice/cpp_api/Hash.hpp +194 -0
  42. data/rice/cpp_api/Hash.ipp +257 -0
  43. data/rice/cpp_api/Identifier.hpp +46 -0
  44. data/rice/cpp_api/Identifier.ipp +31 -0
  45. data/rice/cpp_api/Module.hpp +72 -0
  46. data/rice/cpp_api/Module.ipp +101 -0
  47. data/rice/cpp_api/Object.hpp +272 -0
  48. data/rice/cpp_api/Object.ipp +235 -0
  49. data/rice/cpp_api/String.hpp +74 -0
  50. data/rice/cpp_api/String.ipp +120 -0
  51. data/rice/cpp_api/Struct.hpp +113 -0
  52. data/rice/cpp_api/Struct.ipp +92 -0
  53. data/rice/cpp_api/Symbol.hpp +46 -0
  54. data/rice/cpp_api/Symbol.ipp +93 -0
  55. data/rice/cpp_api/shared_methods.hpp +134 -0
  56. data/rice/detail/MethodInfo.hpp +1 -9
  57. data/rice/detail/MethodInfo.ipp +5 -72
  58. data/rice/detail/Native.hpp +3 -2
  59. data/rice/detail/Native.ipp +32 -4
  60. data/rice/detail/NativeAttributeGet.hpp +3 -2
  61. data/rice/detail/NativeAttributeGet.ipp +8 -2
  62. data/rice/detail/NativeAttributeSet.hpp +3 -2
  63. data/rice/detail/NativeAttributeSet.ipp +8 -2
  64. data/rice/detail/NativeCallbackFFI.ipp +1 -1
  65. data/rice/detail/NativeFunction.hpp +17 -6
  66. data/rice/detail/NativeFunction.ipp +168 -64
  67. data/rice/detail/NativeIterator.hpp +3 -2
  68. data/rice/detail/NativeIterator.ipp +8 -2
  69. data/rice/detail/RubyType.hpp +2 -5
  70. data/rice/detail/RubyType.ipp +50 -5
  71. data/rice/detail/Type.hpp +3 -1
  72. data/rice/detail/Type.ipp +61 -31
  73. data/rice/detail/Wrapper.hpp +68 -33
  74. data/rice/detail/Wrapper.ipp +103 -113
  75. data/rice/detail/from_ruby.hpp +5 -4
  76. data/rice/detail/from_ruby.ipp +737 -365
  77. data/rice/detail/to_ruby.ipp +1092 -186
  78. data/rice/global_function.ipp +1 -1
  79. data/rice/libc/file.hpp +11 -0
  80. data/rice/libc/file.ipp +32 -0
  81. data/rice/rice.hpp +23 -16
  82. data/rice/stl/complex.hpp +6 -0
  83. data/rice/stl/complex.ipp +93 -0
  84. data/rice/stl/exception.hpp +11 -0
  85. data/rice/stl/exception.ipp +29 -0
  86. data/rice/stl/exception_ptr.hpp +6 -0
  87. data/rice/stl/exception_ptr.ipp +27 -0
  88. data/rice/stl/map.hpp +12 -0
  89. data/rice/stl/map.ipp +469 -0
  90. data/rice/stl/monostate.hpp +6 -0
  91. data/rice/stl/monostate.ipp +80 -0
  92. data/rice/stl/multimap.hpp +14 -0
  93. data/rice/stl/multimap.ipp +448 -0
  94. data/rice/stl/optional.hpp +6 -0
  95. data/rice/stl/optional.ipp +118 -0
  96. data/rice/stl/pair.hpp +13 -0
  97. data/rice/stl/pair.ipp +155 -0
  98. data/rice/stl/reference_wrapper.hpp +6 -0
  99. data/rice/stl/reference_wrapper.ipp +41 -0
  100. data/rice/stl/set.hpp +12 -0
  101. data/rice/stl/set.ipp +495 -0
  102. data/rice/stl/shared_ptr.hpp +28 -0
  103. data/rice/stl/shared_ptr.ipp +224 -0
  104. data/rice/stl/string.hpp +6 -0
  105. data/rice/stl/string.ipp +158 -0
  106. data/rice/stl/string_view.hpp +6 -0
  107. data/rice/stl/string_view.ipp +65 -0
  108. data/rice/stl/tuple.hpp +6 -0
  109. data/rice/stl/tuple.ipp +128 -0
  110. data/rice/stl/type_index.hpp +6 -0
  111. data/rice/stl/type_index.ipp +30 -0
  112. data/rice/stl/type_info.hpp +6 -0
  113. data/rice/stl/type_info.ipp +29 -0
  114. data/rice/stl/unique_ptr.hpp +22 -0
  115. data/rice/stl/unique_ptr.ipp +139 -0
  116. data/rice/stl/unordered_map.hpp +12 -0
  117. data/rice/stl/unordered_map.ipp +469 -0
  118. data/rice/stl/variant.hpp +6 -0
  119. data/rice/stl/variant.ipp +242 -0
  120. data/rice/stl/vector.hpp +12 -0
  121. data/rice/stl/vector.ipp +590 -0
  122. data/rice/stl.hpp +7 -3
  123. data/rice/traits/attribute_traits.hpp +26 -0
  124. data/rice/traits/function_traits.hpp +95 -0
  125. data/rice/traits/method_traits.hpp +47 -0
  126. data/rice/traits/rice_traits.hpp +160 -0
  127. data/rice.gemspec +85 -0
  128. data/test/embed_ruby.cpp +3 -0
  129. data/test/ruby/test_multiple_extensions_same_class.rb +14 -14
  130. data/test/test_Array.cpp +6 -3
  131. data/test/test_Attribute.cpp +34 -1
  132. data/test/test_Buffer.cpp +285 -0
  133. data/test/test_Callback.cpp +2 -3
  134. data/test/test_Data_Object.cpp +88 -34
  135. data/test/test_Data_Type.cpp +106 -65
  136. data/test/test_Director.cpp +7 -3
  137. data/test/test_Enum.cpp +5 -2
  138. data/test/test_File.cpp +1 -1
  139. data/test/test_From_Ruby.cpp +181 -114
  140. data/test/test_Iterator.cpp +1 -1
  141. data/test/{test_JumpException.cpp → test_Jump_Exception.cpp} +1 -0
  142. data/test/test_Keep_Alive.cpp +7 -18
  143. data/test/test_Keep_Alive_No_Wrapper.cpp +0 -1
  144. data/test/test_Module.cpp +13 -6
  145. data/test/test_Native_Registry.cpp +0 -1
  146. data/test/test_Overloads.cpp +180 -5
  147. data/test/test_Ownership.cpp +100 -57
  148. data/test/test_Proc.cpp +0 -1
  149. data/test/test_Self.cpp +4 -4
  150. data/test/test_Stl_Map.cpp +37 -39
  151. data/test/test_Stl_Multimap.cpp +693 -0
  152. data/test/test_Stl_Pair.cpp +8 -8
  153. data/test/test_Stl_Reference_Wrapper.cpp +4 -2
  154. data/test/test_Stl_Set.cpp +790 -0
  155. data/test/{test_Stl_SmartPointer.cpp → test_Stl_SharedPtr.cpp} +97 -127
  156. data/test/test_Stl_Tuple.cpp +116 -0
  157. data/test/test_Stl_Type.cpp +1 -1
  158. data/test/test_Stl_UniquePtr.cpp +202 -0
  159. data/test/test_Stl_Unordered_Map.cpp +28 -34
  160. data/test/test_Stl_Variant.cpp +217 -89
  161. data/test/test_Stl_Vector.cpp +209 -83
  162. data/test/test_To_Ruby.cpp +373 -1
  163. data/test/test_Type.cpp +85 -14
  164. data/test/test_global_functions.cpp +17 -4
  165. metadata +94 -10
  166. data/rice/detail/TupleIterator.hpp +0 -14
@@ -3,8 +3,9 @@ namespace Rice
3
3
  {
4
4
  namespace detail
5
5
  {
6
+ // =========== bool ============
6
7
  template<>
7
- class To_Ruby<void>
8
+ class To_Ruby<bool>
8
9
  {
9
10
  public:
10
11
  To_Ruby() = default;
@@ -13,10 +14,9 @@ namespace Rice
13
14
  {
14
15
  }
15
16
 
16
- VALUE convert(const void*)
17
+ VALUE convert(const bool& native)
17
18
  {
18
- throw std::runtime_error("Converting from void pointer is not implemented");
19
- return Qnil;
19
+ return native ? Qtrue : Qfalse;
20
20
  }
21
21
 
22
22
  private:
@@ -24,7 +24,7 @@ namespace Rice
24
24
  };
25
25
 
26
26
  template<>
27
- class To_Ruby<std::nullptr_t>
27
+ class To_Ruby<bool&>
28
28
  {
29
29
  public:
30
30
  To_Ruby() = default;
@@ -33,9 +33,9 @@ namespace Rice
33
33
  {
34
34
  }
35
35
 
36
- VALUE convert(std::nullptr_t const)
36
+ VALUE convert(const bool& native)
37
37
  {
38
- return Qnil;
38
+ return native ? Qtrue : Qfalse;
39
39
  }
40
40
 
41
41
  private:
@@ -43,7 +43,7 @@ namespace Rice
43
43
  };
44
44
 
45
45
  template<>
46
- class To_Ruby<short>
46
+ class To_Ruby<bool*>
47
47
  {
48
48
  public:
49
49
  To_Ruby() = default;
@@ -52,7 +52,63 @@ namespace Rice
52
52
  {
53
53
  }
54
54
 
55
- VALUE convert(const short& native)
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;
69
+ };
70
+
71
+ template<bool N>
72
+ class To_Ruby<bool[N]>
73
+ {
74
+ public:
75
+ To_Ruby() = default;
76
+
77
+ explicit To_Ruby(Arg* arg) : arg_(arg)
78
+ {
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;
89
+ };
90
+
91
+ // =========== int ============
92
+ template<>
93
+ class To_Ruby<int>
94
+ {
95
+ public:
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)
56
112
  {
57
113
  #ifdef rb_int2num_inline
58
114
  return protect(rb_int2num_inline, (int)native);
@@ -66,7 +122,7 @@ namespace Rice
66
122
  };
67
123
 
68
124
  template<>
69
- class To_Ruby<short&>
125
+ class To_Ruby<int&>
70
126
  {
71
127
  public:
72
128
  To_Ruby() = default;
@@ -75,7 +131,7 @@ namespace Rice
75
131
  {
76
132
  }
77
133
 
78
- VALUE convert(const short& native)
134
+ VALUE convert(const int& native)
79
135
  {
80
136
  #ifdef rb_int2num_inline
81
137
  return protect(rb_int2num_inline, (int)native);
@@ -89,7 +145,7 @@ namespace Rice
89
145
  };
90
146
 
91
147
  template<>
92
- class To_Ruby<int>
148
+ class To_Ruby<int*>
93
149
  {
94
150
  public:
95
151
  To_Ruby() = default;
@@ -98,30 +154,840 @@ namespace Rice
98
154
  {
99
155
  }
100
156
 
101
- VALUE convert(const int& native)
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)
165
+ {
166
+ return this->convert((int*)data);
167
+ }
168
+
169
+ private:
170
+ Arg* arg_ = nullptr;
171
+ };
172
+
173
+ template<int N>
174
+ class To_Ruby<int[N]>
175
+ {
176
+ public:
177
+ To_Ruby() = default;
178
+
179
+ explicit To_Ruby(Arg* arg) : arg_(arg)
180
+ {
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;
191
+ };
192
+
193
+ template<>
194
+ class To_Ruby<int**>
195
+ {
196
+ public:
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)
211
+ {
212
+ return this->convert((int**)data);
213
+ }
214
+
215
+ private:
216
+ Arg* arg_ = nullptr;
217
+ };
218
+
219
+ // =========== unsigned int ============
220
+ template<>
221
+ class To_Ruby<unsigned int>
222
+ {
223
+ public:
224
+ To_Ruby() = default;
225
+
226
+ explicit To_Ruby(Arg* arg) : arg_(arg)
227
+ {
228
+ }
229
+
230
+ VALUE convert(const unsigned int& native)
102
231
  {
103
232
  #ifdef rb_int2num_inline
104
- return protect(rb_int2num_inline, (int)native);
233
+ return protect(rb_uint2num_inline, (unsigned int)native);
105
234
  #else
106
- return RB_INT2NUM(native);
235
+ return RB_UINT2NUM(native);
107
236
  #endif
108
237
  }
109
238
 
110
- VALUE convert(const volatile int& native)
239
+ private:
240
+ Arg* arg_ = nullptr;
241
+ };
242
+
243
+ template<>
244
+ class To_Ruby<unsigned int&>
245
+ {
246
+ public:
247
+ To_Ruby() = default;
248
+
249
+ explicit To_Ruby(Arg* arg) : arg_(arg)
250
+ {
251
+ }
252
+
253
+ VALUE convert(const unsigned int& native)
111
254
  {
112
255
  #ifdef rb_int2num_inline
113
- return protect(rb_int2num_inline, (int)native);
256
+ return protect(rb_uint2num_inline, (unsigned int)native);
114
257
  #else
115
- return RB_INT2NUM(native);
258
+ return RB_UINT2NUM(native);
116
259
  #endif
117
260
  }
118
-
261
+
262
+ private:
263
+ Arg* arg_ = nullptr;
264
+ };
265
+
266
+ template<>
267
+ class To_Ruby<unsigned int*>
268
+ {
269
+ public:
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)
299
+ {
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;
310
+ };
311
+
312
+ template<>
313
+ class To_Ruby<unsigned int**>
314
+ {
315
+ public:
316
+ To_Ruby() = default;
317
+
318
+ explicit To_Ruby(Arg* arg) : arg_(arg)
319
+ {
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;
336
+ };
337
+
338
+ // =========== char ============
339
+ template<>
340
+ class To_Ruby<char>
341
+ {
342
+ public:
343
+ To_Ruby() = default;
344
+
345
+ explicit To_Ruby(Arg* arg) : arg_(arg)
346
+ {
347
+ }
348
+
349
+ VALUE convert(const char& native)
350
+ {
351
+ return To_Ruby<int>().convert(native);
352
+ }
353
+
354
+ private:
355
+ Arg* arg_ = nullptr;
356
+ };
357
+
358
+ template<>
359
+ class To_Ruby<char&>
360
+ {
361
+ public:
362
+ To_Ruby() = default;
363
+
364
+ explicit To_Ruby(Arg* arg) : arg_(arg)
365
+ {
366
+ }
367
+
368
+ VALUE convert(const char& native)
369
+ {
370
+ return To_Ruby<int>().convert(native);
371
+ }
372
+
373
+ private:
374
+ Arg* arg_ = nullptr;
375
+ };
376
+
377
+ template<>
378
+ class To_Ruby<char*>
379
+ {
380
+ public:
381
+ To_Ruby() = default;
382
+
383
+ explicit To_Ruby(Arg* arg) : arg_(arg)
384
+ {
385
+ }
386
+
387
+ VALUE convert(const char* data)
388
+ {
389
+ if (!data)
390
+ {
391
+ return Qnil;
392
+ }
393
+ else if (strlen(data) > 0 && data[0] == ':')
394
+ {
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);
408
+ }
409
+ else
410
+ {
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);
416
+ }
417
+ }
418
+
419
+ private:
420
+ Arg* arg_ = nullptr;
421
+ };
422
+
423
+ template<int N>
424
+ class To_Ruby<char[N]>
425
+ {
426
+ public:
427
+ To_Ruby() = default;
428
+
429
+ explicit To_Ruby(Arg* arg) : arg_(arg)
430
+ {
431
+ }
432
+
433
+ VALUE convert(const char buffer[])
434
+ {
435
+ if (N > 0 && buffer[0] == ':')
436
+ {
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);
443
+ }
444
+ else
445
+ {
446
+ long size = (long)strlen(buffer);
447
+ return protect(rb_usascii_str_new_static, buffer, size);
448
+ }
449
+ }
450
+
451
+ private:
452
+ Arg* arg_ = nullptr;
453
+ };
454
+
455
+ template<>
456
+ class To_Ruby<char**>
457
+ {
458
+ public:
459
+ To_Ruby() = default;
460
+
461
+ explicit To_Ruby(Arg* arg) : arg_(arg)
462
+ {
463
+ }
464
+
465
+ VALUE convert(char** data)
466
+ {
467
+ Buffer<char*> buffer(data);
468
+ Data_Object<Buffer<char*>> dataObject(std::move(buffer));
469
+ return dataObject.value();
470
+ }
471
+
472
+ VALUE convert(const char** data)
473
+ {
474
+ return this->convert((char**)data);
475
+ }
476
+
477
+ private:
478
+ Arg* arg_ = nullptr;
479
+ };
480
+
481
+ // =========== unsigned char ============
482
+ template<>
483
+ class To_Ruby<unsigned char>
484
+ {
485
+ public:
486
+ To_Ruby() = default;
487
+
488
+ explicit To_Ruby(Arg* arg) : arg_(arg)
489
+ {
490
+ }
491
+
492
+ VALUE convert(const unsigned char& native)
493
+ {
494
+ return To_Ruby<unsigned int>().convert(native);
495
+ }
496
+
497
+ private:
498
+ Arg* arg_ = nullptr;
499
+ };
500
+
501
+ template<>
502
+ class To_Ruby<unsigned char&>
503
+ {
504
+ public:
505
+ To_Ruby() = default;
506
+
507
+ explicit To_Ruby(Arg* arg) : arg_(arg)
508
+ {
509
+ }
510
+
511
+ VALUE convert(const unsigned char& native)
512
+ {
513
+ return To_Ruby<unsigned int>().convert(native);
514
+ }
515
+
516
+ private:
517
+ Arg* arg_ = nullptr;
518
+ };
519
+
520
+ template<>
521
+ class To_Ruby<unsigned char*>
522
+ {
523
+ public:
524
+ To_Ruby() = default;
525
+
526
+ explicit To_Ruby(Arg* arg) : arg_(arg)
527
+ {
528
+ }
529
+
530
+ VALUE convert(unsigned char* data)
531
+ {
532
+ Buffer<unsigned char> buffer(data);
533
+ Data_Object<Buffer<unsigned char>> dataObject(std::move(buffer));
534
+ return dataObject.value();
535
+ }
536
+
537
+ VALUE convert(const unsigned char* data)
538
+ {
539
+ return this->convert((unsigned char*)data);
540
+ }
541
+
542
+ private:
543
+ Arg* arg_ = nullptr;
544
+ };
545
+
546
+ template<int N>
547
+ class To_Ruby<unsigned char[N]>
548
+ {
549
+ public:
550
+ VALUE convert(unsigned char data[N])
551
+ {
552
+ Buffer<unsigned char> buffer(data, N);
553
+ Data_Object<Buffer<unsigned char>> dataObject(std::move(buffer));
554
+ return dataObject.value();
555
+ }
556
+ private:
557
+ Arg* arg_ = nullptr;
558
+ };
559
+
560
+ template<>
561
+ class To_Ruby<unsigned char**>
562
+ {
563
+ public:
564
+ To_Ruby() = default;
565
+
566
+ explicit To_Ruby(Arg* arg) : arg_(arg)
567
+ {
568
+ }
569
+
570
+ VALUE convert(unsigned char** data)
571
+ {
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
+ }
119
985
  private:
120
986
  Arg* arg_ = nullptr;
121
987
  };
122
988
 
123
989
  template<>
124
- class To_Ruby<int&>
990
+ class To_Ruby<long**>
125
991
  {
126
992
  public:
127
993
  To_Ruby() = default;
@@ -130,21 +996,25 @@ namespace Rice
130
996
  {
131
997
  }
132
998
 
133
- VALUE convert(const int& native)
999
+ VALUE convert(long** data)
134
1000
  {
135
- #ifdef rb_int2num_inline
136
- return protect(rb_int2num_inline, (int)native);
137
- #else
138
- return RB_INT2NUM(native);
139
- #endif
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);
140
1009
  }
141
1010
 
142
1011
  private:
143
1012
  Arg* arg_ = nullptr;
144
1013
  };
145
1014
 
1015
+ // =========== unsigned long ============
146
1016
  template<>
147
- class To_Ruby<long>
1017
+ class To_Ruby<unsigned long>
148
1018
  {
149
1019
  public:
150
1020
  To_Ruby() = default;
@@ -153,9 +1023,16 @@ namespace Rice
153
1023
  {
154
1024
  }
155
1025
 
156
- VALUE convert(const long& native)
1026
+ VALUE convert(const unsigned long& native)
157
1027
  {
158
- return protect(rb_long2num_inline, native);
1028
+ if (this->arg_ && this->arg_->isValue())
1029
+ {
1030
+ return native;
1031
+ }
1032
+ else
1033
+ {
1034
+ return protect(rb_ulong2num_inline, native);
1035
+ }
159
1036
  }
160
1037
 
161
1038
  private:
@@ -163,7 +1040,7 @@ namespace Rice
163
1040
  };
164
1041
 
165
1042
  template<>
166
- class To_Ruby<long&>
1043
+ class To_Ruby<unsigned long&>
167
1044
  {
168
1045
  public:
169
1046
  To_Ruby() = default;
@@ -172,9 +1049,16 @@ namespace Rice
172
1049
  {
173
1050
  }
174
1051
 
175
- VALUE convert(const long& native)
1052
+ VALUE convert(const unsigned long& native)
176
1053
  {
177
- return protect(rb_long2num_inline, native);
1054
+ if (this->arg_ && this->arg_->isValue())
1055
+ {
1056
+ return native;
1057
+ }
1058
+ else
1059
+ {
1060
+ return protect(rb_ulong2num_inline, native);
1061
+ }
178
1062
  }
179
1063
 
180
1064
  private:
@@ -182,7 +1066,7 @@ namespace Rice
182
1066
  };
183
1067
 
184
1068
  template<>
185
- class To_Ruby<long long>
1069
+ class To_Ruby<unsigned long*>
186
1070
  {
187
1071
  public:
188
1072
  To_Ruby() = default;
@@ -191,17 +1075,19 @@ namespace Rice
191
1075
  {
192
1076
  }
193
1077
 
194
- VALUE convert(const long long& native)
1078
+ VALUE convert(unsigned long* data)
195
1079
  {
196
- return protect(rb_ll2inum, native);
1080
+ Buffer<unsigned long> buffer(data);
1081
+ Data_Object<Buffer<unsigned long>> dataObject(std::move(buffer));
1082
+ return dataObject.value();
197
1083
  }
198
1084
 
199
1085
  private:
200
1086
  Arg* arg_ = nullptr;
201
1087
  };
202
1088
 
203
- template<>
204
- class To_Ruby<long long&>
1089
+ template<int N>
1090
+ class To_Ruby<unsigned long[N]>
205
1091
  {
206
1092
  public:
207
1093
  To_Ruby() = default;
@@ -210,17 +1096,18 @@ namespace Rice
210
1096
  {
211
1097
  }
212
1098
 
213
- VALUE convert(const long long& native)
1099
+ VALUE convert(unsigned long data[N])
214
1100
  {
215
- return protect(rb_ll2inum, native);
1101
+ Buffer<unsigned long> buffer(data, N);
1102
+ Data_Object<Buffer<unsigned long>> dataObject(std::move(buffer));
1103
+ return dataObject.value();
216
1104
  }
217
-
218
1105
  private:
219
1106
  Arg* arg_ = nullptr;
220
1107
  };
221
1108
 
222
1109
  template<>
223
- class To_Ruby<unsigned short>
1110
+ class To_Ruby<unsigned long**>
224
1111
  {
225
1112
  public:
226
1113
  To_Ruby() = default;
@@ -229,21 +1116,25 @@ namespace Rice
229
1116
  {
230
1117
  }
231
1118
 
232
- VALUE convert(const unsigned short& native)
1119
+ VALUE convert(unsigned long** data)
233
1120
  {
234
- #ifdef rb_int2num_inline
235
- return protect(rb_uint2num_inline, (unsigned int)native);
236
- #else
237
- return RB_UINT2NUM(native);
238
- #endif
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);
239
1129
  }
240
1130
 
241
1131
  private:
242
1132
  Arg* arg_ = nullptr;
243
1133
  };
244
1134
 
1135
+ // =========== long long ============
245
1136
  template<>
246
- class To_Ruby<unsigned short&>
1137
+ class To_Ruby<long long>
247
1138
  {
248
1139
  public:
249
1140
  To_Ruby() = default;
@@ -252,13 +1143,9 @@ namespace Rice
252
1143
  {
253
1144
  }
254
1145
 
255
- VALUE convert(const unsigned short& native)
1146
+ VALUE convert(const long long& native)
256
1147
  {
257
- #ifdef rb_int2num_inline
258
- return protect(rb_uint2num_inline, (unsigned int)native);
259
- #else
260
- return RB_UINT2NUM(native);
261
- #endif
1148
+ return protect(rb_ll2inum, native);
262
1149
  }
263
1150
 
264
1151
  private:
@@ -266,7 +1153,7 @@ namespace Rice
266
1153
  };
267
1154
 
268
1155
  template<>
269
- class To_Ruby<unsigned int>
1156
+ class To_Ruby<long long&>
270
1157
  {
271
1158
  public:
272
1159
  To_Ruby() = default;
@@ -275,13 +1162,9 @@ namespace Rice
275
1162
  {
276
1163
  }
277
1164
 
278
- VALUE convert(const unsigned int& native)
1165
+ VALUE convert(const long long& native)
279
1166
  {
280
- #ifdef rb_int2num_inline
281
- return protect(rb_uint2num_inline, (unsigned int)native);
282
- #else
283
- return RB_UINT2NUM(native);
284
- #endif
1167
+ return protect(rb_ll2inum, native);
285
1168
  }
286
1169
 
287
1170
  private:
@@ -289,7 +1172,7 @@ namespace Rice
289
1172
  };
290
1173
 
291
1174
  template<>
292
- class To_Ruby<unsigned int&>
1175
+ class To_Ruby<long long*>
293
1176
  {
294
1177
  public:
295
1178
  To_Ruby() = default;
@@ -298,21 +1181,19 @@ namespace Rice
298
1181
  {
299
1182
  }
300
1183
 
301
- VALUE convert(const unsigned int& native)
1184
+ VALUE convert(long long* data)
302
1185
  {
303
- #ifdef rb_int2num_inline
304
- return protect(rb_uint2num_inline, (unsigned int)native);
305
- #else
306
- return RB_UINT2NUM(native);
307
- #endif
1186
+ Buffer<long long> buffer(data);
1187
+ Data_Object<Buffer<long long>> dataObject(std::move(buffer));
1188
+ return dataObject.value();
308
1189
  }
309
1190
 
310
1191
  private:
311
1192
  Arg* arg_ = nullptr;
312
1193
  };
313
1194
 
314
- template<>
315
- class To_Ruby<unsigned long>
1195
+ template<int N>
1196
+ class To_Ruby<long long[N]>
316
1197
  {
317
1198
  public:
318
1199
  To_Ruby() = default;
@@ -321,24 +1202,18 @@ namespace Rice
321
1202
  {
322
1203
  }
323
1204
 
324
- VALUE convert(const unsigned long& native)
1205
+ VALUE convert(long long data[N])
325
1206
  {
326
- if (this->arg_ && this->arg_->isValue())
327
- {
328
- return native;
329
- }
330
- else
331
- {
332
- return protect(rb_ulong2num_inline, native);
333
- }
1207
+ Buffer<long long> buffer(data, N);
1208
+ Data_Object<Buffer<long long>> dataObject(std::move(buffer));
1209
+ return dataObject.value();
334
1210
  }
335
-
336
1211
  private:
337
1212
  Arg* arg_ = nullptr;
338
1213
  };
339
1214
 
340
1215
  template<>
341
- class To_Ruby<unsigned long&>
1216
+ class To_Ruby<long long**>
342
1217
  {
343
1218
  public:
344
1219
  To_Ruby() = default;
@@ -347,22 +1222,23 @@ namespace Rice
347
1222
  {
348
1223
  }
349
1224
 
350
- VALUE convert(const unsigned long& native)
1225
+ VALUE convert(long long** data)
351
1226
  {
352
- if (this->arg_ && this->arg_->isValue())
353
- {
354
- return native;
355
- }
356
- else
357
- {
358
- return protect(rb_ulong2num_inline, native);
359
- }
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);
360
1235
  }
361
1236
 
362
1237
  private:
363
1238
  Arg* arg_ = nullptr;
364
1239
  };
365
1240
 
1241
+ // =========== unsigned long long ============
366
1242
  template<>
367
1243
  class To_Ruby<unsigned long long>
368
1244
  {
@@ -427,7 +1303,7 @@ namespace Rice
427
1303
  };
428
1304
 
429
1305
  template<>
430
- class To_Ruby<float>
1306
+ class To_Ruby<unsigned long long*>
431
1307
  {
432
1308
  public:
433
1309
  To_Ruby() = default;
@@ -436,17 +1312,19 @@ namespace Rice
436
1312
  {
437
1313
  }
438
1314
 
439
- VALUE convert(const float& native)
1315
+ VALUE convert(unsigned long long* data)
440
1316
  {
441
- return protect(rb_float_new, (double)native);
1317
+ Buffer<unsigned long long> buffer(data);
1318
+ Data_Object<Buffer<unsigned long long>> dataObject(std::move(buffer));
1319
+ return dataObject.value();
442
1320
  }
443
1321
 
444
1322
  private:
445
1323
  Arg* arg_ = nullptr;
446
1324
  };
447
1325
 
448
- template<>
449
- class To_Ruby<float&>
1326
+ template<int N>
1327
+ class To_Ruby<unsigned long long[N]>
450
1328
  {
451
1329
  public:
452
1330
  To_Ruby() = default;
@@ -455,17 +1333,18 @@ namespace Rice
455
1333
  {
456
1334
  }
457
1335
 
458
- VALUE convert(const float& native)
1336
+ VALUE convert(unsigned long long data[N])
459
1337
  {
460
- return protect(rb_float_new, (double)native);
1338
+ Buffer<unsigned long long> buffer(data, N);
1339
+ Data_Object<Buffer<unsigned long long>> dataObject(std::move(buffer));
1340
+ return dataObject.value();
461
1341
  }
462
-
463
1342
  private:
464
1343
  Arg* arg_ = nullptr;
465
1344
  };
466
1345
 
467
1346
  template<>
468
- class To_Ruby<double>
1347
+ class To_Ruby<unsigned long long**>
469
1348
  {
470
1349
  public:
471
1350
  To_Ruby() = default;
@@ -474,17 +1353,25 @@ namespace Rice
474
1353
  {
475
1354
  }
476
1355
 
477
- VALUE convert(const double& native)
1356
+ VALUE convert(unsigned long long** data)
478
1357
  {
479
- return protect(rb_float_new, native);
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);
480
1366
  }
481
1367
 
482
1368
  private:
483
1369
  Arg* arg_ = nullptr;
484
1370
  };
485
1371
 
1372
+ // =========== short ============
486
1373
  template<>
487
- class To_Ruby<double&>
1374
+ class To_Ruby<short>
488
1375
  {
489
1376
  public:
490
1377
  To_Ruby() = default;
@@ -493,9 +1380,13 @@ namespace Rice
493
1380
  {
494
1381
  }
495
1382
 
496
- VALUE convert(const double& native)
1383
+ VALUE convert(const short& native)
497
1384
  {
498
- return protect(rb_float_new, native);
1385
+ #ifdef rb_int2num_inline
1386
+ return protect(rb_int2num_inline, (int)native);
1387
+ #else
1388
+ return RB_INT2NUM(native);
1389
+ #endif
499
1390
  }
500
1391
 
501
1392
  private:
@@ -503,7 +1394,7 @@ namespace Rice
503
1394
  };
504
1395
 
505
1396
  template<>
506
- class To_Ruby<bool>
1397
+ class To_Ruby<short&>
507
1398
  {
508
1399
  public:
509
1400
  To_Ruby() = default;
@@ -512,9 +1403,13 @@ namespace Rice
512
1403
  {
513
1404
  }
514
1405
 
515
- VALUE convert(const bool& native)
1406
+ VALUE convert(const short& native)
516
1407
  {
517
- return native ? Qtrue : Qfalse;
1408
+ #ifdef rb_int2num_inline
1409
+ return protect(rb_int2num_inline, (int)native);
1410
+ #else
1411
+ return RB_INT2NUM(native);
1412
+ #endif
518
1413
  }
519
1414
 
520
1415
  private:
@@ -522,7 +1417,7 @@ namespace Rice
522
1417
  };
523
1418
 
524
1419
  template<>
525
- class To_Ruby<bool&>
1420
+ class To_Ruby<short*>
526
1421
  {
527
1422
  public:
528
1423
  To_Ruby() = default;
@@ -531,17 +1426,19 @@ namespace Rice
531
1426
  {
532
1427
  }
533
1428
 
534
- VALUE convert(const bool& native)
1429
+ VALUE convert(short* data)
535
1430
  {
536
- return native ? Qtrue : Qfalse;
1431
+ Buffer<short> buffer(data);
1432
+ Data_Object<Buffer<short>> dataObject(std::move(buffer));
1433
+ return dataObject.value();
537
1434
  }
538
1435
 
539
1436
  private:
540
1437
  Arg* arg_ = nullptr;
541
1438
  };
542
1439
 
543
- template<>
544
- class To_Ruby<char>
1440
+ template<int N>
1441
+ class To_Ruby<short[N]>
545
1442
  {
546
1443
  public:
547
1444
  To_Ruby() = default;
@@ -550,17 +1447,18 @@ namespace Rice
550
1447
  {
551
1448
  }
552
1449
 
553
- VALUE convert(const char& native)
1450
+ VALUE convert(short data[N])
554
1451
  {
555
- return To_Ruby<int>().convert(native);
1452
+ Buffer<short> buffer(data, N);
1453
+ Data_Object<Buffer<short>> dataObject(std::move(buffer));
1454
+ return dataObject.value();
556
1455
  }
557
-
558
1456
  private:
559
1457
  Arg* arg_ = nullptr;
560
1458
  };
561
1459
 
562
1460
  template<>
563
- class To_Ruby<char&>
1461
+ class To_Ruby<short**>
564
1462
  {
565
1463
  public:
566
1464
  To_Ruby() = default;
@@ -569,17 +1467,25 @@ namespace Rice
569
1467
  {
570
1468
  }
571
1469
 
572
- VALUE convert(const char& native)
1470
+ VALUE convert(short** data)
573
1471
  {
574
- return To_Ruby<int>().convert(native);
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);
575
1480
  }
576
1481
 
577
1482
  private:
578
1483
  Arg* arg_ = nullptr;
579
1484
  };
580
1485
 
1486
+ // =========== unsigned short ============
581
1487
  template<>
582
- class To_Ruby<char*>
1488
+ class To_Ruby<unsigned short>
583
1489
  {
584
1490
  public:
585
1491
  To_Ruby() = default;
@@ -588,42 +1494,21 @@ namespace Rice
588
1494
  {
589
1495
  }
590
1496
 
591
- VALUE convert(const char* buffer)
1497
+ VALUE convert(const unsigned short& native)
592
1498
  {
593
- if (!buffer)
594
- {
595
- return Qnil;
596
- }
597
- else if (strlen(buffer) > 0 && buffer[0] == ':')
598
- {
599
- size_t symbolLength = strlen(buffer) - 1;
600
- char* symbol = new char[symbolLength];
601
- strncpy(symbol, buffer + 1, symbolLength);
602
- ID id = protect(rb_intern2, symbol, (long)symbolLength);
603
- delete[] symbol;
604
- return protect(rb_id2sym, id);
605
- }
606
- else if (this->arg_ && this->arg_->isOwner())
607
- {
608
- // This copies the buffer but does not free it. So Ruby is not really
609
- // taking ownership of it. But there isn't a Ruby API for creating a string
610
- // from an existing buffer and later freeing it.
611
- return protect(rb_usascii_str_new_cstr, buffer);
612
- }
613
- else
614
- {
615
- // Does NOT copy the passed in buffer and does NOT free it when the string is GCed
616
- long size = (long)strlen(buffer);
617
- return protect(rb_usascii_str_new_static, buffer, size);
618
- }
1499
+ #ifdef rb_int2num_inline
1500
+ return protect(rb_uint2num_inline, (unsigned int)native);
1501
+ #else
1502
+ return RB_UINT2NUM(native);
1503
+ #endif
619
1504
  }
620
1505
 
621
1506
  private:
622
1507
  Arg* arg_ = nullptr;
623
1508
  };
624
1509
 
625
- template<int N>
626
- class To_Ruby<char[N]>
1510
+ template<>
1511
+ class To_Ruby<unsigned short&>
627
1512
  {
628
1513
  public:
629
1514
  To_Ruby() = default;
@@ -632,22 +1517,13 @@ namespace Rice
632
1517
  {
633
1518
  }
634
1519
 
635
- VALUE convert(const char buffer[])
1520
+ VALUE convert(const unsigned short& native)
636
1521
  {
637
- if (N > 0 && buffer[0] == ':')
638
- {
639
- // N count includes a NULL character at the end of the string
640
- constexpr size_t symbolLength = N - 1;
641
- char symbol[symbolLength];
642
- strncpy(symbol, buffer + 1, symbolLength);
643
- ID id = protect(rb_intern, symbol);
644
- return protect(rb_id2sym, id);
645
- }
646
- else
647
- {
648
- long size = (long)strlen(buffer);
649
- return protect(rb_usascii_str_new_static, buffer, size);
650
- }
1522
+ #ifdef rb_int2num_inline
1523
+ return protect(rb_uint2num_inline, (unsigned int)native);
1524
+ #else
1525
+ return RB_UINT2NUM(native);
1526
+ #endif
651
1527
  }
652
1528
 
653
1529
  private:
@@ -655,7 +1531,7 @@ namespace Rice
655
1531
  };
656
1532
 
657
1533
  template<>
658
- class To_Ruby<unsigned char>
1534
+ class To_Ruby<unsigned short*>
659
1535
  {
660
1536
  public:
661
1537
  To_Ruby() = default;
@@ -664,17 +1540,39 @@ namespace Rice
664
1540
  {
665
1541
  }
666
1542
 
667
- VALUE convert(const unsigned char& native)
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)
668
1561
  {
669
- return To_Ruby<unsigned int>().convert(native);
670
1562
  }
671
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
+ }
672
1570
  private:
673
1571
  Arg* arg_ = nullptr;
674
1572
  };
675
1573
 
676
1574
  template<>
677
- class To_Ruby<unsigned char&>
1575
+ class To_Ruby<unsigned short**>
678
1576
  {
679
1577
  public:
680
1578
  To_Ruby() = default;
@@ -683,17 +1581,25 @@ namespace Rice
683
1581
  {
684
1582
  }
685
1583
 
686
- VALUE convert(const unsigned char& native)
1584
+ VALUE convert(unsigned short** data)
687
1585
  {
688
- return To_Ruby<unsigned int>().convert(native);
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);
689
1594
  }
690
1595
 
691
1596
  private:
692
1597
  Arg* arg_ = nullptr;
693
1598
  };
694
1599
 
1600
+ // =========== std::nullptr_t ============
695
1601
  template<>
696
- class To_Ruby<signed char>
1602
+ class To_Ruby<std::nullptr_t>
697
1603
  {
698
1604
  public:
699
1605
  To_Ruby() = default;
@@ -702,17 +1608,18 @@ namespace Rice
702
1608
  {
703
1609
  }
704
1610
 
705
- VALUE convert(const signed char& native)
1611
+ VALUE convert(std::nullptr_t const)
706
1612
  {
707
- return To_Ruby<signed int>().convert(native);
1613
+ return Qnil;
708
1614
  }
709
1615
 
710
1616
  private:
711
1617
  Arg* arg_ = nullptr;
712
1618
  };
713
1619
 
1620
+ // =========== void ============
714
1621
  template<>
715
- class To_Ruby<signed char&>
1622
+ class To_Ruby<void>
716
1623
  {
717
1624
  public:
718
1625
  To_Ruby() = default;
@@ -721,15 +1628,16 @@ namespace Rice
721
1628
  {
722
1629
  }
723
1630
 
724
- VALUE convert(const signed char& native)
1631
+ VALUE convert(const void*)
725
1632
  {
726
- return To_Ruby<signed int>().convert(native);
1633
+ throw std::runtime_error("Converting from void pointer is not implemented");
1634
+ return Qnil;
727
1635
  }
728
1636
 
729
1637
  private:
730
1638
  Arg* arg_ = nullptr;
731
1639
  };
732
-
1640
+
733
1641
  template <>
734
1642
  class To_Ruby<void*>
735
1643
  {
@@ -742,21 +1650,19 @@ namespace Rice
742
1650
 
743
1651
  VALUE convert(void* data)
744
1652
  {
745
- if (this->arg_ && this->arg_->isOpaque())
1653
+ if (data == nullptr)
746
1654
  {
747
- return VALUE(data);
1655
+ return Qnil;
748
1656
  }
749
- else if (data)
1657
+ else if (this->arg_ && this->arg_->isOpaque())
750
1658
  {
751
- // Note that T could be a pointer or reference to a base class while data is in fact a
752
- // child class. Lookup the correct type so we return an instance of the correct Ruby class
753
- std::pair<VALUE, rb_data_type_t*> rubyTypeInfo = detail::Registries::instance.types.figureType(data);
754
- bool isOwner = this->arg_ && this->arg_->isOwner();
755
- return detail::wrap(rubyTypeInfo.first, rubyTypeInfo.second, data, isOwner);
1659
+ return VALUE(data);
756
1660
  }
757
1661
  else
758
1662
  {
759
- return Qnil;
1663
+ Buffer<void> buffer(data);
1664
+ Data_Object<Buffer<void>> dataObject(std::move(buffer));
1665
+ return dataObject.value();
760
1666
  }
761
1667
  }
762
1668
 
@@ -768,5 +1674,5 @@ namespace Rice
768
1674
  private:
769
1675
  Arg* arg_ = nullptr;
770
1676
  };
771
- }
1677
+ }
772
1678
  }