rice 4.2.1 → 4.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/include/rice/stl.hpp CHANGED
@@ -71,6 +71,40 @@ namespace Rice::detail
71
71
  Arg* arg_ = nullptr;
72
72
  };
73
73
 
74
+ template<>
75
+ class From_Ruby<std::string&>
76
+ {
77
+ public:
78
+ From_Ruby() = default;
79
+
80
+ explicit From_Ruby(Arg* arg) : arg_(arg)
81
+ {
82
+ }
83
+
84
+ bool is_convertible(VALUE value)
85
+ {
86
+ return rb_type(value) == RUBY_T_STRING;
87
+ }
88
+
89
+ std::string& convert(VALUE value)
90
+ {
91
+ if (value == Qnil && this->arg_ && this->arg_->hasDefaultValue())
92
+ {
93
+ return this->arg_->defaultValue<std::string>();
94
+ }
95
+ else
96
+ {
97
+ detail::protect(rb_check_type, value, (int)T_STRING);
98
+ this->converted_ = std::string(RSTRING_PTR(value), RSTRING_LEN(value));
99
+ return this->converted_;
100
+ }
101
+ }
102
+
103
+ private:
104
+ Arg* arg_ = nullptr;
105
+ std::string converted_;
106
+ };
107
+
74
108
  template<>
75
109
  class From_Ruby<std::string*>
76
110
  {
@@ -92,7 +126,65 @@ namespace Rice::detail
92
126
  };
93
127
 
94
128
  template<>
95
- class From_Ruby<std::string&>
129
+ class From_Ruby<std::string*&>
130
+ {
131
+ public:
132
+ bool is_convertible(VALUE value)
133
+ {
134
+ return rb_type(value) == RUBY_T_STRING;
135
+ }
136
+
137
+ std::string* convert(VALUE value)
138
+ {
139
+ detail::protect(rb_check_type, value, (int)T_STRING);
140
+ this->converted_ = std::string(RSTRING_PTR(value), RSTRING_LEN(value));
141
+ return &this->converted_;
142
+ }
143
+
144
+ private:
145
+ std::string converted_;
146
+ };
147
+ }
148
+
149
+ // ========= string_view.hpp =========
150
+
151
+
152
+ // --------- string_view.ipp ---------
153
+ #include <string_view>
154
+
155
+ namespace Rice::detail
156
+ {
157
+ template<>
158
+ struct Type<std::string_view>
159
+ {
160
+ static bool verify()
161
+ {
162
+ return true;
163
+ }
164
+ };
165
+
166
+ template<>
167
+ class To_Ruby<std::string_view>
168
+ {
169
+ public:
170
+ VALUE convert(std::string_view const& x)
171
+ {
172
+ return detail::protect(rb_external_str_new, x.data(), (long)x.size());
173
+ }
174
+ };
175
+
176
+ template<>
177
+ class To_Ruby<std::string_view&>
178
+ {
179
+ public:
180
+ VALUE convert(std::string_view const& x)
181
+ {
182
+ return detail::protect(rb_external_str_new, x.data(), (long)x.size());
183
+ }
184
+ };
185
+
186
+ template<>
187
+ class From_Ruby<std::string_view>
96
188
  {
97
189
  public:
98
190
  From_Ruby() = default;
@@ -106,23 +198,21 @@ namespace Rice::detail
106
198
  return rb_type(value) == RUBY_T_STRING;
107
199
  }
108
200
 
109
- std::string& convert(VALUE value)
201
+ std::string_view convert(VALUE value)
110
202
  {
111
203
  if (value == Qnil && this->arg_ && this->arg_->hasDefaultValue())
112
204
  {
113
- return this->arg_->defaultValue<std::string>();
205
+ return this->arg_->defaultValue<std::string_view>();
114
206
  }
115
207
  else
116
208
  {
117
209
  detail::protect(rb_check_type, value, (int)T_STRING);
118
- this->converted_ = std::string(RSTRING_PTR(value), RSTRING_LEN(value));
119
- return this->converted_;
210
+ return std::string_view(RSTRING_PTR(value), RSTRING_LEN(value));
120
211
  }
121
212
  }
122
213
 
123
214
  private:
124
215
  Arg* arg_ = nullptr;
125
- std::string converted_;
126
216
  };
127
217
  }
128
218
 
@@ -212,7 +302,7 @@ namespace Rice::detail
212
302
  {
213
303
  constexpr static bool verify()
214
304
  {
215
- return Type<T>::verify();
305
+ return Type<intrinsic_type<T>>::verify();
216
306
  }
217
307
  };
218
308
 
@@ -356,7 +446,7 @@ namespace Rice::detail
356
446
  class WrapperSmartPointer : public Wrapper
357
447
  {
358
448
  public:
359
- WrapperSmartPointer(SmartPointer_T<Arg_Ts...>& data);
449
+ WrapperSmartPointer(SmartPointer_T<Arg_Ts...> data);
360
450
  ~WrapperSmartPointer();
361
451
  void* get() override;
362
452
  SmartPointer_T<Arg_Ts...>& data();
@@ -376,7 +466,7 @@ namespace Rice::detail
376
466
  {
377
467
  // ---- WrapperSmartPointer ------
378
468
  template <template <typename, typename...> typename SmartPointer_T, typename...Arg_Ts>
379
- inline WrapperSmartPointer<SmartPointer_T, Arg_Ts...>::WrapperSmartPointer(SmartPointer_T<Arg_Ts...>& data)
469
+ inline WrapperSmartPointer<SmartPointer_T, Arg_Ts...>::WrapperSmartPointer(SmartPointer_T<Arg_Ts...> data)
380
470
  : data_(std::move(data))
381
471
  {
382
472
  }
@@ -414,6 +504,20 @@ namespace Rice::detail
414
504
  }
415
505
  };
416
506
 
507
+ template <typename T>
508
+ class To_Ruby<std::unique_ptr<T>&>
509
+ {
510
+ public:
511
+ VALUE convert(std::unique_ptr<T>& data)
512
+ {
513
+ std::pair<VALUE, rb_data_type_t*> rubyTypeInfo = detail::Registries::instance.types.figureType<T>(*data);
514
+
515
+ // Use custom wrapper type
516
+ using Wrapper_T = WrapperSmartPointer<std::unique_ptr, T>;
517
+ return detail::wrap<std::unique_ptr<T>, Wrapper_T>(rubyTypeInfo.first, rubyTypeInfo.second, data, true);
518
+ }
519
+ };
520
+
417
521
  template <typename T>
418
522
  class From_Ruby<std::unique_ptr<T>&>
419
523
  {
@@ -489,6 +593,20 @@ namespace Rice::detail
489
593
  Arg* arg_ = nullptr;
490
594
  };
491
595
 
596
+ template <typename T>
597
+ class To_Ruby<std::shared_ptr<T>&>
598
+ {
599
+ public:
600
+ VALUE convert(std::shared_ptr<T>& data)
601
+ {
602
+ std::pair<VALUE, rb_data_type_t*> rubyTypeInfo = detail::Registries::instance.types.figureType<T>(*data);
603
+
604
+ // Use custom wrapper type
605
+ using Wrapper_T = WrapperSmartPointer<std::shared_ptr, T>;
606
+ return detail::wrap<std::shared_ptr<T>, Wrapper_T>(rubyTypeInfo.first, rubyTypeInfo.second, data, true);
607
+ }
608
+ };
609
+
492
610
  template <typename T>
493
611
  class From_Ruby<std::shared_ptr<T>&>
494
612
  {
@@ -2305,7 +2423,7 @@ namespace Rice
2305
2423
  {
2306
2424
  static bool verify()
2307
2425
  {
2308
- Type<T>::verify();
2426
+ Type<intrinsic_type<T>>::verify();
2309
2427
 
2310
2428
  if (!detail::Registries::instance.types.isDefined<std::vector<T>>())
2311
2429
  {
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
- module Rice
2
- VERSION = "4.2.1"
3
- end
1
+ module Rice
2
+ VERSION = "4.3.0"
3
+ end