rice 4.7.1 → 4.8.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +29 -1
- data/CMakeLists.txt +14 -22
- data/CMakePresets.json +203 -75
- data/FindRuby.cmake +358 -123
- data/bin/rice-doc.rb +56 -141
- data/include/rice/api.hpp +248 -0
- data/include/rice/rice.hpp +2237 -1657
- data/include/rice/stl.hpp +346 -443
- data/lib/rice/doc/config.rb +70 -0
- data/lib/rice/doc/cpp_reference.rb +1 -4
- data/lib/rice/doc/mkdocs.rb +58 -20
- data/lib/rice/doc/rice.rb +20 -0
- data/lib/rice/doc.rb +1 -0
- data/lib/rice/make_rice_headers.rb +7 -0
- data/lib/rice/native_registry.rb +2 -2
- data/lib/rice/rbs.rb +2 -2
- data/lib/rice/version.rb +1 -1
- data/lib/rubygems_plugin.rb +12 -9
- data/rice/Arg.hpp +12 -6
- data/rice/Arg.ipp +14 -7
- data/rice/Buffer.ipp +44 -40
- data/rice/Callback.hpp +1 -1
- data/rice/Callback.ipp +2 -7
- data/rice/Constructor.hpp +1 -1
- data/rice/Constructor.ipp +11 -11
- data/rice/Data_Object.ipp +15 -15
- data/rice/Data_Type.hpp +9 -10
- data/rice/Data_Type.ipp +22 -25
- data/rice/Director.hpp +1 -0
- data/rice/Enum.ipp +58 -39
- data/rice/Exception.hpp +4 -4
- data/rice/Exception.ipp +7 -7
- data/rice/NoGVL.hpp +13 -0
- data/rice/Reference.hpp +56 -0
- data/rice/Reference.ipp +96 -0
- data/rice/Return.hpp +4 -1
- data/rice/Return.ipp +0 -6
- data/rice/cpp_api/Array.hpp +41 -4
- data/rice/cpp_api/Array.ipp +105 -9
- data/rice/cpp_api/Class.hpp +2 -2
- data/rice/cpp_api/Class.ipp +4 -4
- data/rice/cpp_api/Hash.ipp +7 -4
- data/rice/cpp_api/Module.hpp +4 -4
- data/rice/cpp_api/Module.ipp +12 -10
- data/rice/cpp_api/Object.hpp +4 -4
- data/rice/cpp_api/Object.ipp +15 -12
- data/rice/cpp_api/String.hpp +2 -2
- data/rice/cpp_api/String.ipp +11 -8
- data/rice/cpp_api/Symbol.ipp +7 -7
- data/rice/cpp_api/shared_methods.hpp +5 -9
- data/rice/detail/InstanceRegistry.hpp +0 -2
- data/rice/detail/Native.hpp +31 -21
- data/rice/detail/Native.ipp +282 -130
- data/rice/detail/NativeAttributeGet.hpp +5 -7
- data/rice/detail/NativeAttributeGet.ipp +26 -26
- data/rice/detail/NativeAttributeSet.hpp +2 -4
- data/rice/detail/NativeAttributeSet.ipp +20 -16
- data/rice/detail/NativeCallback.hpp +77 -0
- data/rice/detail/NativeCallback.ipp +280 -0
- data/rice/detail/NativeFunction.hpp +11 -21
- data/rice/detail/NativeFunction.ipp +58 -119
- data/rice/detail/NativeInvoker.hpp +4 -4
- data/rice/detail/NativeInvoker.ipp +7 -7
- data/rice/detail/NativeIterator.hpp +2 -4
- data/rice/detail/NativeIterator.ipp +18 -14
- data/rice/detail/NativeMethod.hpp +10 -20
- data/rice/detail/NativeMethod.ipp +54 -114
- data/rice/detail/NativeProc.hpp +5 -7
- data/rice/detail/NativeProc.ipp +39 -28
- data/rice/detail/NativeRegistry.hpp +0 -1
- data/rice/detail/Parameter.hpp +15 -8
- data/rice/detail/Parameter.ipp +102 -43
- data/rice/detail/Proc.ipp +14 -28
- data/rice/detail/RubyType.ipp +2 -53
- data/rice/detail/Type.hpp +23 -7
- data/rice/detail/Type.ipp +73 -93
- data/rice/detail/TypeRegistry.ipp +5 -4
- data/rice/detail/Wrapper.hpp +1 -1
- data/rice/detail/Wrapper.ipp +18 -10
- data/rice/detail/from_ruby.hpp +8 -6
- data/rice/detail/from_ruby.ipp +306 -173
- data/rice/detail/ruby.hpp +23 -0
- data/rice/libc/file.hpp +4 -4
- data/rice/rice.hpp +6 -8
- data/rice/rice_api/Native.ipp +5 -1
- data/rice/rice_api/Parameter.ipp +1 -1
- data/rice/ruby_mark.hpp +2 -1
- data/rice/stl/complex.ipp +12 -8
- data/rice/stl/map.ipp +27 -22
- data/rice/stl/monostate.ipp +16 -12
- data/rice/stl/multimap.hpp +0 -2
- data/rice/stl/multimap.ipp +27 -22
- data/rice/stl/optional.ipp +27 -11
- data/rice/stl/pair.ipp +5 -5
- data/rice/stl/reference_wrapper.ipp +5 -4
- data/rice/stl/set.ipp +16 -16
- data/rice/stl/shared_ptr.hpp +0 -16
- data/rice/stl/shared_ptr.ipp +34 -190
- data/rice/stl/string.ipp +18 -18
- data/rice/stl/string_view.ipp +1 -1
- data/rice/stl/tuple.ipp +15 -36
- data/rice/stl/unique_ptr.ipp +18 -8
- data/rice/stl/unordered_map.ipp +20 -15
- data/rice/stl/variant.ipp +37 -21
- data/rice/stl/vector.ipp +41 -36
- data/rice/traits/function_traits.hpp +19 -19
- data/rice/traits/method_traits.hpp +4 -4
- data/rice/traits/rice_traits.hpp +162 -39
- data/rice.gemspec +1 -3
- data/test/test_Array.cpp +261 -3
- data/test/test_Attribute.cpp +6 -3
- data/test/test_Buffer.cpp +6 -42
- data/test/test_Callback.cpp +77 -23
- data/test/test_Data_Object.cpp +1 -1
- data/test/test_Data_Type.cpp +21 -22
- data/test/test_Director.cpp +2 -4
- data/test/test_Enum.cpp +34 -5
- data/test/test_File.cpp +9 -5
- data/test/test_From_Ruby.cpp +4 -3
- data/test/test_GVL.cpp +3 -3
- data/test/test_Hash.cpp +1 -1
- data/test/test_Iterator.cpp +54 -22
- data/test/test_Keep_Alive.cpp +1 -1
- data/test/test_Keep_Alive_No_Wrapper.cpp +1 -1
- data/test/test_Module.cpp +5 -5
- data/test/test_Overloads.cpp +345 -48
- data/test/test_Proc.cpp +54 -0
- data/test/test_Reference.cpp +181 -0
- data/test/test_Self.cpp +2 -2
- data/test/test_Stl_Set.cpp +6 -6
- data/test/test_Stl_SharedPtr.cpp +54 -30
- data/test/test_Stl_String_View.cpp +4 -2
- data/test/test_Stl_Tuple.cpp +1 -1
- data/test/test_Stl_Variant.cpp +6 -14
- data/test/test_Stl_Vector.cpp +61 -30
- data/test/test_String.cpp +4 -2
- data/test/test_Struct.cpp +1 -1
- data/test/test_Symbol.cpp +1 -1
- data/test/test_To_Ruby.cpp +1 -0
- data/test/test_Type.cpp +36 -35
- data/test/test_global_functions.cpp +1 -1
- data/test/unittest.cpp +1 -1
- data/test/unittest.hpp +5 -5
- metadata +10 -10
- data/rice/Function.hpp +0 -17
- data/rice/Function.ipp +0 -13
- data/rice/detail/MethodInfo.hpp +0 -48
- data/rice/detail/MethodInfo.ipp +0 -99
- data/rice/detail/NativeCallbackFFI.hpp +0 -55
- data/rice/detail/NativeCallbackFFI.ipp +0 -152
- data/rice/detail/NativeCallbackSimple.hpp +0 -30
- data/rice/detail/NativeCallbackSimple.ipp +0 -29
data/rice/stl/optional.ipp
CHANGED
|
@@ -23,17 +23,17 @@ namespace Rice::detail
|
|
|
23
23
|
public:
|
|
24
24
|
To_Ruby() = default;
|
|
25
25
|
|
|
26
|
-
explicit To_Ruby(
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
@@ -23,7 +23,7 @@ namespace Rice::detail
|
|
|
23
23
|
public:
|
|
24
24
|
To_Ruby() = default;
|
|
25
25
|
|
|
26
|
-
explicit To_Ruby(
|
|
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
|
-
|
|
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
|
-
|
|
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&
|
|
221
|
-
|
|
222
|
-
|
|
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
|
-
|
|
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::
|
|
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 %
|
|
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 %
|
|
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
|
-
|
|
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::
|
|
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 %
|
|
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 %
|
|
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
|
-
|
|
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::
|
|
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 %
|
|
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 %
|
|
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
|
}
|
data/rice/stl/shared_ptr.hpp
CHANGED
|
@@ -1,22 +1,6 @@
|
|
|
1
1
|
#ifndef Rice__stl__shared_ptr__hpp_
|
|
2
2
|
#define Rice__stl__shared_ptr__hpp_
|
|
3
3
|
|
|
4
|
-
namespace Rice::detail
|
|
5
|
-
{
|
|
6
|
-
template<typename T>
|
|
7
|
-
class Wrapper<std::shared_ptr<T>> : public WrapperBase
|
|
8
|
-
{
|
|
9
|
-
public:
|
|
10
|
-
Wrapper(const std::shared_ptr<T>& data);
|
|
11
|
-
~Wrapper();
|
|
12
|
-
void* get() override;
|
|
13
|
-
std::shared_ptr<T>& data();
|
|
14
|
-
|
|
15
|
-
private:
|
|
16
|
-
std::shared_ptr<T> data_;
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
|
|
20
4
|
namespace Rice
|
|
21
5
|
{
|
|
22
6
|
template<typename T>
|
data/rice/stl/shared_ptr.ipp
CHANGED
|
@@ -22,38 +22,22 @@ namespace Rice
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
Identifier id(klassName);
|
|
25
|
-
Data_Type_T result = define_class_under<
|
|
26
|
-
define_constructor(Constructor<SharedPtr_T, typename SharedPtr_T::element_type*>(), Arg("value").takeOwnership());
|
|
25
|
+
Data_Type_T result = define_class_under<SharedPtr_T>(rb_mStd, id);
|
|
27
26
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
template<typename T>
|
|
36
|
-
inline Wrapper<std::shared_ptr<T>>::Wrapper(const std::shared_ptr<T>& data)
|
|
37
|
-
: data_(data)
|
|
38
|
-
{
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
template<typename T>
|
|
42
|
-
inline Wrapper<std::shared_ptr<T>>::~Wrapper()
|
|
43
|
-
{
|
|
44
|
-
Registries::instance.instances.remove(this->get());
|
|
45
|
-
}
|
|
27
|
+
// std::shared_ptr<void> cannot be constructed from void* because void is incomplete
|
|
28
|
+
// and the deleter cannot be determined. So skip the constructor for void.
|
|
29
|
+
// std::shared_ptr<T[]> (array types) also skip constructor - arrays need special handling.
|
|
30
|
+
if constexpr (!std::is_void_v<T> && !std::is_array_v<T>)
|
|
31
|
+
{
|
|
32
|
+
result.define_constructor(Constructor<SharedPtr_T, typename SharedPtr_T::element_type*>(), Arg("value").takeOwnership());
|
|
33
|
+
}
|
|
46
34
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
35
|
+
result.
|
|
36
|
+
define_method("get", &SharedPtr_T::get).
|
|
37
|
+
define_method("use_count", &SharedPtr_T::use_count).
|
|
38
|
+
define_method("empty?", &SharedPtr_T::operator bool);
|
|
52
39
|
|
|
53
|
-
|
|
54
|
-
inline std::shared_ptr<T>& Wrapper<std::shared_ptr<T>>::data()
|
|
55
|
-
{
|
|
56
|
-
return data_;
|
|
40
|
+
return result;
|
|
57
41
|
}
|
|
58
42
|
}
|
|
59
43
|
|
|
@@ -67,185 +51,45 @@ namespace Rice::detail
|
|
|
67
51
|
{
|
|
68
52
|
if constexpr (std::is_fundamental_v<T>)
|
|
69
53
|
{
|
|
70
|
-
|
|
71
|
-
|
|
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;
|
|
54
|
+
Type<Pointer<T>>::verify();
|
|
55
|
+
Type<Buffer<T>>::verify();
|
|
85
56
|
}
|
|
86
57
|
else
|
|
87
58
|
{
|
|
88
|
-
|
|
89
|
-
|
|
59
|
+
if (!Type<intrinsic_type<T>>::verify())
|
|
60
|
+
{
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
90
63
|
}
|
|
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
64
|
|
|
104
|
-
|
|
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
|
-
}
|
|
65
|
+
define_shared_ptr<T>();
|
|
115
66
|
|
|
116
|
-
|
|
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);
|
|
121
|
-
}
|
|
122
|
-
else
|
|
123
|
-
{
|
|
124
|
-
return detail::wrap<std::shared_ptr<T>>(Data_Type<T>::klass(), Data_Type<T>::ruby_data_type(), data, true);
|
|
125
|
-
}
|
|
67
|
+
return true;
|
|
126
68
|
}
|
|
127
69
|
};
|
|
128
70
|
|
|
129
|
-
|
|
130
|
-
|
|
71
|
+
// Specialization for array types std::shared_ptr<T[]>
|
|
72
|
+
template<typename T>
|
|
73
|
+
struct Type<std::shared_ptr<T[]>>
|
|
131
74
|
{
|
|
132
|
-
|
|
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
|
-
|
|
151
|
-
std::shared_ptr<T> convert(VALUE value)
|
|
75
|
+
static bool verify()
|
|
152
76
|
{
|
|
153
|
-
|
|
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>)
|
|
77
|
+
if constexpr (std::is_fundamental_v<T>)
|
|
166
78
|
{
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
return wrapper->data();
|
|
79
|
+
Type<Pointer<T>>::verify();
|
|
80
|
+
Type<Buffer<T>>::verify();
|
|
170
81
|
}
|
|
171
82
|
else
|
|
172
83
|
{
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
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
|
-
|
|
188
|
-
explicit To_Ruby(Arg* arg)
|
|
189
|
-
{
|
|
190
|
-
}
|
|
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;
|
|
84
|
+
if (!Type<intrinsic_type<T>>::verify())
|
|
85
|
+
{
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
217
88
|
}
|
|
218
|
-
}
|
|
219
89
|
|
|
220
|
-
|
|
221
|
-
{
|
|
222
|
-
// Get the wrapper
|
|
223
|
-
WrapperBase* wrapperBase = detail::getWrapper(value);
|
|
90
|
+
define_shared_ptr<T[]>();
|
|
224
91
|
|
|
225
|
-
|
|
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
|
-
}
|
|
92
|
+
return true;
|
|
246
93
|
}
|
|
247
|
-
|
|
248
|
-
private:
|
|
249
|
-
Arg* arg_ = nullptr;
|
|
250
94
|
};
|
|
251
95
|
}
|