rice 4.7.1 → 4.9.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 (160) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +37 -1
  3. data/CMakeLists.txt +14 -22
  4. data/CMakePresets.json +203 -75
  5. data/FindRuby.cmake +358 -123
  6. data/bin/rice-doc.rb +58 -141
  7. data/include/rice/api.hpp +261 -0
  8. data/include/rice/rice.hpp +2459 -1693
  9. data/include/rice/stl.hpp +450 -546
  10. data/lib/rice/doc/config.rb +70 -0
  11. data/lib/rice/doc/cpp_reference.rb +1 -4
  12. data/lib/rice/doc/mkdocs.rb +58 -20
  13. data/lib/rice/doc/rice.rb +21 -0
  14. data/lib/rice/doc.rb +1 -0
  15. data/lib/rice/make_rice_headers.rb +7 -0
  16. data/lib/rice/native_registry.rb +5 -10
  17. data/lib/rice/rbs.rb +6 -6
  18. data/lib/rice/version.rb +1 -1
  19. data/lib/rubygems_plugin.rb +12 -9
  20. data/rice/Arg.hpp +12 -6
  21. data/rice/Arg.ipp +14 -7
  22. data/rice/Buffer.ipp +44 -40
  23. data/rice/Callback.hpp +1 -1
  24. data/rice/Callback.ipp +2 -7
  25. data/rice/Constructor.hpp +1 -1
  26. data/rice/Constructor.ipp +11 -11
  27. data/rice/Data_Object.ipp +15 -15
  28. data/rice/Data_Type.hpp +9 -10
  29. data/rice/Data_Type.ipp +33 -31
  30. data/rice/Director.hpp +1 -0
  31. data/rice/Enum.ipp +58 -39
  32. data/rice/Exception.hpp +4 -4
  33. data/rice/Exception.ipp +7 -7
  34. data/rice/NoGVL.hpp +13 -0
  35. data/rice/Reference.hpp +56 -0
  36. data/rice/Reference.ipp +96 -0
  37. data/rice/Return.hpp +4 -1
  38. data/rice/Return.ipp +0 -6
  39. data/rice/cpp_api/Array.hpp +41 -4
  40. data/rice/cpp_api/Array.ipp +105 -9
  41. data/rice/cpp_api/Class.hpp +7 -2
  42. data/rice/cpp_api/Class.ipp +9 -4
  43. data/rice/cpp_api/Hash.ipp +7 -4
  44. data/rice/cpp_api/Module.hpp +4 -4
  45. data/rice/cpp_api/Module.ipp +12 -10
  46. data/rice/cpp_api/Object.hpp +10 -4
  47. data/rice/cpp_api/Object.ipp +20 -12
  48. data/rice/cpp_api/String.hpp +2 -2
  49. data/rice/cpp_api/String.ipp +11 -8
  50. data/rice/cpp_api/Symbol.ipp +7 -7
  51. data/rice/cpp_api/shared_methods.hpp +5 -9
  52. data/rice/detail/Forwards.hpp +18 -0
  53. data/rice/detail/Forwards.ipp +60 -0
  54. data/rice/detail/InstanceRegistry.hpp +0 -2
  55. data/rice/detail/Native.hpp +31 -21
  56. data/rice/detail/Native.ipp +282 -130
  57. data/rice/detail/NativeAttributeGet.hpp +5 -7
  58. data/rice/detail/NativeAttributeGet.ipp +26 -26
  59. data/rice/detail/NativeAttributeSet.hpp +2 -4
  60. data/rice/detail/NativeAttributeSet.ipp +20 -16
  61. data/rice/detail/NativeCallback.hpp +77 -0
  62. data/rice/detail/NativeCallback.ipp +280 -0
  63. data/rice/detail/NativeFunction.hpp +11 -21
  64. data/rice/detail/NativeFunction.ipp +58 -119
  65. data/rice/detail/NativeInvoker.hpp +4 -4
  66. data/rice/detail/NativeInvoker.ipp +7 -7
  67. data/rice/detail/NativeIterator.hpp +2 -4
  68. data/rice/detail/NativeIterator.ipp +18 -14
  69. data/rice/detail/NativeMethod.hpp +10 -20
  70. data/rice/detail/NativeMethod.ipp +54 -114
  71. data/rice/detail/NativeProc.hpp +5 -7
  72. data/rice/detail/NativeProc.ipp +39 -28
  73. data/rice/detail/NativeRegistry.hpp +1 -1
  74. data/rice/detail/NativeRegistry.ipp +29 -0
  75. data/rice/detail/Parameter.hpp +15 -8
  76. data/rice/detail/Parameter.ipp +102 -43
  77. data/rice/detail/Proc.ipp +14 -28
  78. data/rice/detail/RubyType.ipp +2 -53
  79. data/rice/detail/Type.hpp +23 -7
  80. data/rice/detail/Type.ipp +77 -93
  81. data/rice/detail/TypeRegistry.ipp +5 -4
  82. data/rice/detail/Wrapper.hpp +13 -12
  83. data/rice/detail/Wrapper.ipp +97 -44
  84. data/rice/detail/from_ruby.hpp +8 -6
  85. data/rice/detail/from_ruby.ipp +306 -173
  86. data/rice/detail/ruby.hpp +23 -0
  87. data/rice/libc/file.hpp +4 -4
  88. data/rice/rice.hpp +9 -8
  89. data/rice/rice_api/Native.ipp +5 -1
  90. data/rice/rice_api/NativeRegistry.ipp +14 -1
  91. data/rice/rice_api/Parameter.ipp +1 -1
  92. data/rice/ruby_mark.hpp +2 -1
  93. data/rice/stl/complex.ipp +12 -8
  94. data/rice/stl/map.ipp +27 -22
  95. data/rice/stl/monostate.ipp +16 -12
  96. data/rice/stl/multimap.hpp +0 -2
  97. data/rice/stl/multimap.ipp +27 -22
  98. data/rice/stl/optional.ipp +27 -11
  99. data/rice/stl/pair.ipp +5 -5
  100. data/rice/stl/reference_wrapper.ipp +5 -4
  101. data/rice/stl/set.ipp +16 -16
  102. data/rice/stl/shared_ptr.hpp +9 -9
  103. data/rice/stl/shared_ptr.ipp +52 -185
  104. data/rice/stl/string.ipp +18 -18
  105. data/rice/stl/string_view.ipp +1 -1
  106. data/rice/stl/tuple.ipp +15 -36
  107. data/rice/stl/unique_ptr.hpp +9 -3
  108. data/rice/stl/unique_ptr.ipp +86 -120
  109. data/rice/stl/unordered_map.ipp +20 -15
  110. data/rice/stl/variant.ipp +37 -21
  111. data/rice/stl/vector.ipp +41 -36
  112. data/rice/traits/function_traits.hpp +19 -19
  113. data/rice/traits/method_traits.hpp +4 -4
  114. data/rice/traits/rice_traits.hpp +162 -39
  115. data/rice.gemspec +1 -3
  116. data/test/test_Array.cpp +261 -3
  117. data/test/test_Attribute.cpp +6 -3
  118. data/test/test_Buffer.cpp +6 -42
  119. data/test/test_Callback.cpp +77 -23
  120. data/test/test_Data_Object.cpp +1 -1
  121. data/test/test_Data_Type.cpp +21 -22
  122. data/test/test_Director.cpp +2 -4
  123. data/test/test_Enum.cpp +34 -5
  124. data/test/test_File.cpp +9 -5
  125. data/test/test_From_Ruby.cpp +4 -3
  126. data/test/test_GVL.cpp +3 -3
  127. data/test/test_Hash.cpp +1 -1
  128. data/test/test_Inheritance.cpp +14 -14
  129. data/test/test_Iterator.cpp +54 -22
  130. data/test/test_Keep_Alive.cpp +1 -1
  131. data/test/test_Keep_Alive_No_Wrapper.cpp +7 -3
  132. data/test/test_Module.cpp +5 -5
  133. data/test/test_Overloads.cpp +345 -48
  134. data/test/test_Proc.cpp +54 -0
  135. data/test/test_Reference.cpp +181 -0
  136. data/test/test_Self.cpp +2 -2
  137. data/test/test_Stl_Set.cpp +6 -6
  138. data/test/test_Stl_SharedPtr.cpp +172 -33
  139. data/test/test_Stl_String_View.cpp +4 -2
  140. data/test/test_Stl_Tuple.cpp +1 -1
  141. data/test/test_Stl_UniquePtr.cpp +48 -3
  142. data/test/test_Stl_Variant.cpp +6 -14
  143. data/test/test_Stl_Vector.cpp +61 -30
  144. data/test/test_String.cpp +4 -2
  145. data/test/test_Struct.cpp +1 -1
  146. data/test/test_Symbol.cpp +1 -1
  147. data/test/test_To_Ruby.cpp +1 -0
  148. data/test/test_Type.cpp +36 -35
  149. data/test/test_global_functions.cpp +1 -1
  150. data/test/unittest.cpp +1 -1
  151. data/test/unittest.hpp +5 -5
  152. metadata +12 -10
  153. data/rice/Function.hpp +0 -17
  154. data/rice/Function.ipp +0 -13
  155. data/rice/detail/MethodInfo.hpp +0 -48
  156. data/rice/detail/MethodInfo.ipp +0 -99
  157. data/rice/detail/NativeCallbackFFI.hpp +0 -55
  158. data/rice/detail/NativeCallbackFFI.ipp +0 -152
  159. data/rice/detail/NativeCallbackSimple.hpp +0 -30
  160. data/rice/detail/NativeCallbackSimple.ipp +0 -29
@@ -23,17 +23,17 @@ namespace Rice::detail
23
23
  public:
24
24
  To_Ruby() = default;
25
25
 
26
- explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
26
+ explicit To_Ruby(Arg* arg) : arg_(arg)
27
27
  {
28
28
  }
29
29
 
30
- VALUE convert(const std::nullopt_t& _)
30
+ VALUE convert(const std::nullopt_t&)
31
31
  {
32
32
  return Qnil;
33
33
  }
34
34
 
35
35
  private:
36
- Return* returnInfo_ = nullptr;
36
+ Arg* arg_ = nullptr;
37
37
  };
38
38
 
39
39
  template<typename T>
@@ -42,7 +42,7 @@ namespace Rice::detail
42
42
  public:
43
43
  To_Ruby() = default;
44
44
 
45
- explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
45
+ explicit To_Ruby(Arg* arg) : arg_(arg)
46
46
  {
47
47
  }
48
48
 
@@ -58,8 +58,20 @@ namespace Rice::detail
58
58
  }
59
59
  }
60
60
 
61
+ VALUE convert(const std::optional<T>& data)
62
+ {
63
+ if (data.has_value())
64
+ {
65
+ return To_Ruby<T>().convert(data.value());
66
+ }
67
+ else
68
+ {
69
+ return Qnil;
70
+ }
71
+ }
72
+
61
73
  private:
62
- Return* returnInfo_ = nullptr;
74
+ Arg* arg_ = nullptr;
63
75
  };
64
76
 
65
77
  template<typename T>
@@ -68,7 +80,7 @@ namespace Rice::detail
68
80
  public:
69
81
  To_Ruby() = default;
70
82
 
71
- explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
83
+ explicit To_Ruby(Arg* arg) : arg_(arg)
72
84
  {
73
85
  }
74
86
 
@@ -85,7 +97,7 @@ namespace Rice::detail
85
97
  }
86
98
 
87
99
  private:
88
- Return* returnInfo_ = nullptr;
100
+ Arg* arg_ = nullptr;
89
101
  };
90
102
 
91
103
  template<typename T>
@@ -94,11 +106,11 @@ namespace Rice::detail
94
106
  public:
95
107
  From_Ruby() = default;
96
108
 
97
- explicit From_Ruby(Arg* arg)
109
+ explicit From_Ruby(Arg* arg) : arg_(arg)
98
110
  {
99
111
  }
100
112
 
101
- Convertible is_convertible(VALUE value)
113
+ double is_convertible(VALUE value)
102
114
  {
103
115
  switch (rb_type(value))
104
116
  {
@@ -121,6 +133,9 @@ namespace Rice::detail
121
133
  return From_Ruby<T>().convert(value);
122
134
  }
123
135
  }
136
+
137
+ private:
138
+ Arg* arg_ = nullptr;
124
139
  };
125
140
 
126
141
  template<typename T>
@@ -129,11 +144,11 @@ namespace Rice::detail
129
144
  public:
130
145
  From_Ruby() = default;
131
146
 
132
- explicit From_Ruby(Arg* arg)
147
+ explicit From_Ruby(Arg* arg) : arg_(arg)
133
148
  {
134
149
  }
135
150
 
136
- Convertible is_convertible(VALUE value)
151
+ double is_convertible(VALUE value)
137
152
  {
138
153
  switch (rb_type(value))
139
154
  {
@@ -158,6 +173,7 @@ namespace Rice::detail
158
173
  return this->converted_;
159
174
  }
160
175
  private:
176
+ Arg* arg_ = nullptr;
161
177
  std::optional<T> converted_;
162
178
  };
163
179
  }
data/rice/stl/pair.ipp CHANGED
@@ -62,11 +62,11 @@ namespace Rice
62
62
  }
63
63
  else
64
64
  {
65
- klass_.define_method("to_s", [](const T& pair)
66
- {
67
- return "[Not printable]";
68
- });
69
- }
65
+ klass_.define_method("to_s", [](const T&)
66
+ {
67
+ return "[Not printable]";
68
+ });
69
+ }
70
70
  }
71
71
 
72
72
  private:
@@ -23,7 +23,7 @@ namespace Rice::detail
23
23
  public:
24
24
  To_Ruby() = default;
25
25
 
26
- explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
26
+ explicit To_Ruby(Arg* arg) : arg_(arg)
27
27
  {
28
28
  }
29
29
 
@@ -33,7 +33,7 @@ namespace Rice::detail
33
33
  }
34
34
 
35
35
  private:
36
- Return* returnInfo_ = nullptr;
36
+ Arg* arg_ = nullptr;
37
37
  };
38
38
 
39
39
  template<typename T>
@@ -42,11 +42,11 @@ namespace Rice::detail
42
42
  public:
43
43
  From_Ruby() = default;
44
44
 
45
- explicit From_Ruby(Arg* arg)
45
+ explicit From_Ruby(Arg* arg) : arg_(arg)
46
46
  {
47
47
  }
48
48
 
49
- Convertible is_convertible(VALUE value)
49
+ double is_convertible(VALUE value)
50
50
  {
51
51
  return this->converter_.is_convertible(value);
52
52
  }
@@ -57,6 +57,7 @@ namespace Rice::detail
57
57
  }
58
58
 
59
59
  private:
60
+ Arg* arg_ = nullptr;
60
61
  From_Ruby<T&> converter_;
61
62
  };
62
63
  }
data/rice/stl/set.ipp CHANGED
@@ -217,10 +217,10 @@ namespace Rice
217
217
  }
218
218
  else
219
219
  {
220
- klass_.define_method("to_s", [](const T& self)
221
- {
222
- return "[Not printable]";
223
- });
220
+ klass_.define_method("to_s", [](const T&)
221
+ {
222
+ return "[Not printable]";
223
+ });
224
224
  }
225
225
  }
226
226
 
@@ -307,7 +307,7 @@ namespace Rice
307
307
  {
308
308
  }
309
309
 
310
- Convertible is_convertible(VALUE value)
310
+ double is_convertible(VALUE value)
311
311
  {
312
312
  switch (rb_type(value))
313
313
  {
@@ -319,7 +319,7 @@ namespace Rice
319
319
  Object object(value);
320
320
  if (object.class_name().str() == setName)
321
321
  {
322
- return Convertible::Cast;
322
+ return Convertible::Exact;
323
323
  }
324
324
  }
325
325
  default:
@@ -343,12 +343,12 @@ namespace Rice
343
343
  {
344
344
  return toSet<T>(value);
345
345
  }
346
- throw Exception(rb_eTypeError, "wrong argument type %s (expected % s)",
346
+ throw Exception(rb_eTypeError, "wrong argument type %s (expected %s)",
347
347
  detail::protect(rb_obj_classname, value), "std::set");
348
348
  }
349
349
  default:
350
350
  {
351
- throw Exception(rb_eTypeError, "wrong argument type %s (expected % s)",
351
+ throw Exception(rb_eTypeError, "wrong argument type %s (expected %s)",
352
352
  detail::protect(rb_obj_classname, value), "std::set");
353
353
  }
354
354
  }
@@ -371,7 +371,7 @@ namespace Rice
371
371
  {
372
372
  }
373
373
 
374
- Convertible is_convertible(VALUE value)
374
+ double is_convertible(VALUE value)
375
375
  {
376
376
  switch (rb_type(value))
377
377
  {
@@ -383,7 +383,7 @@ namespace Rice
383
383
  Object object(value);
384
384
  if (object.class_name().str() == setName)
385
385
  {
386
- return Convertible::Cast;
386
+ return Convertible::Exact;
387
387
  }
388
388
  }
389
389
  default:
@@ -412,12 +412,12 @@ namespace Rice
412
412
  return this->converted_;
413
413
  }
414
414
  }
415
- throw Exception(rb_eTypeError, "wrong argument type %s (expected % s)",
415
+ throw Exception(rb_eTypeError, "wrong argument type %s (expected %s)",
416
416
  detail::protect(rb_obj_classname, value), "std::set");
417
417
  }
418
418
  default:
419
419
  {
420
- throw Exception(rb_eTypeError, "wrong argument type %s (expected % s)",
420
+ throw Exception(rb_eTypeError, "wrong argument type %s (expected %s)",
421
421
  detail::protect(rb_obj_classname, value), "std::set");
422
422
  }
423
423
  }
@@ -440,7 +440,7 @@ namespace Rice
440
440
  {
441
441
  }
442
442
 
443
- Convertible is_convertible(VALUE value)
443
+ double is_convertible(VALUE value)
444
444
  {
445
445
  switch (rb_type(value))
446
446
  {
@@ -455,7 +455,7 @@ namespace Rice
455
455
  Object object(value);
456
456
  if (object.class_name().str() == setName)
457
457
  {
458
- return Convertible::Cast;
458
+ return Convertible::Exact;
459
459
  }
460
460
  }
461
461
  default:
@@ -484,12 +484,12 @@ namespace Rice
484
484
  return &this->converted_;
485
485
  }
486
486
  }
487
- throw Exception(rb_eTypeError, "wrong argument type %s (expected % s)",
487
+ throw Exception(rb_eTypeError, "wrong argument type %s (expected %s)",
488
488
  detail::protect(rb_obj_classname, value), "std::set");
489
489
  }
490
490
  default:
491
491
  {
492
- throw Exception(rb_eTypeError, "wrong argument type %s (expected % s)",
492
+ throw Exception(rb_eTypeError, "wrong argument type %s (expected %s)",
493
493
  detail::protect(rb_obj_classname, value), "std::set");
494
494
  }
495
495
  }
@@ -1,28 +1,28 @@
1
1
  #ifndef Rice__stl__shared_ptr__hpp_
2
2
  #define Rice__stl__shared_ptr__hpp_
3
3
 
4
+ namespace Rice
5
+ {
6
+ template<typename T>
7
+ Data_Type<std::shared_ptr<T>> define_shared_ptr(std::string klassName = "");
8
+ }
9
+
4
10
  namespace Rice::detail
5
11
  {
6
12
  template<typename T>
7
13
  class Wrapper<std::shared_ptr<T>> : public WrapperBase
8
14
  {
9
15
  public:
10
- Wrapper(const std::shared_ptr<T>& data);
16
+ Wrapper(rb_data_type_t* rb_data_type, const std::shared_ptr<T>& data);
11
17
  ~Wrapper();
12
- void* get() override;
13
- std::shared_ptr<T>& data();
18
+ void* get(rb_data_type_t* requestedType) override;
14
19
 
15
20
  private:
16
21
  std::shared_ptr<T> data_;
22
+ rb_data_type_t* inner_rb_data_type_;
17
23
  };
18
24
  }
19
25
 
20
- namespace Rice
21
- {
22
- template<typename T>
23
- Data_Type<std::shared_ptr<T>> define_shared_ptr(std::string klassName = "");
24
- }
25
-
26
26
  #include "shared_ptr.ipp"
27
27
 
28
28
  #endif // Rice__stl__shared_ptr__hpp_
@@ -1,6 +1,5 @@
1
1
  #include <memory>
2
2
 
3
- // --------- Enable creation of std::shared_ptr from Ruby ---------
4
3
  namespace Rice
5
4
  {
6
5
  template<typename T>
@@ -23,7 +22,24 @@ namespace Rice
23
22
 
24
23
  Identifier id(klassName);
25
24
  Data_Type_T result = define_class_under<detail::intrinsic_type<SharedPtr_T>>(rb_mStd, id).
26
- define_constructor(Constructor<SharedPtr_T, typename SharedPtr_T::element_type*>(), Arg("value").takeOwnership());
25
+ define_method("get", &SharedPtr_T::get).
26
+ define_method("swap", &SharedPtr_T::swap).
27
+ define_method("use_count", &SharedPtr_T::use_count).
28
+ define_method("empty?", [](SharedPtr_T& self)->bool
29
+ {
30
+ return !self;
31
+ });
32
+
33
+ if constexpr (!std::is_void_v<T>)
34
+ {
35
+ result.define_constructor(Constructor<SharedPtr_T, typename SharedPtr_T::element_type*>(), Arg("value").takeOwnership());
36
+ }
37
+
38
+ // Setup delegation to forward T's methods via get (only for non-fundamental, non-void types)
39
+ if constexpr (!std::is_void_v<T> && !std::is_fundamental_v<T>)
40
+ {
41
+ detail::define_forwarding(result.klass(), Data_Type<T>::klass());
42
+ }
27
43
 
28
44
  return result;
29
45
  }
@@ -33,31 +49,47 @@ namespace Rice
33
49
  namespace Rice::detail
34
50
  {
35
51
  template<typename T>
36
- inline Wrapper<std::shared_ptr<T>>::Wrapper(const std::shared_ptr<T>& data)
37
- : data_(data)
52
+ Wrapper<std::shared_ptr<T>>::Wrapper(rb_data_type_t* rb_data_type, const std::shared_ptr<T>& data)
53
+ : WrapperBase(rb_data_type), data_(data)
38
54
  {
39
- }
55
+ using Intrinsic_T = intrinsic_type<T>;
40
56
 
41
- template<typename T>
42
- inline Wrapper<std::shared_ptr<T>>::~Wrapper()
43
- {
44
- Registries::instance.instances.remove(this->get());
57
+ if constexpr (std::is_fundamental_v<Intrinsic_T>)
58
+ {
59
+ inner_rb_data_type_ = Data_Type<Pointer<Intrinsic_T>>::ruby_data_type();
60
+ }
61
+ else
62
+ {
63
+ inner_rb_data_type_ = Data_Type<Intrinsic_T>::ruby_data_type();
64
+ }
45
65
  }
46
66
 
47
67
  template<typename T>
48
- inline void* Wrapper<std::shared_ptr<T>>::get()
68
+ Wrapper<std::shared_ptr<T>>::~Wrapper()
49
69
  {
50
- return (void*)this->data_.get();
70
+ Registries::instance.instances.remove(this->get(this->rb_data_type_));
51
71
  }
52
72
 
53
73
  template<typename T>
54
- inline std::shared_ptr<T>& Wrapper<std::shared_ptr<T>>::data()
74
+ void* Wrapper<std::shared_ptr<T>>::get(rb_data_type_t* requestedType)
55
75
  {
56
- return data_;
76
+ if (rb_typeddata_inherited_p(this->rb_data_type_, requestedType))
77
+ {
78
+ return &this->data_;
79
+ }
80
+ else if (rb_typeddata_inherited_p(this->inner_rb_data_type_, requestedType))
81
+ {
82
+ return this->data_.get();
83
+ }
84
+ else
85
+ {
86
+ throw Exception(rb_eTypeError, "wrong argument type (expected %s)",
87
+ requestedType->wrap_struct_name);
88
+ }
57
89
  }
58
90
  }
59
91
 
60
- // --------- Type/To_Ruby/From_Ruby ---------
92
+ // --------- Type ---------
61
93
  namespace Rice::detail
62
94
  {
63
95
  template<typename T>
@@ -65,187 +97,22 @@ namespace Rice::detail
65
97
  {
66
98
  static bool verify()
67
99
  {
100
+ bool result = true;
68
101
  if constexpr (std::is_fundamental_v<T>)
69
102
  {
70
- return Type<Pointer<T>>::verify();
71
- return Type<Buffer<T>>::verify();
72
- }
73
- else
74
- {
75
- return Type<T>::verify();
76
- }
77
- }
78
-
79
- static VALUE rubyKlass()
80
- {
81
- if (Data_Type<std::shared_ptr<T>>::is_defined())
82
- {
83
- std::pair<VALUE, rb_data_type_t*> pair = Registries::instance.types.getType<std::shared_ptr<T>>();
84
- return pair.first;
85
- }
86
- else
87
- {
88
- TypeMapper<T> typeMapper;
89
- return typeMapper.rubyKlass();
90
- }
91
- }
92
- };
93
-
94
- template <typename T>
95
- class To_Ruby<std::shared_ptr<T>>
96
- {
97
- public:
98
- To_Ruby() = default;
99
-
100
- explicit To_Ruby(Arg* arv)
101
- {
102
- }
103
-
104
- VALUE convert(std::shared_ptr<T>& data)
105
- {
106
- if constexpr (std::is_fundamental_v<T>)
107
- {
108
- return detail::wrap<std::shared_ptr<T>>(Data_Type<Pointer<T>>::klass(), Data_Type<Pointer<T>>::ruby_data_type(), data, true);
109
- }
110
- else
111
- {
112
- return detail::wrap<std::shared_ptr<T>>(Data_Type<T>::klass(), Data_Type<T>::ruby_data_type(), data, true);
113
- }
114
- }
115
-
116
- VALUE convert(std::shared_ptr<T>&& data)
117
- {
118
- if constexpr (std::is_fundamental_v<T>)
119
- {
120
- return detail::wrap<std::shared_ptr<T>>(Data_Type<Pointer<T>>::klass(), Data_Type<Pointer<T>>::ruby_data_type(), data, true);
103
+ result = result && Type<Pointer<T>>::verify();
121
104
  }
122
105
  else
123
106
  {
124
- return detail::wrap<std::shared_ptr<T>>(Data_Type<T>::klass(), Data_Type<T>::ruby_data_type(), data, true);
107
+ result = result && Type<T>::verify();
125
108
  }
126
- }
127
- };
128
-
129
- template <typename T>
130
- class From_Ruby<std::shared_ptr<T>>
131
- {
132
- public:
133
- From_Ruby() = default;
134
-
135
- explicit From_Ruby(Arg * arg) : arg_(arg)
136
- {
137
- }
138
-
139
- Convertible is_convertible(VALUE value)
140
- {
141
- switch (rb_type(value))
142
- {
143
- case RUBY_T_DATA:
144
- return Convertible::Exact;
145
- break;
146
- default:
147
- return Convertible::None;
148
- }
149
- }
150
109
 
151
- std::shared_ptr<T> convert(VALUE value)
152
- {
153
- // Get the wrapper
154
- WrapperBase* wrapperBase = detail::getWrapper(value);
155
-
156
- // Was this shared_ptr created by the user from Ruby? If so it will
157
- // be wrapped as a pointer, std::shared_ptr<T>*. In the case just
158
- // return the shared pointer
159
- if (dynamic_cast<Wrapper<std::shared_ptr<T>*>*>(wrapperBase))
160
- {
161
- // Use unwrap to validate the underlying wrapper is the correct type
162
- std::shared_ptr<T>* ptr = unwrap<std::shared_ptr<T>>(value, Data_Type<std::shared_ptr<T>>::ruby_data_type(), false);
163
- return *ptr;
164
- }
165
- else if (std::is_fundamental_v<T>)
166
- {
167
- // Get the wrapper again to validate T's type
168
- Wrapper<std::shared_ptr<T>>* wrapper = getWrapper<Wrapper<std::shared_ptr<T>>>(value, Data_Type<Pointer<T>>::ruby_data_type());
169
- return wrapper->data();
170
- }
171
- else
110
+ if (result)
172
111
  {
173
- // Get the wrapper again to validate T's type
174
- Wrapper<std::shared_ptr<T>>* wrapper = getWrapper<Wrapper<std::shared_ptr<T>>>(value, Data_Type<T>::ruby_data_type());
175
- return wrapper->data();
112
+ define_shared_ptr<T>();
176
113
  }
177
- }
178
- private:
179
- Arg* arg_ = nullptr;
180
- };
181
-
182
- template <typename T>
183
- class To_Ruby<std::shared_ptr<T>&>
184
- {
185
- public:
186
- To_Ruby() = default;
187
114
 
188
- explicit To_Ruby(Arg* arg)
189
- {
115
+ return result;
190
116
  }
191
-
192
- VALUE convert(std::shared_ptr<T>& data)
193
- {
194
- return detail::wrap(Data_Type<T>::klass(), Data_Type<T>::ruby_data_type(), data, true);
195
- }
196
- };
197
-
198
- template <typename T>
199
- class From_Ruby<std::shared_ptr<T>&>
200
- {
201
- public:
202
- From_Ruby() = default;
203
-
204
- explicit From_Ruby(Arg * arg) : arg_(arg)
205
- {
206
- }
207
-
208
- Convertible is_convertible(VALUE value)
209
- {
210
- switch (rb_type(value))
211
- {
212
- case RUBY_T_DATA:
213
- return Convertible::Exact;
214
- break;
215
- default:
216
- return Convertible::None;
217
- }
218
- }
219
-
220
- std::shared_ptr<T>& convert(VALUE value)
221
- {
222
- // Get the wrapper
223
- WrapperBase* wrapperBase = detail::getWrapper(value);
224
-
225
- // Was this shared_ptr created by the user from Ruby? If so it will
226
- // be wrapped as a pointer, std::shared_ptr<T>*. In the case just
227
- // return the shared pointer
228
- if (dynamic_cast<Wrapper<std::shared_ptr<T>*>*>(wrapperBase))
229
- {
230
- // Use unwrap to validate the underlying wrapper is the correct type
231
- std::shared_ptr<T>* ptr = unwrap<std::shared_ptr<T>>(value, Data_Type<std::shared_ptr<T>>::ruby_data_type(), false);
232
- return *ptr;
233
- }
234
- else if (std::is_fundamental_v<T>)
235
- {
236
- // Get the wrapper again to validate T's type
237
- Wrapper<std::shared_ptr<T>>* wrapper = getWrapper<Wrapper<std::shared_ptr<T>>>(value, Data_Type<Pointer<T>>::ruby_data_type());
238
- return wrapper->data();
239
- }
240
- else
241
- {
242
- // Get the wrapper again to validate T's type
243
- Wrapper<std::shared_ptr<T>>* wrapper = getWrapper<Wrapper<std::shared_ptr<T>>>(value, Data_Type<T>::ruby_data_type());
244
- return wrapper->data();
245
- }
246
- }
247
-
248
- private:
249
- Arg* arg_ = nullptr;
250
117
  };
251
118
  }