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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +37 -1
- data/CMakeLists.txt +14 -22
- data/CMakePresets.json +203 -75
- data/FindRuby.cmake +358 -123
- data/bin/rice-doc.rb +58 -141
- data/include/rice/api.hpp +261 -0
- data/include/rice/rice.hpp +2459 -1693
- data/include/rice/stl.hpp +450 -546
- 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 +21 -0
- data/lib/rice/doc.rb +1 -0
- data/lib/rice/make_rice_headers.rb +7 -0
- data/lib/rice/native_registry.rb +5 -10
- data/lib/rice/rbs.rb +6 -6
- 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 +33 -31
- 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 +7 -2
- data/rice/cpp_api/Class.ipp +9 -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 +10 -4
- data/rice/cpp_api/Object.ipp +20 -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/Forwards.hpp +18 -0
- data/rice/detail/Forwards.ipp +60 -0
- 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 +1 -1
- data/rice/detail/NativeRegistry.ipp +29 -0
- 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 +77 -93
- data/rice/detail/TypeRegistry.ipp +5 -4
- data/rice/detail/Wrapper.hpp +13 -12
- data/rice/detail/Wrapper.ipp +97 -44
- 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 +9 -8
- data/rice/rice_api/Native.ipp +5 -1
- data/rice/rice_api/NativeRegistry.ipp +14 -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 +9 -9
- data/rice/stl/shared_ptr.ipp +52 -185
- 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.hpp +9 -3
- data/rice/stl/unique_ptr.ipp +86 -120
- 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_Inheritance.cpp +14 -14
- data/test/test_Iterator.cpp +54 -22
- data/test/test_Keep_Alive.cpp +1 -1
- data/test/test_Keep_Alive_No_Wrapper.cpp +7 -3
- 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 +172 -33
- data/test/test_Stl_String_View.cpp +4 -2
- data/test/test_Stl_Tuple.cpp +1 -1
- data/test/test_Stl_UniquePtr.cpp +48 -3
- 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 +12 -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,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_
|
data/rice/stl/shared_ptr.ipp
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
|
|
68
|
+
Wrapper<std::shared_ptr<T>>::~Wrapper()
|
|
49
69
|
{
|
|
50
|
-
|
|
70
|
+
Registries::instance.instances.remove(this->get(this->rb_data_type_));
|
|
51
71
|
}
|
|
52
72
|
|
|
53
73
|
template<typename T>
|
|
54
|
-
|
|
74
|
+
void* Wrapper<std::shared_ptr<T>>::get(rb_data_type_t* requestedType)
|
|
55
75
|
{
|
|
56
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
}
|