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/cpp_api/Class.ipp
CHANGED
|
@@ -13,8 +13,8 @@ namespace Rice
|
|
|
13
13
|
return *this;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
template<typename ...
|
|
17
|
-
inline Object Class::create(
|
|
16
|
+
template<typename ...Parameter_Ts>
|
|
17
|
+
inline Object Class::create(Parameter_Ts ...args)
|
|
18
18
|
{
|
|
19
19
|
return this->call("new", args...);
|
|
20
20
|
}
|
|
@@ -33,6 +33,11 @@ namespace Rice
|
|
|
33
33
|
return result;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
inline Class Class::superclass() const
|
|
37
|
+
{
|
|
38
|
+
return detail::protect(rb_class_superclass, this->value());
|
|
39
|
+
}
|
|
40
|
+
|
|
36
41
|
inline Class define_class_under(Object parent, Identifier id, const Class& superclass)
|
|
37
42
|
{
|
|
38
43
|
VALUE klass = detail::protect(rb_define_class_id_under, parent.value(), id, superclass.value());
|
|
@@ -91,7 +96,7 @@ namespace Rice::detail
|
|
|
91
96
|
public:
|
|
92
97
|
To_Ruby() = default;
|
|
93
98
|
|
|
94
|
-
explicit To_Ruby(
|
|
99
|
+
explicit To_Ruby(Arg* arg) : arg_(arg)
|
|
95
100
|
{
|
|
96
101
|
}
|
|
97
102
|
|
|
@@ -101,7 +106,7 @@ namespace Rice::detail
|
|
|
101
106
|
}
|
|
102
107
|
|
|
103
108
|
private:
|
|
104
|
-
|
|
109
|
+
Arg* arg_ = nullptr;
|
|
105
110
|
};
|
|
106
111
|
|
|
107
112
|
template<>
|
data/rice/cpp_api/Hash.ipp
CHANGED
|
@@ -234,7 +234,7 @@ namespace Rice::detail
|
|
|
234
234
|
public:
|
|
235
235
|
To_Ruby() = default;
|
|
236
236
|
|
|
237
|
-
explicit To_Ruby(
|
|
237
|
+
explicit To_Ruby(Arg* arg) : arg_(arg)
|
|
238
238
|
{
|
|
239
239
|
}
|
|
240
240
|
|
|
@@ -244,7 +244,7 @@ namespace Rice::detail
|
|
|
244
244
|
}
|
|
245
245
|
|
|
246
246
|
private:
|
|
247
|
-
|
|
247
|
+
Arg* arg_ = nullptr;
|
|
248
248
|
};
|
|
249
249
|
|
|
250
250
|
template<>
|
|
@@ -253,11 +253,11 @@ namespace Rice::detail
|
|
|
253
253
|
public:
|
|
254
254
|
From_Ruby() = default;
|
|
255
255
|
|
|
256
|
-
explicit From_Ruby(Arg* arg)
|
|
256
|
+
explicit From_Ruby(Arg* arg) : arg_(arg)
|
|
257
257
|
{
|
|
258
258
|
}
|
|
259
259
|
|
|
260
|
-
|
|
260
|
+
double is_convertible(VALUE value)
|
|
261
261
|
{
|
|
262
262
|
switch (rb_type(value))
|
|
263
263
|
{
|
|
@@ -273,5 +273,8 @@ namespace Rice::detail
|
|
|
273
273
|
{
|
|
274
274
|
return Hash(value);
|
|
275
275
|
}
|
|
276
|
+
|
|
277
|
+
private:
|
|
278
|
+
Arg* arg_ = nullptr;
|
|
276
279
|
};
|
|
277
280
|
}
|
data/rice/cpp_api/Module.hpp
CHANGED
|
@@ -49,11 +49,11 @@ namespace Rice
|
|
|
49
49
|
|
|
50
50
|
#include "shared_methods.hpp"
|
|
51
51
|
protected:
|
|
52
|
-
template<typename Function_T>
|
|
53
|
-
void wrap_native_function(VALUE klass, std::string name, Function_T&& function,
|
|
52
|
+
template<typename Function_T, typename ...Arg_Ts>
|
|
53
|
+
void wrap_native_function(VALUE klass, std::string name, Function_T&& function, const Arg_Ts&...args);
|
|
54
54
|
|
|
55
|
-
template<typename Class_T = VALUE, typename Method_T>
|
|
56
|
-
void wrap_native_method(VALUE klass, std::string name, Method_T&& method,
|
|
55
|
+
template<typename Class_T = VALUE, typename Method_T, typename ...Arg_Ts>
|
|
56
|
+
void wrap_native_method(VALUE klass, std::string name, Method_T&& method, const Arg_Ts&...args);
|
|
57
57
|
};
|
|
58
58
|
|
|
59
59
|
//! Define a new module in the namespace given by module.
|
data/rice/cpp_api/Module.ipp
CHANGED
|
@@ -32,16 +32,18 @@ namespace Rice
|
|
|
32
32
|
this->set_value(result);
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
template<typename Function_T>
|
|
36
|
-
inline void Module::wrap_native_function(VALUE klass, std::string name, Function_T&& function,
|
|
35
|
+
template<typename Function_T, typename ...Arg_Ts>
|
|
36
|
+
inline void Module::wrap_native_function(VALUE klass, std::string name, Function_T&& function, const Arg_Ts&...args)
|
|
37
37
|
{
|
|
38
|
-
detail::
|
|
38
|
+
constexpr bool isNoGVL = detail::tuple_element_index_v<std::tuple<Arg_Ts...>, NoGVL> < (sizeof...(Arg_Ts));
|
|
39
|
+
detail::NativeFunction<Function_T, isNoGVL>::define(klass, name, std::forward<Function_T>(function), args...);
|
|
39
40
|
}
|
|
40
41
|
|
|
41
|
-
template<typename Class_T, typename Method_T>
|
|
42
|
-
inline void Module::wrap_native_method(VALUE klass, std::string name, Method_T&& method,
|
|
42
|
+
template<typename Class_T, typename Method_T, typename ...Arg_Ts>
|
|
43
|
+
inline void Module::wrap_native_method(VALUE klass, std::string name, Method_T&& method, const Arg_Ts&...args)
|
|
43
44
|
{
|
|
44
|
-
detail::
|
|
45
|
+
constexpr bool isNoGVL = detail::tuple_element_index_v<std::tuple<Arg_Ts...>, NoGVL> < (sizeof...(Arg_Ts));
|
|
46
|
+
detail::NativeMethod<Class_T, Method_T, isNoGVL>::define(klass, name, std::forward<Method_T>(method), args...);
|
|
45
47
|
}
|
|
46
48
|
|
|
47
49
|
inline Module define_module_under(Object parent, char const* name)
|
|
@@ -94,7 +96,7 @@ namespace Rice::detail
|
|
|
94
96
|
public:
|
|
95
97
|
To_Ruby() = default;
|
|
96
98
|
|
|
97
|
-
explicit To_Ruby(
|
|
99
|
+
explicit To_Ruby(Arg* arg) : arg_(arg)
|
|
98
100
|
{
|
|
99
101
|
}
|
|
100
102
|
|
|
@@ -104,7 +106,7 @@ namespace Rice::detail
|
|
|
104
106
|
}
|
|
105
107
|
|
|
106
108
|
private:
|
|
107
|
-
|
|
109
|
+
Arg* arg_ = nullptr;
|
|
108
110
|
};
|
|
109
111
|
|
|
110
112
|
|
|
@@ -114,7 +116,7 @@ namespace Rice::detail
|
|
|
114
116
|
public:
|
|
115
117
|
To_Ruby() = default;
|
|
116
118
|
|
|
117
|
-
explicit To_Ruby(
|
|
119
|
+
explicit To_Ruby(Arg* arg) : arg_(arg)
|
|
118
120
|
{
|
|
119
121
|
}
|
|
120
122
|
|
|
@@ -124,7 +126,7 @@ namespace Rice::detail
|
|
|
124
126
|
}
|
|
125
127
|
|
|
126
128
|
private:
|
|
127
|
-
|
|
129
|
+
Arg* arg_ = nullptr;
|
|
128
130
|
};
|
|
129
131
|
|
|
130
132
|
template<>
|
data/rice/cpp_api/Object.hpp
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
namespace Rice
|
|
10
10
|
{
|
|
11
11
|
class Class;
|
|
12
|
+
class Module;
|
|
12
13
|
class String;
|
|
13
14
|
class Array;
|
|
14
15
|
|
|
@@ -116,6 +117,11 @@ namespace Rice
|
|
|
116
117
|
*/
|
|
117
118
|
bool is_a(Object klass) const;
|
|
118
119
|
|
|
120
|
+
//! Extend the object with a module.
|
|
121
|
+
/*! \param mod the module to extend with.
|
|
122
|
+
*/
|
|
123
|
+
void extend(Module const& mod);
|
|
124
|
+
|
|
119
125
|
//! Determine if the objects responds to a method.
|
|
120
126
|
/*! \param id the name of the method
|
|
121
127
|
* \return true if the objects responds to the method, false
|
|
@@ -181,8 +187,8 @@ namespace Rice
|
|
|
181
187
|
* float ret = x.call<float>("foo", z, 42);
|
|
182
188
|
* \endcode
|
|
183
189
|
*/
|
|
184
|
-
template<typename ...
|
|
185
|
-
Object call(Identifier id,
|
|
190
|
+
template<typename ...Parameter_Ts>
|
|
191
|
+
Object call(Identifier id, Parameter_Ts... args) const;
|
|
186
192
|
|
|
187
193
|
//! Call the Ruby method specified by 'id' on object 'obj'.
|
|
188
194
|
/*! Pass in arguments (arg1, arg2, ...). The arguments will be converted to
|
|
@@ -204,8 +210,8 @@ namespace Rice
|
|
|
204
210
|
* float ret = x.call_kw<float>("foo", kw);
|
|
205
211
|
* \endcode
|
|
206
212
|
*/
|
|
207
|
-
template<typename ...
|
|
208
|
-
Object call_kw(Identifier id,
|
|
213
|
+
template<typename ...Parameter_Ts>
|
|
214
|
+
Object call_kw(Identifier id, Parameter_Ts... args) const;
|
|
209
215
|
|
|
210
216
|
//! Vectorized call.
|
|
211
217
|
/*! Calls the method identified by id with the list of arguments
|
data/rice/cpp_api/Object.ipp
CHANGED
|
@@ -27,8 +27,8 @@ namespace Rice
|
|
|
27
27
|
return *this;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
template<typename ...
|
|
31
|
-
inline Object Object::call(Identifier id,
|
|
30
|
+
template<typename ...Parameter_Ts>
|
|
31
|
+
inline Object Object::call(Identifier id, Parameter_Ts... args) const
|
|
32
32
|
{
|
|
33
33
|
/* IMPORTANT - We store VALUEs in an array that is a local variable.
|
|
34
34
|
That allows the Ruby garbage collector to find them when scanning
|
|
@@ -37,15 +37,15 @@ namespace Rice
|
|
|
37
37
|
to the destination method resulting in a segmentation fault. This is
|
|
38
38
|
easy to duplicate by setting GC.stress to true and calling a constructor
|
|
39
39
|
that takes multiple values like a std::pair wrapper. */
|
|
40
|
-
std::array<VALUE, sizeof...(
|
|
40
|
+
std::array<VALUE, sizeof...(Parameter_Ts)> values = { detail::To_Ruby<detail::remove_cv_recursive_t<Parameter_Ts>>().convert(std::forward<Parameter_Ts>(args))... };
|
|
41
41
|
return detail::protect(rb_funcallv, value(), id.id(), (int)values.size(), (const VALUE*)values.data());
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
template<typename ...
|
|
45
|
-
inline Object Object::call_kw(Identifier id,
|
|
44
|
+
template<typename ...Parameter_Ts>
|
|
45
|
+
inline Object Object::call_kw(Identifier id, Parameter_Ts... args) const
|
|
46
46
|
{
|
|
47
47
|
/* IMPORTANT - See call() above */
|
|
48
|
-
std::array<VALUE, sizeof...(
|
|
48
|
+
std::array<VALUE, sizeof...(Parameter_Ts)> values = { detail::To_Ruby<detail::remove_cv_recursive_t<Parameter_Ts>>().convert(args)... };
|
|
49
49
|
return detail::protect(rb_funcallv_kw, value(), id.id(), (int)values.size(), (const VALUE*)values.data(), RB_PASS_KEYWORDS);
|
|
50
50
|
}
|
|
51
51
|
|
|
@@ -99,6 +99,11 @@ namespace Rice
|
|
|
99
99
|
return RB_TEST(result);
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
+
inline void Object::extend(Module const& mod)
|
|
103
|
+
{
|
|
104
|
+
detail::protect(rb_extend_object, this->value(), mod.value());
|
|
105
|
+
}
|
|
106
|
+
|
|
102
107
|
inline bool Object::respond_to(Identifier id) const
|
|
103
108
|
{
|
|
104
109
|
return bool(rb_respond_to(this->value(), id.id()));
|
|
@@ -202,7 +207,7 @@ namespace Rice::detail
|
|
|
202
207
|
public:
|
|
203
208
|
To_Ruby() = default;
|
|
204
209
|
|
|
205
|
-
explicit To_Ruby(
|
|
210
|
+
explicit To_Ruby(Arg* arg) : arg_(arg)
|
|
206
211
|
{
|
|
207
212
|
}
|
|
208
213
|
|
|
@@ -212,7 +217,7 @@ namespace Rice::detail
|
|
|
212
217
|
}
|
|
213
218
|
|
|
214
219
|
private:
|
|
215
|
-
|
|
220
|
+
Arg* arg_ = nullptr;
|
|
216
221
|
};
|
|
217
222
|
|
|
218
223
|
template<>
|
|
@@ -221,7 +226,7 @@ namespace Rice::detail
|
|
|
221
226
|
public:
|
|
222
227
|
To_Ruby() = default;
|
|
223
228
|
|
|
224
|
-
explicit To_Ruby(
|
|
229
|
+
explicit To_Ruby(Arg* arg) : arg_(arg)
|
|
225
230
|
{
|
|
226
231
|
}
|
|
227
232
|
|
|
@@ -231,7 +236,7 @@ namespace Rice::detail
|
|
|
231
236
|
}
|
|
232
237
|
|
|
233
238
|
private:
|
|
234
|
-
|
|
239
|
+
Arg* arg_ = nullptr;
|
|
235
240
|
};
|
|
236
241
|
|
|
237
242
|
template<>
|
|
@@ -240,11 +245,11 @@ namespace Rice::detail
|
|
|
240
245
|
public:
|
|
241
246
|
From_Ruby() = default;
|
|
242
247
|
|
|
243
|
-
explicit From_Ruby(Arg* arg)
|
|
248
|
+
explicit From_Ruby(Arg* arg) : arg_(arg)
|
|
244
249
|
{
|
|
245
250
|
}
|
|
246
251
|
|
|
247
|
-
|
|
252
|
+
double is_convertible(VALUE value)
|
|
248
253
|
{
|
|
249
254
|
switch (rb_type(value))
|
|
250
255
|
{
|
|
@@ -260,5 +265,8 @@ namespace Rice::detail
|
|
|
260
265
|
{
|
|
261
266
|
return Object(value);
|
|
262
267
|
}
|
|
268
|
+
|
|
269
|
+
private:
|
|
270
|
+
Arg* arg_ = nullptr;
|
|
263
271
|
};
|
|
264
272
|
}
|
data/rice/cpp_api/String.hpp
CHANGED
|
@@ -38,8 +38,8 @@ namespace Rice
|
|
|
38
38
|
String(std::string_view const& s);
|
|
39
39
|
|
|
40
40
|
//! Format a string using printf-style formatting.
|
|
41
|
-
template <typename...
|
|
42
|
-
static inline String format(char const* fmt,
|
|
41
|
+
template <typename... Parameter_Ts>
|
|
42
|
+
static inline String format(char const* fmt, Parameter_Ts&&...args);
|
|
43
43
|
|
|
44
44
|
//! Get the length of the String.
|
|
45
45
|
/*! \return the length of the string.
|
data/rice/cpp_api/String.ipp
CHANGED
|
@@ -28,16 +28,16 @@ namespace Rice
|
|
|
28
28
|
{
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
template <typename...
|
|
32
|
-
inline String String::format(char const* fmt,
|
|
31
|
+
template <typename... Parameter_Ts>
|
|
32
|
+
inline String String::format(char const* fmt, Parameter_Ts&&...args)
|
|
33
33
|
{
|
|
34
|
-
size_t size = std::snprintf(nullptr, 0, fmt, std::forward<
|
|
34
|
+
size_t size = std::snprintf(nullptr, 0, fmt, std::forward<Parameter_Ts>(args)...);
|
|
35
35
|
std::string temp(size, '\0');
|
|
36
36
|
|
|
37
37
|
// size+1 avoids truncating the string. Otherwise snprintf writes n - 1 characters
|
|
38
38
|
// to allow space for null character but we don't need that since std::string
|
|
39
39
|
// will add a null character internally at n + 1
|
|
40
|
-
std::snprintf(&temp[0], size + 1, fmt, std::forward<
|
|
40
|
+
std::snprintf(&temp[0], size + 1, fmt, std::forward<Parameter_Ts>(args)...);
|
|
41
41
|
|
|
42
42
|
String s = String(temp.c_str());
|
|
43
43
|
return s;
|
|
@@ -97,7 +97,7 @@ namespace Rice::detail
|
|
|
97
97
|
public:
|
|
98
98
|
To_Ruby() = default;
|
|
99
99
|
|
|
100
|
-
explicit To_Ruby(
|
|
100
|
+
explicit To_Ruby(Arg* arg) : arg_(arg)
|
|
101
101
|
{
|
|
102
102
|
}
|
|
103
103
|
|
|
@@ -107,7 +107,7 @@ namespace Rice::detail
|
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
private:
|
|
110
|
-
|
|
110
|
+
Arg* arg_ = nullptr;
|
|
111
111
|
};
|
|
112
112
|
|
|
113
113
|
template<>
|
|
@@ -116,11 +116,11 @@ namespace Rice::detail
|
|
|
116
116
|
public:
|
|
117
117
|
From_Ruby() = default;
|
|
118
118
|
|
|
119
|
-
explicit From_Ruby(Arg* arg)
|
|
119
|
+
explicit From_Ruby(Arg* arg) : arg_(arg)
|
|
120
120
|
{
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
|
|
123
|
+
double is_convertible(VALUE value)
|
|
124
124
|
{
|
|
125
125
|
switch (rb_type(value))
|
|
126
126
|
{
|
|
@@ -136,5 +136,8 @@ namespace Rice::detail
|
|
|
136
136
|
{
|
|
137
137
|
return String(value);
|
|
138
138
|
}
|
|
139
|
+
|
|
140
|
+
private:
|
|
141
|
+
Arg* arg_ = nullptr;
|
|
139
142
|
};
|
|
140
143
|
}
|
data/rice/cpp_api/Symbol.ipp
CHANGED
|
@@ -67,7 +67,7 @@ namespace Rice::detail
|
|
|
67
67
|
public:
|
|
68
68
|
To_Ruby() = default;
|
|
69
69
|
|
|
70
|
-
explicit To_Ruby(
|
|
70
|
+
explicit To_Ruby(Arg* arg) : arg_(arg)
|
|
71
71
|
{
|
|
72
72
|
}
|
|
73
73
|
|
|
@@ -77,7 +77,7 @@ namespace Rice::detail
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
private:
|
|
80
|
-
|
|
80
|
+
Arg* arg_ = nullptr;
|
|
81
81
|
};
|
|
82
82
|
|
|
83
83
|
|
|
@@ -87,7 +87,7 @@ namespace Rice::detail
|
|
|
87
87
|
public:
|
|
88
88
|
To_Ruby() = default;
|
|
89
89
|
|
|
90
|
-
explicit To_Ruby(
|
|
90
|
+
explicit To_Ruby(Arg* arg) : arg_(arg)
|
|
91
91
|
{
|
|
92
92
|
}
|
|
93
93
|
|
|
@@ -97,7 +97,7 @@ namespace Rice::detail
|
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
private:
|
|
100
|
-
|
|
100
|
+
Arg* arg_ = nullptr;
|
|
101
101
|
};
|
|
102
102
|
|
|
103
103
|
template<>
|
|
@@ -110,15 +110,15 @@ namespace Rice::detail
|
|
|
110
110
|
{
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
|
|
113
|
+
double is_convertible(VALUE value)
|
|
114
114
|
{
|
|
115
115
|
switch (rb_type(value))
|
|
116
116
|
{
|
|
117
117
|
case RUBY_T_SYMBOL:
|
|
118
118
|
return Convertible::Exact;
|
|
119
119
|
break;
|
|
120
|
-
|
|
121
|
-
return Convertible::
|
|
120
|
+
case RUBY_T_STRING:
|
|
121
|
+
return Convertible::Exact;
|
|
122
122
|
break;
|
|
123
123
|
default:
|
|
124
124
|
return Convertible::None;
|
|
@@ -33,8 +33,7 @@ inline auto& include_module(Module const& inc)
|
|
|
33
33
|
template<typename Method_T, typename...Arg_Ts>
|
|
34
34
|
inline auto& define_method(std::string name, Method_T&& method, const Arg_Ts&...args)
|
|
35
35
|
{
|
|
36
|
-
|
|
37
|
-
this->wrap_native_method(this->value(), name, std::forward<Method_T>(method), methodInfo);
|
|
36
|
+
this->wrap_native_method(this->value(), name, std::forward<Method_T>(method), args...);
|
|
38
37
|
return *this;
|
|
39
38
|
}
|
|
40
39
|
|
|
@@ -52,8 +51,7 @@ inline auto& define_method(std::string name, Method_T&& method, const Arg_Ts&...
|
|
|
52
51
|
template<typename Function_T, typename...Arg_Ts>
|
|
53
52
|
inline auto& define_function(std::string name, Function_T&& func, const Arg_Ts&...args)
|
|
54
53
|
{
|
|
55
|
-
|
|
56
|
-
this->wrap_native_function(this->value(), name, std::forward<Function_T>(func), methodInfo);
|
|
54
|
+
this->wrap_native_function(this->value(), name, std::forward<Function_T>(func), args...);
|
|
57
55
|
return *this;
|
|
58
56
|
}
|
|
59
57
|
|
|
@@ -75,8 +73,7 @@ inline auto& define_function(std::string name, Function_T&& func, const Arg_Ts&.
|
|
|
75
73
|
template<typename Method_T, typename...Arg_Ts>
|
|
76
74
|
inline auto& define_singleton_method(std::string name, Method_T&& method, const Arg_Ts&...args)
|
|
77
75
|
{
|
|
78
|
-
|
|
79
|
-
this->wrap_native_method(rb_singleton_class(*this), name, std::forward<Method_T>(method), methodInfo);
|
|
76
|
+
this->wrap_native_method(rb_singleton_class(*this), name, std::forward<Method_T>(method), args...);
|
|
80
77
|
return *this;
|
|
81
78
|
}
|
|
82
79
|
|
|
@@ -94,8 +91,7 @@ inline auto& define_singleton_method(std::string name, Method_T&& method, const
|
|
|
94
91
|
template<typename Function_T, typename...Arg_Ts>
|
|
95
92
|
inline auto& define_singleton_function(std::string name, Function_T&& func, const Arg_Ts& ...args)
|
|
96
93
|
{
|
|
97
|
-
|
|
98
|
-
this->wrap_native_function(rb_singleton_class(*this), name, std::forward<Function_T>(func), methodInfo);
|
|
94
|
+
this->wrap_native_function(rb_singleton_class(*this), name, std::forward<Function_T>(func), args...);
|
|
99
95
|
return *this;
|
|
100
96
|
}
|
|
101
97
|
|
|
@@ -112,7 +108,7 @@ inline auto& define_singleton_function(std::string name, Function_T&& func, cons
|
|
|
112
108
|
* \return *this
|
|
113
109
|
*/
|
|
114
110
|
template<typename Function_T, typename...Arg_Ts>
|
|
115
|
-
inline auto& define_module_function(std::string name, Function_T&& func,
|
|
111
|
+
inline auto& define_module_function(std::string name, Function_T&& func, Arg_Ts&& ...args)
|
|
116
112
|
{
|
|
117
113
|
if (this->rb_type() != T_MODULE)
|
|
118
114
|
{
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#ifndef Rice__detail__Forwards__hpp_
|
|
2
|
+
#define Rice__detail__Forwards__hpp_
|
|
3
|
+
|
|
4
|
+
namespace Rice::detail
|
|
5
|
+
{
|
|
6
|
+
// Setup method forwarding from a wrapper class to its wrapped type using Ruby's Forwardable.
|
|
7
|
+
// This allows calling methods on the wrapper that get delegated to the wrapped object via
|
|
8
|
+
// a "get" method that returns the wrapped object.
|
|
9
|
+
//
|
|
10
|
+
// Parameters:
|
|
11
|
+
// wrapper_klass - The Ruby class to add forwarding to (e.g., SharedPtr_MyClass)
|
|
12
|
+
// wrapped_klass - The Ruby class whose methods should be forwarded (e.g., MyClass)
|
|
13
|
+
void define_forwarding(VALUE wrapper_klass, VALUE wrapped_klass);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
#include "Forwards.ipp"
|
|
17
|
+
|
|
18
|
+
#endif // Rice__detail__Forwards__hpp_
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
namespace Rice::detail
|
|
2
|
+
{
|
|
3
|
+
inline void define_forwarding(VALUE wrapper_klass, VALUE wrapped_klass)
|
|
4
|
+
{
|
|
5
|
+
protect(rb_require, "forwardable");
|
|
6
|
+
Object forwardable = Object(rb_cObject).const_get("Forwardable");
|
|
7
|
+
Object(wrapper_klass).extend(forwardable.value());
|
|
8
|
+
|
|
9
|
+
// Get wrapper class's method names to avoid conflicts
|
|
10
|
+
std::set<std::string> wrapperMethodSet;
|
|
11
|
+
for (Native* native : Registries::instance.natives.lookup(wrapper_klass, NativeKind::Method))
|
|
12
|
+
{
|
|
13
|
+
wrapperMethodSet.insert(native->name());
|
|
14
|
+
}
|
|
15
|
+
for (Native* native : Registries::instance.natives.lookup(wrapper_klass, NativeKind::AttributeReader))
|
|
16
|
+
{
|
|
17
|
+
wrapperMethodSet.insert(native->name());
|
|
18
|
+
}
|
|
19
|
+
for (Native* native : Registries::instance.natives.lookup(wrapper_klass, NativeKind::AttributeWriter))
|
|
20
|
+
{
|
|
21
|
+
wrapperMethodSet.insert(native->name() + "=");
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Get wrapped class's method names from the registry, including ancestor classes
|
|
25
|
+
std::set<std::string> wrappedMethodSet;
|
|
26
|
+
Class klass(wrapped_klass);
|
|
27
|
+
while (klass.value() != rb_cObject && klass.value() != Qnil)
|
|
28
|
+
{
|
|
29
|
+
for (Native* native : Registries::instance.natives.lookup(klass.value(), NativeKind::Method))
|
|
30
|
+
{
|
|
31
|
+
wrappedMethodSet.insert(native->name());
|
|
32
|
+
}
|
|
33
|
+
for (Native* native : Registries::instance.natives.lookup(klass.value(), NativeKind::AttributeReader))
|
|
34
|
+
{
|
|
35
|
+
wrappedMethodSet.insert(native->name());
|
|
36
|
+
}
|
|
37
|
+
for (Native* native : Registries::instance.natives.lookup(klass.value(), NativeKind::AttributeWriter))
|
|
38
|
+
{
|
|
39
|
+
wrappedMethodSet.insert(native->name() + "=");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
klass = klass.superclass();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Build the arguments array for def_delegators: [:get, :method1, :method2, ...]
|
|
46
|
+
// Skip methods that are already defined on the wrapper class
|
|
47
|
+
Array args;
|
|
48
|
+
args.push(Symbol("get"));
|
|
49
|
+
for (const std::string& method : wrappedMethodSet)
|
|
50
|
+
{
|
|
51
|
+
if (wrapperMethodSet.find(method) == wrapperMethodSet.end())
|
|
52
|
+
{
|
|
53
|
+
args.push(Symbol(method));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Call def_delegators(*args)
|
|
58
|
+
Object(wrapper_klass).vcall("def_delegators", args);
|
|
59
|
+
}
|
|
60
|
+
}
|
data/rice/detail/Native.hpp
CHANGED
|
@@ -11,8 +11,7 @@ namespace Rice::detail
|
|
|
11
11
|
inline bool operator<(Resolved other);
|
|
12
12
|
inline bool operator>(Resolved other);
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
double parameterMatch;
|
|
14
|
+
double score; // Combined score: minParameterScore * parameterMatch
|
|
16
15
|
Native* native;
|
|
17
16
|
};
|
|
18
17
|
|
|
@@ -23,7 +22,8 @@ namespace Rice::detail
|
|
|
23
22
|
Iterator,
|
|
24
23
|
AttributeReader,
|
|
25
24
|
AttributeWriter,
|
|
26
|
-
Proc
|
|
25
|
+
Proc,
|
|
26
|
+
Callback
|
|
27
27
|
};
|
|
28
28
|
|
|
29
29
|
class Native
|
|
@@ -31,8 +31,9 @@ namespace Rice::detail
|
|
|
31
31
|
public:
|
|
32
32
|
static VALUE resolve(int argc, VALUE* argv, VALUE self);
|
|
33
33
|
public:
|
|
34
|
-
Native()
|
|
35
|
-
Native(std::
|
|
34
|
+
Native(std::string name);
|
|
35
|
+
Native(std::string name, std::unique_ptr<Return>&& returnInfo);
|
|
36
|
+
Native(std::string name, std::unique_ptr<Return>&& returnInfo, std::vector<std::unique_ptr<ParameterAbstract>>&& parameters);
|
|
36
37
|
virtual ~Native() = default;
|
|
37
38
|
|
|
38
39
|
Native(const Native&) = delete;
|
|
@@ -40,36 +41,45 @@ namespace Rice::detail
|
|
|
40
41
|
void operator=(const Native&) = delete;
|
|
41
42
|
void operator=(Native&&) = delete;
|
|
42
43
|
|
|
43
|
-
virtual Resolved matches(
|
|
44
|
-
virtual VALUE operator()(
|
|
44
|
+
virtual Resolved matches(std::map<std::string, VALUE>& values);
|
|
45
|
+
virtual VALUE operator()(std::map<std::string, VALUE>& values, VALUE self) = 0;
|
|
45
46
|
virtual std::string toString() = 0;
|
|
46
47
|
|
|
47
48
|
// Ruby API access
|
|
48
|
-
|
|
49
|
+
std::string name();
|
|
50
|
+
std::vector<const ParameterAbstract*> parameters();
|
|
49
51
|
virtual NativeKind kind() = 0;
|
|
50
52
|
virtual VALUE returnKlass() = 0;
|
|
51
|
-
std::vector<const ParameterAbstract*> parameters();
|
|
52
53
|
|
|
53
54
|
protected:
|
|
54
|
-
template<typename T>
|
|
55
|
-
static void verify_type(
|
|
55
|
+
template<typename T, bool isBuffer>
|
|
56
|
+
static void verify_type();
|
|
56
57
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
std::vector<std::optional<VALUE>> getRubyValues(size_t argc, const VALUE* argv, bool validate);
|
|
58
|
+
static std::map<std::string, VALUE> readRubyArgs(size_t argc, const VALUE* argv);
|
|
59
|
+
std::vector<std::optional<VALUE>> getRubyValues(std::map<std::string, VALUE> values, bool validate);
|
|
61
60
|
ParameterAbstract* getParameterByName(std::string name);
|
|
62
|
-
|
|
61
|
+
double matchParameters(std::vector<std::optional<VALUE>>& values, size_t argc);
|
|
62
|
+
|
|
63
|
+
template<typename Parameter_Tuple, typename... Arg_Ts>
|
|
64
|
+
static std::vector<std::unique_ptr<ParameterAbstract>> create_parameters(Arg_Ts&& ...args);
|
|
63
65
|
|
|
64
|
-
template<typename
|
|
65
|
-
static std::
|
|
66
|
+
template<typename... Arg_Ts>
|
|
67
|
+
static std::unique_ptr<Return> create_return(Arg_Ts& ...args);
|
|
66
68
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
+
// Do we need to keep alive any arguments?
|
|
70
|
+
void checkKeepAlive(VALUE self, VALUE returnValue, std::vector<std::optional<VALUE>>& rubyValues);
|
|
71
|
+
|
|
72
|
+
private:
|
|
73
|
+
template<typename Parameter_Tuple, typename Arg_Tuple, std::size_t ...Indices>
|
|
74
|
+
static inline void create_parameters_impl(std::vector<std::unique_ptr<ParameterAbstract>>& parameters, std::index_sequence<Indices...> indices, std::vector<std::unique_ptr<Arg>>&& args);
|
|
75
|
+
|
|
76
|
+
template<typename Parameter_Tuple, typename Arg_Tuple, size_t I>
|
|
77
|
+
static void verify_parameter();
|
|
69
78
|
|
|
70
79
|
protected:
|
|
80
|
+
std::string name_;
|
|
81
|
+
std::unique_ptr<Return> returnInfo_;
|
|
71
82
|
std::vector<std::unique_ptr<ParameterAbstract>> parameters_;
|
|
72
|
-
|
|
73
83
|
};
|
|
74
84
|
}
|
|
75
85
|
|