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/Enum.ipp
CHANGED
|
@@ -29,48 +29,52 @@ namespace Rice
|
|
|
29
29
|
klass.define_constructor(Constructor<Enum_T>());
|
|
30
30
|
|
|
31
31
|
klass.define_method("to_s", [](Enum_T& self) -> String
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
32
|
+
{
|
|
33
|
+
return String(valuesToNames_[self]);
|
|
34
|
+
})
|
|
35
|
+
.define_method("to_int", [](Enum_T& self) -> Underlying_T
|
|
36
|
+
{
|
|
37
|
+
return (Underlying_T)(self);
|
|
38
|
+
})
|
|
39
|
+
.define_method("coerce", [](Enum_T& self, Underlying_T& other) -> Array
|
|
40
|
+
{
|
|
41
|
+
/* Other will be a numeric value that matches the underlying type of the enum, for example an int.
|
|
42
|
+
Convert that to the enum type and then create new Ruby object to wrap it. This then enables code
|
|
43
|
+
like this:
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
Colors::Red | Colors:Blue | Colors:Green
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
Colors::Red | Colors:Blue returns an integer. Then this method converts the integer back into an Enum
|
|
48
|
+
instance so that Colors:Blue | Colors:Green works. */
|
|
49
|
+
Enum_T otherEnum = (Enum_T)other;
|
|
50
50
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
51
|
+
Array result;
|
|
52
|
+
result.push(otherEnum, true);
|
|
53
|
+
result.push(self, false);
|
|
54
|
+
return result;
|
|
55
|
+
})
|
|
56
|
+
.define_method("inspect", [](Enum_T& self)
|
|
57
|
+
{
|
|
58
|
+
std::stringstream result;
|
|
59
|
+
VALUE rubyKlass = Enum<Enum_T>::klass().value();
|
|
60
|
+
result << "#<" << detail::protect(rb_class2name, rubyKlass)
|
|
61
|
+
<< "::" << Enum<Enum_T>::valuesToNames_[self] << ">";
|
|
62
|
+
|
|
63
|
+
// We have to return string because we don't know if std::string support has
|
|
64
|
+
// been included by the user
|
|
65
|
+
return String(result.str());
|
|
66
|
+
})
|
|
67
|
+
.define_method("hash", [](Enum_T& self) -> Underlying_T
|
|
68
|
+
{
|
|
69
|
+
return (Underlying_T)self;
|
|
70
|
+
})
|
|
71
|
+
.define_method("eql?", [](Enum_T& self, Enum_T& other)
|
|
72
|
+
{
|
|
73
|
+
return self == other;
|
|
74
|
+
})
|
|
75
|
+
.define_method("eql?", [](Enum_T& self, Underlying_T& other)
|
|
76
|
+
{
|
|
77
|
+
return self == (Enum_T)other;
|
|
74
78
|
});
|
|
75
79
|
|
|
76
80
|
// Add aliases
|
|
@@ -93,6 +97,21 @@ namespace Rice
|
|
|
93
97
|
{
|
|
94
98
|
return 1;
|
|
95
99
|
}
|
|
100
|
+
})
|
|
101
|
+
.define_method("<=>", [](Enum_T& self, Underlying_T& other)
|
|
102
|
+
{
|
|
103
|
+
if (self == (Enum_T)other)
|
|
104
|
+
{
|
|
105
|
+
return 0;
|
|
106
|
+
}
|
|
107
|
+
else if (self < (Enum_T)other)
|
|
108
|
+
{
|
|
109
|
+
return -1;
|
|
110
|
+
}
|
|
111
|
+
else
|
|
112
|
+
{
|
|
113
|
+
return 1;
|
|
114
|
+
}
|
|
96
115
|
});
|
|
97
116
|
|
|
98
117
|
// Add ability to get enum values
|
data/rice/Exception.hpp
CHANGED
|
@@ -28,8 +28,8 @@ namespace Rice
|
|
|
28
28
|
* \param fmt a printf-style format string
|
|
29
29
|
* \param ... the arguments to the format string.
|
|
30
30
|
*/
|
|
31
|
-
template <typename...
|
|
32
|
-
Exception(const Exception& other, char const* fmt,
|
|
31
|
+
template <typename... Parameter_Ts>
|
|
32
|
+
Exception(const Exception& other, char const* fmt, Parameter_Ts&&...args);
|
|
33
33
|
|
|
34
34
|
//! Construct a Exception with printf-style formatting.
|
|
35
35
|
/*! \param exc either an exception object or a class that inherits
|
|
@@ -37,8 +37,8 @@ namespace Rice
|
|
|
37
37
|
* \param fmt a printf-style format string
|
|
38
38
|
* \param ... the arguments to the format string.
|
|
39
39
|
*/
|
|
40
|
-
template <typename...
|
|
41
|
-
Exception(const VALUE exceptionType, char const* fmt,
|
|
40
|
+
template <typename... Parameter_Ts>
|
|
41
|
+
Exception(const VALUE exceptionType, char const* fmt, Parameter_Ts&&...args);
|
|
42
42
|
|
|
43
43
|
//! Destructor
|
|
44
44
|
virtual ~Exception() noexcept = default;
|
data/rice/Exception.ipp
CHANGED
|
@@ -5,27 +5,27 @@ namespace Rice
|
|
|
5
5
|
{
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
template <typename...
|
|
9
|
-
inline Exception::Exception(const Exception& other, char const* fmt,
|
|
10
|
-
: Exception(other.class_of(), fmt, std::forward<
|
|
8
|
+
template <typename... Parameter_Ts>
|
|
9
|
+
inline Exception::Exception(const Exception& other, char const* fmt, Parameter_Ts&&...args)
|
|
10
|
+
: Exception(other.class_of(), fmt, std::forward<Parameter_Ts>(args)...)
|
|
11
11
|
{
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
template <typename...
|
|
15
|
-
inline Exception::Exception(const VALUE exceptionClass, char const* fmt,
|
|
14
|
+
template <typename... Parameter_Ts>
|
|
15
|
+
inline Exception::Exception(const VALUE exceptionClass, char const* fmt, Parameter_Ts&&...args)
|
|
16
16
|
{
|
|
17
17
|
#if defined(__GNUC__) || defined(__clang__)
|
|
18
18
|
#pragma GCC diagnostic push
|
|
19
19
|
#pragma GCC diagnostic ignored "-Wformat-security"
|
|
20
20
|
#endif
|
|
21
21
|
|
|
22
|
-
size_t size = std::snprintf(nullptr, 0, fmt, std::forward<
|
|
22
|
+
size_t size = std::snprintf(nullptr, 0, fmt, std::forward<Parameter_Ts>(args)...);
|
|
23
23
|
this->message_ = std::string(size, '\0');
|
|
24
24
|
|
|
25
25
|
// size+1 avoids truncating the string. Otherwise snprintf writes n - 1 characters
|
|
26
26
|
// to allow space for null character but we don't need that since std::string
|
|
27
27
|
// will add a null character internally at n + 1
|
|
28
|
-
std::snprintf(&this->message_[0], size + 1, fmt, std::forward<
|
|
28
|
+
std::snprintf(&this->message_[0], size + 1, fmt, std::forward<Parameter_Ts>(args)...);
|
|
29
29
|
|
|
30
30
|
#if defined(__GNUC__) || defined(__clang__)
|
|
31
31
|
#pragma GCC diagnostic pop
|
data/rice/NoGVL.hpp
ADDED
data/rice/Reference.hpp
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
#ifndef Rice__Reference__hpp_
|
|
2
|
+
#define Rice__Reference__hpp_
|
|
3
|
+
|
|
4
|
+
namespace Rice
|
|
5
|
+
{
|
|
6
|
+
template<typename T>
|
|
7
|
+
class Reference
|
|
8
|
+
{
|
|
9
|
+
static_assert(!detail::is_wrapped_v<detail::intrinsic_type<T>>,
|
|
10
|
+
"Reference can only be used with fundamental types");
|
|
11
|
+
|
|
12
|
+
public:
|
|
13
|
+
Reference();
|
|
14
|
+
Reference(T& data);
|
|
15
|
+
Reference(VALUE value);
|
|
16
|
+
T& get();
|
|
17
|
+
|
|
18
|
+
private:
|
|
19
|
+
T data_;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// Specialization needed when VALUE type matches T, causing constructor ambiguity
|
|
23
|
+
// between Reference(T&) and Reference(VALUE). VALUE is unsigned long when
|
|
24
|
+
// SIZEOF_LONG == SIZEOF_VOIDP (Linux/macOS) and unsigned long long when
|
|
25
|
+
// SIZEOF_LONG_LONG == SIZEOF_VOIDP (Windows x64).
|
|
26
|
+
#if SIZEOF_LONG == SIZEOF_VOIDP
|
|
27
|
+
template<>
|
|
28
|
+
class Reference<unsigned long>
|
|
29
|
+
{
|
|
30
|
+
public:
|
|
31
|
+
Reference();
|
|
32
|
+
Reference(unsigned long value, bool isValue = true);
|
|
33
|
+
unsigned long& get();
|
|
34
|
+
|
|
35
|
+
private:
|
|
36
|
+
unsigned long data_;
|
|
37
|
+
};
|
|
38
|
+
#else
|
|
39
|
+
template<>
|
|
40
|
+
class Reference<unsigned long long>
|
|
41
|
+
{
|
|
42
|
+
public:
|
|
43
|
+
Reference();
|
|
44
|
+
Reference(unsigned long long value, bool isValue = true);
|
|
45
|
+
unsigned long long& get();
|
|
46
|
+
|
|
47
|
+
private:
|
|
48
|
+
unsigned long long data_;
|
|
49
|
+
};
|
|
50
|
+
#endif
|
|
51
|
+
|
|
52
|
+
template<typename T>
|
|
53
|
+
Data_Type<Reference<T>> define_reference(std::string klassName = "");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
#endif // Rice__Reference__hpp_
|
data/rice/Reference.ipp
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
namespace Rice
|
|
2
|
+
{
|
|
3
|
+
template<typename T>
|
|
4
|
+
inline Reference<T>::Reference() : data_{}
|
|
5
|
+
{
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
template<typename T>
|
|
9
|
+
inline Reference<T>::Reference(T& data) : data_(data)
|
|
10
|
+
{
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
template<typename T>
|
|
14
|
+
inline Reference<T>::Reference(VALUE value) : data_(detail::FromRubyFundamental<T>::convert(value))
|
|
15
|
+
{
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
template<typename T>
|
|
19
|
+
inline T& Reference<T>::get()
|
|
20
|
+
{
|
|
21
|
+
return data_;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Specialization implementations - only one is compiled per platform
|
|
25
|
+
#if SIZEOF_LONG == SIZEOF_VOIDP
|
|
26
|
+
// VALUE is unsigned long on Linux/macOS
|
|
27
|
+
inline Reference<unsigned long>::Reference() : data_{}
|
|
28
|
+
{
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
inline Reference<unsigned long>::Reference(unsigned long value, bool isValue) :
|
|
32
|
+
data_(isValue ? detail::FromRubyFundamental<unsigned long>::convert(value) : value)
|
|
33
|
+
{
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
inline unsigned long& Reference<unsigned long>::get()
|
|
37
|
+
{
|
|
38
|
+
return data_;
|
|
39
|
+
}
|
|
40
|
+
#else
|
|
41
|
+
// VALUE is unsigned long long on Windows x64
|
|
42
|
+
inline Reference<unsigned long long>::Reference() : data_{}
|
|
43
|
+
{
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
inline Reference<unsigned long long>::Reference(unsigned long long value, bool isValue) :
|
|
47
|
+
data_(isValue ? detail::FromRubyFundamental<unsigned long long>::convert(value) : value)
|
|
48
|
+
{
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
inline unsigned long long& Reference<unsigned long long>::get()
|
|
52
|
+
{
|
|
53
|
+
return data_;
|
|
54
|
+
}
|
|
55
|
+
#endif
|
|
56
|
+
|
|
57
|
+
template<typename T>
|
|
58
|
+
inline Data_Type<Reference<T>> define_reference(std::string klassName)
|
|
59
|
+
{
|
|
60
|
+
using Reference_T = Reference<T>;
|
|
61
|
+
using Data_Type_T = Data_Type<Reference_T>;
|
|
62
|
+
|
|
63
|
+
if (klassName.empty())
|
|
64
|
+
{
|
|
65
|
+
detail::TypeMapper<Reference_T> typeMapper;
|
|
66
|
+
klassName = typeMapper.rubyName();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
Module rb_mRice = define_module("Rice");
|
|
70
|
+
|
|
71
|
+
if (Data_Type_T::check_defined(klassName, rb_mRice))
|
|
72
|
+
{
|
|
73
|
+
return Data_Type_T();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
Data_Type<Reference<T>> result = define_class_under<Reference_T>(rb_mRice, klassName).
|
|
77
|
+
define_constructor(Constructor<Reference_T, T>()).
|
|
78
|
+
define_method("value", &Reference_T::get);
|
|
79
|
+
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
namespace Rice::detail
|
|
85
|
+
{
|
|
86
|
+
template<typename T>
|
|
87
|
+
struct Type<Reference<T>>
|
|
88
|
+
{
|
|
89
|
+
static bool verify()
|
|
90
|
+
{
|
|
91
|
+
detail::verifyType<T>();
|
|
92
|
+
define_reference<T>();
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}
|
data/rice/Return.hpp
CHANGED
data/rice/Return.ipp
CHANGED
data/rice/cpp_api/Array.hpp
CHANGED
|
@@ -116,6 +116,12 @@ namespace Rice
|
|
|
116
116
|
template<typename Array_Ptr_T, typename Value_T>
|
|
117
117
|
class Iterator;
|
|
118
118
|
|
|
119
|
+
// Friend declaration for non-member operator+
|
|
120
|
+
template<typename Array_Ptr_T, typename Value_T>
|
|
121
|
+
friend Iterator<Array_Ptr_T, Value_T> operator+(
|
|
122
|
+
long n,
|
|
123
|
+
Iterator<Array_Ptr_T, Value_T> const& it);
|
|
124
|
+
|
|
119
125
|
long position_of(long index) const;
|
|
120
126
|
|
|
121
127
|
public:
|
|
@@ -164,13 +170,12 @@ namespace Rice
|
|
|
164
170
|
long index_;
|
|
165
171
|
};
|
|
166
172
|
|
|
167
|
-
//! A
|
|
168
|
-
// TODO: This really should be a random-access iterator.
|
|
173
|
+
//! A random-access iterator for Array.
|
|
169
174
|
template<typename Array_Ptr_T, typename Value_T>
|
|
170
175
|
class Array::Iterator
|
|
171
176
|
{
|
|
172
177
|
public:
|
|
173
|
-
using iterator_category = std::
|
|
178
|
+
using iterator_category = std::random_access_iterator_tag;
|
|
174
179
|
using value_type = Value_T;
|
|
175
180
|
using difference_type = long;
|
|
176
181
|
using pointer = Object*;
|
|
@@ -184,17 +189,43 @@ namespace Rice
|
|
|
184
189
|
template<typename Array_Ptr_T_, typename Value_T_>
|
|
185
190
|
Iterator& operator=(Iterator<Array_Ptr_T_, Value_T_> const& rhs);
|
|
186
191
|
|
|
192
|
+
// Forward iterator operations
|
|
187
193
|
Iterator& operator++();
|
|
188
194
|
Iterator operator++(int);
|
|
189
|
-
Value_T operator*();
|
|
195
|
+
Value_T operator*() const;
|
|
190
196
|
Object* operator->();
|
|
191
197
|
|
|
198
|
+
// Bidirectional iterator operations
|
|
199
|
+
Iterator& operator--();
|
|
200
|
+
Iterator operator--(int);
|
|
201
|
+
|
|
202
|
+
// Random access iterator operations
|
|
203
|
+
Iterator& operator+=(difference_type n);
|
|
204
|
+
Iterator& operator-=(difference_type n);
|
|
205
|
+
Iterator operator+(difference_type n) const;
|
|
206
|
+
Iterator operator-(difference_type n) const;
|
|
207
|
+
difference_type operator-(Iterator const& rhs) const;
|
|
208
|
+
Value_T operator[](difference_type n) const;
|
|
209
|
+
|
|
210
|
+
// Comparison operators
|
|
192
211
|
template<typename Array_Ptr_T_, typename Value_T_>
|
|
193
212
|
bool operator==(Iterator<Array_Ptr_T_, Value_T_> const& rhs) const;
|
|
194
213
|
|
|
195
214
|
template<typename Array_Ptr_T_, typename Value_T_>
|
|
196
215
|
bool operator!=(Iterator<Array_Ptr_T_, Value_T_> const& rhs) const;
|
|
197
216
|
|
|
217
|
+
template<typename Array_Ptr_T_, typename Value_T_>
|
|
218
|
+
bool operator<(Iterator<Array_Ptr_T_, Value_T_> const& rhs) const;
|
|
219
|
+
|
|
220
|
+
template<typename Array_Ptr_T_, typename Value_T_>
|
|
221
|
+
bool operator>(Iterator<Array_Ptr_T_, Value_T_> const& rhs) const;
|
|
222
|
+
|
|
223
|
+
template<typename Array_Ptr_T_, typename Value_T_>
|
|
224
|
+
bool operator<=(Iterator<Array_Ptr_T_, Value_T_> const& rhs) const;
|
|
225
|
+
|
|
226
|
+
template<typename Array_Ptr_T_, typename Value_T_>
|
|
227
|
+
bool operator>=(Iterator<Array_Ptr_T_, Value_T_> const& rhs) const;
|
|
228
|
+
|
|
198
229
|
Array_Ptr_T array() const;
|
|
199
230
|
long index() const;
|
|
200
231
|
|
|
@@ -204,6 +235,12 @@ namespace Rice
|
|
|
204
235
|
|
|
205
236
|
Object tmp_;
|
|
206
237
|
};
|
|
238
|
+
|
|
239
|
+
// Non-member operator+ for n + iterator (allows n + iterator syntax)
|
|
240
|
+
template<typename Array_Ptr_T, typename Value_T>
|
|
241
|
+
Array::Iterator<Array_Ptr_T, Value_T> operator+(
|
|
242
|
+
long n,
|
|
243
|
+
Array::Iterator<Array_Ptr_T, Value_T> const& it);
|
|
207
244
|
} // namespace Rice
|
|
208
245
|
|
|
209
246
|
#endif // Rice__Array__hpp_
|
data/rice/cpp_api/Array.ipp
CHANGED
|
@@ -186,7 +186,7 @@ namespace Rice
|
|
|
186
186
|
}
|
|
187
187
|
|
|
188
188
|
template<typename Array_Ptr_T, typename Value_T>
|
|
189
|
-
inline Value_T Array::Iterator<Array_Ptr_T, Value_T>::operator*()
|
|
189
|
+
inline Value_T Array::Iterator<Array_Ptr_T, Value_T>::operator*() const
|
|
190
190
|
{
|
|
191
191
|
return (*array_)[index_];
|
|
192
192
|
}
|
|
@@ -212,6 +212,99 @@ namespace Rice
|
|
|
212
212
|
return !(*this == rhs);
|
|
213
213
|
}
|
|
214
214
|
|
|
215
|
+
template<typename Array_Ptr_T, typename Value_T>
|
|
216
|
+
template<typename Array_Ptr_T_, typename Value_T_>
|
|
217
|
+
inline bool Array::Iterator<Array_Ptr_T, Value_T>::operator<(Iterator<Array_Ptr_T_, Value_T_> const& rhs) const
|
|
218
|
+
{
|
|
219
|
+
return index_ < rhs.index_;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
template<typename Array_Ptr_T, typename Value_T>
|
|
223
|
+
template<typename Array_Ptr_T_, typename Value_T_>
|
|
224
|
+
inline bool Array::Iterator<Array_Ptr_T, Value_T>::operator>(Iterator<Array_Ptr_T_, Value_T_> const& rhs) const
|
|
225
|
+
{
|
|
226
|
+
return index_ > rhs.index_;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
template<typename Array_Ptr_T, typename Value_T>
|
|
230
|
+
template<typename Array_Ptr_T_, typename Value_T_>
|
|
231
|
+
inline bool Array::Iterator<Array_Ptr_T, Value_T>::operator<=(Iterator<Array_Ptr_T_, Value_T_> const& rhs) const
|
|
232
|
+
{
|
|
233
|
+
return index_ <= rhs.index_;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
template<typename Array_Ptr_T, typename Value_T>
|
|
237
|
+
template<typename Array_Ptr_T_, typename Value_T_>
|
|
238
|
+
inline bool Array::Iterator<Array_Ptr_T, Value_T>::operator>=(Iterator<Array_Ptr_T_, Value_T_> const& rhs) const
|
|
239
|
+
{
|
|
240
|
+
return index_ >= rhs.index_;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// Bidirectional iterator operations
|
|
244
|
+
template<typename Array_Ptr_T, typename Value_T>
|
|
245
|
+
inline Array::Iterator<Array_Ptr_T, Value_T>& Array::Iterator<Array_Ptr_T, Value_T>::operator--()
|
|
246
|
+
{
|
|
247
|
+
--index_;
|
|
248
|
+
return *this;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
template<typename Array_Ptr_T, typename Value_T>
|
|
252
|
+
inline Array::Iterator<Array_Ptr_T, Value_T> Array::Iterator<Array_Ptr_T, Value_T>::operator--(int)
|
|
253
|
+
{
|
|
254
|
+
Iterator copy(*this);
|
|
255
|
+
--(*this);
|
|
256
|
+
return copy;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// Random access iterator operations
|
|
260
|
+
template<typename Array_Ptr_T, typename Value_T>
|
|
261
|
+
inline Array::Iterator<Array_Ptr_T, Value_T>& Array::Iterator<Array_Ptr_T, Value_T>::operator+=(difference_type n)
|
|
262
|
+
{
|
|
263
|
+
index_ += n;
|
|
264
|
+
return *this;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
template<typename Array_Ptr_T, typename Value_T>
|
|
268
|
+
inline Array::Iterator<Array_Ptr_T, Value_T>& Array::Iterator<Array_Ptr_T, Value_T>::operator-=(difference_type n)
|
|
269
|
+
{
|
|
270
|
+
index_ -= n;
|
|
271
|
+
return *this;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
template<typename Array_Ptr_T, typename Value_T>
|
|
275
|
+
inline Array::Iterator<Array_Ptr_T, Value_T> Array::Iterator<Array_Ptr_T, Value_T>::operator+(difference_type n) const
|
|
276
|
+
{
|
|
277
|
+
return Iterator(array_, index_ + n);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
template<typename Array_Ptr_T, typename Value_T>
|
|
281
|
+
inline Array::Iterator<Array_Ptr_T, Value_T> Array::Iterator<Array_Ptr_T, Value_T>::operator-(difference_type n) const
|
|
282
|
+
{
|
|
283
|
+
return Iterator(array_, index_ - n);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
template<typename Array_Ptr_T, typename Value_T>
|
|
287
|
+
inline typename Array::Iterator<Array_Ptr_T, Value_T>::difference_type
|
|
288
|
+
Array::Iterator<Array_Ptr_T, Value_T>::operator-(Iterator const& rhs) const
|
|
289
|
+
{
|
|
290
|
+
return index_ - rhs.index_;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
template<typename Array_Ptr_T, typename Value_T>
|
|
294
|
+
inline Value_T Array::Iterator<Array_Ptr_T, Value_T>::operator[](difference_type n) const
|
|
295
|
+
{
|
|
296
|
+
return (*array_)[index_ + n];
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// Non-member operator+ (allows n + iterator syntax)
|
|
300
|
+
template<typename Array_Ptr_T, typename Value_T>
|
|
301
|
+
inline Array::Iterator<Array_Ptr_T, Value_T> operator+(
|
|
302
|
+
long n,
|
|
303
|
+
Array::Iterator<Array_Ptr_T, Value_T> const& it)
|
|
304
|
+
{
|
|
305
|
+
return it + n;
|
|
306
|
+
}
|
|
307
|
+
|
|
215
308
|
template<typename Array_Ptr_T, typename Value_T>
|
|
216
309
|
Array_Ptr_T Array::Iterator<Array_Ptr_T, Value_T>::array() const
|
|
217
310
|
{
|
|
@@ -267,7 +360,7 @@ namespace Rice::detail
|
|
|
267
360
|
public:
|
|
268
361
|
To_Ruby() = default;
|
|
269
362
|
|
|
270
|
-
explicit To_Ruby(
|
|
363
|
+
explicit To_Ruby(Arg* arg) : arg_(arg)
|
|
271
364
|
{
|
|
272
365
|
}
|
|
273
366
|
|
|
@@ -277,7 +370,7 @@ namespace Rice::detail
|
|
|
277
370
|
}
|
|
278
371
|
|
|
279
372
|
private:
|
|
280
|
-
|
|
373
|
+
Arg* arg_ = nullptr;
|
|
281
374
|
};
|
|
282
375
|
|
|
283
376
|
template<>
|
|
@@ -286,7 +379,7 @@ namespace Rice::detail
|
|
|
286
379
|
public:
|
|
287
380
|
To_Ruby() = default;
|
|
288
381
|
|
|
289
|
-
explicit To_Ruby(
|
|
382
|
+
explicit To_Ruby(Arg* arg) : arg_(arg)
|
|
290
383
|
{
|
|
291
384
|
}
|
|
292
385
|
|
|
@@ -296,7 +389,7 @@ namespace Rice::detail
|
|
|
296
389
|
}
|
|
297
390
|
|
|
298
391
|
private:
|
|
299
|
-
|
|
392
|
+
Arg* arg_ = nullptr;
|
|
300
393
|
};
|
|
301
394
|
|
|
302
395
|
template<>
|
|
@@ -305,7 +398,7 @@ namespace Rice::detail
|
|
|
305
398
|
public:
|
|
306
399
|
To_Ruby() = default;
|
|
307
400
|
|
|
308
|
-
explicit To_Ruby(
|
|
401
|
+
explicit To_Ruby(Arg* arg) : arg_(arg)
|
|
309
402
|
{
|
|
310
403
|
}
|
|
311
404
|
|
|
@@ -315,7 +408,7 @@ namespace Rice::detail
|
|
|
315
408
|
}
|
|
316
409
|
|
|
317
410
|
private:
|
|
318
|
-
|
|
411
|
+
Arg* arg_ = nullptr;
|
|
319
412
|
};
|
|
320
413
|
|
|
321
414
|
template<>
|
|
@@ -324,11 +417,11 @@ namespace Rice::detail
|
|
|
324
417
|
public:
|
|
325
418
|
From_Ruby() = default;
|
|
326
419
|
|
|
327
|
-
explicit From_Ruby(Arg* arg)
|
|
420
|
+
explicit From_Ruby(Arg* arg) : arg_(arg)
|
|
328
421
|
{
|
|
329
422
|
}
|
|
330
423
|
|
|
331
|
-
|
|
424
|
+
double is_convertible(VALUE value)
|
|
332
425
|
{
|
|
333
426
|
switch (rb_type(value))
|
|
334
427
|
{
|
|
@@ -344,6 +437,9 @@ namespace Rice::detail
|
|
|
344
437
|
{
|
|
345
438
|
return Array(value);
|
|
346
439
|
}
|
|
440
|
+
|
|
441
|
+
private:
|
|
442
|
+
Arg* arg_ = nullptr;
|
|
347
443
|
};
|
|
348
444
|
}
|
|
349
445
|
#endif // Rice__Array__ipp_
|
data/rice/cpp_api/Class.hpp
CHANGED
|
@@ -24,8 +24,8 @@ namespace Rice
|
|
|
24
24
|
Class & undef_creation_funcs();
|
|
25
25
|
|
|
26
26
|
// Create a new instance
|
|
27
|
-
template<typename ...
|
|
28
|
-
Object create(
|
|
27
|
+
template<typename ...Parameter_Ts>
|
|
28
|
+
Object create(Parameter_Ts ...args);
|
|
29
29
|
|
|
30
30
|
//! Class name
|
|
31
31
|
/*! \return std::string.
|
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
|
}
|
|
@@ -91,7 +91,7 @@ namespace Rice::detail
|
|
|
91
91
|
public:
|
|
92
92
|
To_Ruby() = default;
|
|
93
93
|
|
|
94
|
-
explicit To_Ruby(
|
|
94
|
+
explicit To_Ruby(Arg* arg) : arg_(arg)
|
|
95
95
|
{
|
|
96
96
|
}
|
|
97
97
|
|
|
@@ -101,7 +101,7 @@ namespace Rice::detail
|
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
private:
|
|
104
|
-
|
|
104
|
+
Arg* arg_ = nullptr;
|
|
105
105
|
};
|
|
106
106
|
|
|
107
107
|
template<>
|