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
data/rice/detail/ruby.hpp CHANGED
@@ -8,10 +8,33 @@
8
8
 
9
9
  #include <cmath>
10
10
 
11
+ // Clang has to be first because on Windows it defines _MSC_VER too
12
+ #if defined(__clang__)
13
+ #pragma clang diagnostic push
14
+ #pragma clang diagnostic ignored "-Wunknown-pragmas"
15
+ #pragma clang diagnostic ignored "-Wunused-parameter"
16
+ #elif defined(_MSC_VER)
17
+ #pragma warning(push)
18
+ #pragma warning(disable: 4100) // unreferenced formal parameter
19
+ #pragma warning(disable: 4702) // unreachable code
20
+ #elif defined(__GNUC__ )
21
+ #pragma GCC diagnostic push
22
+ #pragma GCC diagnostic ignored "-Wunknown-pragmas"
23
+ #endif
24
+
11
25
  #include <ruby.h>
12
26
  #include <ruby/encoding.h>
13
27
  #include <ruby/thread.h>
14
28
 
29
+ // Clang has to be first because on Windows it defines _MSC_VER too
30
+ #if defined(__clang__)
31
+ #pragma clang diagnostic pop
32
+ #elif defined(_MSC_VER)
33
+ #pragma warning(pop)
34
+ #elif defined(__GNUC__ )
35
+ #pragma GCC diagnostic pop
36
+ #endif
37
+
15
38
  // ruby.h has a few defines that conflict with Visual Studio's STL
16
39
  #if defined(_MSC_VER)
17
40
  #undef write
data/rice/libc/file.hpp CHANGED
@@ -1,11 +1,11 @@
1
- #ifndef Rice__libc__file__hpp_
2
- #define Rice__libc__file__hpp_
1
+ #ifndef Rice__Libc__file__hpp_
2
+ #define Rice__Libc__file__hpp_
3
3
 
4
- namespace Rice::libc
4
+ namespace Rice::Libc
5
5
  {
6
6
  extern Class rb_cLibcFile;
7
7
  }
8
8
 
9
9
  #include "file.ipp"
10
10
 
11
- #endif // Rice__libc__file__hpp_
11
+ #endif // Rice__Libc__file__hpp_
data/rice/rice.hpp CHANGED
@@ -7,6 +7,7 @@
7
7
  // C++ headers have to come after Ruby on MacOS for reasons I do not understand
8
8
  #include <cstdio>
9
9
  #include <cstring> // For std::memset
10
+ #include <map>
10
11
  #include <string>
11
12
  #include <typeinfo>
12
13
  #include <typeindex>
@@ -37,8 +38,6 @@
37
38
  // Code for Ruby to call C++
38
39
  #include "Arg.hpp"
39
40
  #include "Return.hpp"
40
- #include "Function.hpp"
41
- #include "detail/MethodInfo.hpp"
42
41
  #include "detail/from_ruby.hpp"
43
42
  #include "detail/RubyType.hpp"
44
43
  #include "detail/Parameter.hpp"
@@ -76,16 +75,18 @@
76
75
  // To / From Ruby
77
76
  #include "Arg.ipp"
78
77
  #include "detail/Parameter.ipp"
78
+ #include "NoGVL.hpp"
79
79
  #include "Return.ipp"
80
- #include "Function.ipp"
81
80
  #include "Constructor.hpp"
82
81
  #include "Buffer.hpp"
83
82
  #include "Pointer.hpp"
83
+ #include "Reference.hpp"
84
84
  #include "Buffer.ipp"
85
85
  #include "Pointer.ipp"
86
86
  #include "detail/Types.ipp"
87
87
  #include "detail/to_ruby.ipp"
88
88
  #include "detail/from_ruby.ipp"
89
+ #include "Reference.ipp"
89
90
  #include "detail/Proc.hpp"
90
91
 
91
92
  // Registries
@@ -103,7 +104,6 @@
103
104
  #include "Exception.ipp"
104
105
  #include "detail/cpp_protect.hpp"
105
106
  #include "detail/Wrapper.ipp"
106
- #include "detail/MethodInfo.ipp"
107
107
  #include "detail/Native.ipp"
108
108
  #include "detail/NativeAttributeGet.ipp"
109
109
  #include "detail/NativeAttributeSet.ipp"
@@ -115,10 +115,8 @@
115
115
  #include "detail/NativeMethod.ipp"
116
116
  #include "detail/NativeProc.hpp"
117
117
  #include "detail/NativeProc.ipp"
118
- #include "detail/NativeCallbackFFI.hpp"
119
- #include "detail/NativeCallbackFFI.ipp"
120
- #include "detail/NativeCallbackSimple.hpp"
121
- #include "detail/NativeCallbackSimple.ipp"
118
+ #include "detail/NativeCallback.hpp"
119
+ #include "detail/NativeCallback.ipp"
122
120
  #include "detail/Proc.ipp"
123
121
 
124
122
  // C++ API definitions
@@ -12,7 +12,8 @@ inline void Init_Native()
12
12
  .define_value("Method", detail::NativeKind::Method)
13
13
  .define_value("AttributeReader", detail::NativeKind::AttributeReader)
14
14
  .define_value("AttributeWriter", detail::NativeKind::AttributeWriter)
15
- .define_value("Proc", detail::NativeKind::Proc);
15
+ .define_value("Proc", detail::NativeKind::Proc)
16
+ .define_value("Callback", detail::NativeKind::Callback);
16
17
 
17
18
  define_class_under<detail::Native>(rb_mRice, "Native").
18
19
  define_method("name", &detail::Native::name).
@@ -44,6 +45,9 @@ inline void Init_Native()
44
45
  case detail::NativeKind::Proc:
45
46
  stream << "Proc";
46
47
  break;
48
+ case detail::NativeKind::Callback:
49
+ stream << "Callback";
50
+ break;
47
51
  }
48
52
 
49
53
  stream << "<" << self.name() << "> ";
@@ -5,7 +5,7 @@ inline void Init_Parameter()
5
5
  Module rb_mRice = define_module("Rice");
6
6
 
7
7
  define_class_under<detail::ParameterAbstract>(rb_mRice, "Parameter").
8
- define_attr("arg", &detail::ParameterAbstract::arg).
8
+ define_method("arg", &detail::ParameterAbstract::arg).
9
9
  define_method("klass", &detail::ParameterAbstract::klass, Return().setValue()).
10
10
  define_method("cpp_klass", &detail::ParameterAbstract::cppTypeName);
11
11
  }
data/rice/ruby_mark.hpp CHANGED
@@ -8,8 +8,9 @@
8
8
  namespace Rice
9
9
  {
10
10
  template<typename T>
11
- void ruby_mark(T* data)
11
+ void ruby_mark(T*)
12
12
  {
13
+ // Do nothing by default
13
14
  }
14
15
  }
15
16
  #endif // Rice__ruby_mark__hpp_
data/rice/stl/complex.ipp CHANGED
@@ -22,7 +22,7 @@ namespace Rice::detail
22
22
  public:
23
23
  To_Ruby() = default;
24
24
 
25
- explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
25
+ explicit To_Ruby(Arg* arg) : arg_(arg)
26
26
  {
27
27
  }
28
28
 
@@ -35,7 +35,7 @@ namespace Rice::detail
35
35
  }
36
36
 
37
37
  private:
38
- Return* returnInfo_ = nullptr;
38
+ Arg* arg_ = nullptr;
39
39
  };
40
40
 
41
41
  template<typename T>
@@ -44,7 +44,7 @@ namespace Rice::detail
44
44
  public:
45
45
  To_Ruby() = default;
46
46
 
47
- explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
47
+ explicit To_Ruby(Arg* arg) : arg_(arg)
48
48
  {
49
49
  }
50
50
 
@@ -57,7 +57,7 @@ namespace Rice::detail
57
57
  }
58
58
 
59
59
  private:
60
- Return* returnInfo_ = nullptr;
60
+ Arg* arg_ = nullptr;
61
61
  };
62
62
 
63
63
  template<typename T>
@@ -66,11 +66,11 @@ namespace Rice::detail
66
66
  public:
67
67
  From_Ruby() = default;
68
68
 
69
- explicit From_Ruby(Arg* arg)
69
+ explicit From_Ruby(Arg* arg) :arg_(arg)
70
70
  {
71
71
  }
72
72
 
73
- Convertible is_convertible(VALUE value)
73
+ double is_convertible(VALUE value)
74
74
  {
75
75
  switch (rb_type(value))
76
76
  {
@@ -89,6 +89,9 @@ namespace Rice::detail
89
89
 
90
90
  return std::complex<T>(From_Ruby<T>().convert(real), From_Ruby<T>().convert(imaginary));
91
91
  }
92
+
93
+ private:
94
+ Arg* arg_ = nullptr;
92
95
  };
93
96
 
94
97
  template<typename T>
@@ -97,11 +100,11 @@ namespace Rice::detail
97
100
  public:
98
101
  From_Ruby() = default;
99
102
 
100
- explicit From_Ruby(Arg* arg)
103
+ explicit From_Ruby(Arg* arg) : arg_(arg)
101
104
  {
102
105
  }
103
106
 
104
- Convertible is_convertible(VALUE value)
107
+ double is_convertible(VALUE value)
105
108
  {
106
109
  switch (rb_type(value))
107
110
  {
@@ -123,6 +126,7 @@ namespace Rice::detail
123
126
  }
124
127
 
125
128
  private:
129
+ Arg* arg_ = nullptr;
126
130
  std::complex<T> converted_;
127
131
  };
128
132
  }
data/rice/stl/map.ipp CHANGED
@@ -107,20 +107,25 @@ namespace Rice
107
107
  {
108
108
  if constexpr (detail::is_comparable_v<Mapped_T>)
109
109
  {
110
- klass_.define_method("value?", [](T& map, Mapped_T& value) -> bool
111
- {
112
- auto it = std::find_if(map.begin(), map.end(),
113
- [&value](auto& pair)
114
- {
115
- return pair.second == value;
116
- });
110
+ klass_.define_method("==", [](T& map, T& other)->bool
111
+ {
112
+ return map == other;
113
+ })
114
+ .define_method("value?", [](T& map, Mapped_T& value) -> bool
115
+ {
116
+ auto it = std::find_if(map.begin(), map.end(),
117
+ [&value](auto& pair)
118
+ {
119
+ return pair.second == value;
120
+ });
117
121
 
118
- return it != map.end();
122
+ return it != map.end();
119
123
  });
124
+ rb_define_alias(klass_, "eql?", "==");
120
125
  }
121
126
  else
122
127
  {
123
- klass_.define_method("value?", [](T& map, Mapped_T& value) -> bool
128
+ klass_.define_method("value?", [](T&, Mapped_T&) -> bool
124
129
  {
125
130
  return false;
126
131
  });
@@ -205,10 +210,10 @@ namespace Rice
205
210
  }
206
211
  else
207
212
  {
208
- klass_.define_method("to_s", [](const T& map)
209
- {
210
- return "[Not printable]";
211
- });
213
+ klass_.define_method("to_s", [](const T&)
214
+ {
215
+ return "[Not printable]";
216
+ });
212
217
  }
213
218
  }
214
219
 
@@ -299,7 +304,7 @@ namespace Rice
299
304
  {
300
305
  }
301
306
 
302
- Convertible is_convertible(VALUE value)
307
+ double is_convertible(VALUE value)
303
308
  {
304
309
  switch (rb_type(value))
305
310
  {
@@ -307,7 +312,7 @@ namespace Rice
307
312
  return Data_Type<std::map<T, U>>::is_descendant(value) ? Convertible::Exact : Convertible::None;
308
313
  break;
309
314
  case RUBY_T_HASH:
310
- return Convertible::Cast;
315
+ return Convertible::Exact;
311
316
  break;
312
317
  default:
313
318
  return Convertible::None;
@@ -333,7 +338,7 @@ namespace Rice
333
338
  }
334
339
  default:
335
340
  {
336
- throw Exception(rb_eTypeError, "wrong argument type %s (expected % s)",
341
+ throw Exception(rb_eTypeError, "wrong argument type %s (expected %s)",
337
342
  detail::protect(rb_obj_classname, value), "std::map");
338
343
  }
339
344
  }
@@ -353,7 +358,7 @@ namespace Rice
353
358
  {
354
359
  }
355
360
 
356
- Convertible is_convertible(VALUE value)
361
+ double is_convertible(VALUE value)
357
362
  {
358
363
  switch (rb_type(value))
359
364
  {
@@ -361,7 +366,7 @@ namespace Rice
361
366
  return Data_Type<std::map<T, U>>::is_descendant(value) ? Convertible::Exact : Convertible::None;
362
367
  break;
363
368
  case RUBY_T_HASH:
364
- return Convertible::Cast;
369
+ return Convertible::Exact;
365
370
  break;
366
371
  default:
367
372
  return Convertible::None;
@@ -388,7 +393,7 @@ namespace Rice
388
393
  }
389
394
  default:
390
395
  {
391
- throw Exception(rb_eTypeError, "wrong argument type %s (expected % s)",
396
+ throw Exception(rb_eTypeError, "wrong argument type %s (expected %s)",
392
397
  detail::protect(rb_obj_classname, value), "std::map");
393
398
  }
394
399
  }
@@ -409,7 +414,7 @@ namespace Rice
409
414
  {
410
415
  }
411
416
 
412
- Convertible is_convertible(VALUE value)
417
+ double is_convertible(VALUE value)
413
418
  {
414
419
  switch (rb_type(value))
415
420
  {
@@ -420,7 +425,7 @@ namespace Rice
420
425
  return Convertible::Exact;
421
426
  break;
422
427
  case RUBY_T_HASH:
423
- return Convertible::Cast;
428
+ return Convertible::Exact;
424
429
  break;
425
430
  default:
426
431
  return Convertible::None;
@@ -447,7 +452,7 @@ namespace Rice
447
452
  }
448
453
  default:
449
454
  {
450
- throw Exception(rb_eTypeError, "wrong argument type %s (expected % s)",
455
+ throw Exception(rb_eTypeError, "wrong argument type %s (expected %s)",
451
456
  detail::protect(rb_obj_classname, value), "std::map");
452
457
  }
453
458
  }
@@ -22,18 +22,18 @@ namespace Rice::detail
22
22
  public:
23
23
  To_Ruby() = default;
24
24
 
25
- explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
25
+ explicit To_Ruby(Arg* arg) : arg_(arg)
26
26
  {
27
27
  }
28
28
 
29
- VALUE convert(const std::monostate& _)
29
+ VALUE convert(const std::monostate&)
30
30
  {
31
31
  return Qnil;
32
32
  }
33
33
 
34
34
 
35
35
  private:
36
- Return* returnInfo_ = nullptr;
36
+ Arg* arg_ = nullptr;
37
37
  };
38
38
 
39
39
  template<>
@@ -42,17 +42,17 @@ namespace Rice::detail
42
42
  public:
43
43
  To_Ruby() = default;
44
44
 
45
- explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
45
+ explicit To_Ruby(Arg* arg) : arg_(arg)
46
46
  {
47
47
  }
48
48
 
49
- VALUE convert(const std::monostate& data)
49
+ VALUE convert(const std::monostate&)
50
50
  {
51
51
  return Qnil;
52
52
  }
53
53
 
54
54
  private:
55
- Return* returnInfo_ = nullptr;
55
+ Arg* arg_ = nullptr;
56
56
  };
57
57
 
58
58
  template<>
@@ -61,13 +61,13 @@ namespace Rice::detail
61
61
  public:
62
62
  From_Ruby() = default;
63
63
 
64
- explicit From_Ruby(Arg* arg)
64
+ explicit From_Ruby(Arg* arg) : arg_(arg)
65
65
  {
66
66
  }
67
67
 
68
- Convertible is_convertible(VALUE value)
68
+ double is_convertible(VALUE value)
69
69
  {
70
- return value == Qnil ? Convertible::Exact : Convertible::None;
70
+ return value == Qnil ? 1.0 : 0.0;
71
71
  }
72
72
 
73
73
  std::monostate convert(VALUE value)
@@ -81,6 +81,9 @@ namespace Rice::detail
81
81
  throw std::runtime_error("Can only convert nil values to std::monostate");
82
82
  }
83
83
  }
84
+
85
+ private:
86
+ Arg* arg_ = nullptr;
84
87
  };
85
88
 
86
89
  template<>
@@ -89,13 +92,13 @@ namespace Rice::detail
89
92
  public:
90
93
  From_Ruby() = default;
91
94
 
92
- explicit From_Ruby(Arg* arg)
95
+ explicit From_Ruby(Arg* arg) : arg_(arg)
93
96
  {
94
97
  }
95
98
 
96
- Convertible is_convertible(VALUE value)
99
+ double is_convertible(VALUE value)
97
100
  {
98
- return value == Qnil ? Convertible::Exact : Convertible::None;
101
+ return value == Qnil ? 1.0 : 0.0;
99
102
  }
100
103
 
101
104
  std::monostate& convert(VALUE value)
@@ -111,6 +114,7 @@ namespace Rice::detail
111
114
  }
112
115
 
113
116
  private:
117
+ Arg* arg_ = nullptr;
114
118
  std::monostate converted_ = std::monostate();
115
119
  };
116
120
  }
@@ -1,8 +1,6 @@
1
1
  #ifndef Rice__stl__multimap__hpp_
2
2
  #define Rice__stl__multimap__hpp_
3
3
 
4
- #include <map>
5
-
6
4
  namespace Rice
7
5
  {
8
6
  template<typename K, typename T>
@@ -106,20 +106,25 @@ namespace Rice
106
106
  {
107
107
  if constexpr (detail::is_comparable_v<Mapped_T>)
108
108
  {
109
- klass_.define_method("value?", [](T& multimap, Mapped_T& value) -> bool
110
- {
111
- auto it = std::find_if(multimap.begin(), multimap.end(),
112
- [&value](auto& pair)
113
- {
114
- return pair.second == value;
115
- });
109
+ klass_.define_method("==", [](T& multimap, T& other)->bool
110
+ {
111
+ return multimap == other;
112
+ })
113
+ .define_method("value?", [](T& multimap, Mapped_T& value) -> bool
114
+ {
115
+ auto it = std::find_if(multimap.begin(), multimap.end(),
116
+ [&value](auto& pair)
117
+ {
118
+ return pair.second == value;
119
+ });
116
120
 
117
- return it != multimap.end();
121
+ return it != multimap.end();
118
122
  });
123
+ rb_define_alias(klass_, "eql?", "==");
119
124
  }
120
125
  else
121
126
  {
122
- klass_.define_method("value?", [](T& multimap, Mapped_T& value) -> bool
127
+ klass_.define_method("value?", [](T&, Mapped_T&) -> bool
123
128
  {
124
129
  return false;
125
130
  });
@@ -188,10 +193,10 @@ namespace Rice
188
193
  }
189
194
  else
190
195
  {
191
- klass_.define_method("to_s", [](const T& multimap)
192
- {
193
- return "[Not printable]";
194
- });
196
+ klass_.define_method("to_s", [](const T&)
197
+ {
198
+ return "[Not printable]";
199
+ });
195
200
  }
196
201
  }
197
202
 
@@ -279,7 +284,7 @@ namespace Rice
279
284
  {
280
285
  }
281
286
 
282
- Convertible is_convertible(VALUE value)
287
+ double is_convertible(VALUE value)
283
288
  {
284
289
  switch (rb_type(value))
285
290
  {
@@ -287,7 +292,7 @@ namespace Rice
287
292
  return Data_Type<std::multimap<T, U>>::is_descendant(value) ? Convertible::Exact : Convertible::None;
288
293
  break;
289
294
  case RUBY_T_HASH:
290
- return Convertible::Cast;
295
+ return Convertible::Exact;
291
296
  break;
292
297
  default:
293
298
  return Convertible::None;
@@ -313,7 +318,7 @@ namespace Rice
313
318
  }
314
319
  default:
315
320
  {
316
- throw Exception(rb_eTypeError, "wrong argument type %s (expected % s)",
321
+ throw Exception(rb_eTypeError, "wrong argument type %s (expected %s)",
317
322
  detail::protect(rb_obj_classname, value), "std::multimap");
318
323
  }
319
324
  }
@@ -333,7 +338,7 @@ namespace Rice
333
338
  {
334
339
  }
335
340
 
336
- Convertible is_convertible(VALUE value)
341
+ double is_convertible(VALUE value)
337
342
  {
338
343
  switch (rb_type(value))
339
344
  {
@@ -341,7 +346,7 @@ namespace Rice
341
346
  return Data_Type<std::multimap<T, U>>::is_descendant(value) ? Convertible::Exact : Convertible::None;
342
347
  break;
343
348
  case RUBY_T_HASH:
344
- return Convertible::Cast;
349
+ return Convertible::Exact;
345
350
  break;
346
351
  default:
347
352
  return Convertible::None;
@@ -368,7 +373,7 @@ namespace Rice
368
373
  }
369
374
  default:
370
375
  {
371
- throw Exception(rb_eTypeError, "wrong argument type %s (expected % s)",
376
+ throw Exception(rb_eTypeError, "wrong argument type %s (expected %s)",
372
377
  detail::protect(rb_obj_classname, value), "std::multimap");
373
378
  }
374
379
  }
@@ -389,7 +394,7 @@ namespace Rice
389
394
  {
390
395
  }
391
396
 
392
- Convertible is_convertible(VALUE value)
397
+ double is_convertible(VALUE value)
393
398
  {
394
399
  switch (rb_type(value))
395
400
  {
@@ -400,7 +405,7 @@ namespace Rice
400
405
  return Convertible::Exact;
401
406
  break;
402
407
  case RUBY_T_HASH:
403
- return Convertible::Cast;
408
+ return Convertible::Exact;
404
409
  break;
405
410
  default:
406
411
  return Convertible::None;
@@ -427,7 +432,7 @@ namespace Rice
427
432
  }
428
433
  default:
429
434
  {
430
- throw Exception(rb_eTypeError, "wrong argument type %s (expected % s)",
435
+ throw Exception(rb_eTypeError, "wrong argument type %s (expected %s)",
431
436
  detail::protect(rb_obj_classname, value), "std::multimap");
432
437
  }
433
438
  }