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.
Files changed (153) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +29 -1
  3. data/CMakeLists.txt +14 -22
  4. data/CMakePresets.json +203 -75
  5. data/FindRuby.cmake +358 -123
  6. data/bin/rice-doc.rb +56 -141
  7. data/include/rice/api.hpp +248 -0
  8. data/include/rice/rice.hpp +2237 -1657
  9. data/include/rice/stl.hpp +346 -443
  10. data/lib/rice/doc/config.rb +70 -0
  11. data/lib/rice/doc/cpp_reference.rb +1 -4
  12. data/lib/rice/doc/mkdocs.rb +58 -20
  13. data/lib/rice/doc/rice.rb +20 -0
  14. data/lib/rice/doc.rb +1 -0
  15. data/lib/rice/make_rice_headers.rb +7 -0
  16. data/lib/rice/native_registry.rb +2 -2
  17. data/lib/rice/rbs.rb +2 -2
  18. data/lib/rice/version.rb +1 -1
  19. data/lib/rubygems_plugin.rb +12 -9
  20. data/rice/Arg.hpp +12 -6
  21. data/rice/Arg.ipp +14 -7
  22. data/rice/Buffer.ipp +44 -40
  23. data/rice/Callback.hpp +1 -1
  24. data/rice/Callback.ipp +2 -7
  25. data/rice/Constructor.hpp +1 -1
  26. data/rice/Constructor.ipp +11 -11
  27. data/rice/Data_Object.ipp +15 -15
  28. data/rice/Data_Type.hpp +9 -10
  29. data/rice/Data_Type.ipp +22 -25
  30. data/rice/Director.hpp +1 -0
  31. data/rice/Enum.ipp +58 -39
  32. data/rice/Exception.hpp +4 -4
  33. data/rice/Exception.ipp +7 -7
  34. data/rice/NoGVL.hpp +13 -0
  35. data/rice/Reference.hpp +56 -0
  36. data/rice/Reference.ipp +96 -0
  37. data/rice/Return.hpp +4 -1
  38. data/rice/Return.ipp +0 -6
  39. data/rice/cpp_api/Array.hpp +41 -4
  40. data/rice/cpp_api/Array.ipp +105 -9
  41. data/rice/cpp_api/Class.hpp +2 -2
  42. data/rice/cpp_api/Class.ipp +4 -4
  43. data/rice/cpp_api/Hash.ipp +7 -4
  44. data/rice/cpp_api/Module.hpp +4 -4
  45. data/rice/cpp_api/Module.ipp +12 -10
  46. data/rice/cpp_api/Object.hpp +4 -4
  47. data/rice/cpp_api/Object.ipp +15 -12
  48. data/rice/cpp_api/String.hpp +2 -2
  49. data/rice/cpp_api/String.ipp +11 -8
  50. data/rice/cpp_api/Symbol.ipp +7 -7
  51. data/rice/cpp_api/shared_methods.hpp +5 -9
  52. data/rice/detail/InstanceRegistry.hpp +0 -2
  53. data/rice/detail/Native.hpp +31 -21
  54. data/rice/detail/Native.ipp +282 -130
  55. data/rice/detail/NativeAttributeGet.hpp +5 -7
  56. data/rice/detail/NativeAttributeGet.ipp +26 -26
  57. data/rice/detail/NativeAttributeSet.hpp +2 -4
  58. data/rice/detail/NativeAttributeSet.ipp +20 -16
  59. data/rice/detail/NativeCallback.hpp +77 -0
  60. data/rice/detail/NativeCallback.ipp +280 -0
  61. data/rice/detail/NativeFunction.hpp +11 -21
  62. data/rice/detail/NativeFunction.ipp +58 -119
  63. data/rice/detail/NativeInvoker.hpp +4 -4
  64. data/rice/detail/NativeInvoker.ipp +7 -7
  65. data/rice/detail/NativeIterator.hpp +2 -4
  66. data/rice/detail/NativeIterator.ipp +18 -14
  67. data/rice/detail/NativeMethod.hpp +10 -20
  68. data/rice/detail/NativeMethod.ipp +54 -114
  69. data/rice/detail/NativeProc.hpp +5 -7
  70. data/rice/detail/NativeProc.ipp +39 -28
  71. data/rice/detail/NativeRegistry.hpp +0 -1
  72. data/rice/detail/Parameter.hpp +15 -8
  73. data/rice/detail/Parameter.ipp +102 -43
  74. data/rice/detail/Proc.ipp +14 -28
  75. data/rice/detail/RubyType.ipp +2 -53
  76. data/rice/detail/Type.hpp +23 -7
  77. data/rice/detail/Type.ipp +73 -93
  78. data/rice/detail/TypeRegistry.ipp +5 -4
  79. data/rice/detail/Wrapper.hpp +1 -1
  80. data/rice/detail/Wrapper.ipp +18 -10
  81. data/rice/detail/from_ruby.hpp +8 -6
  82. data/rice/detail/from_ruby.ipp +306 -173
  83. data/rice/detail/ruby.hpp +23 -0
  84. data/rice/libc/file.hpp +4 -4
  85. data/rice/rice.hpp +6 -8
  86. data/rice/rice_api/Native.ipp +5 -1
  87. data/rice/rice_api/Parameter.ipp +1 -1
  88. data/rice/ruby_mark.hpp +2 -1
  89. data/rice/stl/complex.ipp +12 -8
  90. data/rice/stl/map.ipp +27 -22
  91. data/rice/stl/monostate.ipp +16 -12
  92. data/rice/stl/multimap.hpp +0 -2
  93. data/rice/stl/multimap.ipp +27 -22
  94. data/rice/stl/optional.ipp +27 -11
  95. data/rice/stl/pair.ipp +5 -5
  96. data/rice/stl/reference_wrapper.ipp +5 -4
  97. data/rice/stl/set.ipp +16 -16
  98. data/rice/stl/shared_ptr.hpp +0 -16
  99. data/rice/stl/shared_ptr.ipp +34 -190
  100. data/rice/stl/string.ipp +18 -18
  101. data/rice/stl/string_view.ipp +1 -1
  102. data/rice/stl/tuple.ipp +15 -36
  103. data/rice/stl/unique_ptr.ipp +18 -8
  104. data/rice/stl/unordered_map.ipp +20 -15
  105. data/rice/stl/variant.ipp +37 -21
  106. data/rice/stl/vector.ipp +41 -36
  107. data/rice/traits/function_traits.hpp +19 -19
  108. data/rice/traits/method_traits.hpp +4 -4
  109. data/rice/traits/rice_traits.hpp +162 -39
  110. data/rice.gemspec +1 -3
  111. data/test/test_Array.cpp +261 -3
  112. data/test/test_Attribute.cpp +6 -3
  113. data/test/test_Buffer.cpp +6 -42
  114. data/test/test_Callback.cpp +77 -23
  115. data/test/test_Data_Object.cpp +1 -1
  116. data/test/test_Data_Type.cpp +21 -22
  117. data/test/test_Director.cpp +2 -4
  118. data/test/test_Enum.cpp +34 -5
  119. data/test/test_File.cpp +9 -5
  120. data/test/test_From_Ruby.cpp +4 -3
  121. data/test/test_GVL.cpp +3 -3
  122. data/test/test_Hash.cpp +1 -1
  123. data/test/test_Iterator.cpp +54 -22
  124. data/test/test_Keep_Alive.cpp +1 -1
  125. data/test/test_Keep_Alive_No_Wrapper.cpp +1 -1
  126. data/test/test_Module.cpp +5 -5
  127. data/test/test_Overloads.cpp +345 -48
  128. data/test/test_Proc.cpp +54 -0
  129. data/test/test_Reference.cpp +181 -0
  130. data/test/test_Self.cpp +2 -2
  131. data/test/test_Stl_Set.cpp +6 -6
  132. data/test/test_Stl_SharedPtr.cpp +54 -30
  133. data/test/test_Stl_String_View.cpp +4 -2
  134. data/test/test_Stl_Tuple.cpp +1 -1
  135. data/test/test_Stl_Variant.cpp +6 -14
  136. data/test/test_Stl_Vector.cpp +61 -30
  137. data/test/test_String.cpp +4 -2
  138. data/test/test_Struct.cpp +1 -1
  139. data/test/test_Symbol.cpp +1 -1
  140. data/test/test_To_Ruby.cpp +1 -0
  141. data/test/test_Type.cpp +36 -35
  142. data/test/test_global_functions.cpp +1 -1
  143. data/test/unittest.cpp +1 -1
  144. data/test/unittest.hpp +5 -5
  145. metadata +10 -10
  146. data/rice/Function.hpp +0 -17
  147. data/rice/Function.ipp +0 -13
  148. data/rice/detail/MethodInfo.hpp +0 -48
  149. data/rice/detail/MethodInfo.ipp +0 -99
  150. data/rice/detail/NativeCallbackFFI.hpp +0 -55
  151. data/rice/detail/NativeCallbackFFI.ipp +0 -152
  152. data/rice/detail/NativeCallbackSimple.hpp +0 -30
  153. data/rice/detail/NativeCallbackSimple.ipp +0 -29
@@ -1,64 +1,72 @@
1
1
  namespace Rice::detail
2
2
  {
3
3
  // ----------- ParameterAbstract ----------------
4
- inline ParameterAbstract::ParameterAbstract(Arg* arg) : arg(arg)
4
+ inline ParameterAbstract::ParameterAbstract(std::unique_ptr<Arg>&& arg) : arg_(std::move(arg))
5
5
  {
6
6
  }
7
7
 
8
+ inline ParameterAbstract::ParameterAbstract(const ParameterAbstract& other)
9
+ {
10
+ this->arg_ = std::make_unique<Arg>(*other.arg_);
11
+ }
12
+
13
+ inline Arg* ParameterAbstract::arg()
14
+ {
15
+ return this->arg_.get();
16
+ }
17
+
8
18
  // ----------- Parameter ----------------
9
19
  template<typename T>
10
- inline Parameter<T>::Parameter(Arg* arg) : ParameterAbstract(arg), fromRuby_(arg)
20
+ inline Parameter<T>::Parameter(std::unique_ptr<Arg>&& arg) : ParameterAbstract(std::move(arg)),
21
+ fromRuby_(this->arg()), toRuby_(this->arg())
11
22
  {
12
23
  }
13
24
 
14
25
  template<typename T>
15
- inline Convertible Parameter<T>::matches(std::optional<VALUE>& valueOpt)
26
+ inline double Parameter<T>::matches(std::optional<VALUE>& valueOpt)
16
27
  {
17
- Convertible result = Convertible::None;
28
+ if (!valueOpt.has_value())
29
+ {
30
+ return Convertible::None;
31
+ }
32
+ else if (this->arg()->isValue())
33
+ {
34
+ return Convertible::Exact;
35
+ }
18
36
 
19
- // Is a VALUE being passed directly to C++ ?
20
- if (valueOpt.has_value())
37
+ VALUE value = valueOpt.value();
38
+
39
+ // Check with FromRuby if the VALUE is convertible to C++
40
+ double result = this->fromRuby_.is_convertible(value);
41
+
42
+ // If this is an exact match check if the const-ness of the value and the parameter match.
43
+ // One caveat - procs are also RUBY_T_DATA so don't check if this is a function type
44
+ if (result == Convertible::Exact && rb_type(value) == RUBY_T_DATA && !std::is_function_v<std::remove_pointer_t<T>>)
21
45
  {
22
- VALUE value = valueOpt.value();
23
- if (this->arg->isValue())
46
+ // Check the constness of the Ruby wrapped value and the parameter
47
+ WrapperBase* wrapper = getWrapper(value);
48
+
49
+ // Do not send a const value to a non-const parameter
50
+ if (wrapper->isConst() && !is_const_any_v<T>)
24
51
  {
25
- result = Convertible::Exact;
52
+ result = Convertible::None;
26
53
  }
27
- // If index is less than argc then check with FromRuby if the VALUE is convertible
28
- // to C++.
29
- else
54
+ // It is ok to send a non-const value to a const parameter but
55
+ // prefer non-const to non-const by slightly decreasing the score
56
+ else if (!wrapper->isConst() && is_const_any_v<T>)
30
57
  {
31
- result = this->fromRuby_.is_convertible(value);
32
-
33
- // If this is an exact match check if the const-ness of the value and the parameter match
34
- if (result == Convertible::Exact && rb_type(value) == RUBY_T_DATA)
35
- {
36
- // Check the constness of the Ruby wrapped value and the parameter
37
- WrapperBase* wrapper = getWrapper(value);
38
-
39
- // Do not send a const value to a non-const parameter
40
- if (wrapper->isConst() && !is_const_any_v<T>)
41
- {
42
- result = Convertible::None;
43
- }
44
- // It is ok to send a non-const value to a const parameter but
45
- // prefer non-const to non-const by slighly decreasing the convertible value
46
- else if (!wrapper->isConst() && is_const_any_v<T>)
47
- {
48
- result = Convertible::Const;
49
- }
50
- }
58
+ result = Convertible::ConstMismatch;
51
59
  }
52
60
  }
53
- // Last check if a default value has been set
54
- else if (this->arg->hasDefaultValue())
55
- {
56
- result = Convertible::Exact;
57
- }
58
61
 
59
62
  return result;
60
63
  }
61
64
 
65
+ #ifdef _MSC_VER
66
+ #pragma warning(push)
67
+ #pragma warning(disable: 4702) // unreachable code
68
+ #endif
69
+
62
70
  template<typename T>
63
71
  inline T Parameter<T>::convertToNative(std::optional<VALUE>& valueOpt)
64
72
  {
@@ -78,22 +86,73 @@ namespace Rice::detail
78
86
  {
79
87
  return this->fromRuby_.convert(valueOpt.value());
80
88
  }
81
- else if constexpr (std::is_constructible_v<std::remove_cv_t<T>, std::remove_cv_t<std::remove_reference_t<T>>&>)
89
+ // Remember std::is_copy_constructible_v<std::vector<std::unique_ptr<T>>>> returns true. Sigh.
90
+ // So special case vector handling
91
+ else if constexpr (detail::is_std_vector_v<detail::intrinsic_type<T>>)
92
+ {
93
+ if constexpr (std::is_copy_constructible_v<typename detail::intrinsic_type<T>::value_type>)
94
+ {
95
+ if (this->arg()->hasDefaultValue())
96
+ {
97
+ return this->arg()->template defaultValue<T>();
98
+ }
99
+ }
100
+ }
101
+ else if constexpr (std::is_copy_constructible_v<T>)
82
102
  {
83
- if (this->arg->hasDefaultValue())
103
+ if (this->arg()->hasDefaultValue())
104
+ {
105
+ return this->arg()->template defaultValue<T>();
106
+ }
107
+ }
108
+
109
+ // This can be unreachable code
110
+ throw std::invalid_argument("Could not convert Ruby value");
111
+ }
112
+
113
+ #ifdef _MSC_VER
114
+ #pragma warning(pop)
115
+ #endif
116
+
117
+ template<typename T>
118
+ inline VALUE Parameter<T>::convertToRuby(T& object)
119
+ {
120
+ return this->toRuby_.convert(object);
121
+ }
122
+
123
+ template<typename T>
124
+ inline VALUE Parameter<T>::defaultValueRuby()
125
+ {
126
+ if constexpr (std::is_constructible_v<std::remove_cv_t<T>, std::remove_cv_t<std::remove_reference_t<T>>&>)
127
+ {
128
+ // Remember std::is_copy_constructible_v<std::vector<std::unique_ptr<T>>>> returns true. Sigh.
129
+ // So special case vector handling
130
+ if constexpr (detail::is_std_vector_v<detail::intrinsic_type<T>>)
131
+ {
132
+ if constexpr (std::is_copy_constructible_v<typename detail::intrinsic_type<T>::value_type>)
133
+ {
134
+ if (this->arg()->hasDefaultValue())
135
+ {
136
+ T defaultValue = this->arg()->template defaultValue<T>();
137
+ return this->toRuby_.convert(defaultValue);
138
+ }
139
+ }
140
+ }
141
+ else if (this->arg()->hasDefaultValue())
84
142
  {
85
- return this->arg->template defaultValue<T>();
143
+ T defaultValue = this->arg()->template defaultValue<T>();
144
+ return this->toRuby_.convert((remove_cv_recursive_t<T>)defaultValue);
86
145
  }
87
146
  }
88
147
 
89
- throw std::invalid_argument("Could not convert Rubyy value");
148
+ throw std::runtime_error("No default value set for parameter " + this->arg()->name);
90
149
  }
91
150
 
92
151
  template<typename T>
93
152
  inline std::string Parameter<T>::cppTypeName()
94
153
  {
95
- detail::TypeMapper<T> typeMapper;
96
- return typeMapper.simplifiedName();
154
+ detail::TypeIndexParser typeIndexParser(typeid(T), std::is_fundamental_v<detail::intrinsic_type<T>>);
155
+ return typeIndexParser.simplifiedName();
97
156
  }
98
157
 
99
158
  template<typename T>
data/rice/detail/Proc.ipp CHANGED
@@ -1,7 +1,7 @@
1
1
  namespace Rice::detail
2
2
  {
3
- template<typename Return_T, typename ...Arg_Ts>
4
- struct Type<Return_T(*)(Arg_Ts...)>
3
+ template<typename Return_T, typename ...Parameter_Ts>
4
+ struct Type<Return_T(*)(Parameter_Ts...)>
5
5
  {
6
6
  static bool verify()
7
7
  {
@@ -15,15 +15,15 @@ namespace Rice::detail
15
15
  };
16
16
 
17
17
  // Wraps a C++ function as a Ruby proc
18
- template<typename Return_T, typename ...Arg_Ts>
19
- class To_Ruby<Return_T(*)(Arg_Ts...)>
18
+ template<typename Return_T, typename ...Parameter_Ts>
19
+ class To_Ruby<Return_T(*)(Parameter_Ts...)>
20
20
  {
21
21
  public:
22
- using Proc_T = Return_T(*)(Arg_Ts...);
22
+ using Proc_T = Return_T(*)(Parameter_Ts...);
23
23
 
24
24
  To_Ruby() = default;
25
25
 
26
- explicit To_Ruby(Arg* arg)
26
+ explicit To_Ruby(Arg*)
27
27
  {
28
28
  }
29
29
 
@@ -35,11 +35,11 @@ namespace Rice::detail
35
35
  };
36
36
 
37
37
  // Makes a Ruby proc callable as C callback
38
- template<typename Return_T, typename ...Arg_Ts>
39
- class From_Ruby<Return_T(*)(Arg_Ts...)>
38
+ template<typename Return_T, typename ...Parameter_Ts>
39
+ class From_Ruby<Return_T(*)(Parameter_Ts...)>
40
40
  {
41
41
  public:
42
- using Callback_T = Return_T(*)(Arg_Ts...);
42
+ using Callback_T = Return_T(*)(Parameter_Ts...);
43
43
 
44
44
  From_Ruby() = default;
45
45
 
@@ -47,9 +47,9 @@ namespace Rice::detail
47
47
  {
48
48
  }
49
49
 
50
- Convertible is_convertible(VALUE value)
50
+ double is_convertible(VALUE value)
51
51
  {
52
- if (protect(rb_obj_is_proc, value) == Qtrue || protect(rb_proc_lambda_p, value))
52
+ if (protect(rb_obj_is_proc, value) == Qtrue || protect(rb_proc_lambda_p, value) == Qtrue)
53
53
  {
54
54
  return Convertible::Exact;
55
55
  }
@@ -59,26 +59,12 @@ namespace Rice::detail
59
59
  }
60
60
  }
61
61
 
62
- #ifdef HAVE_LIBFFI
63
62
  Callback_T convert(VALUE value)
64
63
  {
65
- using NativeCallback_T = NativeCallbackFFI<Return_T(*)(Arg_Ts...)>;
66
- NativeCallback_T* nativeCallback = new NativeCallback_T(value);
67
-
68
- // Tie the lifetime of the NativeCallback C++ instance to the lifetime of the Ruby proc object
69
- VALUE finalizer = rb_proc_new(NativeCallback_T::finalizerCallback, (VALUE)nativeCallback);
70
- rb_define_finalizer(value, finalizer);
71
-
72
- return nativeCallback->callback();
73
- }
74
- #else
75
- Callback_T convert(VALUE value)
76
- {
77
- using NativeCallback_T = NativeCallbackSimple<Return_T(*)(Arg_Ts...)>;
78
- NativeCallback_T::proc = value;
79
- return &NativeCallback_T::callback;
64
+ using NativeCallback_T = NativeCallback<Callback_T>;
65
+ NativeCallback_T* callback = new NativeCallback_T(value);
66
+ return callback->callback();
80
67
  }
81
- #endif
82
68
 
83
69
  private:
84
70
  Arg* arg_ = nullptr;
@@ -7,9 +7,6 @@ namespace Rice::detail
7
7
  using FromRuby_T = bool(*)(VALUE);
8
8
 
9
9
  static inline FromRuby_T fromRuby = RB_TEST;
10
- static inline std::set<ruby_value_type> Exact = { RUBY_T_TRUE, RUBY_T_FALSE };
11
- static inline std::set<ruby_value_type> Castable = { RUBY_T_NIL };
12
- static inline std::set<ruby_value_type> Narrowable = { };
13
10
  static inline std::string packTemplate = "not supported";
14
11
  static inline std::string name = "bool";
15
12
  };
@@ -21,9 +18,6 @@ namespace Rice::detail
21
18
  using FromRuby_T = char(*)(VALUE);
22
19
 
23
20
  static inline FromRuby_T fromRuby = rb_num2char_inline;
24
- static inline std::set<ruby_value_type> Exact = { };
25
- static inline std::set<ruby_value_type> Castable = { RUBY_T_STRING };
26
- static inline std::set<ruby_value_type> Narrowable = { RUBY_T_FIXNUM };
27
21
  static inline std::string packTemplate = CHAR_MIN < 0 ? "c*" : "C*";
28
22
  static inline std::string name = "String";
29
23
  };
@@ -32,13 +26,9 @@ namespace Rice::detail
32
26
  class RubyType<signed char>
33
27
  {
34
28
  public:
35
- // Hack - need to later typecast
36
- using FromRuby_T = char(*)(VALUE);
29
+ using FromRuby_T = char(*)(VALUE);
37
30
 
38
31
  static inline FromRuby_T fromRuby = rb_num2char_inline;
39
- static inline std::set<ruby_value_type> Exact = { };
40
- static inline std::set<ruby_value_type> Castable = { RUBY_T_STRING };
41
- static inline std::set<ruby_value_type> Narrowable = { RUBY_T_FIXNUM };
42
32
  static inline std::string packTemplate = "c*";
43
33
  static inline std::string name = "String";
44
34
  };
@@ -47,13 +37,9 @@ namespace Rice::detail
47
37
  class RubyType<unsigned char>
48
38
  {
49
39
  public:
50
- // Hack - need to later typecast, although char's in ruby are unsigned
51
40
  using FromRuby_T = char(*)(VALUE);
52
41
 
53
42
  static inline FromRuby_T fromRuby = rb_num2char_inline;
54
- static inline std::set<ruby_value_type> Exact = { };
55
- static inline std::set<ruby_value_type> Castable = { RUBY_T_STRING };
56
- static inline std::set<ruby_value_type> Narrowable = { RUBY_T_FIXNUM };
57
43
  static inline std::string packTemplate = "C*";
58
44
  static inline std::string name = "String";
59
45
  };
@@ -65,9 +51,6 @@ namespace Rice::detail
65
51
  using FromRuby_T = short(*)(VALUE);
66
52
 
67
53
  static inline FromRuby_T fromRuby = rb_num2short_inline;
68
- static inline std::set<ruby_value_type> Exact = { };
69
- static inline std::set<ruby_value_type> Castable = { };
70
- static inline std::set<ruby_value_type> Narrowable = { RUBY_T_FIXNUM };
71
54
  static inline std::string packTemplate = "s*";
72
55
  static inline std::string name = "Integer";
73
56
  };
@@ -79,9 +62,6 @@ namespace Rice::detail
79
62
  using FromRuby_T = unsigned short(*)(VALUE);
80
63
 
81
64
  static inline FromRuby_T fromRuby = rb_num2ushort;
82
- static inline std::set<ruby_value_type> Exact = { };
83
- static inline std::set<ruby_value_type> Castable = { };
84
- static inline std::set<ruby_value_type> Narrowable = { RUBY_T_FIXNUM };
85
65
  static inline std::string packTemplate = "S*";
86
66
  static inline std::string name = "Integer";
87
67
  };
@@ -93,11 +73,6 @@ namespace Rice::detail
93
73
  using FromRuby_T = int(*)(VALUE);
94
74
 
95
75
  static inline FromRuby_T fromRuby = rb_num2int_inline;
96
- static inline std::set<ruby_value_type> Exact = { RUBY_T_FIXNUM };
97
- static inline std::set<ruby_value_type> Castable = { };
98
- // We allow bignum to integer because Ruby switches to bignum at about 2 billion on 64 bit systems,
99
- // while int can go up to 4 billion
100
- static inline std::set<ruby_value_type> Narrowable = { RUBY_T_BIGNUM };
101
76
  static inline std::string packTemplate = "i*";
102
77
  static inline std::string name = "Integer";
103
78
  };
@@ -109,11 +84,6 @@ namespace Rice::detail
109
84
  using FromRuby_T = unsigned int(*)(VALUE);
110
85
 
111
86
  static inline FromRuby_T fromRuby = RB_NUM2UINT;
112
- static inline std::set<ruby_value_type> Exact = { RUBY_T_FIXNUM };
113
- static inline std::set<ruby_value_type> Castable = { };
114
- // We allow bignum to integer because Ruby switches to bignum at about 2 billion on 64 bit systems,
115
- // while int can go up to 4 billion
116
- static inline std::set<ruby_value_type> Narrowable = { RUBY_T_BIGNUM };
117
87
  static inline std::string packTemplate = "I*";
118
88
  static inline std::string name = "Integer";
119
89
  };
@@ -125,9 +95,6 @@ namespace Rice::detail
125
95
  using FromRuby_T = long(*)(VALUE);
126
96
 
127
97
  static inline FromRuby_T fromRuby = rb_num2long_inline;
128
- static inline std::set<ruby_value_type> Exact = { RUBY_T_FIXNUM };
129
- static inline std::set<ruby_value_type> Castable = { };
130
- static inline std::set<ruby_value_type> Narrowable = { RUBY_T_BIGNUM };
131
98
  static inline std::string packTemplate = "l_*";
132
99
  static inline std::string name = "Integer";
133
100
  };
@@ -139,9 +106,6 @@ namespace Rice::detail
139
106
  using FromRuby_T = unsigned long(*)(VALUE);
140
107
 
141
108
  static inline FromRuby_T fromRuby = rb_num2ulong_inline;
142
- static inline std::set<ruby_value_type> Exact = { RUBY_T_FIXNUM };
143
- static inline std::set<ruby_value_type> Castable = { };
144
- static inline std::set<ruby_value_type> Narrowable = { RUBY_T_BIGNUM};
145
109
  static inline std::string packTemplate = "L_*";
146
110
  static inline std::string name = "Integer";
147
111
  };
@@ -153,9 +117,6 @@ namespace Rice::detail
153
117
  using FromRuby_T = long long(*)(VALUE);
154
118
 
155
119
  static inline FromRuby_T fromRuby = rb_num2ll_inline;
156
- static inline std::set<ruby_value_type> Exact = { RUBY_T_FIXNUM, RUBY_T_BIGNUM };
157
- static inline std::set<ruby_value_type> Castable = { };
158
- static inline std::set<ruby_value_type> Narrowable = { };
159
120
  static inline std::string packTemplate = "q_*";
160
121
  static inline std::string name = "Integer";
161
122
  };
@@ -167,9 +128,6 @@ namespace Rice::detail
167
128
  using FromRuby_T = unsigned long long(*)(VALUE);
168
129
 
169
130
  static inline FromRuby_T fromRuby = RB_NUM2ULL;
170
- static inline std::set<ruby_value_type> Exact = { RUBY_T_FIXNUM, RUBY_T_BIGNUM };
171
- static inline std::set<ruby_value_type> Castable = { };
172
- static inline std::set<ruby_value_type> Narrowable = { };
173
131
  static inline std::string packTemplate = "Q_*";
174
132
  static inline std::string name = "Integer";
175
133
  };
@@ -181,9 +139,6 @@ namespace Rice::detail
181
139
  using FromRuby_T = double(*)(VALUE);
182
140
 
183
141
  static inline FromRuby_T fromRuby = rb_num2dbl;
184
- static inline std::set<ruby_value_type> Exact = { };
185
- static inline std::set<ruby_value_type> Castable = { RUBY_T_FIXNUM };
186
- static inline std::set<ruby_value_type> Narrowable = { RUBY_T_FLOAT };
187
142
  static inline std::string packTemplate = "f*";
188
143
  static inline std::string name = "Float";
189
144
  };
@@ -195,9 +150,6 @@ namespace Rice::detail
195
150
  using FromRuby_T = double(*)(VALUE);
196
151
 
197
152
  static inline FromRuby_T fromRuby = rb_num2dbl;
198
- static inline std::set<ruby_value_type> Exact = { RUBY_T_FLOAT };
199
- static inline std::set<ruby_value_type> Castable = { RUBY_T_FIXNUM, RUBY_T_BIGNUM };
200
- static inline std::set<ruby_value_type> Narrowable = { };
201
153
  static inline std::string packTemplate = "d*";
202
154
  static inline std::string name = "Float";
203
155
  };
@@ -206,9 +158,6 @@ namespace Rice::detail
206
158
  class RubyType<void>
207
159
  {
208
160
  public:
209
- static inline std::set<ruby_value_type> Exact = { };
210
- static inline std::set<ruby_value_type> Castable = { };
211
- static inline std::set<ruby_value_type> Narrowable = { };
212
161
  static inline std::string name = "void";
213
162
  };
214
- }
163
+ }
data/rice/detail/Type.hpp CHANGED
@@ -35,25 +35,41 @@ namespace Rice::detail
35
35
  static bool verify();
36
36
  };
37
37
 
38
- template<typename T>
39
- class TypeMapper
38
+ class TypeIndexParser
40
39
  {
41
40
  public:
41
+ TypeIndexParser(const std::type_index& typeIndex, bool isFundamental = false);
42
42
  std::string name();
43
- std::string name(const std::type_index& typeIndex);
44
43
  std::string simplifiedName();
45
- std::string rubyName();
46
- VALUE rubyKlass();
44
+ std::string rubyName(std::string rubyTypeName);
47
45
 
48
46
  // public only for testing
49
47
  std::string findGroup(std::string& string, size_t start = 0);
48
+
50
49
  private:
51
50
  std::string demangle(char const* mangled_name);
52
- std::string rubyTypeName();
53
51
  void removeGroup(std::string& string, std::regex regex);
54
52
  void replaceGroup(std::string& string, std::regex regex, std::string replacement);
55
- void replaceAll(std::string& string, std::regex regex, std::string replacement);
56
53
  void capitalizeHelper(std::string& content, std::regex& regex);
54
+ void replaceAll(std::string& string, std::regex regex, std::string replacement);
55
+
56
+ private:
57
+ const std::type_index typeIndex_;
58
+ bool isFundamental_ = false;
59
+ };
60
+
61
+ template<typename T>
62
+ class TypeMapper
63
+ {
64
+ public:
65
+ VALUE rubyKlass();
66
+ std::string rubyName();
67
+
68
+ private:
69
+ std::string rubyTypeName();
70
+
71
+ private:
72
+ TypeIndexParser typeIndexParser_{ typeid(T), std::is_fundamental_v<intrinsic_type<T>> };
57
73
  };
58
74
 
59
75
  template<typename T>