rice 4.6.1 → 4.7.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 (185) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +31 -0
  3. data/CMakeLists.txt +0 -4
  4. data/Rakefile +2 -8
  5. data/bin/rice-doc.rb +212 -0
  6. data/bin/rice-rbs.rb +93 -0
  7. data/include/rice/rice.hpp +4972 -4015
  8. data/include/rice/stl.hpp +822 -294
  9. data/lib/rice/doc/cpp_reference.rb +166 -0
  10. data/lib/rice/doc/doxygen.rb +294 -0
  11. data/lib/rice/doc/mkdocs.rb +298 -0
  12. data/lib/rice/doc/rice.rb +29 -0
  13. data/lib/rice/doc/ruby.rb +37 -0
  14. data/lib/rice/doc.rb +5 -0
  15. data/lib/{make_rice_headers.rb → rice/make_rice_headers.rb} +3 -0
  16. data/lib/rice/native.rb +18 -0
  17. data/lib/rice/native_registry.rb +21 -0
  18. data/lib/rice/parameter.rb +7 -0
  19. data/lib/rice/rbs.rb +104 -0
  20. data/lib/rice/version.rb +1 -1
  21. data/lib/rice.rb +4 -0
  22. data/lib/rubygems/cmake_builder.rb +24 -27
  23. data/rice/Arg.hpp +4 -4
  24. data/rice/Arg.ipp +4 -4
  25. data/rice/Buffer.hpp +32 -28
  26. data/rice/Buffer.ipp +306 -178
  27. data/rice/Data_Object.ipp +101 -82
  28. data/rice/Data_Type.hpp +5 -7
  29. data/rice/Data_Type.ipp +48 -29
  30. data/rice/Enum.ipp +15 -21
  31. data/rice/Function.hpp +17 -0
  32. data/rice/Function.ipp +13 -0
  33. data/rice/Pointer.hpp +15 -0
  34. data/rice/Pointer.ipp +49 -0
  35. data/rice/Return.hpp +1 -1
  36. data/rice/Return.ipp +2 -2
  37. data/rice/api.hpp +30 -0
  38. data/rice/cpp_api/Array.hpp +2 -2
  39. data/rice/cpp_api/Array.ipp +50 -5
  40. data/rice/cpp_api/Class.hpp +0 -5
  41. data/rice/cpp_api/Class.ipp +19 -0
  42. data/rice/cpp_api/Hash.ipp +20 -0
  43. data/rice/cpp_api/Module.hpp +6 -3
  44. data/rice/cpp_api/Module.ipp +49 -11
  45. data/rice/cpp_api/Object.ipp +31 -2
  46. data/rice/cpp_api/String.hpp +1 -2
  47. data/rice/cpp_api/String.ipp +21 -1
  48. data/rice/cpp_api/Struct.ipp +5 -0
  49. data/rice/cpp_api/Symbol.ipp +34 -0
  50. data/rice/cpp_api/shared_methods.hpp +12 -12
  51. data/rice/detail/MethodInfo.hpp +4 -2
  52. data/rice/detail/MethodInfo.ipp +19 -3
  53. data/rice/detail/ModuleRegistry.hpp +18 -0
  54. data/rice/detail/ModuleRegistry.ipp +25 -0
  55. data/rice/detail/Native.hpp +45 -2
  56. data/rice/detail/Native.ipp +196 -2
  57. data/rice/detail/NativeAttributeGet.hpp +9 -4
  58. data/rice/detail/NativeAttributeGet.ipp +65 -11
  59. data/rice/detail/NativeAttributeSet.hpp +4 -0
  60. data/rice/detail/NativeAttributeSet.ipp +30 -2
  61. data/rice/detail/NativeCallbackFFI.ipp +2 -2
  62. data/rice/detail/NativeCallbackSimple.ipp +1 -1
  63. data/rice/detail/NativeFunction.hpp +11 -49
  64. data/rice/detail/NativeFunction.ipp +82 -379
  65. data/rice/detail/NativeInvoker.hpp +74 -0
  66. data/rice/detail/NativeInvoker.ipp +197 -0
  67. data/rice/detail/NativeIterator.hpp +4 -0
  68. data/rice/detail/NativeIterator.ipp +19 -0
  69. data/rice/detail/NativeMethod.hpp +97 -0
  70. data/rice/detail/NativeMethod.ipp +332 -0
  71. data/rice/detail/NativeProc.hpp +51 -0
  72. data/rice/detail/NativeProc.ipp +133 -0
  73. data/rice/detail/NativeRegistry.hpp +8 -0
  74. data/rice/detail/NativeRegistry.ipp +27 -0
  75. data/rice/detail/Parameter.hpp +47 -0
  76. data/rice/detail/Parameter.ipp +105 -0
  77. data/rice/detail/Proc.ipp +14 -13
  78. data/rice/detail/Registries.hpp +1 -0
  79. data/rice/detail/RubyType.hpp +0 -2
  80. data/rice/detail/RubyType.ipp +15 -33
  81. data/rice/detail/Type.hpp +44 -8
  82. data/rice/detail/Type.ipp +151 -49
  83. data/rice/detail/TypeRegistry.hpp +3 -0
  84. data/rice/detail/TypeRegistry.ipp +17 -27
  85. data/rice/detail/Types.ipp +430 -0
  86. data/rice/detail/Wrapper.hpp +12 -0
  87. data/rice/detail/Wrapper.ipp +45 -2
  88. data/rice/detail/from_ruby.ipp +567 -1073
  89. data/rice/detail/ruby.hpp +1 -0
  90. data/rice/detail/to_ruby.ipp +4 -635
  91. data/rice/libc/file.ipp +3 -6
  92. data/rice/rice.hpp +22 -12
  93. data/rice/rice_api/Arg.hpp +7 -0
  94. data/rice/rice_api/Arg.ipp +9 -0
  95. data/rice/rice_api/ModuleRegistry.hpp +7 -0
  96. data/rice/rice_api/ModuleRegistry.ipp +10 -0
  97. data/rice/rice_api/Native.hpp +7 -0
  98. data/rice/rice_api/Native.ipp +52 -0
  99. data/rice/rice_api/NativeRegistry.hpp +7 -0
  100. data/rice/rice_api/NativeRegistry.ipp +21 -0
  101. data/rice/rice_api/Parameter.hpp +7 -0
  102. data/rice/rice_api/Parameter.ipp +11 -0
  103. data/rice/rice_api/Registries.hpp +6 -0
  104. data/rice/rice_api/Registries.ipp +12 -0
  105. data/rice/rice_api/TypeRegistry.hpp +7 -0
  106. data/rice/rice_api/TypeRegistry.ipp +10 -0
  107. data/rice/stl/complex.ipp +35 -0
  108. data/rice/stl/exception.ipp +20 -7
  109. data/rice/stl/filesystem.hpp +6 -0
  110. data/rice/stl/filesystem.ipp +34 -0
  111. data/rice/stl/map.ipp +13 -21
  112. data/rice/stl/monostate.ipp +37 -1
  113. data/rice/stl/multimap.ipp +17 -24
  114. data/rice/stl/optional.ipp +47 -2
  115. data/rice/stl/pair.ipp +23 -58
  116. data/rice/stl/reference_wrapper.ipp +22 -1
  117. data/rice/stl/set.ipp +17 -9
  118. data/rice/stl/shared_ptr.ipp +44 -17
  119. data/rice/stl/string.ipp +175 -7
  120. data/rice/stl/string_view.ipp +5 -0
  121. data/rice/stl/tuple.ipp +38 -9
  122. data/rice/stl/unique_ptr.ipp +46 -2
  123. data/rice/stl/unordered_map.ipp +13 -21
  124. data/rice/stl/variant.ipp +47 -11
  125. data/rice/stl/vector.ipp +183 -104
  126. data/rice/stl.hpp +1 -0
  127. data/rice/traits/function_traits.hpp +2 -2
  128. data/rice/traits/method_traits.hpp +5 -16
  129. data/rice/traits/rice_traits.hpp +24 -4
  130. data/rice.gemspec +11 -22
  131. data/test/embed_ruby.cpp +0 -3
  132. data/test/test_Array.cpp +38 -38
  133. data/test/test_Attribute.cpp +187 -2
  134. data/test/test_Buffer.cpp +302 -26
  135. data/test/test_Callback.cpp +2 -3
  136. data/test/test_Class.cpp +5 -5
  137. data/test/test_Data_Object.cpp +0 -55
  138. data/test/test_Data_Type.cpp +19 -30
  139. data/test/test_Enum.cpp +4 -46
  140. data/test/test_From_Ruby.cpp +88 -81
  141. data/test/test_GVL.cpp +109 -0
  142. data/test/test_Iterator.cpp +1 -1
  143. data/test/test_Keep_Alive_No_Wrapper.cpp +5 -3
  144. data/test/test_Module.cpp +8 -9
  145. data/test/test_Object.cpp +1 -1
  146. data/test/test_Overloads.cpp +3 -3
  147. data/test/test_Stl_Map.cpp +8 -8
  148. data/test/test_Stl_Multimap.cpp +4 -4
  149. data/test/test_Stl_Pair.cpp +5 -3
  150. data/test/test_Stl_SharedPtr.cpp +24 -12
  151. data/test/test_Stl_Tuple.cpp +1 -1
  152. data/test/test_Stl_UniquePtr.cpp +8 -0
  153. data/test/test_Stl_Unordered_Map.cpp +9 -9
  154. data/test/test_Stl_Variant.cpp +9 -3
  155. data/test/test_Stl_Vector.cpp +118 -13
  156. data/test/test_To_Ruby.cpp +35 -28
  157. data/test/test_Type.cpp +256 -53
  158. data/test/unittest.hpp +35 -0
  159. metadata +66 -34
  160. data/rice/Init.hpp +0 -8
  161. data/rice/Init.ipp +0 -8
  162. data/rice/detail/RubyFunction.hpp +0 -31
  163. data/rice/detail/RubyFunction.ipp +0 -77
  164. data/sample/callbacks/extconf.rb +0 -5
  165. data/sample/callbacks/sample_callbacks.cpp +0 -35
  166. data/sample/callbacks/test.rb +0 -28
  167. data/sample/enum/extconf.rb +0 -5
  168. data/sample/enum/sample_enum.cpp +0 -40
  169. data/sample/enum/test.rb +0 -8
  170. data/sample/inheritance/animals.cpp +0 -82
  171. data/sample/inheritance/extconf.rb +0 -5
  172. data/sample/inheritance/test.rb +0 -7
  173. data/sample/map/extconf.rb +0 -5
  174. data/sample/map/map.cpp +0 -73
  175. data/sample/map/test.rb +0 -7
  176. data/test/ext/t1/Foo.hpp +0 -10
  177. data/test/ext/t1/extconf.rb +0 -4
  178. data/test/ext/t1/t1.cpp +0 -13
  179. data/test/ext/t2/extconf.rb +0 -4
  180. data/test/ext/t2/t2.cpp +0 -11
  181. data/test/ruby/test_callbacks_sample.rb +0 -28
  182. data/test/ruby/test_multiple_extensions.rb +0 -18
  183. data/test/ruby/test_multiple_extensions_same_class.rb +0 -14
  184. data/test/ruby/test_multiple_extensions_with_inheritance.rb +0 -20
  185. /data/test/{test_Stl_Type.cpp → test_Stl_Type_Info.cpp} +0 -0
data/test/test_Array.cpp CHANGED
@@ -74,7 +74,7 @@ TESTCASE(push_no_items)
74
74
  TESTCASE(push_one_item)
75
75
  {
76
76
  Array a;
77
- a.push(Rice::True);
77
+ a.push(Rice::True, false);
78
78
  ASSERT_EQUAL(1, a.size());
79
79
  ASSERT_EQUAL(Qtrue, a[0]);
80
80
  }
@@ -82,8 +82,8 @@ TESTCASE(push_one_item)
82
82
  TESTCASE(push_two_items)
83
83
  {
84
84
  Array a;
85
- a.push(42);
86
- a.push(43);
85
+ a.push(42, false);
86
+ a.push(43, false);
87
87
  ASSERT_EQUAL(2, a.size());
88
88
  ASSERT_EQUAL(42, detail::From_Ruby<int>().convert(a[0].value()));
89
89
  ASSERT_EQUAL(43, detail::From_Ruby<int>().convert(a[1].value()));
@@ -92,9 +92,9 @@ TESTCASE(push_two_items)
92
92
  TESTCASE(push_three_items)
93
93
  {
94
94
  Array a;
95
- a.push(42);
96
- a.push(43);
97
- a.push(44);
95
+ a.push(42, false);
96
+ a.push(43, false);
97
+ a.push(44, false);
98
98
  ASSERT_EQUAL(3, a.size());
99
99
  ASSERT_EQUAL(42, detail::From_Ruby<int>().convert(a[0].value()));
100
100
  ASSERT_EQUAL(43, detail::From_Ruby<int>().convert(a[1].value()));
@@ -104,7 +104,7 @@ TESTCASE(push_three_items)
104
104
  TESTCASE(push_int)
105
105
  {
106
106
  Array a;
107
- a.push(42);
107
+ a.push(42, false);
108
108
  ASSERT_EQUAL(1, a.size());
109
109
  ASSERT(rb_equal(detail::to_ruby(42), a[0].value()));
110
110
  }
@@ -112,9 +112,9 @@ TESTCASE(push_int)
112
112
  TESTCASE(bracket_equals)
113
113
  {
114
114
  Array a;
115
- a.push(42);
116
- a.push(43);
117
- a.push(44);
115
+ a.push(42, false);
116
+ a.push(43, false);
117
+ a.push(44, false);
118
118
  a[1] = 10;
119
119
  ASSERT_EQUAL(10, detail::From_Ruby<int>().convert(a[1].value()));
120
120
  }
@@ -122,9 +122,9 @@ TESTCASE(bracket_equals)
122
122
  TESTCASE(to_s)
123
123
  {
124
124
  Array a;
125
- a.push(42);
126
- a.push(43);
127
- a.push(44);
125
+ a.push(42, false);
126
+ a.push(43, false);
127
+ a.push(44, false);
128
128
  String s1(a.call("to_s"));
129
129
  String s2(a.to_s());
130
130
  ASSERT_EQUAL(s1.str(), s2.str());
@@ -133,9 +133,9 @@ TESTCASE(to_s)
133
133
  TESTCASE(pop)
134
134
  {
135
135
  Array a;
136
- a.push(42);
137
- a.push(43);
138
- a.push(44);
136
+ a.push(42, false);
137
+ a.push(43, false);
138
+ a.push(44, false);
139
139
  VALUE result = a.pop();
140
140
  ASSERT_EQUAL(2, a.size());
141
141
  ASSERT_EQUAL(42, detail::From_Ruby<int>().convert(a[0].value()));
@@ -146,9 +146,9 @@ TESTCASE(pop)
146
146
  TESTCASE(unshift)
147
147
  {
148
148
  Array a;
149
- a.push(42);
150
- a.push(43);
151
- a.push(44);
149
+ a.push(42, false);
150
+ a.push(43, false);
151
+ a.push(44, false);
152
152
  a.unshift(10);
153
153
  ASSERT_EQUAL(4, a.size());
154
154
  ASSERT_EQUAL(10, detail::From_Ruby<int>().convert(a[0].value()));
@@ -168,9 +168,9 @@ TESTCASE(unshift_int)
168
168
  TESTCASE(shift)
169
169
  {
170
170
  Array a;
171
- a.push(42);
172
- a.push(43);
173
- a.push(44);
171
+ a.push(42, false);
172
+ a.push(43, false);
173
+ a.push(44, false);
174
174
  VALUE result = a.shift();
175
175
  ASSERT_EQUAL(2, a.size());
176
176
  ASSERT_EQUAL(42, detail::From_Ruby<int>().convert(result));
@@ -181,9 +181,9 @@ TESTCASE(shift)
181
181
  TESTCASE(iterate)
182
182
  {
183
183
  Array a;
184
- a.push(42);
185
- a.push(43);
186
- a.push(44);
184
+ a.push(42, false);
185
+ a.push(43, false);
186
+ a.push(44, false);
187
187
  int ca[] = { 42, 43, 44 };
188
188
  Array::iterator it = a.begin();
189
189
  Array::iterator end = a.end();
@@ -196,9 +196,9 @@ TESTCASE(iterate)
196
196
  TESTCASE(const_iterate)
197
197
  {
198
198
  Array a;
199
- a.push(42);
200
- a.push(43);
201
- a.push(44);
199
+ a.push(42, false);
200
+ a.push(43, false);
201
+ a.push(44, false);
202
202
  int ca[] = { 42, 43, 44 };
203
203
  Array::const_iterator it = a.begin();
204
204
  Array::const_iterator end = a.end();
@@ -211,9 +211,9 @@ TESTCASE(const_iterate)
211
211
  TESTCASE(iterate_and_change)
212
212
  {
213
213
  Array a;
214
- a.push(42);
215
- a.push(43);
216
- a.push(44);
214
+ a.push(42, false);
215
+ a.push(43, false);
216
+ a.push(44, false);
217
217
  Array::iterator it = a.begin();
218
218
  Array::iterator end = a.end();
219
219
  for(int j = 0; it != end; ++j, ++it)
@@ -229,9 +229,9 @@ TESTCASE(iterate_and_change)
229
229
  TESTCASE(iterate_and_call_member)
230
230
  {
231
231
  Array a;
232
- a.push(42);
233
- a.push(43);
234
- a.push(44);
232
+ a.push(42, false);
233
+ a.push(43, false);
234
+ a.push(44, false);
235
235
  Array::iterator it = a.begin();
236
236
  Array::iterator end = a.end();
237
237
  std::vector<Object> v;
@@ -251,9 +251,9 @@ TESTCASE(iterate_and_call_member)
251
251
  TESTCASE(find_if)
252
252
  {
253
253
  Array rubyValues;
254
- rubyValues.push(42);
255
- rubyValues.push(43);
256
- rubyValues.push(44);
254
+ rubyValues.push(42, false);
255
+ rubyValues.push(43, false);
256
+ rubyValues.push(44, false);
257
257
 
258
258
  auto iter = std::find_if(rubyValues.begin(), rubyValues.end(),
259
259
  [&rubyValues](const Object& object)
@@ -267,7 +267,7 @@ TESTCASE(find_if)
267
267
  TESTCASE(assign_int)
268
268
  {
269
269
  Array a;
270
- a.push(42);
270
+ a.push(42, false);
271
271
  a[0] = 10;
272
272
  ASSERT_EQUAL(10, detail::From_Ruby<int>().convert(a[0].value()));
273
273
  }
@@ -1,4 +1,4 @@
1
- #include <assert.h>
1
+ #include <assert.h>
2
2
 
3
3
  #include "unittest.hpp"
4
4
  #include "embed_ruby.hpp"
@@ -38,6 +38,18 @@ namespace
38
38
  NotCopyable(const NotCopyable& other) = delete;
39
39
  };
40
40
 
41
+ enum OldEnum
42
+ {
43
+ OldValue1,
44
+ OldValue2
45
+ };
46
+
47
+ enum class NewEnum
48
+ {
49
+ NewValue1,
50
+ NewValue2
51
+ };
52
+
41
53
  struct DataStruct
42
54
  {
43
55
  static inline float staticFloat = 1.0;
@@ -46,11 +58,15 @@ namespace
46
58
 
47
59
  std::string readWriteString = "Read Write";
48
60
  int writeInt = 0;
61
+ const char* chars = "Some chars!";
49
62
  const char* readChars = "Read some chars!";
50
63
  const int constInt = 5;
51
64
  SomeClass someClass;
52
65
  NotAssignable notAssignable;
53
66
  NotCopyable notCopyable;
67
+ char buf[2] = { '0', '1' };
68
+ OldEnum oldEnum = OldValue1;
69
+ NewEnum newEnum = NewEnum::NewValue1;
54
70
 
55
71
  std::string inspect()
56
72
  {
@@ -83,6 +99,7 @@ TESTCASE(attributes)
83
99
  Class c = define_class<DataStruct>("DataStruct")
84
100
  .define_constructor(Constructor<DataStruct>())
85
101
  .define_method("inspect", &DataStruct::inspect)
102
+ .define_attr("chars", &DataStruct::chars)
86
103
  .define_attr("read_chars", &DataStruct::readChars, Rice::AttrAccess::Read)
87
104
  .define_attr("write_int", &DataStruct::writeInt, Rice::AttrAccess::Write)
88
105
  .define_attr("read_write_string", &DataStruct::readWriteString);
@@ -90,8 +107,15 @@ TESTCASE(attributes)
90
107
  Object o = c.call("new");
91
108
  DataStruct* dataStruct = detail::From_Ruby<DataStruct*>().convert(o);
92
109
 
110
+ Object result = o.call("chars");
111
+ ASSERT_EQUAL("Some chars!", detail::From_Ruby<char*>().convert(result));
112
+
113
+ o.call("chars=", "New chars!");
114
+ result = o.call("chars");
115
+ ASSERT_EQUAL("New chars!", detail::From_Ruby<char*>().convert(result));
116
+
93
117
  // Test readonly attribute
94
- Object result = o.call("read_chars");
118
+ result = o.call("read_chars");
95
119
  ASSERT_EQUAL("Read some chars!", detail::From_Ruby<char*>().convert(result));
96
120
 
97
121
  if constexpr (!oldRuby)
@@ -125,6 +149,56 @@ TESTCASE(attributes)
125
149
  ASSERT_EQUAL("Set a string", detail::From_Ruby<std::string>().convert(result.value()));
126
150
  }
127
151
 
152
+ TESTCASE(Enums)
153
+ {
154
+ static Enum<OldEnum> oldEnum = define_enum<OldEnum>("OldEnum")
155
+ .define_value("OldValue1", OldValue1)
156
+ .define_value("OldValue2", OldValue2);
157
+
158
+ static Enum<NewEnum> newEnum = define_enum<NewEnum>("NewEnum")
159
+ .define_value("NewValue1", NewEnum::NewValue1)
160
+ .define_value("NewValue2", NewEnum::NewValue2);
161
+
162
+ Class c = define_class<DataStruct>("DataStruct")
163
+ .define_constructor(Constructor<DataStruct>())
164
+ .define_attr("oldEnum", &DataStruct::oldEnum)
165
+ .define_attr("newEnum", &DataStruct::newEnum);
166
+
167
+ Object o = c.call("new");
168
+ DataStruct* dataStruct = detail::From_Ruby<DataStruct*>().convert(o);
169
+ ASSERT_NOT_EQUAL(nullptr, dataStruct);
170
+
171
+ Object result = o.call("oldEnum");
172
+ ASSERT_EQUAL(OldValue1, detail::From_Ruby<OldEnum>().convert(result));
173
+
174
+ o.call("oldEnum=", OldValue2);
175
+ result = o.call("oldEnum");
176
+ ASSERT_EQUAL(OldValue2, detail::From_Ruby<OldEnum>().convert(result));
177
+
178
+ result = o.call("newEnum");
179
+ ASSERT_EQUAL(NewEnum::NewValue1, detail::From_Ruby<NewEnum>().convert(result));
180
+
181
+ o.call("newEnum=", NewEnum::NewValue2);
182
+ result = o.call("newEnum");
183
+ ASSERT_EQUAL(NewEnum::NewValue2, detail::From_Ruby<NewEnum>().convert(result));
184
+ }
185
+
186
+ TESTCASE(Array)
187
+ {
188
+ Module m = define_module("Testing");
189
+
190
+ Class c = define_class<DataStruct>("DataStruct")
191
+ .define_constructor(Constructor<DataStruct>())
192
+ .define_attr("buf", &DataStruct::buf, Rice::AttrAccess::Read);
193
+
194
+ Object o = c.call("new");
195
+ DataStruct* dataStruct = detail::From_Ruby<DataStruct*>().convert(o);
196
+ ASSERT_NOT_EQUAL(nullptr, dataStruct);
197
+
198
+ Object result = o.call("buf");
199
+ ASSERT_EQUAL("01", detail::From_Ruby<std::string>().convert(result));
200
+ }
201
+
128
202
  TESTCASE(vector)
129
203
  {
130
204
  // See https ://github.com/ruby-rice/rice/issues/283
@@ -308,4 +382,115 @@ TESTCASE(not_defined)
308
382
  o.call("some_class"),
309
383
  ASSERT_EQUAL(message, ex.what())
310
384
  );
385
+ }
386
+
387
+ namespace
388
+ {
389
+ class Counter
390
+ {
391
+ public:
392
+ Counter() = default;
393
+
394
+ Counter(int i): value(i)
395
+ {
396
+ }
397
+
398
+ int value;
399
+ };
400
+
401
+ struct BufferAttrs
402
+ {
403
+ BufferAttrs() : stringArray{"one", "two", "three"}
404
+ {
405
+ this->buffer = new unsigned char[4]{'a', 'b', 'c', '\0'};
406
+ this->countersBuffer = new Counter[2]{ 0, 1 };
407
+ }
408
+
409
+ ~BufferAttrs()
410
+ {
411
+ delete[] this->buffer;
412
+ delete[] this->countersBuffer;
413
+ }
414
+
415
+ inline static float floatArray[3] = {1.0, 2.0, 3.0};
416
+ std::string stringArray[3];
417
+ unsigned char* buffer = nullptr;
418
+ Counter counters[2];
419
+ Counter* countersBuffer = nullptr;
420
+ };
421
+ }
422
+
423
+ TESTCASE(ArrayStaticAttribute)
424
+ {
425
+ Module m = define_module("Testing");
426
+
427
+ Class c = define_class<BufferAttrs>("BufferAttrs")
428
+ .define_constructor(Constructor<BufferAttrs>())
429
+ .define_singleton_attr("floats", &BufferAttrs::floatArray, Rice::AttrAccess::Read);
430
+
431
+ std::string code = R"(BufferAttrs.floats.class)";
432
+ Class klass = (Class)m.module_eval(code);
433
+ ASSERT_EQUAL("Rice::Buffer≺float≻", klass.name().c_str());
434
+ }
435
+
436
+ TESTCASE(ArrayAttribute)
437
+ {
438
+ Module m = define_module("Testing");
439
+
440
+ Class c = define_class<BufferAttrs>("BufferAttrs")
441
+ .define_constructor(Constructor<BufferAttrs>())
442
+ .define_attr("strings", &BufferAttrs::stringArray, Rice::AttrAccess::Read);
443
+
444
+ std::string code = R"(struct = BufferAttrs.new
445
+ struct.strings.class)";
446
+ Class klass = (Class)m.module_eval(code);
447
+ ASSERT_EQUAL("Rice::Buffer≺string≻", klass.name().c_str());
448
+ }
449
+
450
+ TESTCASE(BufferAttribute)
451
+ {
452
+ Module m = define_module("Testing");
453
+
454
+ Class c = define_class<BufferAttrs>("BufferAttrs")
455
+ .define_constructor(Constructor<BufferAttrs>())
456
+ .define_attr("buffer", &BufferAttrs::buffer, Rice::AttrAccess::Read, Return().setBuffer());
457
+
458
+ std::string code = R"(struct = BufferAttrs.new
459
+ struct.buffer.class)";
460
+ Class klass = (Class)m.module_eval(code);
461
+ ASSERT_EQUAL("Rice::Pointer≺unsigned char≻", klass.name().c_str());
462
+ }
463
+
464
+ TESTCASE(CounterArrayAttribute)
465
+ {
466
+ Module m = define_module("Testing");
467
+
468
+ define_class<Counter>("Counter")
469
+ .define_attr("value", &Counter::value, Rice::AttrAccess::Read);
470
+
471
+ define_class<BufferAttrs>("BufferAttrs")
472
+ .define_constructor(Constructor<BufferAttrs>())
473
+ .define_attr("counters", &BufferAttrs::counters, Rice::AttrAccess::Read);
474
+
475
+ std::string code = R"(struct = BufferAttrs.new
476
+ struct.counters.class)";
477
+ Class klass = (Class)m.module_eval(code);
478
+ ASSERT_EQUAL("Rice::Buffer≺AnonymousNamespace꞉꞉Counter≻", klass.name().c_str());
479
+ }
480
+
481
+ TESTCASE(CounterBufferAttribute)
482
+ {
483
+ Module m = define_module("Testing");
484
+
485
+ define_class<Counter>("Counter")
486
+ .define_attr("value", &Counter::value, Rice::AttrAccess::Read);
487
+
488
+ define_class<BufferAttrs>("BufferAttrs")
489
+ .define_constructor(Constructor<BufferAttrs>())
490
+ .define_attr("counters_buffer", &BufferAttrs::countersBuffer, Rice::AttrAccess::Read, Return().setBuffer());
491
+
492
+ std::string code = R"(struct = BufferAttrs.new
493
+ struct.counters_buffer.class)";
494
+ Class klass = (Class)m.module_eval(code);
495
+ ASSERT_EQUAL("Rice::Pointer≺AnonymousNamespace꞉꞉Counter≻", klass.name().c_str());
311
496
  }