rice 4.5.0 → 4.6.1

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 (167) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +33 -0
  3. data/CMakeLists.txt +31 -0
  4. data/CMakePresets.json +75 -0
  5. data/COPYING +3 -2
  6. data/FindRuby.cmake +437 -0
  7. data/Rakefile +5 -4
  8. data/include/rice/rice.hpp +5619 -3129
  9. data/include/rice/stl.hpp +2319 -1234
  10. data/lib/make_rice_headers.rb +79 -0
  11. data/lib/mkmf-rice.rb +4 -0
  12. data/lib/rice/version.rb +3 -0
  13. data/lib/rice.rb +1 -0
  14. data/lib/rubygems/builder.rb +11 -0
  15. data/lib/rubygems/cmake_builder.rb +113 -0
  16. data/lib/rubygems_plugin.rb +9 -0
  17. data/rice/Arg.hpp +7 -1
  18. data/rice/Arg.ipp +11 -2
  19. data/rice/Buffer.hpp +168 -0
  20. data/rice/Buffer.ipp +788 -0
  21. data/rice/Constructor.ipp +3 -3
  22. data/rice/Data_Object.hpp +2 -3
  23. data/rice/Data_Object.ipp +188 -188
  24. data/rice/Data_Type.hpp +7 -5
  25. data/rice/Data_Type.ipp +79 -52
  26. data/rice/Enum.hpp +0 -1
  27. data/rice/Enum.ipp +26 -23
  28. data/rice/Init.hpp +8 -0
  29. data/rice/Init.ipp +8 -0
  30. data/rice/MemoryView.ipp +1 -41
  31. data/rice/Return.hpp +1 -1
  32. data/rice/Return.ipp +6 -0
  33. data/rice/cpp_api/Array.hpp +209 -0
  34. data/rice/cpp_api/Array.ipp +304 -0
  35. data/rice/cpp_api/Builtin_Object.hpp +31 -0
  36. data/rice/cpp_api/Builtin_Object.ipp +37 -0
  37. data/rice/cpp_api/Class.hpp +70 -0
  38. data/rice/cpp_api/Class.ipp +97 -0
  39. data/rice/cpp_api/Encoding.hpp +32 -0
  40. data/rice/cpp_api/Encoding.ipp +59 -0
  41. data/rice/cpp_api/Hash.hpp +194 -0
  42. data/rice/cpp_api/Hash.ipp +257 -0
  43. data/rice/cpp_api/Identifier.hpp +46 -0
  44. data/rice/cpp_api/Identifier.ipp +31 -0
  45. data/rice/cpp_api/Module.hpp +72 -0
  46. data/rice/cpp_api/Module.ipp +101 -0
  47. data/rice/cpp_api/Object.hpp +272 -0
  48. data/rice/cpp_api/Object.ipp +235 -0
  49. data/rice/cpp_api/String.hpp +74 -0
  50. data/rice/cpp_api/String.ipp +120 -0
  51. data/rice/cpp_api/Struct.hpp +113 -0
  52. data/rice/cpp_api/Struct.ipp +92 -0
  53. data/rice/cpp_api/Symbol.hpp +46 -0
  54. data/rice/cpp_api/Symbol.ipp +93 -0
  55. data/rice/cpp_api/shared_methods.hpp +134 -0
  56. data/rice/detail/MethodInfo.hpp +1 -9
  57. data/rice/detail/MethodInfo.ipp +5 -72
  58. data/rice/detail/Native.hpp +3 -2
  59. data/rice/detail/Native.ipp +32 -4
  60. data/rice/detail/NativeAttributeGet.hpp +3 -2
  61. data/rice/detail/NativeAttributeGet.ipp +20 -3
  62. data/rice/detail/NativeAttributeSet.hpp +3 -2
  63. data/rice/detail/NativeAttributeSet.ipp +11 -23
  64. data/rice/detail/NativeCallbackFFI.ipp +2 -1
  65. data/rice/detail/NativeFunction.hpp +17 -6
  66. data/rice/detail/NativeFunction.ipp +169 -64
  67. data/rice/detail/NativeIterator.hpp +3 -2
  68. data/rice/detail/NativeIterator.ipp +8 -2
  69. data/rice/detail/RubyFunction.ipp +1 -0
  70. data/rice/detail/RubyType.hpp +2 -5
  71. data/rice/detail/RubyType.ipp +50 -5
  72. data/rice/detail/Type.hpp +3 -1
  73. data/rice/detail/Type.ipp +60 -31
  74. data/rice/detail/Wrapper.hpp +68 -33
  75. data/rice/detail/Wrapper.ipp +103 -113
  76. data/rice/detail/from_ruby.hpp +5 -4
  77. data/rice/detail/from_ruby.ipp +737 -365
  78. data/rice/detail/to_ruby.ipp +1092 -186
  79. data/rice/global_function.ipp +1 -1
  80. data/rice/libc/file.hpp +11 -0
  81. data/rice/libc/file.ipp +32 -0
  82. data/rice/rice.hpp +23 -16
  83. data/rice/stl/complex.hpp +6 -0
  84. data/rice/stl/complex.ipp +93 -0
  85. data/rice/stl/exception.hpp +11 -0
  86. data/rice/stl/exception.ipp +29 -0
  87. data/rice/stl/exception_ptr.hpp +6 -0
  88. data/rice/stl/exception_ptr.ipp +27 -0
  89. data/rice/stl/map.hpp +12 -0
  90. data/rice/stl/map.ipp +469 -0
  91. data/rice/stl/monostate.hpp +6 -0
  92. data/rice/stl/monostate.ipp +80 -0
  93. data/rice/stl/multimap.hpp +14 -0
  94. data/rice/stl/multimap.ipp +448 -0
  95. data/rice/stl/optional.hpp +6 -0
  96. data/rice/stl/optional.ipp +118 -0
  97. data/rice/stl/pair.hpp +13 -0
  98. data/rice/stl/pair.ipp +155 -0
  99. data/rice/stl/reference_wrapper.hpp +6 -0
  100. data/rice/stl/reference_wrapper.ipp +41 -0
  101. data/rice/stl/set.hpp +12 -0
  102. data/rice/stl/set.ipp +495 -0
  103. data/rice/stl/shared_ptr.hpp +28 -0
  104. data/rice/stl/shared_ptr.ipp +224 -0
  105. data/rice/stl/string.hpp +6 -0
  106. data/rice/stl/string.ipp +158 -0
  107. data/rice/stl/string_view.hpp +6 -0
  108. data/rice/stl/string_view.ipp +65 -0
  109. data/rice/stl/tuple.hpp +6 -0
  110. data/rice/stl/tuple.ipp +128 -0
  111. data/rice/stl/type_index.hpp +6 -0
  112. data/rice/stl/type_index.ipp +30 -0
  113. data/rice/stl/type_info.hpp +6 -0
  114. data/rice/stl/type_info.ipp +29 -0
  115. data/rice/stl/unique_ptr.hpp +22 -0
  116. data/rice/stl/unique_ptr.ipp +139 -0
  117. data/rice/stl/unordered_map.hpp +12 -0
  118. data/rice/stl/unordered_map.ipp +469 -0
  119. data/rice/stl/variant.hpp +6 -0
  120. data/rice/stl/variant.ipp +242 -0
  121. data/rice/stl/vector.hpp +12 -0
  122. data/rice/stl/vector.ipp +589 -0
  123. data/rice/stl.hpp +7 -3
  124. data/rice/traits/attribute_traits.hpp +26 -0
  125. data/rice/traits/function_traits.hpp +95 -0
  126. data/rice/traits/method_traits.hpp +47 -0
  127. data/rice/traits/rice_traits.hpp +172 -0
  128. data/rice.gemspec +85 -0
  129. data/test/embed_ruby.cpp +3 -0
  130. data/test/ruby/test_multiple_extensions_same_class.rb +14 -14
  131. data/test/test_Array.cpp +6 -3
  132. data/test/test_Attribute.cpp +91 -9
  133. data/test/test_Buffer.cpp +340 -0
  134. data/test/test_Callback.cpp +2 -3
  135. data/test/test_Data_Object.cpp +88 -34
  136. data/test/test_Data_Type.cpp +106 -65
  137. data/test/test_Director.cpp +7 -3
  138. data/test/test_Enum.cpp +5 -2
  139. data/test/test_File.cpp +1 -1
  140. data/test/test_From_Ruby.cpp +180 -113
  141. data/test/test_Iterator.cpp +1 -1
  142. data/test/{test_JumpException.cpp → test_Jump_Exception.cpp} +1 -0
  143. data/test/test_Keep_Alive.cpp +7 -18
  144. data/test/test_Keep_Alive_No_Wrapper.cpp +0 -1
  145. data/test/test_Module.cpp +13 -6
  146. data/test/test_Native_Registry.cpp +0 -1
  147. data/test/test_Overloads.cpp +180 -5
  148. data/test/test_Ownership.cpp +100 -57
  149. data/test/test_Proc.cpp +0 -1
  150. data/test/test_Self.cpp +4 -4
  151. data/test/test_Stl_Map.cpp +37 -39
  152. data/test/test_Stl_Multimap.cpp +693 -0
  153. data/test/test_Stl_Pair.cpp +8 -8
  154. data/test/test_Stl_Reference_Wrapper.cpp +4 -2
  155. data/test/test_Stl_Set.cpp +790 -0
  156. data/test/{test_Stl_SmartPointer.cpp → test_Stl_SharedPtr.cpp} +97 -127
  157. data/test/test_Stl_Tuple.cpp +116 -0
  158. data/test/test_Stl_Type.cpp +1 -1
  159. data/test/test_Stl_UniquePtr.cpp +202 -0
  160. data/test/test_Stl_Unordered_Map.cpp +28 -34
  161. data/test/test_Stl_Variant.cpp +217 -89
  162. data/test/test_Stl_Vector.cpp +209 -83
  163. data/test/test_To_Ruby.cpp +373 -1
  164. data/test/test_Type.cpp +85 -14
  165. data/test/test_global_functions.cpp +17 -4
  166. metadata +94 -10
  167. data/rice/detail/TupleIterator.hpp +0 -14
@@ -89,7 +89,9 @@ namespace Rice::detail
89
89
  static inline FromRuby_T fromRuby = rb_num2int_inline;
90
90
  static inline std::set<ruby_value_type> Exact = { RUBY_T_FIXNUM };
91
91
  static inline std::set<ruby_value_type> Castable = { };
92
- static inline std::set<ruby_value_type> Narrowable = { };
92
+ // We allow bignum to integer because Ruby switches to bignum at about 2 billion on 64 bit systems,
93
+ // while int can go up to 4 billion
94
+ static inline std::set<ruby_value_type> Narrowable = { RUBY_T_BIGNUM };
93
95
  static inline std::string packTemplate = "i*";
94
96
  };
95
97
 
@@ -102,7 +104,9 @@ namespace Rice::detail
102
104
  static inline FromRuby_T fromRuby = RB_NUM2UINT;
103
105
  static inline std::set<ruby_value_type> Exact = { RUBY_T_FIXNUM };
104
106
  static inline std::set<ruby_value_type> Castable = { };
105
- static inline std::set<ruby_value_type> Narrowable = { };
107
+ // We allow bignum to integer because Ruby switches to bignum at about 2 billion on 64 bit systems,
108
+ // while int can go up to 4 billion
109
+ static inline std::set<ruby_value_type> Narrowable = { RUBY_T_BIGNUM };
106
110
  static inline std::string packTemplate = "I*";
107
111
  };
108
112
 
@@ -115,7 +119,7 @@ namespace Rice::detail
115
119
  static inline FromRuby_T fromRuby = rb_num2long_inline;
116
120
  static inline std::set<ruby_value_type> Exact = { RUBY_T_FIXNUM };
117
121
  static inline std::set<ruby_value_type> Castable = { };
118
- static inline std::set<ruby_value_type> Narrowable = { };
122
+ static inline std::set<ruby_value_type> Narrowable = { RUBY_T_BIGNUM };
119
123
  static inline std::string packTemplate = "l_*";
120
124
  };
121
125
 
@@ -128,7 +132,7 @@ namespace Rice::detail
128
132
  static inline FromRuby_T fromRuby = rb_num2ulong_inline;
129
133
  static inline std::set<ruby_value_type> Exact = { RUBY_T_FIXNUM };
130
134
  static inline std::set<ruby_value_type> Castable = { };
131
- static inline std::set<ruby_value_type> Narrowable = { };
135
+ static inline std::set<ruby_value_type> Narrowable = { RUBY_T_BIGNUM};
132
136
  static inline std::string packTemplate = "L_*";
133
137
  };
134
138
 
@@ -158,7 +162,6 @@ namespace Rice::detail
158
162
  static inline std::string packTemplate = "Q_*";
159
163
  };
160
164
 
161
-
162
165
  template<>
163
166
  class RubyType<float>
164
167
  {
@@ -184,4 +187,46 @@ namespace Rice::detail
184
187
  static inline std::set<ruby_value_type> Narrowable = { };
185
188
  static inline std::string packTemplate = "d*";
186
189
  };
190
+
191
+ template<>
192
+ class RubyType<void>
193
+ {
194
+ public:
195
+ static inline std::set<ruby_value_type> Exact = { };
196
+ static inline std::set<ruby_value_type> Castable = { };
197
+ static inline std::set<ruby_value_type> Narrowable = { };
198
+ };
199
+ }
200
+
201
+ namespace Rice::detail
202
+ {
203
+ template<typename T>
204
+ inline Data_Type<T> define_ruby_type()
205
+ {
206
+ std::string name = detail::typeName(typeid(T*));
207
+ std::string klassName = detail::rubyClassName(name);
208
+ Identifier id(klassName);
209
+
210
+ Module rb_mRice = define_module("Rice");
211
+ return define_class_under<T>(rb_mRice, id);
212
+ }
213
+
214
+ inline void define_ruby_types()
215
+ {
216
+ define_ruby_type<bool>();
217
+ define_ruby_type<char>();
218
+ define_ruby_type<signed char>();
219
+ define_ruby_type<unsigned char>();
220
+ define_ruby_type<short>();
221
+ define_ruby_type<unsigned short>();
222
+ define_ruby_type<int>();
223
+ define_ruby_type<unsigned int>();
224
+ define_ruby_type<long>();
225
+ define_ruby_type<unsigned long>();
226
+ define_ruby_type<long long>();
227
+ define_ruby_type<unsigned long long>();
228
+ define_ruby_type<float>();
229
+ define_ruby_type<double>();
230
+ define_ruby_type<void>();
231
+ }
187
232
  }
data/rice/detail/Type.hpp CHANGED
@@ -14,8 +14,10 @@ namespace Rice::detail
14
14
  // Return the name of a type
15
15
  std::string typeName(const std::type_info& typeInfo);
16
16
  std::string typeName(const std::type_index& typeIndex);
17
- std::string makeClassName(const std::string& typeInfoName);
17
+ std::string cppClassName(const std::string& typeInfoName);
18
+ std::string rubyClassName(const std::string& typeInfoName);
18
19
  std::string findGroup(std::string& string, size_t start = 0);
20
+ void replaceGroup(std::string& string, std::regex regex, std::string replacement);
19
21
  void replaceAll(std::string& string, std::regex regex, std::string replacement);
20
22
 
21
23
  template<typename T>
data/rice/detail/Type.ipp CHANGED
@@ -13,21 +13,16 @@ namespace Rice::detail
13
13
  {
14
14
  return true;
15
15
  }
16
+ else if constexpr (std::is_array_v<T> && std::is_fundamental_v<std::remove_extent_t<T>>)
17
+ {
18
+ return true;
19
+ }
16
20
  else
17
21
  {
18
22
  return Registries::instance.types.verify<T>();
19
23
  }
20
24
  }
21
25
 
22
- template<>
23
- struct Type<void>
24
- {
25
- static bool verify()
26
- {
27
- return true;
28
- }
29
- };
30
-
31
26
  template<typename T>
32
27
  void verifyType()
33
28
  {
@@ -35,7 +30,7 @@ namespace Rice::detail
35
30
  }
36
31
 
37
32
  template<typename Tuple_T, size_t...Is>
38
- void verifyTypesImpl()
33
+ void verifyTypesImpl(std::index_sequence<Is...> indexes)
39
34
  {
40
35
  (verifyType<typename std::tuple_element<Is, Tuple_T>::type>(), ...);
41
36
  }
@@ -43,10 +38,8 @@ namespace Rice::detail
43
38
  template<typename Tuple_T>
44
39
  void verifyTypes()
45
40
  {
46
- if constexpr (std::tuple_size<Tuple_T>::value > 0)
47
- {
48
- verifyTypesImpl<Tuple_T, std::tuple_size<Tuple_T>::value - 1>();
49
- }
41
+ std::make_index_sequence<std::tuple_size_v<Tuple_T>> indexes;
42
+ verifyTypesImpl<Tuple_T>(indexes);
50
43
  }
51
44
 
52
45
  inline std::string demangle(char const* mangled_name)
@@ -156,7 +149,18 @@ namespace Rice::detail
156
149
  }
157
150
  }
158
151
 
159
- inline std::string makeClassName(const std::string& typeInfoName)
152
+ inline void replaceGroup(std::string& string, std::regex regex, std::string replacement)
153
+ {
154
+ std::smatch match;
155
+ while (std::regex_search(string, match, regex))
156
+ {
157
+ std::string group = findGroup(string, match.position());
158
+ group = match.str() + group;
159
+ string.replace(match.position(), group.length(), replacement);
160
+ }
161
+ }
162
+
163
+ inline std::string cppClassName(const std::string& typeInfoName)
160
164
  {
161
165
  std::string base = typeInfoName;
162
166
 
@@ -170,34 +174,26 @@ namespace Rice::detail
170
174
 
171
175
  // Remove std::__[^:]*::
172
176
  auto stdClangRegex = std::regex("std::__[^:]+::");
173
- base = std::regex_replace(base, stdClangRegex, "");
174
-
175
- // Remove std::
176
- auto stdRegex = std::regex("std::");
177
- base = std::regex_replace(base, stdRegex, "");
177
+ base = std::regex_replace(base, stdClangRegex, "std::");
178
178
 
179
- // Replace basic_string with string
180
- auto basicStringRegex = std::regex(R"(basic_string)");
181
- replaceAll(base, basicStringRegex, "string");
182
-
183
179
  // Remove allocators
184
- std::regex allocatorRegex(R"(,\s*allocator)");
180
+ std::regex allocatorRegex(R"(,\s*std::allocator)");
185
181
  removeGroup(base, allocatorRegex);
186
182
 
187
183
  // Remove char_traits
188
- std::regex charTraitsRegex(R"(,\s*char_traits)");
184
+ std::regex charTraitsRegex(R"(,\s*std::char_traits)");
189
185
  removeGroup(base, charTraitsRegex);
190
186
 
191
187
  // Remove less (std::map)
192
- std::regex lessRegex(R"(,\s*less)");
188
+ std::regex lessRegex(R"(,\s*std::less)");
193
189
  removeGroup(base, lessRegex);
194
190
 
195
191
  // Remove hash (std::unordered_map)
196
- std::regex hashRegex(R"(,\s*hash)");
192
+ std::regex hashRegex(R"(,\s*std::hash)");
197
193
  removeGroup(base, hashRegex);
198
194
 
199
195
  // Remove equal_to (std::unordered_map)
200
- std::regex equalRegex(R"(,\s*equal_to)");
196
+ std::regex equalRegex(R"(,\s*std::equal_to)");
201
197
  removeGroup(base, equalRegex);
202
198
 
203
199
  // Remove spaces before pointers
@@ -216,6 +212,35 @@ namespace Rice::detail
216
212
  auto commaSpaceRegex = std::regex(R"(,(\S))");
217
213
  replaceAll(base, commaSpaceRegex, ", $1");
218
214
 
215
+ // Fix strings
216
+ auto stringRegex = std::regex(R"(basic_string<char>)");
217
+ replaceAll(base, stringRegex, "string");
218
+
219
+ auto wstringRegex = std::regex(R"(basic_string<wchar_t>)");
220
+ replaceAll(base, wstringRegex, "wstring");
221
+
222
+ // Normalize Anonymous namespace
223
+ auto anonymousNamespaceGcc = std::regex(R"(\(anonymous namespace\))");
224
+ replaceAll(base, anonymousNamespaceGcc, "AnonymousNamespace");
225
+ auto anonymousNamespaceMsvc = std::regex(R"(`anonymous namespace')");
226
+ replaceAll(base, anonymousNamespaceMsvc, "AnonymousNamespace");
227
+
228
+ return base;
229
+ }
230
+
231
+ inline std::string rubyClassName(const std::string& typeInfoName)
232
+ {
233
+ std::string base = cppClassName(typeInfoName);
234
+
235
+ // Remove std:: these could be embedded in template types
236
+ auto stdRegex = std::regex("std::");
237
+ base = std::regex_replace(base, stdRegex, "");
238
+
239
+ // Remove leading namespaces. This will not remove namespaces
240
+ // embedded in template types like std::vector<mynamespace::foo>
241
+ auto leadingNamespacesRegex = std::regex("^[^<]*::");
242
+ base = std::regex_replace(base, leadingNamespacesRegex, "");
243
+
219
244
  // Capitalize first letter
220
245
  base[0] = std::toupper(base[0]);
221
246
 
@@ -239,18 +264,22 @@ namespace Rice::detail
239
264
 
240
265
  // Replace < with unicode U+227A (Precedes)
241
266
  auto lessThanRegex = std::regex("<");
242
- //replaceAll(base, lessThanRegex, u8"≺");
267
+ //replaceAll(base, lessThanRegex, "≺");
243
268
  replaceAll(base, lessThanRegex, "\u227A");
244
269
 
245
270
  // Replace > with unicode U+227B (Succeeds)
246
271
  auto greaterThanRegex = std::regex(">");
247
- //replaceAll(base, greaterThanRegex, u8"≻");
272
+ //replaceAll(base, greaterThanRegex, "≻");
248
273
  replaceAll(base, greaterThanRegex, "\u227B");
249
274
 
250
275
  // Replace , with Unicode Character (U+066C) - Arabic Thousands Separator
251
276
  auto commaRegex = std::regex(R"(,\s*)");
252
277
  replaceAll(base, commaRegex, "\u201A");
253
278
 
279
+ // Replace * with Unicode Character (U+2217) - Asterisk Operator
280
+ auto asteriskRegex = std::regex(R"(\*)");
281
+ replaceAll(base, asteriskRegex, "\u2217");
282
+
254
283
  return base;
255
284
  }
256
285
  }
@@ -1,50 +1,85 @@
1
1
  #ifndef Rice__detail__Wrapper__hpp_
2
2
  #define Rice__detail__Wrapper__hpp_
3
3
 
4
- namespace Rice
5
- {
6
- namespace detail
4
+ namespace Rice::detail
7
5
  {
6
+ class WrapperBase
7
+ {
8
+ public:
9
+ WrapperBase() = default;
10
+ virtual ~WrapperBase() = default;
11
+ virtual void* get() = 0;
12
+ bool isConst();
8
13
 
9
- class Wrapper
10
- {
11
- public:
12
- Wrapper(bool isOwner = false);
13
- virtual ~Wrapper() = default;
14
- virtual void* get() = 0;
14
+ void ruby_mark();
15
+ void addKeepAlive(VALUE value);
16
+ void setOwner(bool value);
15
17
 
16
- void ruby_mark();
17
- void addKeepAlive(VALUE value);
18
- void setOwner(bool value);
18
+ protected:
19
+ bool isOwner_ = false;
20
+ bool isConst_ = false;
19
21
 
20
- protected:
21
- bool isOwner_ = false;
22
+ private:
23
+ // We use a vector for speed and memory locality versus a set which does
24
+ // not scale well when getting to tens of thousands of objects (not expecting
25
+ // that to happen...but just in case)
26
+ std::vector<VALUE> keepAlive_;
27
+ };
22
28
 
23
- private:
24
- // We use a vector for speed and memory locality versus a set which does
25
- // not scale well when getting to tens of thousands of objects (not expecting
26
- // that to happen...but just in case)
27
- std::vector<VALUE> keepAlive_;
28
- };
29
+ template <typename T>
30
+ class Wrapper : public WrapperBase
31
+ {
32
+ public:
33
+ Wrapper(T& data);
34
+ Wrapper(T&& data);
35
+ ~Wrapper();
36
+ void* get() override;
29
37
 
30
- template <typename T, typename Wrapper_T = void>
31
- VALUE wrap(VALUE klass, rb_data_type_t* rb_type, T& data, bool isOwner);
38
+ private:
39
+ T data_;
40
+ };
32
41
 
33
- template <typename T, typename Wrapper_T = void>
34
- VALUE wrap(VALUE klass, rb_data_type_t* rb_type, T* data, bool isOwner);
42
+ template<typename T>
43
+ class Wrapper<T&> : public WrapperBase
44
+ {
45
+ public:
46
+ Wrapper(T& data);
47
+ ~Wrapper();
48
+ void* get() override;
35
49
 
36
- template <typename T>
37
- T* unwrap(VALUE value, rb_data_type_t* rb_type, bool takeOwnership);
50
+ private:
51
+ T& data_;
52
+ };
38
53
 
39
- Wrapper* getWrapper(VALUE value, rb_data_type_t* rb_type);
54
+ template <typename T>
55
+ class Wrapper<T*> : public WrapperBase
56
+ {
57
+ public:
58
+ Wrapper(T* data, bool isOwner);
59
+ ~Wrapper();
60
+ void* get() override;
40
61
 
41
- template <typename T>
42
- void replace(VALUE value, rb_data_type_t* rb_type, T* data, bool isOwner);
62
+ private:
63
+ T* data_ = nullptr;
64
+ };
43
65
 
44
- Wrapper* getWrapper(VALUE value);
66
+ // ---- Helper Functions ---------
67
+ template <typename T>
68
+ void wrapConstructed(VALUE value, rb_data_type_t* rb_data_type, T* data, bool isOwner);
45
69
 
46
- } // namespace detail
47
- } // namespace Rice
70
+ template <typename T>
71
+ VALUE wrap(VALUE klass, rb_data_type_t* rb_data_type, T& data, bool isOwner);
48
72
 
49
- #endif // Rice__detail__Wrapper__hpp_
73
+ template <typename T>
74
+ VALUE wrap(VALUE klass, rb_data_type_t* rb_data_type, T* data, bool isOwner);
50
75
 
76
+ template <typename T>
77
+ T* unwrap(VALUE value, rb_data_type_t* rb_data_type, bool takeOwnership);
78
+
79
+ template <typename Wrapper_T = WrapperBase>
80
+ Wrapper_T* getWrapper(VALUE value, rb_data_type_t* rb_data_type);
81
+
82
+ WrapperBase* getWrapper(VALUE value);
83
+ }
84
+ #endif // Rice__detail__Wrapper__hpp_
85
+