rice 4.3.2 → 4.5.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 (151) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +66 -25
  3. data/README.md +7 -2
  4. data/Rakefile +7 -1
  5. data/include/rice/rice.hpp +7321 -4470
  6. data/include/rice/stl.hpp +769 -222
  7. data/lib/mkmf-rice.rb +37 -95
  8. data/rice/Address_Registration_Guard.hpp +72 -3
  9. data/rice/Arg.hpp +19 -5
  10. data/rice/Arg.ipp +24 -0
  11. data/rice/Callback.hpp +21 -0
  12. data/rice/Callback.ipp +13 -0
  13. data/rice/Constructor.hpp +4 -27
  14. data/rice/Constructor.ipp +79 -0
  15. data/rice/Data_Object.hpp +74 -3
  16. data/rice/Data_Object.ipp +324 -32
  17. data/rice/Data_Type.hpp +215 -3
  18. data/rice/Data_Type.ipp +125 -64
  19. data/rice/Director.hpp +0 -2
  20. data/rice/Enum.hpp +4 -6
  21. data/rice/Enum.ipp +101 -57
  22. data/rice/Exception.hpp +62 -2
  23. data/rice/Exception.ipp +7 -12
  24. data/rice/JumpException.hpp +44 -0
  25. data/rice/JumpException.ipp +48 -0
  26. data/rice/MemoryView.hpp +11 -0
  27. data/rice/MemoryView.ipp +43 -0
  28. data/rice/Return.hpp +6 -26
  29. data/rice/Return.ipp +10 -16
  30. data/rice/detail/DefaultHandler.hpp +12 -0
  31. data/rice/detail/DefaultHandler.ipp +8 -0
  32. data/rice/detail/HandlerRegistry.hpp +5 -35
  33. data/rice/detail/HandlerRegistry.ipp +7 -11
  34. data/rice/detail/InstanceRegistry.hpp +1 -4
  35. data/rice/detail/MethodInfo.hpp +15 -5
  36. data/rice/detail/MethodInfo.ipp +78 -6
  37. data/rice/detail/Native.hpp +32 -0
  38. data/rice/detail/Native.ipp +129 -0
  39. data/rice/detail/NativeAttributeGet.hpp +51 -0
  40. data/rice/detail/NativeAttributeGet.ipp +51 -0
  41. data/rice/detail/NativeAttributeSet.hpp +43 -0
  42. data/rice/detail/NativeAttributeSet.ipp +82 -0
  43. data/rice/detail/NativeCallbackFFI.hpp +55 -0
  44. data/rice/detail/NativeCallbackFFI.ipp +151 -0
  45. data/rice/detail/NativeCallbackSimple.hpp +30 -0
  46. data/rice/detail/NativeCallbackSimple.ipp +29 -0
  47. data/rice/detail/NativeFunction.hpp +20 -21
  48. data/rice/detail/NativeFunction.ipp +199 -64
  49. data/rice/detail/NativeIterator.hpp +8 -11
  50. data/rice/detail/NativeIterator.ipp +27 -31
  51. data/rice/detail/NativeRegistry.hpp +24 -17
  52. data/rice/detail/NativeRegistry.ipp +23 -56
  53. data/rice/detail/Proc.hpp +4 -0
  54. data/rice/detail/Proc.ipp +85 -0
  55. data/rice/detail/Registries.hpp +0 -7
  56. data/rice/detail/Registries.ipp +0 -18
  57. data/rice/detail/RubyFunction.hpp +0 -3
  58. data/rice/detail/RubyFunction.ipp +4 -8
  59. data/rice/detail/RubyType.hpp +19 -0
  60. data/rice/detail/RubyType.ipp +187 -0
  61. data/rice/detail/TupleIterator.hpp +14 -0
  62. data/rice/detail/Type.hpp +5 -6
  63. data/rice/detail/Type.ipp +150 -33
  64. data/rice/detail/TypeRegistry.hpp +15 -7
  65. data/rice/detail/TypeRegistry.ipp +105 -12
  66. data/rice/detail/Wrapper.hpp +6 -5
  67. data/rice/detail/Wrapper.ipp +45 -23
  68. data/rice/detail/cpp_protect.hpp +5 -6
  69. data/rice/detail/default_allocation_func.ipp +0 -2
  70. data/rice/detail/from_ruby.hpp +37 -3
  71. data/rice/detail/from_ruby.ipp +911 -454
  72. data/rice/detail/ruby.hpp +18 -0
  73. data/rice/detail/to_ruby.hpp +41 -3
  74. data/rice/detail/to_ruby.ipp +437 -113
  75. data/rice/global_function.hpp +0 -4
  76. data/rice/global_function.ipp +1 -2
  77. data/rice/rice.hpp +105 -22
  78. data/rice/ruby_mark.hpp +4 -3
  79. data/rice/stl.hpp +4 -0
  80. data/test/embed_ruby.cpp +4 -1
  81. data/test/extconf.rb +2 -0
  82. data/test/ruby/test_multiple_extensions_same_class.rb +14 -14
  83. data/test/test_Address_Registration_Guard.cpp +5 -0
  84. data/test/test_Array.cpp +12 -1
  85. data/test/test_Attribute.cpp +103 -21
  86. data/test/test_Builtin_Object.cpp +5 -0
  87. data/test/test_Callback.cpp +231 -0
  88. data/test/test_Class.cpp +5 -31
  89. data/test/test_Constructor.cpp +69 -6
  90. data/test/test_Data_Object.cpp +9 -4
  91. data/test/test_Data_Type.cpp +428 -64
  92. data/test/test_Director.cpp +10 -5
  93. data/test/test_Enum.cpp +152 -40
  94. data/test/test_Exception.cpp +235 -0
  95. data/test/test_File.cpp +70 -0
  96. data/test/test_From_Ruby.cpp +542 -0
  97. data/test/test_Hash.cpp +5 -0
  98. data/test/test_Identifier.cpp +5 -0
  99. data/test/test_Inheritance.cpp +6 -1
  100. data/test/test_Iterator.cpp +5 -0
  101. data/test/test_JumpException.cpp +22 -0
  102. data/test/test_Keep_Alive.cpp +6 -1
  103. data/test/test_Keep_Alive_No_Wrapper.cpp +5 -0
  104. data/test/test_Memory_Management.cpp +5 -0
  105. data/test/test_Module.cpp +118 -64
  106. data/test/test_Native_Registry.cpp +2 -33
  107. data/test/test_Object.cpp +5 -0
  108. data/test/test_Overloads.cpp +631 -0
  109. data/test/test_Ownership.cpp +67 -4
  110. data/test/test_Proc.cpp +45 -0
  111. data/test/test_Self.cpp +5 -0
  112. data/test/test_Stl_Exception.cpp +109 -0
  113. data/test/test_Stl_Map.cpp +22 -8
  114. data/test/test_Stl_Optional.cpp +5 -0
  115. data/test/test_Stl_Pair.cpp +7 -2
  116. data/test/test_Stl_Reference_Wrapper.cpp +5 -0
  117. data/test/test_Stl_SmartPointer.cpp +210 -5
  118. data/test/test_Stl_String.cpp +5 -0
  119. data/test/test_Stl_String_View.cpp +5 -0
  120. data/test/test_Stl_Type.cpp +147 -0
  121. data/test/test_Stl_Unordered_Map.cpp +18 -7
  122. data/test/test_Stl_Variant.cpp +5 -0
  123. data/test/test_Stl_Vector.cpp +130 -8
  124. data/test/test_String.cpp +5 -0
  125. data/test/test_Struct.cpp +5 -0
  126. data/test/test_Symbol.cpp +5 -0
  127. data/test/test_Template.cpp +192 -0
  128. data/test/test_To_Ruby.cpp +152 -0
  129. data/test/test_Tracking.cpp +1 -0
  130. data/test/test_Type.cpp +100 -0
  131. data/test/test_global_functions.cpp +53 -6
  132. data/test/unittest.cpp +8 -0
  133. metadata +37 -20
  134. data/lib/version.rb +0 -3
  135. data/rice/Address_Registration_Guard_defn.hpp +0 -79
  136. data/rice/Data_Object_defn.hpp +0 -84
  137. data/rice/Data_Type_defn.hpp +0 -190
  138. data/rice/Exception_defn.hpp +0 -68
  139. data/rice/HandlerRegistration.hpp +0 -15
  140. data/rice/Identifier.hpp +0 -50
  141. data/rice/Identifier.ipp +0 -29
  142. data/rice/detail/ExceptionHandler.hpp +0 -8
  143. data/rice/detail/ExceptionHandler.ipp +0 -28
  144. data/rice/detail/ExceptionHandler_defn.hpp +0 -77
  145. data/rice/detail/Jump_Tag.hpp +0 -21
  146. data/rice/detail/NativeAttribute.hpp +0 -64
  147. data/rice/detail/NativeAttribute.ipp +0 -112
  148. data/rice/detail/from_ruby_defn.hpp +0 -38
  149. data/rice/detail/to_ruby_defn.hpp +0 -48
  150. data/test/test_Jump_Tag.cpp +0 -17
  151. data/test/test_To_From_Ruby.cpp +0 -399
@@ -11,6 +11,11 @@ SETUP(GlobalFunction)
11
11
  embed_ruby();
12
12
  }
13
13
 
14
+ TEARDOWN(GlobalFunctions)
15
+ {
16
+ rb_gc_start();
17
+ }
18
+
14
19
  namespace {
15
20
 
16
21
  bool no_args()
@@ -18,9 +23,9 @@ namespace {
18
23
  return true;
19
24
  }
20
25
 
21
- int int_arg(int arg)
26
+ int int_arg(int value)
22
27
  {
23
- return 2 * arg;
28
+ return 2 * value;
24
29
  }
25
30
  }
26
31
 
@@ -52,6 +57,28 @@ TESTCASE(int_arg)
52
57
  ASSERT_EQUAL(20, detail::From_Ruby<int>().convert(result));
53
58
  }
54
59
 
60
+ TESTCASE(int_kw_arg)
61
+ {
62
+ define_global_function("method_with_kw_args_1", &int_arg, Arg("value"));
63
+ Module m = Module(rb_mKernel);
64
+ std::string code = R"(method_with_kw_args_1(value: 15))";
65
+ Object result = m.instance_eval(code);
66
+ ASSERT_EQUAL(30, detail::From_Ruby<int>().convert(result));
67
+ }
68
+
69
+ TESTCASE(int_kw_arg_invalid)
70
+ {
71
+ define_global_function("method_with_kw_args_2", &int_arg, Arg("value"));
72
+ Module m = Module(rb_mKernel);
73
+ std::string code = R"(method_with_kw_args_2(wrong: 15))";
74
+
75
+ ASSERT_EXCEPTION_CHECK(
76
+ Exception,
77
+ m.instance_eval(code),
78
+ ASSERT_EQUAL("Unknown keyword: wrong", ex.what())
79
+ );
80
+ }
81
+
55
82
  TESTCASE(int_arg_lambda)
56
83
  {
57
84
  define_global_function("method_with_args", [](int value)
@@ -85,7 +112,7 @@ namespace
85
112
 
86
113
  TESTCASE(default_arguments_for_define_global_function)
87
114
  {
88
- define_global_function("foo", &defaults_method_one, Arg("arg1"), Arg("arg2") = (int)3, Arg("arg3") = (bool)true);
115
+ define_global_function("foo", &defaults_method_one, Arg("arg1"), Arg("arg2") = (int)3, Arg("arg3") = true);
89
116
  Module m(rb_mKernel);
90
117
 
91
118
  m.call("foo", 2);
@@ -107,7 +134,26 @@ TESTCASE(default_arguments_for_define_global_function)
107
134
  ASSERT(!defaults_method_one_arg3);
108
135
  }
109
136
 
110
- TESTCASE(default_arguments_for_define_global_function_and_returning)
137
+ TESTCASE(default_arguments_kw)
138
+ {
139
+ define_global_function("defaults_method_one_kw", &defaults_method_one,
140
+ Arg("arg1"), Arg("arg2"), Arg("arg3") = true);
141
+ Module m = Module(rb_mKernel);
142
+
143
+ std::string code = R"(defaults_method_one_kw(4, arg2: 5))";
144
+ m.instance_eval(code);
145
+ ASSERT_EQUAL(4, defaults_method_one_arg1);
146
+ ASSERT_EQUAL(5, defaults_method_one_arg2);
147
+ ASSERT(defaults_method_one_arg3);
148
+
149
+ code = R"(defaults_method_one_kw(arg1: 9, arg2: 11, arg3: false))";
150
+ m.instance_eval(code);
151
+ ASSERT_EQUAL(9, defaults_method_one_arg1);
152
+ ASSERT_EQUAL(11, defaults_method_one_arg2);
153
+ ASSERT(!defaults_method_one_arg3);
154
+ }
155
+
156
+ TESTCASE(default_arguments_and_returning)
111
157
  {
112
158
  define_global_function("foo_ret", &defaults_returns, Arg("arg1"), Arg("arg2") = (int)3);
113
159
  Module m(rb_mKernel);
@@ -119,7 +165,8 @@ TESTCASE(default_arguments_for_define_global_function_and_returning)
119
165
  ASSERT_EQUAL(INT2NUM(50), o.value());
120
166
  }
121
167
 
122
- namespace {
168
+ namespace
169
+ {
123
170
  int the_one_default_arg = 0;
124
171
  void method_with_one_default_arg(int num = 4) {
125
172
  the_one_default_arg = num;
@@ -132,4 +179,4 @@ TESTCASE(single_default_argument)
132
179
  Module m(rb_mKernel);
133
180
  m.call("foo");
134
181
  ASSERT_EQUAL(4, the_one_default_arg);
135
- }
182
+ }
data/test/unittest.cpp CHANGED
@@ -3,6 +3,10 @@
3
3
  #include <map>
4
4
  #include "unittest.hpp"
5
5
 
6
+ #ifdef _WIN32
7
+ #include <windows.h>
8
+ #endif
9
+
6
10
  size_t assertions;
7
11
 
8
12
  namespace
@@ -98,6 +102,10 @@ char* findOption(char** begin, char** end, const std::string& option)
98
102
 
99
103
  int main(int argc, char** argv)
100
104
  {
105
+ #ifdef _WIN32
106
+ SetConsoleOutputCP(CP_UTF8);
107
+ #endif
108
+
101
109
  std::vector<Test_Suite> suites;
102
110
 
103
111
  char* moduleName = findOption(argv, argv + argc, "--suite");
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rice
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.3.2
4
+ version: 4.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Brannan
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2024-10-18 00:00:00.000000000 Z
13
+ date: 2025-02-10 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -76,52 +76,62 @@ files:
76
76
  - include/rice/rice.hpp
77
77
  - include/rice/stl.hpp
78
78
  - lib/mkmf-rice.rb
79
- - lib/version.rb
80
79
  - rice/Address_Registration_Guard.hpp
81
80
  - rice/Address_Registration_Guard.ipp
82
- - rice/Address_Registration_Guard_defn.hpp
83
81
  - rice/Arg.hpp
84
82
  - rice/Arg.ipp
83
+ - rice/Callback.hpp
84
+ - rice/Callback.ipp
85
85
  - rice/Constructor.hpp
86
+ - rice/Constructor.ipp
86
87
  - rice/Data_Object.hpp
87
88
  - rice/Data_Object.ipp
88
- - rice/Data_Object_defn.hpp
89
89
  - rice/Data_Type.hpp
90
90
  - rice/Data_Type.ipp
91
- - rice/Data_Type_defn.hpp
92
91
  - rice/Director.hpp
93
92
  - rice/Enum.hpp
94
93
  - rice/Enum.ipp
95
94
  - rice/Exception.hpp
96
95
  - rice/Exception.ipp
97
- - rice/Exception_defn.hpp
98
- - rice/HandlerRegistration.hpp
99
- - rice/Identifier.hpp
100
- - rice/Identifier.ipp
96
+ - rice/JumpException.hpp
97
+ - rice/JumpException.ipp
98
+ - rice/MemoryView.hpp
99
+ - rice/MemoryView.ipp
101
100
  - rice/Return.hpp
102
101
  - rice/Return.ipp
103
- - rice/detail/ExceptionHandler.hpp
104
- - rice/detail/ExceptionHandler.ipp
105
- - rice/detail/ExceptionHandler_defn.hpp
102
+ - rice/detail/DefaultHandler.hpp
103
+ - rice/detail/DefaultHandler.ipp
106
104
  - rice/detail/HandlerRegistry.hpp
107
105
  - rice/detail/HandlerRegistry.ipp
108
106
  - rice/detail/InstanceRegistry.hpp
109
107
  - rice/detail/InstanceRegistry.ipp
110
- - rice/detail/Jump_Tag.hpp
111
108
  - rice/detail/MethodInfo.hpp
112
109
  - rice/detail/MethodInfo.ipp
113
- - rice/detail/NativeAttribute.hpp
114
- - rice/detail/NativeAttribute.ipp
110
+ - rice/detail/Native.hpp
111
+ - rice/detail/Native.ipp
112
+ - rice/detail/NativeAttributeGet.hpp
113
+ - rice/detail/NativeAttributeGet.ipp
114
+ - rice/detail/NativeAttributeSet.hpp
115
+ - rice/detail/NativeAttributeSet.ipp
116
+ - rice/detail/NativeCallbackFFI.hpp
117
+ - rice/detail/NativeCallbackFFI.ipp
118
+ - rice/detail/NativeCallbackSimple.hpp
119
+ - rice/detail/NativeCallbackSimple.ipp
115
120
  - rice/detail/NativeFunction.hpp
116
121
  - rice/detail/NativeFunction.ipp
117
122
  - rice/detail/NativeIterator.hpp
118
123
  - rice/detail/NativeIterator.ipp
119
124
  - rice/detail/NativeRegistry.hpp
120
125
  - rice/detail/NativeRegistry.ipp
126
+ - rice/detail/Proc.hpp
127
+ - rice/detail/Proc.ipp
121
128
  - rice/detail/Registries.hpp
122
129
  - rice/detail/Registries.ipp
123
130
  - rice/detail/RubyFunction.hpp
124
131
  - rice/detail/RubyFunction.ipp
132
+ - rice/detail/RubyType.hpp
133
+ - rice/detail/RubyType.ipp
134
+ - rice/detail/TupleIterator.hpp
125
135
  - rice/detail/Type.hpp
126
136
  - rice/detail/Type.ipp
127
137
  - rice/detail/TypeRegistry.hpp
@@ -133,11 +143,9 @@ files:
133
143
  - rice/detail/default_allocation_func.ipp
134
144
  - rice/detail/from_ruby.hpp
135
145
  - rice/detail/from_ruby.ipp
136
- - rice/detail/from_ruby_defn.hpp
137
146
  - rice/detail/ruby.hpp
138
147
  - rice/detail/to_ruby.hpp
139
148
  - rice/detail/to_ruby.ipp
140
- - rice/detail/to_ruby_defn.hpp
141
149
  - rice/forward_declares.ipp
142
150
  - rice/global_function.hpp
143
151
  - rice/global_function.ipp
@@ -172,6 +180,7 @@ files:
172
180
  - test/test_Array.cpp
173
181
  - test/test_Attribute.cpp
174
182
  - test/test_Builtin_Object.cpp
183
+ - test/test_Callback.cpp
175
184
  - test/test_Class.cpp
176
185
  - test/test_Constructor.cpp
177
186
  - test/test_Data_Object.cpp
@@ -179,19 +188,24 @@ files:
179
188
  - test/test_Director.cpp
180
189
  - test/test_Enum.cpp
181
190
  - test/test_Exception.cpp
191
+ - test/test_File.cpp
192
+ - test/test_From_Ruby.cpp
182
193
  - test/test_Hash.cpp
183
194
  - test/test_Identifier.cpp
184
195
  - test/test_Inheritance.cpp
185
196
  - test/test_Iterator.cpp
186
- - test/test_Jump_Tag.cpp
197
+ - test/test_JumpException.cpp
187
198
  - test/test_Keep_Alive.cpp
188
199
  - test/test_Keep_Alive_No_Wrapper.cpp
189
200
  - test/test_Memory_Management.cpp
190
201
  - test/test_Module.cpp
191
202
  - test/test_Native_Registry.cpp
192
203
  - test/test_Object.cpp
204
+ - test/test_Overloads.cpp
193
205
  - test/test_Ownership.cpp
206
+ - test/test_Proc.cpp
194
207
  - test/test_Self.cpp
208
+ - test/test_Stl_Exception.cpp
195
209
  - test/test_Stl_Map.cpp
196
210
  - test/test_Stl_Optional.cpp
197
211
  - test/test_Stl_Pair.cpp
@@ -199,14 +213,17 @@ files:
199
213
  - test/test_Stl_SmartPointer.cpp
200
214
  - test/test_Stl_String.cpp
201
215
  - test/test_Stl_String_View.cpp
216
+ - test/test_Stl_Type.cpp
202
217
  - test/test_Stl_Unordered_Map.cpp
203
218
  - test/test_Stl_Variant.cpp
204
219
  - test/test_Stl_Vector.cpp
205
220
  - test/test_String.cpp
206
221
  - test/test_Struct.cpp
207
222
  - test/test_Symbol.cpp
208
- - test/test_To_From_Ruby.cpp
223
+ - test/test_Template.cpp
224
+ - test/test_To_Ruby.cpp
209
225
  - test/test_Tracking.cpp
226
+ - test/test_Type.cpp
210
227
  - test/test_global_functions.cpp
211
228
  - test/unittest.cpp
212
229
  - test/unittest.hpp
data/lib/version.rb DELETED
@@ -1,3 +0,0 @@
1
- module Rice
2
- VERSION = "4.3.2"
3
- end
@@ -1,79 +0,0 @@
1
- #ifndef Rice__Address_Registration_Guard_defn__hpp_
2
- #define Rice__Address_Registration_Guard_defn__hpp_
3
-
4
- #include "cpp_api/Object_defn.hpp"
5
- #include "detail/ruby.hpp"
6
-
7
- namespace Rice
8
- {
9
- //! A guard to register a given address with the GC.
10
- /*! Calls rb_gc_register_address upon construction and
11
- * rb_gc_unregister_address upon destruction.
12
- * For example:
13
- * \code
14
- * Class Foo
15
- * {
16
- * public:
17
- * Foo()
18
- * : string_(rb_str_new2())
19
- * , guard_(&string_);
20
- *
21
- * private:
22
- * VALUE string_;
23
- * Address_Registration_Guard guard_;
24
- * };
25
- * \endcode
26
- */
27
- class Address_Registration_Guard
28
- {
29
- public:
30
- //! Register an address with the GC.
31
- /* \param address The address to register with the GC. The address
32
- * must point to a valid ruby object (RObject).
33
- */
34
- Address_Registration_Guard(VALUE* address);
35
-
36
- //! Register an Object with the GC.
37
- /*! \param object The Object to register with the GC. The object must
38
- * not be destroyed before the Address_Registration_Guard is
39
- * destroyed.
40
- */
41
- Address_Registration_Guard(Object* object);
42
-
43
- //! Unregister an address/Object with the GC.
44
- /*! Destruct an Address_Registration_Guard. The address registered
45
- * with the Address_Registration_Guard when it was constructed will
46
- * be unregistered from the GC.
47
- */
48
- ~Address_Registration_Guard();
49
-
50
- // Disable copying
51
- Address_Registration_Guard(Address_Registration_Guard const& other) = delete;
52
- Address_Registration_Guard& operator=(Address_Registration_Guard const& other) = delete;
53
-
54
- // Enable moving
55
- Address_Registration_Guard(Address_Registration_Guard&& other);
56
- Address_Registration_Guard& operator=(Address_Registration_Guard&& other);
57
-
58
- //! Get the address that is registered with the GC.
59
- VALUE* address() const;
60
-
61
- /** Called during Ruby's exit process since we should not call
62
- * rb_gc unregister_address there
63
- */
64
- static void disable();
65
-
66
- private:
67
- inline static bool enabled = true;
68
- inline static bool exit_handler_registered = false;
69
- static void registerExitHandler();
70
-
71
- private:
72
- void registerAddress() const;
73
- void unregisterAddress();
74
-
75
- VALUE* address_ = nullptr;
76
- };
77
- } // namespace Rice
78
-
79
- #endif // Rice__Address_Registration_Guard_defn__hpp_
@@ -1,84 +0,0 @@
1
- #ifndef Rice__Data_Object_defn__hpp_
2
- #define Rice__Data_Object_defn__hpp_
3
-
4
- #include <optional>
5
-
6
- #include "detail/to_ruby.hpp"
7
- #include "detail/ruby.hpp"
8
- #include "cpp_api/Object_defn.hpp"
9
-
10
- /*! \file
11
- * \brief Provides a helper class for wrapping and unwrapping C++
12
- * objects as Ruby objects.
13
- */
14
-
15
- namespace Rice
16
- {
17
- //! A smartpointer-like wrapper for Ruby data objects.
18
- /*! A data object is a ruby object of type T_DATA, which is usually
19
- * created by using the Data_Wrap_Struct or Data_Make_Struct macro.
20
- * This class wraps creation of the data structure, providing a
21
- * type-safe object-oriented interface to the underlying C interface.
22
- * This class works in conjunction with the Data_Type class to ensure
23
- * type safety.
24
- *
25
- * Example:
26
- * \code
27
- * class Foo { };
28
- * ...
29
- * Data_Type<Foo> rb_cFoo = define_class("Foo");
30
- * ...
31
- * // Wrap:
32
- * Data_Object<Foo> foo1(new Foo);
33
- *
34
- * // Get value to return:
35
- * VALUE v = foo1.value()
36
- *
37
- * // Unwrap:
38
- * Data_Object<Foo> foo2(v, rb_cFoo);
39
- * \endcode
40
- */
41
- template<typename T>
42
- class Data_Object : public Object
43
- {
44
- static_assert(!std::is_pointer_v<T>);
45
- static_assert(!std::is_reference_v<T>);
46
- static_assert(!std::is_const_v<T>);
47
- static_assert(!std::is_volatile_v<T>);
48
-
49
- public:
50
- static T* from_ruby(VALUE value);
51
-
52
- public:
53
- //! Wrap a C++ object.
54
- /*! This constructor is analogous to calling Data_Wrap_Struct. Be
55
- * careful not to call this function more than once for the same
56
- * pointer (in general, it should only be called for newly
57
- * constructed objects that need to be managed by Ruby's garbage
58
- * collector).
59
- * \param obj the object to wrap.
60
- * \param isOwner Should the Data_Object take ownership of the object?
61
- * \param klass the Ruby class to use for the newly created Ruby
62
- * object.
63
- */
64
- Data_Object(T* obj, bool isOwner = false, Class klass = Data_Type<T>::klass());
65
- Data_Object(T& obj, bool isOwner = false, Class klass = Data_Type<T>::klass());
66
-
67
- //! Unwrap a Ruby object.
68
- /*! This constructor is analogous to calling Data_Get_Struct. Uses
69
- * Data_Type<T>::klass as the class of the object.
70
- * \param value the Ruby object to unwrap.
71
- */
72
- Data_Object(Object value);
73
-
74
- T& operator*() const; //!< Return a reference to obj_
75
- T* operator->() const; //!< Return a pointer to obj_
76
- T* get() const; //!< Return a pointer to obj_
77
-
78
- private:
79
- static void check_ruby_type(VALUE value);
80
- };
81
- } // namespace Rice
82
-
83
- #endif // Rice__Data_Object_defn__hpp_
84
-
@@ -1,190 +0,0 @@
1
- #ifndef Rice__Data_Type_defn__hpp_
2
- #define Rice__Data_Type_defn__hpp_
3
-
4
- #include "cpp_api/Class_defn.hpp"
5
- #include "detail/ruby.hpp"
6
- #include <set>
7
-
8
- namespace Rice
9
- {
10
- //! A mechanism for binding ruby types to C++ types.
11
- /*! This class binds run-time types (Ruby VALUEs) to compile-time types
12
- * (C++ types). The binding can occur only once.
13
- */
14
- template<typename T>
15
- class Data_Type : public Class
16
- {
17
- static_assert(std::is_same_v<detail::intrinsic_type<T>, T>);
18
-
19
- public:
20
- //! Default constructor which does not bind.
21
- /*! No member functions must be called on this Data_Type except bind,
22
- * until the type is bound.
23
- */
24
- Data_Type();
25
-
26
- //! Constructor which takes a Module.
27
- /*! Binds the type to the given VALUE according to the rules given
28
- * above.
29
- * \param klass the module to which to bind.
30
- */
31
- Data_Type(Module const & v);
32
-
33
- //! Destructor.
34
- virtual ~Data_Type();
35
-
36
- //! Return the Ruby class.
37
- /*! \return the ruby class to which the type is bound.
38
- */
39
- static Class klass();
40
-
41
- //! Return the Ruby data type.
42
- static rb_data_type_t* ruby_data_type();
43
-
44
- //! Assignment operator which takes a Module
45
- /*! \param klass must be the class to which this data type is already
46
- * bound.
47
- * \return *this
48
- */
49
- virtual Data_Type & operator=(Module const & klass);
50
-
51
- /*! Creates a singleton method allocate and an instance method called
52
- * initialize which together create a new instance of the class. The
53
- * allocate method allocates memory for the object reference and the
54
- * initialize method constructs the object.
55
- * \param constructor an object that has a static member function
56
- * construct() that constructs a new instance of T and sets the object's data
57
- * member to point to the new instance. A helper class Constructor
58
- * is provided that does precisely this.
59
- * \param args a list of Arg instance used to define default parameters (optional)
60
- *
61
- * For example:
62
- * \code
63
- * define_class<Foo>("Foo")
64
- * .define_constructor(Constructor<Foo>());
65
- * \endcode
66
- */
67
- template<typename Constructor_T, typename...Arg_Ts>
68
- Data_Type<T> & define_constructor(Constructor_T constructor, Arg_Ts const& ...args);
69
-
70
- //! Register a Director class for this class.
71
- /*! For any class that uses Rice::Director to enable polymorphism
72
- * across the languages, you need to register that director proxy
73
- * class with this method. Not doing so will cause the resulting
74
- * library to die at run time when it tries to convert the base
75
- * type into the Director proxy type.
76
- *
77
- * This method takes no methodInfo, just needs the type of the
78
- * Director proxy class.
79
- *
80
- * For example:
81
- * \code
82
- * class FooDirector : public Foo, public Rice::Director {
83
- * ...
84
- * };
85
- *
86
- * define_class<Foo>("Foo")
87
- * .define_director<FooDirector>()
88
- * .define_constructor(Constructor<FooDirector, Rice::Object>());
89
- * \endcode
90
- */
91
- template<typename Director_T>
92
- Data_Type<T>& define_director();
93
-
94
- //! Determine if the type is bound.
95
- /*! \return true if the object is bound, false otherwise.
96
- */
97
- static bool is_bound();
98
- static void check_is_bound();
99
-
100
- // This is only for testing - DO NOT USE!!!
101
- static void unbind();
102
-
103
- static bool is_descendant(VALUE value);
104
-
105
- //! Define an iterator.
106
- /*! Essentially this is a conversion from a C++-style begin/end
107
- * iterator to a Ruby-style \#each iterator.
108
- * \param begin a member function pointer to a function that returns
109
- * an iterator to the beginning of the sequence.
110
- * \param end a member function pointer to a function that returns an
111
- * iterator to the end of the sequence.
112
- * \param name the name of the iterator.
113
- * \return *this
114
- */
115
-
116
- template<typename Iterator_Func_T>
117
- Data_Type<T>& define_iterator(Iterator_Func_T begin, Iterator_Func_T end, std::string name = "each");
118
-
119
- template <typename Attribute_T>
120
- Data_Type<T>& define_attr(std::string name, Attribute_T attribute, AttrAccess access = AttrAccess::ReadWrite);
121
-
122
- template <typename Attribute_T>
123
- Data_Type<T>& define_singleton_attr(std::string name, Attribute_T attribute, AttrAccess access = AttrAccess::ReadWrite);
124
-
125
- #include "cpp_api/shared_methods.hpp"
126
-
127
- protected:
128
- //! Bind a Data_Type to a VALUE.
129
- /*! Throws an exception if the Data_Type is already bound to a
130
- * different class. Any existing instances of the Data_Type will be
131
- * bound after this function returns.
132
- * \param klass the ruby type to which to bind.
133
- * \return *this
134
- */
135
- template <typename Base_T = void>
136
- static Data_Type bind(const Module& klass);
137
-
138
- template<typename T_, typename Base_T_>
139
- friend Rice::Data_Type<T_> define_class_under(Object module, char const * name);
140
-
141
- template<typename T_, typename Base_T_>
142
- friend Rice::Data_Type<T_> define_class(char const * name);
143
-
144
- template<bool IsMethod, typename Function_T>
145
- void wrap_native_call(VALUE klass, std::string name, Function_T&& function, MethodInfo* methodInfo);
146
-
147
- private:
148
- template<typename T_>
149
- friend class Data_Type;
150
-
151
- static inline VALUE klass_ = Qnil;
152
-
153
- // Typed Data support
154
- static inline rb_data_type_t* rb_data_type_ = nullptr;
155
-
156
- typedef std::set<Data_Type<T> *> Instances;
157
-
158
- static Instances & unbound_instances()
159
- {
160
- static Instances unbound_instances;
161
- return unbound_instances;
162
- }
163
- };
164
-
165
- //! Define a new data class in the namespace given by module.
166
- /*! By default the class will inherit from Ruby's rb_cObject. This
167
- * can be overriden via the Base_T template parameter. Note that
168
- * Base_T must already have been registered.
169
- * \param T the C++ type of the wrapped class.
170
- * \param module the the Module in which to define the class.
171
- * \return the new class.
172
- */
173
- template<typename T, typename Base_T = void>
174
- Data_Type<T> define_class_under(Object module, char const* name);
175
-
176
- //! Define a new data class in the default namespace.
177
- /*! By default the class will inherit from Ruby's rb_cObject. This
178
- * can be overriden via the Base_T template parameter. Note that
179
- * Base_T must already have been registered.
180
- * \param T the C++ type of the wrapped class.
181
- * \param module the the Module in which to define the class.
182
- * \return the new class.
183
- */
184
- template<typename T, typename Base_T = void>
185
- Data_Type<T> define_class(char const* name);
186
- } // namespace Rice
187
-
188
- #include "Data_Type.ipp"
189
-
190
- #endif // Rice__Data_Type_defn__hpp_