rice 4.7.0 → 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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +36 -1
- data/CMakeLists.txt +14 -22
- data/CMakePresets.json +203 -75
- data/FindRuby.cmake +358 -123
- data/bin/rice-doc.rb +56 -142
- data/bin/rice-rbs.rb +1 -2
- data/include/rice/api.hpp +248 -0
- data/include/rice/rice.hpp +2281 -1668
- data/include/rice/stl.hpp +364 -443
- data/lib/rice/doc/config.rb +70 -0
- data/lib/rice/doc/cpp_reference.rb +1 -4
- data/lib/rice/doc/mkdocs.rb +58 -20
- data/lib/rice/doc/rice.rb +20 -0
- data/lib/rice/doc.rb +1 -0
- data/lib/rice/make_rice_headers.rb +7 -0
- data/lib/rice/native_registry.rb +2 -2
- data/lib/rice/rbs.rb +4 -4
- data/lib/rice/version.rb +1 -1
- data/lib/rubygems_plugin.rb +12 -9
- data/rice/Arg.hpp +12 -6
- data/rice/Arg.ipp +14 -7
- data/rice/Buffer.ipp +44 -40
- data/rice/Callback.hpp +1 -1
- data/rice/Callback.ipp +2 -7
- data/rice/Constructor.hpp +1 -1
- data/rice/Constructor.ipp +11 -11
- data/rice/Data_Object.ipp +59 -30
- data/rice/Data_Type.hpp +9 -10
- data/rice/Data_Type.ipp +22 -25
- data/rice/Director.hpp +1 -0
- data/rice/Enum.ipp +58 -39
- data/rice/Exception.hpp +4 -4
- data/rice/Exception.ipp +7 -7
- data/rice/NoGVL.hpp +13 -0
- data/rice/Reference.hpp +56 -0
- data/rice/Reference.ipp +96 -0
- data/rice/Return.hpp +4 -1
- data/rice/Return.ipp +0 -6
- data/rice/cpp_api/Array.hpp +44 -7
- data/rice/cpp_api/Array.ipp +105 -9
- data/rice/cpp_api/Class.hpp +2 -2
- data/rice/cpp_api/Class.ipp +4 -4
- data/rice/cpp_api/Hash.ipp +7 -4
- data/rice/cpp_api/Module.hpp +4 -4
- data/rice/cpp_api/Module.ipp +12 -10
- data/rice/cpp_api/Object.hpp +4 -4
- data/rice/cpp_api/Object.ipp +15 -12
- data/rice/cpp_api/String.hpp +2 -2
- data/rice/cpp_api/String.ipp +11 -8
- data/rice/cpp_api/Symbol.ipp +16 -7
- data/rice/cpp_api/shared_methods.hpp +5 -9
- data/rice/detail/InstanceRegistry.hpp +0 -2
- data/rice/detail/Native.hpp +31 -21
- data/rice/detail/Native.ipp +281 -133
- data/rice/detail/NativeAttributeGet.hpp +5 -7
- data/rice/detail/NativeAttributeGet.ipp +26 -26
- data/rice/detail/NativeAttributeSet.hpp +2 -4
- data/rice/detail/NativeAttributeSet.ipp +20 -16
- data/rice/detail/NativeCallback.hpp +77 -0
- data/rice/detail/NativeCallback.ipp +280 -0
- data/rice/detail/NativeFunction.hpp +11 -21
- data/rice/detail/NativeFunction.ipp +58 -119
- data/rice/detail/NativeInvoker.hpp +4 -4
- data/rice/detail/NativeInvoker.ipp +7 -7
- data/rice/detail/NativeIterator.hpp +2 -4
- data/rice/detail/NativeIterator.ipp +18 -14
- data/rice/detail/NativeMethod.hpp +10 -20
- data/rice/detail/NativeMethod.ipp +54 -114
- data/rice/detail/NativeProc.hpp +5 -7
- data/rice/detail/NativeProc.ipp +39 -28
- data/rice/detail/NativeRegistry.hpp +0 -1
- data/rice/detail/NativeRegistry.ipp +0 -1
- data/rice/detail/Parameter.hpp +15 -8
- data/rice/detail/Parameter.ipp +102 -43
- data/rice/detail/Proc.ipp +14 -28
- data/rice/detail/RubyType.ipp +2 -53
- data/rice/detail/Type.hpp +23 -7
- data/rice/detail/Type.ipp +73 -93
- data/rice/detail/TypeRegistry.ipp +5 -4
- data/rice/detail/Wrapper.hpp +1 -1
- data/rice/detail/Wrapper.ipp +18 -10
- data/rice/detail/from_ruby.hpp +8 -6
- data/rice/detail/from_ruby.ipp +306 -173
- data/rice/detail/ruby.hpp +23 -0
- data/rice/libc/file.hpp +4 -4
- data/rice/rice.hpp +6 -8
- data/rice/rice_api/Native.ipp +5 -1
- data/rice/rice_api/Parameter.ipp +1 -1
- data/rice/ruby_mark.hpp +2 -1
- data/rice/stl/complex.ipp +12 -8
- data/rice/stl/map.ipp +27 -22
- data/rice/stl/monostate.ipp +16 -12
- data/rice/stl/multimap.hpp +0 -2
- data/rice/stl/multimap.ipp +27 -22
- data/rice/stl/optional.ipp +27 -11
- data/rice/stl/pair.ipp +5 -5
- data/rice/stl/reference_wrapper.ipp +5 -4
- data/rice/stl/set.ipp +16 -16
- data/rice/stl/shared_ptr.hpp +0 -16
- data/rice/stl/shared_ptr.ipp +34 -190
- data/rice/stl/string.ipp +18 -18
- data/rice/stl/string_view.ipp +19 -1
- data/rice/stl/tuple.ipp +15 -36
- data/rice/stl/unique_ptr.ipp +18 -8
- data/rice/stl/unordered_map.ipp +20 -15
- data/rice/stl/variant.ipp +37 -21
- data/rice/stl/vector.ipp +41 -36
- data/rice/traits/function_traits.hpp +19 -19
- data/rice/traits/method_traits.hpp +4 -4
- data/rice/traits/rice_traits.hpp +162 -39
- data/rice.gemspec +1 -4
- data/test/test_Array.cpp +261 -3
- data/test/test_Attribute.cpp +6 -3
- data/test/test_Buffer.cpp +6 -42
- data/test/test_Callback.cpp +77 -23
- data/test/test_Data_Object.cpp +2 -2
- data/test/test_Data_Type.cpp +23 -23
- data/test/test_Director.cpp +2 -4
- data/test/test_Enum.cpp +34 -5
- data/test/test_File.cpp +9 -5
- data/test/test_From_Ruby.cpp +7 -6
- data/test/test_GVL.cpp +3 -3
- data/test/test_Hash.cpp +1 -1
- data/test/test_Iterator.cpp +54 -22
- data/test/test_Keep_Alive.cpp +1 -1
- data/test/test_Keep_Alive_No_Wrapper.cpp +1 -1
- data/test/test_Module.cpp +5 -5
- data/test/test_Overloads.cpp +395 -50
- data/test/test_Proc.cpp +54 -0
- data/test/test_Reference.cpp +181 -0
- data/test/test_Self.cpp +2 -2
- data/test/test_Stl_Set.cpp +6 -6
- data/test/test_Stl_SharedPtr.cpp +54 -30
- data/test/test_Stl_String_View.cpp +12 -0
- data/test/test_Stl_Tuple.cpp +1 -1
- data/test/test_Stl_Variant.cpp +6 -14
- data/test/test_Stl_Vector.cpp +61 -30
- data/test/test_String.cpp +4 -2
- data/test/test_Struct.cpp +1 -1
- data/test/test_Symbol.cpp +12 -0
- data/test/test_To_Ruby.cpp +1 -0
- data/test/test_Type.cpp +36 -35
- data/test/test_global_functions.cpp +1 -1
- data/test/unittest.cpp +1 -1
- data/test/unittest.hpp +5 -5
- metadata +10 -24
- data/rice/Function.hpp +0 -17
- data/rice/Function.ipp +0 -13
- data/rice/detail/MethodInfo.hpp +0 -48
- data/rice/detail/MethodInfo.ipp +0 -99
- data/rice/detail/NativeCallbackFFI.hpp +0 -55
- data/rice/detail/NativeCallbackFFI.ipp +0 -152
- data/rice/detail/NativeCallbackSimple.hpp +0 -30
- data/rice/detail/NativeCallbackSimple.ipp +0 -29
data/include/rice/stl.hpp
CHANGED
|
@@ -1,3 +1,30 @@
|
|
|
1
|
+
// This file is part of [rice](https://github.com/ruby-rice/rice).
|
|
2
|
+
//
|
|
3
|
+
// Copyright (C) 2025 Jason Roelofs <jasongroelofs@gmail.com>
|
|
4
|
+
// Paul Brannan <curlypaul924@gmail.com>,
|
|
5
|
+
// Charlie Savage
|
|
6
|
+
//
|
|
7
|
+
// Redistribution and use in source and binary forms, with or without
|
|
8
|
+
// modification, are permitted provided that the following conditions
|
|
9
|
+
// are met:
|
|
10
|
+
//
|
|
11
|
+
// 1. Redistributions of source code must retain the above copyright
|
|
12
|
+
// notice, this list of conditions and the following disclaimer.
|
|
13
|
+
// 2. Redistributions in binary form must reproduce the above copyright
|
|
14
|
+
// notice, this list of conditions and the following disclaimer in the
|
|
15
|
+
// documentation and/or other materials provided with the distribution.
|
|
16
|
+
//
|
|
17
|
+
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
18
|
+
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
19
|
+
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
20
|
+
// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
21
|
+
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
22
|
+
// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
23
|
+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
24
|
+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
25
|
+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
26
|
+
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
27
|
+
|
|
1
28
|
#ifndef Rice__stl__hpp_
|
|
2
29
|
#define Rice__stl__hpp_
|
|
3
30
|
|
|
@@ -162,7 +189,7 @@ namespace Rice::detail
|
|
|
162
189
|
public:
|
|
163
190
|
To_Ruby() = default;
|
|
164
191
|
|
|
165
|
-
explicit To_Ruby(
|
|
192
|
+
explicit To_Ruby(Arg* arg) : arg_(arg)
|
|
166
193
|
{
|
|
167
194
|
}
|
|
168
195
|
|
|
@@ -172,7 +199,7 @@ namespace Rice::detail
|
|
|
172
199
|
}
|
|
173
200
|
|
|
174
201
|
private:
|
|
175
|
-
|
|
202
|
+
Arg* arg_ = nullptr;
|
|
176
203
|
};
|
|
177
204
|
|
|
178
205
|
template<>
|
|
@@ -181,7 +208,7 @@ namespace Rice::detail
|
|
|
181
208
|
public:
|
|
182
209
|
To_Ruby() = default;
|
|
183
210
|
|
|
184
|
-
explicit To_Ruby(
|
|
211
|
+
explicit To_Ruby(Arg* arg) : arg_(arg)
|
|
185
212
|
{
|
|
186
213
|
}
|
|
187
214
|
|
|
@@ -191,7 +218,7 @@ namespace Rice::detail
|
|
|
191
218
|
}
|
|
192
219
|
|
|
193
220
|
private:
|
|
194
|
-
|
|
221
|
+
Arg* arg_ = nullptr;
|
|
195
222
|
};
|
|
196
223
|
|
|
197
224
|
template<int N>
|
|
@@ -200,7 +227,7 @@ namespace Rice::detail
|
|
|
200
227
|
public:
|
|
201
228
|
To_Ruby() = default;
|
|
202
229
|
|
|
203
|
-
explicit To_Ruby(
|
|
230
|
+
explicit To_Ruby(Arg* arg) : arg_(arg)
|
|
204
231
|
{
|
|
205
232
|
}
|
|
206
233
|
|
|
@@ -211,7 +238,7 @@ namespace Rice::detail
|
|
|
211
238
|
return dataObject.value();
|
|
212
239
|
}
|
|
213
240
|
private:
|
|
214
|
-
|
|
241
|
+
Arg* arg_ = nullptr;
|
|
215
242
|
};
|
|
216
243
|
|
|
217
244
|
template<>
|
|
@@ -220,14 +247,14 @@ namespace Rice::detail
|
|
|
220
247
|
public:
|
|
221
248
|
To_Ruby() = default;
|
|
222
249
|
|
|
223
|
-
explicit To_Ruby(
|
|
250
|
+
explicit To_Ruby(Arg* arg) : arg_(arg)
|
|
224
251
|
{
|
|
225
252
|
}
|
|
226
253
|
|
|
227
254
|
VALUE convert(const std::string* value)
|
|
228
255
|
{
|
|
229
|
-
bool isOwner = this->
|
|
230
|
-
bool isBuffer = this->
|
|
256
|
+
bool isOwner = this->arg_ && this->arg_->isOwner();
|
|
257
|
+
bool isBuffer = dynamic_cast<ReturnBuffer*>(this->arg_) ? true : false;
|
|
231
258
|
|
|
232
259
|
if (isBuffer)
|
|
233
260
|
{
|
|
@@ -241,7 +268,7 @@ namespace Rice::detail
|
|
|
241
268
|
}
|
|
242
269
|
|
|
243
270
|
private:
|
|
244
|
-
|
|
271
|
+
Arg* arg_ = nullptr;
|
|
245
272
|
};
|
|
246
273
|
|
|
247
274
|
template<>
|
|
@@ -250,7 +277,7 @@ namespace Rice::detail
|
|
|
250
277
|
public:
|
|
251
278
|
To_Ruby() = default;
|
|
252
279
|
|
|
253
|
-
explicit To_Ruby(
|
|
280
|
+
explicit To_Ruby(Arg* arg) : arg_(arg)
|
|
254
281
|
{
|
|
255
282
|
}
|
|
256
283
|
|
|
@@ -260,7 +287,7 @@ namespace Rice::detail
|
|
|
260
287
|
}
|
|
261
288
|
|
|
262
289
|
private:
|
|
263
|
-
|
|
290
|
+
Arg* arg_ = nullptr;
|
|
264
291
|
};
|
|
265
292
|
|
|
266
293
|
/*template<>
|
|
@@ -269,7 +296,7 @@ namespace Rice::detail
|
|
|
269
296
|
public:
|
|
270
297
|
To_Ruby() = default;
|
|
271
298
|
|
|
272
|
-
explicit To_Ruby(
|
|
299
|
+
explicit To_Ruby(Arg* arg) : arg_(arg)
|
|
273
300
|
{
|
|
274
301
|
}
|
|
275
302
|
|
|
@@ -281,7 +308,7 @@ namespace Rice::detail
|
|
|
281
308
|
}
|
|
282
309
|
|
|
283
310
|
private:
|
|
284
|
-
|
|
311
|
+
Arg* arg_ = nullptr;
|
|
285
312
|
};*/
|
|
286
313
|
|
|
287
314
|
template<>
|
|
@@ -294,7 +321,7 @@ namespace Rice::detail
|
|
|
294
321
|
{
|
|
295
322
|
}
|
|
296
323
|
|
|
297
|
-
|
|
324
|
+
double is_convertible(VALUE value)
|
|
298
325
|
{
|
|
299
326
|
switch (rb_type(value))
|
|
300
327
|
{
|
|
@@ -326,7 +353,7 @@ namespace Rice::detail
|
|
|
326
353
|
{
|
|
327
354
|
}
|
|
328
355
|
|
|
329
|
-
|
|
356
|
+
double is_convertible(VALUE value)
|
|
330
357
|
{
|
|
331
358
|
switch (rb_type(value))
|
|
332
359
|
{
|
|
@@ -360,7 +387,7 @@ namespace Rice::detail
|
|
|
360
387
|
{
|
|
361
388
|
}
|
|
362
389
|
|
|
363
|
-
|
|
390
|
+
double is_convertible(VALUE value)
|
|
364
391
|
{
|
|
365
392
|
switch (rb_type(value))
|
|
366
393
|
{
|
|
@@ -394,7 +421,7 @@ namespace Rice::detail
|
|
|
394
421
|
{
|
|
395
422
|
}
|
|
396
423
|
|
|
397
|
-
|
|
424
|
+
double is_convertible(VALUE value)
|
|
398
425
|
{
|
|
399
426
|
switch (rb_type(value))
|
|
400
427
|
{
|
|
@@ -445,20 +472,38 @@ namespace Rice::detail
|
|
|
445
472
|
class To_Ruby<std::string_view>
|
|
446
473
|
{
|
|
447
474
|
public:
|
|
475
|
+
To_Ruby() = default;
|
|
476
|
+
|
|
477
|
+
explicit To_Ruby(Arg* arg) : arg_(arg)
|
|
478
|
+
{
|
|
479
|
+
}
|
|
480
|
+
|
|
448
481
|
VALUE convert(std::string_view const& x)
|
|
449
482
|
{
|
|
450
483
|
return detail::protect(rb_external_str_new, x.data(), (long)x.size());
|
|
451
484
|
}
|
|
485
|
+
|
|
486
|
+
private:
|
|
487
|
+
Arg* arg_ = nullptr;
|
|
452
488
|
};
|
|
453
489
|
|
|
454
490
|
template<>
|
|
455
491
|
class To_Ruby<std::string_view&>
|
|
456
492
|
{
|
|
457
493
|
public:
|
|
494
|
+
To_Ruby() = default;
|
|
495
|
+
|
|
496
|
+
explicit To_Ruby(Arg* arg) : arg_(arg)
|
|
497
|
+
{
|
|
498
|
+
}
|
|
499
|
+
|
|
458
500
|
VALUE convert(std::string_view const& x)
|
|
459
501
|
{
|
|
460
502
|
return detail::protect(rb_external_str_new, x.data(), (long)x.size());
|
|
461
503
|
}
|
|
504
|
+
|
|
505
|
+
private:
|
|
506
|
+
Arg* arg_ = nullptr;
|
|
462
507
|
};
|
|
463
508
|
|
|
464
509
|
template<>
|
|
@@ -471,7 +516,7 @@ namespace Rice::detail
|
|
|
471
516
|
{
|
|
472
517
|
}
|
|
473
518
|
|
|
474
|
-
|
|
519
|
+
double is_convertible(VALUE value)
|
|
475
520
|
{
|
|
476
521
|
switch (rb_type(value))
|
|
477
522
|
{
|
|
@@ -522,7 +567,7 @@ namespace Rice::detail
|
|
|
522
567
|
public:
|
|
523
568
|
To_Ruby() = default;
|
|
524
569
|
|
|
525
|
-
explicit To_Ruby(
|
|
570
|
+
explicit To_Ruby(Arg* arg) : arg_(arg)
|
|
526
571
|
{
|
|
527
572
|
}
|
|
528
573
|
|
|
@@ -535,7 +580,7 @@ namespace Rice::detail
|
|
|
535
580
|
}
|
|
536
581
|
|
|
537
582
|
private:
|
|
538
|
-
|
|
583
|
+
Arg* arg_ = nullptr;
|
|
539
584
|
};
|
|
540
585
|
|
|
541
586
|
template<typename T>
|
|
@@ -544,7 +589,7 @@ namespace Rice::detail
|
|
|
544
589
|
public:
|
|
545
590
|
To_Ruby() = default;
|
|
546
591
|
|
|
547
|
-
explicit To_Ruby(
|
|
592
|
+
explicit To_Ruby(Arg* arg) : arg_(arg)
|
|
548
593
|
{
|
|
549
594
|
}
|
|
550
595
|
|
|
@@ -557,7 +602,7 @@ namespace Rice::detail
|
|
|
557
602
|
}
|
|
558
603
|
|
|
559
604
|
private:
|
|
560
|
-
|
|
605
|
+
Arg* arg_ = nullptr;
|
|
561
606
|
};
|
|
562
607
|
|
|
563
608
|
template<typename T>
|
|
@@ -566,11 +611,11 @@ namespace Rice::detail
|
|
|
566
611
|
public:
|
|
567
612
|
From_Ruby() = default;
|
|
568
613
|
|
|
569
|
-
explicit From_Ruby(Arg* arg)
|
|
614
|
+
explicit From_Ruby(Arg* arg) :arg_(arg)
|
|
570
615
|
{
|
|
571
616
|
}
|
|
572
617
|
|
|
573
|
-
|
|
618
|
+
double is_convertible(VALUE value)
|
|
574
619
|
{
|
|
575
620
|
switch (rb_type(value))
|
|
576
621
|
{
|
|
@@ -589,6 +634,9 @@ namespace Rice::detail
|
|
|
589
634
|
|
|
590
635
|
return std::complex<T>(From_Ruby<T>().convert(real), From_Ruby<T>().convert(imaginary));
|
|
591
636
|
}
|
|
637
|
+
|
|
638
|
+
private:
|
|
639
|
+
Arg* arg_ = nullptr;
|
|
592
640
|
};
|
|
593
641
|
|
|
594
642
|
template<typename T>
|
|
@@ -597,11 +645,11 @@ namespace Rice::detail
|
|
|
597
645
|
public:
|
|
598
646
|
From_Ruby() = default;
|
|
599
647
|
|
|
600
|
-
explicit From_Ruby(Arg* arg)
|
|
648
|
+
explicit From_Ruby(Arg* arg) : arg_(arg)
|
|
601
649
|
{
|
|
602
650
|
}
|
|
603
651
|
|
|
604
|
-
|
|
652
|
+
double is_convertible(VALUE value)
|
|
605
653
|
{
|
|
606
654
|
switch (rb_type(value))
|
|
607
655
|
{
|
|
@@ -623,6 +671,7 @@ namespace Rice::detail
|
|
|
623
671
|
}
|
|
624
672
|
|
|
625
673
|
private:
|
|
674
|
+
Arg* arg_ = nullptr;
|
|
626
675
|
std::complex<T> converted_;
|
|
627
676
|
};
|
|
628
677
|
}
|
|
@@ -697,17 +746,17 @@ namespace Rice::detail
|
|
|
697
746
|
public:
|
|
698
747
|
To_Ruby() = default;
|
|
699
748
|
|
|
700
|
-
explicit To_Ruby(
|
|
749
|
+
explicit To_Ruby(Arg* arg) : arg_(arg)
|
|
701
750
|
{
|
|
702
751
|
}
|
|
703
752
|
|
|
704
|
-
VALUE convert(const std::nullopt_t&
|
|
753
|
+
VALUE convert(const std::nullopt_t&)
|
|
705
754
|
{
|
|
706
755
|
return Qnil;
|
|
707
756
|
}
|
|
708
757
|
|
|
709
758
|
private:
|
|
710
|
-
|
|
759
|
+
Arg* arg_ = nullptr;
|
|
711
760
|
};
|
|
712
761
|
|
|
713
762
|
template<typename T>
|
|
@@ -716,7 +765,7 @@ namespace Rice::detail
|
|
|
716
765
|
public:
|
|
717
766
|
To_Ruby() = default;
|
|
718
767
|
|
|
719
|
-
explicit To_Ruby(
|
|
768
|
+
explicit To_Ruby(Arg* arg) : arg_(arg)
|
|
720
769
|
{
|
|
721
770
|
}
|
|
722
771
|
|
|
@@ -732,8 +781,20 @@ namespace Rice::detail
|
|
|
732
781
|
}
|
|
733
782
|
}
|
|
734
783
|
|
|
784
|
+
VALUE convert(const std::optional<T>& data)
|
|
785
|
+
{
|
|
786
|
+
if (data.has_value())
|
|
787
|
+
{
|
|
788
|
+
return To_Ruby<T>().convert(data.value());
|
|
789
|
+
}
|
|
790
|
+
else
|
|
791
|
+
{
|
|
792
|
+
return Qnil;
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
|
|
735
796
|
private:
|
|
736
|
-
|
|
797
|
+
Arg* arg_ = nullptr;
|
|
737
798
|
};
|
|
738
799
|
|
|
739
800
|
template<typename T>
|
|
@@ -742,7 +803,7 @@ namespace Rice::detail
|
|
|
742
803
|
public:
|
|
743
804
|
To_Ruby() = default;
|
|
744
805
|
|
|
745
|
-
explicit To_Ruby(
|
|
806
|
+
explicit To_Ruby(Arg* arg) : arg_(arg)
|
|
746
807
|
{
|
|
747
808
|
}
|
|
748
809
|
|
|
@@ -759,7 +820,7 @@ namespace Rice::detail
|
|
|
759
820
|
}
|
|
760
821
|
|
|
761
822
|
private:
|
|
762
|
-
|
|
823
|
+
Arg* arg_ = nullptr;
|
|
763
824
|
};
|
|
764
825
|
|
|
765
826
|
template<typename T>
|
|
@@ -768,11 +829,11 @@ namespace Rice::detail
|
|
|
768
829
|
public:
|
|
769
830
|
From_Ruby() = default;
|
|
770
831
|
|
|
771
|
-
explicit From_Ruby(Arg* arg)
|
|
832
|
+
explicit From_Ruby(Arg* arg) : arg_(arg)
|
|
772
833
|
{
|
|
773
834
|
}
|
|
774
835
|
|
|
775
|
-
|
|
836
|
+
double is_convertible(VALUE value)
|
|
776
837
|
{
|
|
777
838
|
switch (rb_type(value))
|
|
778
839
|
{
|
|
@@ -795,6 +856,9 @@ namespace Rice::detail
|
|
|
795
856
|
return From_Ruby<T>().convert(value);
|
|
796
857
|
}
|
|
797
858
|
}
|
|
859
|
+
|
|
860
|
+
private:
|
|
861
|
+
Arg* arg_ = nullptr;
|
|
798
862
|
};
|
|
799
863
|
|
|
800
864
|
template<typename T>
|
|
@@ -803,11 +867,11 @@ namespace Rice::detail
|
|
|
803
867
|
public:
|
|
804
868
|
From_Ruby() = default;
|
|
805
869
|
|
|
806
|
-
explicit From_Ruby(Arg* arg)
|
|
870
|
+
explicit From_Ruby(Arg* arg) : arg_(arg)
|
|
807
871
|
{
|
|
808
872
|
}
|
|
809
873
|
|
|
810
|
-
|
|
874
|
+
double is_convertible(VALUE value)
|
|
811
875
|
{
|
|
812
876
|
switch (rb_type(value))
|
|
813
877
|
{
|
|
@@ -832,6 +896,7 @@ namespace Rice::detail
|
|
|
832
896
|
return this->converted_;
|
|
833
897
|
}
|
|
834
898
|
private:
|
|
899
|
+
Arg* arg_ = nullptr;
|
|
835
900
|
std::optional<T> converted_;
|
|
836
901
|
};
|
|
837
902
|
}
|
|
@@ -866,7 +931,7 @@ namespace Rice::detail
|
|
|
866
931
|
public:
|
|
867
932
|
To_Ruby() = default;
|
|
868
933
|
|
|
869
|
-
explicit To_Ruby(
|
|
934
|
+
explicit To_Ruby(Arg* arg) : arg_(arg)
|
|
870
935
|
{
|
|
871
936
|
}
|
|
872
937
|
|
|
@@ -876,7 +941,7 @@ namespace Rice::detail
|
|
|
876
941
|
}
|
|
877
942
|
|
|
878
943
|
private:
|
|
879
|
-
|
|
944
|
+
Arg* arg_ = nullptr;
|
|
880
945
|
};
|
|
881
946
|
|
|
882
947
|
template<typename T>
|
|
@@ -885,11 +950,11 @@ namespace Rice::detail
|
|
|
885
950
|
public:
|
|
886
951
|
From_Ruby() = default;
|
|
887
952
|
|
|
888
|
-
explicit From_Ruby(Arg* arg)
|
|
953
|
+
explicit From_Ruby(Arg* arg) : arg_(arg)
|
|
889
954
|
{
|
|
890
955
|
}
|
|
891
956
|
|
|
892
|
-
|
|
957
|
+
double is_convertible(VALUE value)
|
|
893
958
|
{
|
|
894
959
|
return this->converter_.is_convertible(value);
|
|
895
960
|
}
|
|
@@ -900,6 +965,7 @@ namespace Rice::detail
|
|
|
900
965
|
}
|
|
901
966
|
|
|
902
967
|
private:
|
|
968
|
+
Arg* arg_ = nullptr;
|
|
903
969
|
From_Ruby<T&> converter_;
|
|
904
970
|
};
|
|
905
971
|
}
|
|
@@ -979,11 +1045,11 @@ namespace Rice
|
|
|
979
1045
|
}
|
|
980
1046
|
else
|
|
981
1047
|
{
|
|
982
|
-
klass_.define_method("to_s", [](const T&
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
1048
|
+
klass_.define_method("to_s", [](const T&)
|
|
1049
|
+
{
|
|
1050
|
+
return "[Not printable]";
|
|
1051
|
+
});
|
|
1052
|
+
}
|
|
987
1053
|
}
|
|
988
1054
|
|
|
989
1055
|
private:
|
|
@@ -1157,20 +1223,25 @@ namespace Rice
|
|
|
1157
1223
|
{
|
|
1158
1224
|
if constexpr (detail::is_comparable_v<Mapped_T>)
|
|
1159
1225
|
{
|
|
1160
|
-
klass_.define_method("
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1226
|
+
klass_.define_method("==", [](T& map, T& other)->bool
|
|
1227
|
+
{
|
|
1228
|
+
return map == other;
|
|
1229
|
+
})
|
|
1230
|
+
.define_method("value?", [](T& map, Mapped_T& value) -> bool
|
|
1231
|
+
{
|
|
1232
|
+
auto it = std::find_if(map.begin(), map.end(),
|
|
1233
|
+
[&value](auto& pair)
|
|
1234
|
+
{
|
|
1235
|
+
return pair.second == value;
|
|
1236
|
+
});
|
|
1167
1237
|
|
|
1168
|
-
|
|
1238
|
+
return it != map.end();
|
|
1169
1239
|
});
|
|
1240
|
+
rb_define_alias(klass_, "eql?", "==");
|
|
1170
1241
|
}
|
|
1171
1242
|
else
|
|
1172
1243
|
{
|
|
1173
|
-
klass_.define_method("value?", [](T
|
|
1244
|
+
klass_.define_method("value?", [](T&, Mapped_T&) -> bool
|
|
1174
1245
|
{
|
|
1175
1246
|
return false;
|
|
1176
1247
|
});
|
|
@@ -1255,10 +1326,10 @@ namespace Rice
|
|
|
1255
1326
|
}
|
|
1256
1327
|
else
|
|
1257
1328
|
{
|
|
1258
|
-
klass_.define_method("to_s", [](const T&
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1329
|
+
klass_.define_method("to_s", [](const T&)
|
|
1330
|
+
{
|
|
1331
|
+
return "[Not printable]";
|
|
1332
|
+
});
|
|
1262
1333
|
}
|
|
1263
1334
|
}
|
|
1264
1335
|
|
|
@@ -1349,7 +1420,7 @@ namespace Rice
|
|
|
1349
1420
|
{
|
|
1350
1421
|
}
|
|
1351
1422
|
|
|
1352
|
-
|
|
1423
|
+
double is_convertible(VALUE value)
|
|
1353
1424
|
{
|
|
1354
1425
|
switch (rb_type(value))
|
|
1355
1426
|
{
|
|
@@ -1357,7 +1428,7 @@ namespace Rice
|
|
|
1357
1428
|
return Data_Type<std::map<T, U>>::is_descendant(value) ? Convertible::Exact : Convertible::None;
|
|
1358
1429
|
break;
|
|
1359
1430
|
case RUBY_T_HASH:
|
|
1360
|
-
return Convertible::
|
|
1431
|
+
return Convertible::Exact;
|
|
1361
1432
|
break;
|
|
1362
1433
|
default:
|
|
1363
1434
|
return Convertible::None;
|
|
@@ -1383,7 +1454,7 @@ namespace Rice
|
|
|
1383
1454
|
}
|
|
1384
1455
|
default:
|
|
1385
1456
|
{
|
|
1386
|
-
throw Exception(rb_eTypeError, "wrong argument type %s (expected %
|
|
1457
|
+
throw Exception(rb_eTypeError, "wrong argument type %s (expected %s)",
|
|
1387
1458
|
detail::protect(rb_obj_classname, value), "std::map");
|
|
1388
1459
|
}
|
|
1389
1460
|
}
|
|
@@ -1403,7 +1474,7 @@ namespace Rice
|
|
|
1403
1474
|
{
|
|
1404
1475
|
}
|
|
1405
1476
|
|
|
1406
|
-
|
|
1477
|
+
double is_convertible(VALUE value)
|
|
1407
1478
|
{
|
|
1408
1479
|
switch (rb_type(value))
|
|
1409
1480
|
{
|
|
@@ -1411,7 +1482,7 @@ namespace Rice
|
|
|
1411
1482
|
return Data_Type<std::map<T, U>>::is_descendant(value) ? Convertible::Exact : Convertible::None;
|
|
1412
1483
|
break;
|
|
1413
1484
|
case RUBY_T_HASH:
|
|
1414
|
-
return Convertible::
|
|
1485
|
+
return Convertible::Exact;
|
|
1415
1486
|
break;
|
|
1416
1487
|
default:
|
|
1417
1488
|
return Convertible::None;
|
|
@@ -1438,7 +1509,7 @@ namespace Rice
|
|
|
1438
1509
|
}
|
|
1439
1510
|
default:
|
|
1440
1511
|
{
|
|
1441
|
-
throw Exception(rb_eTypeError, "wrong argument type %s (expected %
|
|
1512
|
+
throw Exception(rb_eTypeError, "wrong argument type %s (expected %s)",
|
|
1442
1513
|
detail::protect(rb_obj_classname, value), "std::map");
|
|
1443
1514
|
}
|
|
1444
1515
|
}
|
|
@@ -1459,7 +1530,7 @@ namespace Rice
|
|
|
1459
1530
|
{
|
|
1460
1531
|
}
|
|
1461
1532
|
|
|
1462
|
-
|
|
1533
|
+
double is_convertible(VALUE value)
|
|
1463
1534
|
{
|
|
1464
1535
|
switch (rb_type(value))
|
|
1465
1536
|
{
|
|
@@ -1470,7 +1541,7 @@ namespace Rice
|
|
|
1470
1541
|
return Convertible::Exact;
|
|
1471
1542
|
break;
|
|
1472
1543
|
case RUBY_T_HASH:
|
|
1473
|
-
return Convertible::
|
|
1544
|
+
return Convertible::Exact;
|
|
1474
1545
|
break;
|
|
1475
1546
|
default:
|
|
1476
1547
|
return Convertible::None;
|
|
@@ -1497,7 +1568,7 @@ namespace Rice
|
|
|
1497
1568
|
}
|
|
1498
1569
|
default:
|
|
1499
1570
|
{
|
|
1500
|
-
throw Exception(rb_eTypeError, "wrong argument type %s (expected %
|
|
1571
|
+
throw Exception(rb_eTypeError, "wrong argument type %s (expected %s)",
|
|
1501
1572
|
detail::protect(rb_obj_classname, value), "std::map");
|
|
1502
1573
|
}
|
|
1503
1574
|
}
|
|
@@ -1538,18 +1609,18 @@ namespace Rice::detail
|
|
|
1538
1609
|
public:
|
|
1539
1610
|
To_Ruby() = default;
|
|
1540
1611
|
|
|
1541
|
-
explicit To_Ruby(
|
|
1612
|
+
explicit To_Ruby(Arg* arg) : arg_(arg)
|
|
1542
1613
|
{
|
|
1543
1614
|
}
|
|
1544
1615
|
|
|
1545
|
-
VALUE convert(const std::monostate&
|
|
1616
|
+
VALUE convert(const std::monostate&)
|
|
1546
1617
|
{
|
|
1547
1618
|
return Qnil;
|
|
1548
1619
|
}
|
|
1549
1620
|
|
|
1550
1621
|
|
|
1551
1622
|
private:
|
|
1552
|
-
|
|
1623
|
+
Arg* arg_ = nullptr;
|
|
1553
1624
|
};
|
|
1554
1625
|
|
|
1555
1626
|
template<>
|
|
@@ -1558,17 +1629,17 @@ namespace Rice::detail
|
|
|
1558
1629
|
public:
|
|
1559
1630
|
To_Ruby() = default;
|
|
1560
1631
|
|
|
1561
|
-
explicit To_Ruby(
|
|
1632
|
+
explicit To_Ruby(Arg* arg) : arg_(arg)
|
|
1562
1633
|
{
|
|
1563
1634
|
}
|
|
1564
1635
|
|
|
1565
|
-
VALUE convert(const std::monostate&
|
|
1636
|
+
VALUE convert(const std::monostate&)
|
|
1566
1637
|
{
|
|
1567
1638
|
return Qnil;
|
|
1568
1639
|
}
|
|
1569
1640
|
|
|
1570
1641
|
private:
|
|
1571
|
-
|
|
1642
|
+
Arg* arg_ = nullptr;
|
|
1572
1643
|
};
|
|
1573
1644
|
|
|
1574
1645
|
template<>
|
|
@@ -1577,13 +1648,13 @@ namespace Rice::detail
|
|
|
1577
1648
|
public:
|
|
1578
1649
|
From_Ruby() = default;
|
|
1579
1650
|
|
|
1580
|
-
explicit From_Ruby(Arg* arg)
|
|
1651
|
+
explicit From_Ruby(Arg* arg) : arg_(arg)
|
|
1581
1652
|
{
|
|
1582
1653
|
}
|
|
1583
1654
|
|
|
1584
|
-
|
|
1655
|
+
double is_convertible(VALUE value)
|
|
1585
1656
|
{
|
|
1586
|
-
return value == Qnil ?
|
|
1657
|
+
return value == Qnil ? 1.0 : 0.0;
|
|
1587
1658
|
}
|
|
1588
1659
|
|
|
1589
1660
|
std::monostate convert(VALUE value)
|
|
@@ -1597,6 +1668,9 @@ namespace Rice::detail
|
|
|
1597
1668
|
throw std::runtime_error("Can only convert nil values to std::monostate");
|
|
1598
1669
|
}
|
|
1599
1670
|
}
|
|
1671
|
+
|
|
1672
|
+
private:
|
|
1673
|
+
Arg* arg_ = nullptr;
|
|
1600
1674
|
};
|
|
1601
1675
|
|
|
1602
1676
|
template<>
|
|
@@ -1605,13 +1679,13 @@ namespace Rice::detail
|
|
|
1605
1679
|
public:
|
|
1606
1680
|
From_Ruby() = default;
|
|
1607
1681
|
|
|
1608
|
-
explicit From_Ruby(Arg* arg)
|
|
1682
|
+
explicit From_Ruby(Arg* arg) : arg_(arg)
|
|
1609
1683
|
{
|
|
1610
1684
|
}
|
|
1611
1685
|
|
|
1612
|
-
|
|
1686
|
+
double is_convertible(VALUE value)
|
|
1613
1687
|
{
|
|
1614
|
-
return value == Qnil ?
|
|
1688
|
+
return value == Qnil ? 1.0 : 0.0;
|
|
1615
1689
|
}
|
|
1616
1690
|
|
|
1617
1691
|
std::monostate& convert(VALUE value)
|
|
@@ -1627,6 +1701,7 @@ namespace Rice::detail
|
|
|
1627
1701
|
}
|
|
1628
1702
|
|
|
1629
1703
|
private:
|
|
1704
|
+
Arg* arg_ = nullptr;
|
|
1630
1705
|
std::monostate converted_ = std::monostate();
|
|
1631
1706
|
};
|
|
1632
1707
|
}
|
|
@@ -1634,8 +1709,6 @@ namespace Rice::detail
|
|
|
1634
1709
|
|
|
1635
1710
|
// ========= multimap.hpp =========
|
|
1636
1711
|
|
|
1637
|
-
#include <map>
|
|
1638
|
-
|
|
1639
1712
|
namespace Rice
|
|
1640
1713
|
{
|
|
1641
1714
|
template<typename K, typename T>
|
|
@@ -1752,20 +1825,25 @@ namespace Rice
|
|
|
1752
1825
|
{
|
|
1753
1826
|
if constexpr (detail::is_comparable_v<Mapped_T>)
|
|
1754
1827
|
{
|
|
1755
|
-
klass_.define_method("
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1828
|
+
klass_.define_method("==", [](T& multimap, T& other)->bool
|
|
1829
|
+
{
|
|
1830
|
+
return multimap == other;
|
|
1831
|
+
})
|
|
1832
|
+
.define_method("value?", [](T& multimap, Mapped_T& value) -> bool
|
|
1833
|
+
{
|
|
1834
|
+
auto it = std::find_if(multimap.begin(), multimap.end(),
|
|
1835
|
+
[&value](auto& pair)
|
|
1836
|
+
{
|
|
1837
|
+
return pair.second == value;
|
|
1838
|
+
});
|
|
1762
1839
|
|
|
1763
|
-
|
|
1840
|
+
return it != multimap.end();
|
|
1764
1841
|
});
|
|
1842
|
+
rb_define_alias(klass_, "eql?", "==");
|
|
1765
1843
|
}
|
|
1766
1844
|
else
|
|
1767
1845
|
{
|
|
1768
|
-
klass_.define_method("value?", [](T
|
|
1846
|
+
klass_.define_method("value?", [](T&, Mapped_T&) -> bool
|
|
1769
1847
|
{
|
|
1770
1848
|
return false;
|
|
1771
1849
|
});
|
|
@@ -1834,10 +1912,10 @@ namespace Rice
|
|
|
1834
1912
|
}
|
|
1835
1913
|
else
|
|
1836
1914
|
{
|
|
1837
|
-
klass_.define_method("to_s", [](const T&
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1915
|
+
klass_.define_method("to_s", [](const T&)
|
|
1916
|
+
{
|
|
1917
|
+
return "[Not printable]";
|
|
1918
|
+
});
|
|
1841
1919
|
}
|
|
1842
1920
|
}
|
|
1843
1921
|
|
|
@@ -1925,7 +2003,7 @@ namespace Rice
|
|
|
1925
2003
|
{
|
|
1926
2004
|
}
|
|
1927
2005
|
|
|
1928
|
-
|
|
2006
|
+
double is_convertible(VALUE value)
|
|
1929
2007
|
{
|
|
1930
2008
|
switch (rb_type(value))
|
|
1931
2009
|
{
|
|
@@ -1933,7 +2011,7 @@ namespace Rice
|
|
|
1933
2011
|
return Data_Type<std::multimap<T, U>>::is_descendant(value) ? Convertible::Exact : Convertible::None;
|
|
1934
2012
|
break;
|
|
1935
2013
|
case RUBY_T_HASH:
|
|
1936
|
-
return Convertible::
|
|
2014
|
+
return Convertible::Exact;
|
|
1937
2015
|
break;
|
|
1938
2016
|
default:
|
|
1939
2017
|
return Convertible::None;
|
|
@@ -1959,7 +2037,7 @@ namespace Rice
|
|
|
1959
2037
|
}
|
|
1960
2038
|
default:
|
|
1961
2039
|
{
|
|
1962
|
-
throw Exception(rb_eTypeError, "wrong argument type %s (expected %
|
|
2040
|
+
throw Exception(rb_eTypeError, "wrong argument type %s (expected %s)",
|
|
1963
2041
|
detail::protect(rb_obj_classname, value), "std::multimap");
|
|
1964
2042
|
}
|
|
1965
2043
|
}
|
|
@@ -1979,7 +2057,7 @@ namespace Rice
|
|
|
1979
2057
|
{
|
|
1980
2058
|
}
|
|
1981
2059
|
|
|
1982
|
-
|
|
2060
|
+
double is_convertible(VALUE value)
|
|
1983
2061
|
{
|
|
1984
2062
|
switch (rb_type(value))
|
|
1985
2063
|
{
|
|
@@ -1987,7 +2065,7 @@ namespace Rice
|
|
|
1987
2065
|
return Data_Type<std::multimap<T, U>>::is_descendant(value) ? Convertible::Exact : Convertible::None;
|
|
1988
2066
|
break;
|
|
1989
2067
|
case RUBY_T_HASH:
|
|
1990
|
-
return Convertible::
|
|
2068
|
+
return Convertible::Exact;
|
|
1991
2069
|
break;
|
|
1992
2070
|
default:
|
|
1993
2071
|
return Convertible::None;
|
|
@@ -2014,7 +2092,7 @@ namespace Rice
|
|
|
2014
2092
|
}
|
|
2015
2093
|
default:
|
|
2016
2094
|
{
|
|
2017
|
-
throw Exception(rb_eTypeError, "wrong argument type %s (expected %
|
|
2095
|
+
throw Exception(rb_eTypeError, "wrong argument type %s (expected %s)",
|
|
2018
2096
|
detail::protect(rb_obj_classname, value), "std::multimap");
|
|
2019
2097
|
}
|
|
2020
2098
|
}
|
|
@@ -2035,7 +2113,7 @@ namespace Rice
|
|
|
2035
2113
|
{
|
|
2036
2114
|
}
|
|
2037
2115
|
|
|
2038
|
-
|
|
2116
|
+
double is_convertible(VALUE value)
|
|
2039
2117
|
{
|
|
2040
2118
|
switch (rb_type(value))
|
|
2041
2119
|
{
|
|
@@ -2046,7 +2124,7 @@ namespace Rice
|
|
|
2046
2124
|
return Convertible::Exact;
|
|
2047
2125
|
break;
|
|
2048
2126
|
case RUBY_T_HASH:
|
|
2049
|
-
return Convertible::
|
|
2127
|
+
return Convertible::Exact;
|
|
2050
2128
|
break;
|
|
2051
2129
|
default:
|
|
2052
2130
|
return Convertible::None;
|
|
@@ -2073,7 +2151,7 @@ namespace Rice
|
|
|
2073
2151
|
}
|
|
2074
2152
|
default:
|
|
2075
2153
|
{
|
|
2076
|
-
throw Exception(rb_eTypeError, "wrong argument type %s (expected %
|
|
2154
|
+
throw Exception(rb_eTypeError, "wrong argument type %s (expected %s)",
|
|
2077
2155
|
detail::protect(rb_obj_classname, value), "std::multimap");
|
|
2078
2156
|
}
|
|
2079
2157
|
}
|
|
@@ -2315,10 +2393,10 @@ namespace Rice
|
|
|
2315
2393
|
}
|
|
2316
2394
|
else
|
|
2317
2395
|
{
|
|
2318
|
-
klass_.define_method("to_s", [](const T&
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2396
|
+
klass_.define_method("to_s", [](const T&)
|
|
2397
|
+
{
|
|
2398
|
+
return "[Not printable]";
|
|
2399
|
+
});
|
|
2322
2400
|
}
|
|
2323
2401
|
}
|
|
2324
2402
|
|
|
@@ -2405,7 +2483,7 @@ namespace Rice
|
|
|
2405
2483
|
{
|
|
2406
2484
|
}
|
|
2407
2485
|
|
|
2408
|
-
|
|
2486
|
+
double is_convertible(VALUE value)
|
|
2409
2487
|
{
|
|
2410
2488
|
switch (rb_type(value))
|
|
2411
2489
|
{
|
|
@@ -2417,7 +2495,7 @@ namespace Rice
|
|
|
2417
2495
|
Object object(value);
|
|
2418
2496
|
if (object.class_name().str() == setName)
|
|
2419
2497
|
{
|
|
2420
|
-
return Convertible::
|
|
2498
|
+
return Convertible::Exact;
|
|
2421
2499
|
}
|
|
2422
2500
|
}
|
|
2423
2501
|
default:
|
|
@@ -2441,12 +2519,12 @@ namespace Rice
|
|
|
2441
2519
|
{
|
|
2442
2520
|
return toSet<T>(value);
|
|
2443
2521
|
}
|
|
2444
|
-
throw Exception(rb_eTypeError, "wrong argument type %s (expected %
|
|
2522
|
+
throw Exception(rb_eTypeError, "wrong argument type %s (expected %s)",
|
|
2445
2523
|
detail::protect(rb_obj_classname, value), "std::set");
|
|
2446
2524
|
}
|
|
2447
2525
|
default:
|
|
2448
2526
|
{
|
|
2449
|
-
throw Exception(rb_eTypeError, "wrong argument type %s (expected %
|
|
2527
|
+
throw Exception(rb_eTypeError, "wrong argument type %s (expected %s)",
|
|
2450
2528
|
detail::protect(rb_obj_classname, value), "std::set");
|
|
2451
2529
|
}
|
|
2452
2530
|
}
|
|
@@ -2469,7 +2547,7 @@ namespace Rice
|
|
|
2469
2547
|
{
|
|
2470
2548
|
}
|
|
2471
2549
|
|
|
2472
|
-
|
|
2550
|
+
double is_convertible(VALUE value)
|
|
2473
2551
|
{
|
|
2474
2552
|
switch (rb_type(value))
|
|
2475
2553
|
{
|
|
@@ -2481,7 +2559,7 @@ namespace Rice
|
|
|
2481
2559
|
Object object(value);
|
|
2482
2560
|
if (object.class_name().str() == setName)
|
|
2483
2561
|
{
|
|
2484
|
-
return Convertible::
|
|
2562
|
+
return Convertible::Exact;
|
|
2485
2563
|
}
|
|
2486
2564
|
}
|
|
2487
2565
|
default:
|
|
@@ -2510,12 +2588,12 @@ namespace Rice
|
|
|
2510
2588
|
return this->converted_;
|
|
2511
2589
|
}
|
|
2512
2590
|
}
|
|
2513
|
-
throw Exception(rb_eTypeError, "wrong argument type %s (expected %
|
|
2591
|
+
throw Exception(rb_eTypeError, "wrong argument type %s (expected %s)",
|
|
2514
2592
|
detail::protect(rb_obj_classname, value), "std::set");
|
|
2515
2593
|
}
|
|
2516
2594
|
default:
|
|
2517
2595
|
{
|
|
2518
|
-
throw Exception(rb_eTypeError, "wrong argument type %s (expected %
|
|
2596
|
+
throw Exception(rb_eTypeError, "wrong argument type %s (expected %s)",
|
|
2519
2597
|
detail::protect(rb_obj_classname, value), "std::set");
|
|
2520
2598
|
}
|
|
2521
2599
|
}
|
|
@@ -2538,7 +2616,7 @@ namespace Rice
|
|
|
2538
2616
|
{
|
|
2539
2617
|
}
|
|
2540
2618
|
|
|
2541
|
-
|
|
2619
|
+
double is_convertible(VALUE value)
|
|
2542
2620
|
{
|
|
2543
2621
|
switch (rb_type(value))
|
|
2544
2622
|
{
|
|
@@ -2553,7 +2631,7 @@ namespace Rice
|
|
|
2553
2631
|
Object object(value);
|
|
2554
2632
|
if (object.class_name().str() == setName)
|
|
2555
2633
|
{
|
|
2556
|
-
return Convertible::
|
|
2634
|
+
return Convertible::Exact;
|
|
2557
2635
|
}
|
|
2558
2636
|
}
|
|
2559
2637
|
default:
|
|
@@ -2582,12 +2660,12 @@ namespace Rice
|
|
|
2582
2660
|
return &this->converted_;
|
|
2583
2661
|
}
|
|
2584
2662
|
}
|
|
2585
|
-
throw Exception(rb_eTypeError, "wrong argument type %s (expected %
|
|
2663
|
+
throw Exception(rb_eTypeError, "wrong argument type %s (expected %s)",
|
|
2586
2664
|
detail::protect(rb_obj_classname, value), "std::set");
|
|
2587
2665
|
}
|
|
2588
2666
|
default:
|
|
2589
2667
|
{
|
|
2590
|
-
throw Exception(rb_eTypeError, "wrong argument type %s (expected %
|
|
2668
|
+
throw Exception(rb_eTypeError, "wrong argument type %s (expected %s)",
|
|
2591
2669
|
detail::protect(rb_obj_classname, value), "std::set");
|
|
2592
2670
|
}
|
|
2593
2671
|
}
|
|
@@ -2603,22 +2681,6 @@ namespace Rice
|
|
|
2603
2681
|
|
|
2604
2682
|
// ========= shared_ptr.hpp =========
|
|
2605
2683
|
|
|
2606
|
-
namespace Rice::detail
|
|
2607
|
-
{
|
|
2608
|
-
template<typename T>
|
|
2609
|
-
class Wrapper<std::shared_ptr<T>> : public WrapperBase
|
|
2610
|
-
{
|
|
2611
|
-
public:
|
|
2612
|
-
Wrapper(const std::shared_ptr<T>& data);
|
|
2613
|
-
~Wrapper();
|
|
2614
|
-
void* get() override;
|
|
2615
|
-
std::shared_ptr<T>& data();
|
|
2616
|
-
|
|
2617
|
-
private:
|
|
2618
|
-
std::shared_ptr<T> data_;
|
|
2619
|
-
};
|
|
2620
|
-
}
|
|
2621
|
-
|
|
2622
2684
|
namespace Rice
|
|
2623
2685
|
{
|
|
2624
2686
|
template<typename T>
|
|
@@ -2651,38 +2713,22 @@ namespace Rice
|
|
|
2651
2713
|
}
|
|
2652
2714
|
|
|
2653
2715
|
Identifier id(klassName);
|
|
2654
|
-
Data_Type_T result = define_class_under<
|
|
2655
|
-
define_constructor(Constructor<SharedPtr_T, typename SharedPtr_T::element_type*>(), Arg("value").takeOwnership());
|
|
2716
|
+
Data_Type_T result = define_class_under<SharedPtr_T>(rb_mStd, id);
|
|
2656
2717
|
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
template<typename T>
|
|
2665
|
-
inline Wrapper<std::shared_ptr<T>>::Wrapper(const std::shared_ptr<T>& data)
|
|
2666
|
-
: data_(data)
|
|
2667
|
-
{
|
|
2668
|
-
}
|
|
2669
|
-
|
|
2670
|
-
template<typename T>
|
|
2671
|
-
inline Wrapper<std::shared_ptr<T>>::~Wrapper()
|
|
2672
|
-
{
|
|
2673
|
-
Registries::instance.instances.remove(this->get());
|
|
2674
|
-
}
|
|
2718
|
+
// std::shared_ptr<void> cannot be constructed from void* because void is incomplete
|
|
2719
|
+
// and the deleter cannot be determined. So skip the constructor for void.
|
|
2720
|
+
// std::shared_ptr<T[]> (array types) also skip constructor - arrays need special handling.
|
|
2721
|
+
if constexpr (!std::is_void_v<T> && !std::is_array_v<T>)
|
|
2722
|
+
{
|
|
2723
|
+
result.define_constructor(Constructor<SharedPtr_T, typename SharedPtr_T::element_type*>(), Arg("value").takeOwnership());
|
|
2724
|
+
}
|
|
2675
2725
|
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
}
|
|
2726
|
+
result.
|
|
2727
|
+
define_method("get", &SharedPtr_T::get).
|
|
2728
|
+
define_method("use_count", &SharedPtr_T::use_count).
|
|
2729
|
+
define_method("empty?", &SharedPtr_T::operator bool);
|
|
2681
2730
|
|
|
2682
|
-
|
|
2683
|
-
inline std::shared_ptr<T>& Wrapper<std::shared_ptr<T>>::data()
|
|
2684
|
-
{
|
|
2685
|
-
return data_;
|
|
2731
|
+
return result;
|
|
2686
2732
|
}
|
|
2687
2733
|
}
|
|
2688
2734
|
|
|
@@ -2696,186 +2742,46 @@ namespace Rice::detail
|
|
|
2696
2742
|
{
|
|
2697
2743
|
if constexpr (std::is_fundamental_v<T>)
|
|
2698
2744
|
{
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
}
|
|
2702
|
-
else
|
|
2703
|
-
{
|
|
2704
|
-
return Type<T>::verify();
|
|
2705
|
-
}
|
|
2706
|
-
}
|
|
2707
|
-
|
|
2708
|
-
static VALUE rubyKlass()
|
|
2709
|
-
{
|
|
2710
|
-
if (Data_Type<std::shared_ptr<T>>::is_defined())
|
|
2711
|
-
{
|
|
2712
|
-
std::pair<VALUE, rb_data_type_t*> pair = Registries::instance.types.getType<std::shared_ptr<T>>();
|
|
2713
|
-
return pair.first;
|
|
2745
|
+
Type<Pointer<T>>::verify();
|
|
2746
|
+
Type<Buffer<T>>::verify();
|
|
2714
2747
|
}
|
|
2715
2748
|
else
|
|
2716
2749
|
{
|
|
2717
|
-
|
|
2718
|
-
|
|
2750
|
+
if (!Type<intrinsic_type<T>>::verify())
|
|
2751
|
+
{
|
|
2752
|
+
return false;
|
|
2753
|
+
}
|
|
2719
2754
|
}
|
|
2720
|
-
}
|
|
2721
|
-
};
|
|
2722
|
-
|
|
2723
|
-
template <typename T>
|
|
2724
|
-
class To_Ruby<std::shared_ptr<T>>
|
|
2725
|
-
{
|
|
2726
|
-
public:
|
|
2727
|
-
To_Ruby() = default;
|
|
2728
2755
|
|
|
2729
|
-
|
|
2730
|
-
{
|
|
2731
|
-
}
|
|
2732
|
-
|
|
2733
|
-
VALUE convert(std::shared_ptr<T>& data)
|
|
2734
|
-
{
|
|
2735
|
-
if constexpr (std::is_fundamental_v<T>)
|
|
2736
|
-
{
|
|
2737
|
-
return detail::wrap<std::shared_ptr<T>>(Data_Type<Pointer<T>>::klass(), Data_Type<Pointer<T>>::ruby_data_type(), data, true);
|
|
2738
|
-
}
|
|
2739
|
-
else
|
|
2740
|
-
{
|
|
2741
|
-
return detail::wrap<std::shared_ptr<T>>(Data_Type<T>::klass(), Data_Type<T>::ruby_data_type(), data, true);
|
|
2742
|
-
}
|
|
2743
|
-
}
|
|
2756
|
+
define_shared_ptr<T>();
|
|
2744
2757
|
|
|
2745
|
-
|
|
2746
|
-
{
|
|
2747
|
-
if constexpr (std::is_fundamental_v<T>)
|
|
2748
|
-
{
|
|
2749
|
-
return detail::wrap<std::shared_ptr<T>>(Data_Type<Pointer<T>>::klass(), Data_Type<Pointer<T>>::ruby_data_type(), data, true);
|
|
2750
|
-
}
|
|
2751
|
-
else
|
|
2752
|
-
{
|
|
2753
|
-
return detail::wrap<std::shared_ptr<T>>(Data_Type<T>::klass(), Data_Type<T>::ruby_data_type(), data, true);
|
|
2754
|
-
}
|
|
2758
|
+
return true;
|
|
2755
2759
|
}
|
|
2756
2760
|
};
|
|
2757
2761
|
|
|
2758
|
-
|
|
2759
|
-
|
|
2762
|
+
// Specialization for array types std::shared_ptr<T[]>
|
|
2763
|
+
template<typename T>
|
|
2764
|
+
struct Type<std::shared_ptr<T[]>>
|
|
2760
2765
|
{
|
|
2761
|
-
|
|
2762
|
-
From_Ruby() = default;
|
|
2763
|
-
|
|
2764
|
-
explicit From_Ruby(Arg * arg) : arg_(arg)
|
|
2765
|
-
{
|
|
2766
|
-
}
|
|
2767
|
-
|
|
2768
|
-
Convertible is_convertible(VALUE value)
|
|
2769
|
-
{
|
|
2770
|
-
switch (rb_type(value))
|
|
2771
|
-
{
|
|
2772
|
-
case RUBY_T_DATA:
|
|
2773
|
-
return Convertible::Exact;
|
|
2774
|
-
break;
|
|
2775
|
-
default:
|
|
2776
|
-
return Convertible::None;
|
|
2777
|
-
}
|
|
2778
|
-
}
|
|
2779
|
-
|
|
2780
|
-
std::shared_ptr<T> convert(VALUE value)
|
|
2766
|
+
static bool verify()
|
|
2781
2767
|
{
|
|
2782
|
-
|
|
2783
|
-
WrapperBase* wrapperBase = detail::getWrapper(value);
|
|
2784
|
-
|
|
2785
|
-
// Was this shared_ptr created by the user from Ruby? If so it will
|
|
2786
|
-
// be wrapped as a pointer, std::shared_ptr<T>*. In the case just
|
|
2787
|
-
// return the shared pointer
|
|
2788
|
-
if (dynamic_cast<Wrapper<std::shared_ptr<T>*>*>(wrapperBase))
|
|
2789
|
-
{
|
|
2790
|
-
// Use unwrap to validate the underlying wrapper is the correct type
|
|
2791
|
-
std::shared_ptr<T>* ptr = unwrap<std::shared_ptr<T>>(value, Data_Type<std::shared_ptr<T>>::ruby_data_type(), false);
|
|
2792
|
-
return *ptr;
|
|
2793
|
-
}
|
|
2794
|
-
else if (std::is_fundamental_v<T>)
|
|
2768
|
+
if constexpr (std::is_fundamental_v<T>)
|
|
2795
2769
|
{
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
return wrapper->data();
|
|
2770
|
+
Type<Pointer<T>>::verify();
|
|
2771
|
+
Type<Buffer<T>>::verify();
|
|
2799
2772
|
}
|
|
2800
2773
|
else
|
|
2801
2774
|
{
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
}
|
|
2807
|
-
private:
|
|
2808
|
-
Arg* arg_ = nullptr;
|
|
2809
|
-
};
|
|
2810
|
-
|
|
2811
|
-
template <typename T>
|
|
2812
|
-
class To_Ruby<std::shared_ptr<T>&>
|
|
2813
|
-
{
|
|
2814
|
-
public:
|
|
2815
|
-
To_Ruby() = default;
|
|
2816
|
-
|
|
2817
|
-
explicit To_Ruby(Arg* arg)
|
|
2818
|
-
{
|
|
2819
|
-
}
|
|
2820
|
-
|
|
2821
|
-
VALUE convert(std::shared_ptr<T>& data)
|
|
2822
|
-
{
|
|
2823
|
-
return detail::wrap(Data_Type<T>::klass(), Data_Type<T>::ruby_data_type(), data, true);
|
|
2824
|
-
}
|
|
2825
|
-
};
|
|
2826
|
-
|
|
2827
|
-
template <typename T>
|
|
2828
|
-
class From_Ruby<std::shared_ptr<T>&>
|
|
2829
|
-
{
|
|
2830
|
-
public:
|
|
2831
|
-
From_Ruby() = default;
|
|
2832
|
-
|
|
2833
|
-
explicit From_Ruby(Arg * arg) : arg_(arg)
|
|
2834
|
-
{
|
|
2835
|
-
}
|
|
2836
|
-
|
|
2837
|
-
Convertible is_convertible(VALUE value)
|
|
2838
|
-
{
|
|
2839
|
-
switch (rb_type(value))
|
|
2840
|
-
{
|
|
2841
|
-
case RUBY_T_DATA:
|
|
2842
|
-
return Convertible::Exact;
|
|
2843
|
-
break;
|
|
2844
|
-
default:
|
|
2845
|
-
return Convertible::None;
|
|
2775
|
+
if (!Type<intrinsic_type<T>>::verify())
|
|
2776
|
+
{
|
|
2777
|
+
return false;
|
|
2778
|
+
}
|
|
2846
2779
|
}
|
|
2847
|
-
}
|
|
2848
2780
|
|
|
2849
|
-
|
|
2850
|
-
{
|
|
2851
|
-
// Get the wrapper
|
|
2852
|
-
WrapperBase* wrapperBase = detail::getWrapper(value);
|
|
2781
|
+
define_shared_ptr<T[]>();
|
|
2853
2782
|
|
|
2854
|
-
|
|
2855
|
-
// be wrapped as a pointer, std::shared_ptr<T>*. In the case just
|
|
2856
|
-
// return the shared pointer
|
|
2857
|
-
if (dynamic_cast<Wrapper<std::shared_ptr<T>*>*>(wrapperBase))
|
|
2858
|
-
{
|
|
2859
|
-
// Use unwrap to validate the underlying wrapper is the correct type
|
|
2860
|
-
std::shared_ptr<T>* ptr = unwrap<std::shared_ptr<T>>(value, Data_Type<std::shared_ptr<T>>::ruby_data_type(), false);
|
|
2861
|
-
return *ptr;
|
|
2862
|
-
}
|
|
2863
|
-
else if (std::is_fundamental_v<T>)
|
|
2864
|
-
{
|
|
2865
|
-
// Get the wrapper again to validate T's type
|
|
2866
|
-
Wrapper<std::shared_ptr<T>>* wrapper = getWrapper<Wrapper<std::shared_ptr<T>>>(value, Data_Type<Pointer<T>>::ruby_data_type());
|
|
2867
|
-
return wrapper->data();
|
|
2868
|
-
}
|
|
2869
|
-
else
|
|
2870
|
-
{
|
|
2871
|
-
// Get the wrapper again to validate T's type
|
|
2872
|
-
Wrapper<std::shared_ptr<T>>* wrapper = getWrapper<Wrapper<std::shared_ptr<T>>>(value, Data_Type<T>::ruby_data_type());
|
|
2873
|
-
return wrapper->data();
|
|
2874
|
-
}
|
|
2783
|
+
return true;
|
|
2875
2784
|
}
|
|
2876
|
-
|
|
2877
|
-
private:
|
|
2878
|
-
Arg* arg_ = nullptr;
|
|
2879
2785
|
};
|
|
2880
2786
|
}
|
|
2881
2787
|
|
|
@@ -2894,7 +2800,7 @@ namespace Rice::detail
|
|
|
2894
2800
|
using Tuple_T = std::tuple<Types...>;
|
|
2895
2801
|
|
|
2896
2802
|
template<std::size_t... I>
|
|
2897
|
-
constexpr static bool verifyTypes(std::index_sequence<I...>&
|
|
2803
|
+
constexpr static bool verifyTypes(std::index_sequence<I...>&)
|
|
2898
2804
|
{
|
|
2899
2805
|
return (Type<std::tuple_element_t<I, Tuple_T>>::verify() && ...);
|
|
2900
2806
|
}
|
|
@@ -2918,7 +2824,7 @@ namespace Rice::detail
|
|
|
2918
2824
|
public:
|
|
2919
2825
|
To_Ruby() = default;
|
|
2920
2826
|
|
|
2921
|
-
explicit To_Ruby(
|
|
2827
|
+
explicit To_Ruby(Arg* arg) : arg_(arg)
|
|
2922
2828
|
{
|
|
2923
2829
|
}
|
|
2924
2830
|
|
|
@@ -2935,7 +2841,7 @@ namespace Rice::detail
|
|
|
2935
2841
|
}
|
|
2936
2842
|
|
|
2937
2843
|
private:
|
|
2938
|
-
|
|
2844
|
+
Arg* arg_ = nullptr;
|
|
2939
2845
|
};
|
|
2940
2846
|
|
|
2941
2847
|
template<typename...Types>
|
|
@@ -2944,7 +2850,7 @@ namespace Rice::detail
|
|
|
2944
2850
|
public:
|
|
2945
2851
|
To_Ruby() = default;
|
|
2946
2852
|
|
|
2947
|
-
explicit To_Ruby(
|
|
2853
|
+
explicit To_Ruby(Arg* arg) : arg_(arg)
|
|
2948
2854
|
{
|
|
2949
2855
|
}
|
|
2950
2856
|
|
|
@@ -2952,7 +2858,7 @@ namespace Rice::detail
|
|
|
2952
2858
|
{
|
|
2953
2859
|
Array result;
|
|
2954
2860
|
|
|
2955
|
-
bool isOwner = (this->
|
|
2861
|
+
bool isOwner = (this->arg_ && this->arg_->isOwner());
|
|
2956
2862
|
|
|
2957
2863
|
for_each_tuple(data, [&](auto& element)
|
|
2958
2864
|
{
|
|
@@ -2963,7 +2869,7 @@ namespace Rice::detail
|
|
|
2963
2869
|
}
|
|
2964
2870
|
|
|
2965
2871
|
private:
|
|
2966
|
-
|
|
2872
|
+
Arg* arg_ = nullptr;
|
|
2967
2873
|
};
|
|
2968
2874
|
|
|
2969
2875
|
template<typename...Types>
|
|
@@ -2972,35 +2878,28 @@ namespace Rice::detail
|
|
|
2972
2878
|
public:
|
|
2973
2879
|
using Tuple_T = std::tuple<Types...>;
|
|
2974
2880
|
|
|
2975
|
-
template<std::size_t... I>
|
|
2976
|
-
constexpr static bool verifyTypes(Array& array, std::index_sequence<I...>& indices)
|
|
2977
|
-
{
|
|
2978
|
-
return (Type<std::tuple_element_t<I, Tuple_T>>::verify() && ...);
|
|
2979
|
-
}
|
|
2980
|
-
|
|
2981
2881
|
From_Ruby() = default;
|
|
2982
2882
|
|
|
2983
|
-
explicit From_Ruby(Arg* arg)
|
|
2883
|
+
explicit From_Ruby(Arg* arg) : arg_(arg)
|
|
2984
2884
|
{
|
|
2985
2885
|
}
|
|
2986
2886
|
|
|
2987
|
-
|
|
2887
|
+
double is_convertible(VALUE value)
|
|
2988
2888
|
{
|
|
2989
|
-
Convertible result = Convertible::None;
|
|
2990
|
-
|
|
2991
2889
|
// The ruby value must be an array of the correct size
|
|
2992
2890
|
if (rb_type(value) != RUBY_T_ARRAY || Array(value).size() != std::tuple_size_v<Tuple_T>)
|
|
2993
2891
|
{
|
|
2994
|
-
return
|
|
2892
|
+
return Convertible::None;
|
|
2995
2893
|
}
|
|
2996
|
-
|
|
2997
|
-
// Now check that each tuple type is convertible
|
|
2894
|
+
|
|
2895
|
+
// Now check that each tuple type is convertible - use minimum score
|
|
2896
|
+
double result = Convertible::Exact;
|
|
2998
2897
|
Array array(value);
|
|
2999
2898
|
int i = 0;
|
|
3000
2899
|
for_each_tuple(this->fromRubys_,
|
|
3001
2900
|
[&](auto& fromRuby)
|
|
3002
2901
|
{
|
|
3003
|
-
result = result
|
|
2902
|
+
result = (std::min)(result, fromRuby.is_convertible(array[i].value()));
|
|
3004
2903
|
i++;
|
|
3005
2904
|
});
|
|
3006
2905
|
|
|
@@ -3008,7 +2907,7 @@ namespace Rice::detail
|
|
|
3008
2907
|
}
|
|
3009
2908
|
|
|
3010
2909
|
template <std::size_t... I>
|
|
3011
|
-
std::tuple<Types...> convertInternal(Array array, std::index_sequence<I...>&
|
|
2910
|
+
std::tuple<Types...> convertInternal(Array array, std::index_sequence<I...>&)
|
|
3012
2911
|
{
|
|
3013
2912
|
return std::forward_as_tuple(std::get<I>(this->fromRubys_).convert(array[I].value())...);
|
|
3014
2913
|
}
|
|
@@ -3021,25 +2920,11 @@ namespace Rice::detail
|
|
|
3021
2920
|
}
|
|
3022
2921
|
|
|
3023
2922
|
private:
|
|
2923
|
+
Arg* arg_ = nullptr;
|
|
3024
2924
|
// Possible converters we could use for this variant
|
|
3025
2925
|
using From_Ruby_Ts = std::tuple<From_Ruby<Types>...>;
|
|
3026
2926
|
From_Ruby_Ts fromRubys_;
|
|
3027
2927
|
};
|
|
3028
|
-
|
|
3029
|
-
/* template<typename...Types>
|
|
3030
|
-
class From_Ruby<std::tuple<Types...>&> : public From_Ruby<std::tuple<Types...>>
|
|
3031
|
-
{
|
|
3032
|
-
public:
|
|
3033
|
-
std::tuple<Types...>& convert(VALUE value)
|
|
3034
|
-
{
|
|
3035
|
-
int index = this->figureIndex(value);
|
|
3036
|
-
this->converted_ = this->convertInternal(value, index);
|
|
3037
|
-
return this->converted_;
|
|
3038
|
-
}
|
|
3039
|
-
|
|
3040
|
-
private:
|
|
3041
|
-
std::tuple<Types...> converted_;
|
|
3042
|
-
};*/
|
|
3043
2928
|
}
|
|
3044
2929
|
|
|
3045
2930
|
|
|
@@ -3128,7 +3013,7 @@ namespace Rice::detail
|
|
|
3128
3013
|
using Tuple_T = std::tuple<Types...>;
|
|
3129
3014
|
|
|
3130
3015
|
template<std::size_t... I>
|
|
3131
|
-
constexpr static bool verifyTypes(std::index_sequence<I...>&
|
|
3016
|
+
constexpr static bool verifyTypes(std::index_sequence<I...>&)
|
|
3132
3017
|
{
|
|
3133
3018
|
return (Type<std::tuple_element_t<I, Tuple_T>>::verify() && ...);
|
|
3134
3019
|
}
|
|
@@ -3152,18 +3037,23 @@ namespace Rice::detail
|
|
|
3152
3037
|
public:
|
|
3153
3038
|
To_Ruby() = default;
|
|
3154
3039
|
|
|
3155
|
-
explicit To_Ruby(
|
|
3040
|
+
explicit To_Ruby(Arg* arg) : arg_(arg)
|
|
3156
3041
|
{
|
|
3157
3042
|
}
|
|
3158
3043
|
|
|
3159
3044
|
template<typename U, typename V>
|
|
3160
3045
|
VALUE convertElement(U& data, bool takeOwnership)
|
|
3161
3046
|
{
|
|
3162
|
-
|
|
3047
|
+
Arg arg("arg1");
|
|
3048
|
+
if (takeOwnership)
|
|
3049
|
+
{
|
|
3050
|
+
arg.takeOwnership();
|
|
3051
|
+
}
|
|
3052
|
+
return To_Ruby<V>(&arg).convert(std::forward<V>(std::get<V>(data)));
|
|
3163
3053
|
}
|
|
3164
3054
|
|
|
3165
3055
|
template<typename U, std::size_t... I>
|
|
3166
|
-
VALUE convertIterator(U& data, bool takeOwnership, std::index_sequence<I...>&
|
|
3056
|
+
VALUE convertIterator(U& data, bool takeOwnership, std::index_sequence<I...>&)
|
|
3167
3057
|
{
|
|
3168
3058
|
// Create a tuple of the variant types so we can look over the tuple's types
|
|
3169
3059
|
using Tuple_T = std::tuple<Types...>;
|
|
@@ -3221,7 +3111,7 @@ namespace Rice::detail
|
|
|
3221
3111
|
}
|
|
3222
3112
|
|
|
3223
3113
|
private:
|
|
3224
|
-
|
|
3114
|
+
Arg* arg_ = nullptr;
|
|
3225
3115
|
};
|
|
3226
3116
|
|
|
3227
3117
|
template<typename...Types>
|
|
@@ -3230,25 +3120,31 @@ namespace Rice::detail
|
|
|
3230
3120
|
public:
|
|
3231
3121
|
To_Ruby() = default;
|
|
3232
3122
|
|
|
3233
|
-
explicit To_Ruby(
|
|
3123
|
+
explicit To_Ruby(Arg* arg) : arg_(arg)
|
|
3234
3124
|
{
|
|
3235
3125
|
}
|
|
3236
3126
|
|
|
3237
3127
|
template<typename U, typename V>
|
|
3238
3128
|
VALUE convertElement(U& data, bool takeOwnership)
|
|
3239
3129
|
{
|
|
3130
|
+
Arg arg("arg1");
|
|
3131
|
+
if (takeOwnership)
|
|
3132
|
+
{
|
|
3133
|
+
arg.takeOwnership();
|
|
3134
|
+
}
|
|
3135
|
+
|
|
3240
3136
|
if constexpr (std::is_const_v<U>)
|
|
3241
3137
|
{
|
|
3242
|
-
return To_Ruby<V>().convert(std::get<V>(data));
|
|
3138
|
+
return To_Ruby<V>(&arg).convert(std::get<V>(data));
|
|
3243
3139
|
}
|
|
3244
3140
|
else
|
|
3245
3141
|
{
|
|
3246
|
-
return To_Ruby<V>().convert(std::forward<V>(std::get<V>(data)));
|
|
3142
|
+
return To_Ruby<V>(&arg).convert(std::forward<V>(std::get<V>(data)));
|
|
3247
3143
|
}
|
|
3248
3144
|
}
|
|
3249
3145
|
|
|
3250
3146
|
template<typename U, std::size_t... I>
|
|
3251
|
-
VALUE convertIterator(U& data, bool takeOwnership, std::index_sequence<I...>&
|
|
3147
|
+
VALUE convertIterator(U& data, bool takeOwnership, std::index_sequence<I...>&)
|
|
3252
3148
|
{
|
|
3253
3149
|
// Create a tuple of the variant types so we can look over the tuple's types
|
|
3254
3150
|
using Tuple_T = std::tuple<Types...>;
|
|
@@ -3274,13 +3170,13 @@ namespace Rice::detail
|
|
|
3274
3170
|
template<typename U>
|
|
3275
3171
|
VALUE convert(U& data)
|
|
3276
3172
|
{
|
|
3277
|
-
bool isOwner = (this->
|
|
3173
|
+
bool isOwner = (this->arg_ && this->arg_->isOwner());
|
|
3278
3174
|
auto indices = std::make_index_sequence<std::variant_size_v<std::variant<Types...>>>{};
|
|
3279
3175
|
return convertIterator(data, isOwner, indices);
|
|
3280
3176
|
}
|
|
3281
3177
|
|
|
3282
3178
|
private:
|
|
3283
|
-
|
|
3179
|
+
Arg* arg_ = nullptr;
|
|
3284
3180
|
};
|
|
3285
3181
|
|
|
3286
3182
|
template<typename...Types>
|
|
@@ -3289,18 +3185,18 @@ namespace Rice::detail
|
|
|
3289
3185
|
public:
|
|
3290
3186
|
From_Ruby() = default;
|
|
3291
3187
|
|
|
3292
|
-
explicit From_Ruby(Arg* arg)
|
|
3188
|
+
explicit From_Ruby(Arg* arg) : arg_(arg)
|
|
3293
3189
|
{
|
|
3294
3190
|
}
|
|
3295
3191
|
|
|
3296
|
-
|
|
3192
|
+
double is_convertible(VALUE value)
|
|
3297
3193
|
{
|
|
3298
|
-
|
|
3194
|
+
double result = Convertible::None;
|
|
3299
3195
|
|
|
3300
3196
|
for_each_tuple(this->fromRubys_,
|
|
3301
3197
|
[&](auto& fromRuby)
|
|
3302
3198
|
{
|
|
3303
|
-
result = result
|
|
3199
|
+
result = (std::max)(result, fromRuby.is_convertible(value));
|
|
3304
3200
|
});
|
|
3305
3201
|
|
|
3306
3202
|
return result;
|
|
@@ -3312,17 +3208,17 @@ namespace Rice::detail
|
|
|
3312
3208
|
{
|
|
3313
3209
|
int i = 0;
|
|
3314
3210
|
int index = -1;
|
|
3315
|
-
|
|
3211
|
+
double foundScore = Convertible::None;
|
|
3316
3212
|
|
|
3317
3213
|
for_each_tuple(this->fromRubys_,
|
|
3318
3214
|
[&](auto& fromRuby)
|
|
3319
3215
|
{
|
|
3320
|
-
|
|
3216
|
+
double score = fromRuby.is_convertible(value);
|
|
3321
3217
|
|
|
3322
|
-
if (
|
|
3218
|
+
if (score > foundScore)
|
|
3323
3219
|
{
|
|
3324
3220
|
index = i;
|
|
3325
|
-
|
|
3221
|
+
foundScore = score;
|
|
3326
3222
|
}
|
|
3327
3223
|
i++;
|
|
3328
3224
|
});
|
|
@@ -3360,7 +3256,10 @@ namespace Rice::detail
|
|
|
3360
3256
|
return convertInternal<I + 1>(value, index);
|
|
3361
3257
|
}
|
|
3362
3258
|
}
|
|
3363
|
-
|
|
3259
|
+
else
|
|
3260
|
+
{
|
|
3261
|
+
rb_raise(rb_eArgError, "Could not find converter for variant");
|
|
3262
|
+
}
|
|
3364
3263
|
}
|
|
3365
3264
|
|
|
3366
3265
|
std::variant<Types...> convert(VALUE value)
|
|
@@ -3370,6 +3269,7 @@ namespace Rice::detail
|
|
|
3370
3269
|
}
|
|
3371
3270
|
|
|
3372
3271
|
private:
|
|
3272
|
+
Arg* arg_ = nullptr;
|
|
3373
3273
|
// Possible converters we could use for this variant
|
|
3374
3274
|
using From_Ruby_Ts = std::tuple<From_Ruby<Types>...>;
|
|
3375
3275
|
From_Ruby_Ts fromRubys_;
|
|
@@ -3381,7 +3281,7 @@ namespace Rice::detail
|
|
|
3381
3281
|
public:
|
|
3382
3282
|
From_Ruby() = default;
|
|
3383
3283
|
|
|
3384
|
-
explicit From_Ruby(Arg* arg)
|
|
3284
|
+
explicit From_Ruby(Arg* arg) : arg_(arg)
|
|
3385
3285
|
{
|
|
3386
3286
|
}
|
|
3387
3287
|
|
|
@@ -3393,6 +3293,7 @@ namespace Rice::detail
|
|
|
3393
3293
|
}
|
|
3394
3294
|
|
|
3395
3295
|
private:
|
|
3296
|
+
Arg* arg_ = nullptr;
|
|
3396
3297
|
std::variant<Types...> converted_;
|
|
3397
3298
|
};
|
|
3398
3299
|
}
|
|
@@ -3452,7 +3353,7 @@ namespace Rice::detail
|
|
|
3452
3353
|
public:
|
|
3453
3354
|
To_Ruby() = default;
|
|
3454
3355
|
|
|
3455
|
-
explicit To_Ruby(
|
|
3356
|
+
explicit To_Ruby(Arg* arg) : arg_(arg)
|
|
3456
3357
|
{
|
|
3457
3358
|
}
|
|
3458
3359
|
|
|
@@ -3469,7 +3370,7 @@ namespace Rice::detail
|
|
|
3469
3370
|
}
|
|
3470
3371
|
|
|
3471
3372
|
private:
|
|
3472
|
-
|
|
3373
|
+
Arg* arg_ = nullptr;
|
|
3473
3374
|
};
|
|
3474
3375
|
|
|
3475
3376
|
template <typename T>
|
|
@@ -3478,7 +3379,7 @@ namespace Rice::detail
|
|
|
3478
3379
|
public:
|
|
3479
3380
|
To_Ruby() = default;
|
|
3480
3381
|
|
|
3481
|
-
explicit To_Ruby(
|
|
3382
|
+
explicit To_Ruby(Arg* arg) : arg_(arg)
|
|
3482
3383
|
{
|
|
3483
3384
|
}
|
|
3484
3385
|
|
|
@@ -3489,7 +3390,7 @@ namespace Rice::detail
|
|
|
3489
3390
|
}
|
|
3490
3391
|
|
|
3491
3392
|
private:
|
|
3492
|
-
|
|
3393
|
+
Arg* arg_ = nullptr;
|
|
3493
3394
|
};
|
|
3494
3395
|
|
|
3495
3396
|
template <typename T>
|
|
@@ -3504,14 +3405,16 @@ namespace Rice::detail
|
|
|
3504
3405
|
|
|
3505
3406
|
From_Ruby() = default;
|
|
3506
3407
|
|
|
3507
|
-
explicit From_Ruby(Arg* arg)
|
|
3408
|
+
explicit From_Ruby(Arg* arg) : arg_(arg)
|
|
3508
3409
|
{
|
|
3509
3410
|
}
|
|
3510
3411
|
|
|
3511
|
-
|
|
3412
|
+
double is_convertible(VALUE value)
|
|
3512
3413
|
{
|
|
3513
3414
|
if (!is_same_smart_ptr(value))
|
|
3415
|
+
{
|
|
3514
3416
|
return Convertible::None;
|
|
3417
|
+
}
|
|
3515
3418
|
|
|
3516
3419
|
switch (rb_type(value))
|
|
3517
3420
|
{
|
|
@@ -3533,6 +3436,9 @@ namespace Rice::detail
|
|
|
3533
3436
|
}
|
|
3534
3437
|
return std::move(wrapper->data());
|
|
3535
3438
|
}
|
|
3439
|
+
|
|
3440
|
+
private:
|
|
3441
|
+
Arg* arg_ = nullptr;
|
|
3536
3442
|
};
|
|
3537
3443
|
|
|
3538
3444
|
template <typename T>
|
|
@@ -3547,14 +3453,16 @@ namespace Rice::detail
|
|
|
3547
3453
|
|
|
3548
3454
|
From_Ruby() = default;
|
|
3549
3455
|
|
|
3550
|
-
explicit From_Ruby(Arg* arg)
|
|
3456
|
+
explicit From_Ruby(Arg* arg) : arg_(arg)
|
|
3551
3457
|
{
|
|
3552
3458
|
}
|
|
3553
3459
|
|
|
3554
|
-
|
|
3460
|
+
double is_convertible(VALUE value)
|
|
3555
3461
|
{
|
|
3556
3462
|
if (!is_same_smart_ptr(value))
|
|
3463
|
+
{
|
|
3557
3464
|
return Convertible::None;
|
|
3465
|
+
}
|
|
3558
3466
|
|
|
3559
3467
|
switch (rb_type(value))
|
|
3560
3468
|
{
|
|
@@ -3576,6 +3484,9 @@ namespace Rice::detail
|
|
|
3576
3484
|
}
|
|
3577
3485
|
return wrapper->data();
|
|
3578
3486
|
}
|
|
3487
|
+
|
|
3488
|
+
private:
|
|
3489
|
+
Arg* arg_ = nullptr;
|
|
3579
3490
|
};
|
|
3580
3491
|
|
|
3581
3492
|
template<typename T>
|
|
@@ -3722,7 +3633,11 @@ namespace Rice
|
|
|
3722
3633
|
{
|
|
3723
3634
|
if constexpr (detail::is_comparable_v<Mapped_T>)
|
|
3724
3635
|
{
|
|
3725
|
-
klass_.define_method("
|
|
3636
|
+
klass_.define_method("==", [](T& unordered_map, T& other)->bool
|
|
3637
|
+
{
|
|
3638
|
+
return unordered_map == other;
|
|
3639
|
+
})
|
|
3640
|
+
.define_method("value?", [](T& unordered_map, Mapped_T& value) -> bool
|
|
3726
3641
|
{
|
|
3727
3642
|
auto it = std::find_if(unordered_map.begin(), unordered_map.end(),
|
|
3728
3643
|
[&value](auto& pair)
|
|
@@ -3732,10 +3647,11 @@ namespace Rice
|
|
|
3732
3647
|
|
|
3733
3648
|
return it != unordered_map.end();
|
|
3734
3649
|
});
|
|
3650
|
+
rb_define_alias(klass_, "eql?", "==");
|
|
3735
3651
|
}
|
|
3736
3652
|
else
|
|
3737
3653
|
{
|
|
3738
|
-
klass_.define_method("value?", [](T
|
|
3654
|
+
klass_.define_method("value?", [](T&, Mapped_T&) -> bool
|
|
3739
3655
|
{
|
|
3740
3656
|
return false;
|
|
3741
3657
|
});
|
|
@@ -3820,10 +3736,10 @@ namespace Rice
|
|
|
3820
3736
|
}
|
|
3821
3737
|
else
|
|
3822
3738
|
{
|
|
3823
|
-
klass_.define_method("to_s", [](const T&
|
|
3824
|
-
|
|
3825
|
-
|
|
3826
|
-
|
|
3739
|
+
klass_.define_method("to_s", [](const T&)
|
|
3740
|
+
{
|
|
3741
|
+
return "[Not printable]";
|
|
3742
|
+
});
|
|
3827
3743
|
}
|
|
3828
3744
|
}
|
|
3829
3745
|
|
|
@@ -3914,7 +3830,7 @@ namespace Rice
|
|
|
3914
3830
|
{
|
|
3915
3831
|
}
|
|
3916
3832
|
|
|
3917
|
-
|
|
3833
|
+
double is_convertible(VALUE value)
|
|
3918
3834
|
{
|
|
3919
3835
|
switch (rb_type(value))
|
|
3920
3836
|
{
|
|
@@ -3922,7 +3838,7 @@ namespace Rice
|
|
|
3922
3838
|
return Data_Type<std::unordered_map<T, U>>::is_descendant(value) ? Convertible::Exact : Convertible::None;
|
|
3923
3839
|
break;
|
|
3924
3840
|
case RUBY_T_HASH:
|
|
3925
|
-
return Convertible::
|
|
3841
|
+
return Convertible::Exact;
|
|
3926
3842
|
break;
|
|
3927
3843
|
default:
|
|
3928
3844
|
return Convertible::None;
|
|
@@ -3948,7 +3864,7 @@ namespace Rice
|
|
|
3948
3864
|
}
|
|
3949
3865
|
default:
|
|
3950
3866
|
{
|
|
3951
|
-
throw Exception(rb_eTypeError, "wrong argument type %s (expected %
|
|
3867
|
+
throw Exception(rb_eTypeError, "wrong argument type %s (expected %s)",
|
|
3952
3868
|
detail::protect(rb_obj_classname, value), "std::unordered_map");
|
|
3953
3869
|
}
|
|
3954
3870
|
}
|
|
@@ -3968,7 +3884,7 @@ namespace Rice
|
|
|
3968
3884
|
{
|
|
3969
3885
|
}
|
|
3970
3886
|
|
|
3971
|
-
|
|
3887
|
+
double is_convertible(VALUE value)
|
|
3972
3888
|
{
|
|
3973
3889
|
switch (rb_type(value))
|
|
3974
3890
|
{
|
|
@@ -3976,7 +3892,7 @@ namespace Rice
|
|
|
3976
3892
|
return Data_Type<std::unordered_map<T, U>>::is_descendant(value) ? Convertible::Exact : Convertible::None;
|
|
3977
3893
|
break;
|
|
3978
3894
|
case RUBY_T_HASH:
|
|
3979
|
-
return Convertible::
|
|
3895
|
+
return Convertible::Exact;
|
|
3980
3896
|
break;
|
|
3981
3897
|
default:
|
|
3982
3898
|
return Convertible::None;
|
|
@@ -4003,7 +3919,7 @@ namespace Rice
|
|
|
4003
3919
|
}
|
|
4004
3920
|
default:
|
|
4005
3921
|
{
|
|
4006
|
-
throw Exception(rb_eTypeError, "wrong argument type %s (expected %
|
|
3922
|
+
throw Exception(rb_eTypeError, "wrong argument type %s (expected %s)",
|
|
4007
3923
|
detail::protect(rb_obj_classname, value), "std::unordered_map");
|
|
4008
3924
|
}
|
|
4009
3925
|
}
|
|
@@ -4024,7 +3940,7 @@ namespace Rice
|
|
|
4024
3940
|
{
|
|
4025
3941
|
}
|
|
4026
3942
|
|
|
4027
|
-
|
|
3943
|
+
double is_convertible(VALUE value)
|
|
4028
3944
|
{
|
|
4029
3945
|
switch (rb_type(value))
|
|
4030
3946
|
{
|
|
@@ -4035,7 +3951,7 @@ namespace Rice
|
|
|
4035
3951
|
return Convertible::Exact;
|
|
4036
3952
|
break;
|
|
4037
3953
|
case RUBY_T_HASH:
|
|
4038
|
-
return Convertible::
|
|
3954
|
+
return Convertible::Exact;
|
|
4039
3955
|
break;
|
|
4040
3956
|
default:
|
|
4041
3957
|
return Convertible::None;
|
|
@@ -4062,7 +3978,7 @@ namespace Rice
|
|
|
4062
3978
|
}
|
|
4063
3979
|
default:
|
|
4064
3980
|
{
|
|
4065
|
-
throw Exception(rb_eTypeError, "wrong argument type %s (expected %
|
|
3981
|
+
throw Exception(rb_eTypeError, "wrong argument type %s (expected %s)",
|
|
4066
3982
|
detail::protect(rb_obj_classname, value), "std::unordered_map");
|
|
4067
3983
|
}
|
|
4068
3984
|
}
|
|
@@ -4126,7 +4042,7 @@ namespace Rice
|
|
|
4126
4042
|
Difference_T normalizeIndex(Size_T size, Difference_T index, bool enforceBounds = false)
|
|
4127
4043
|
{
|
|
4128
4044
|
// Negative indices mean count from the right
|
|
4129
|
-
if (index < 0 && (-index <= size))
|
|
4045
|
+
if (index < 0 && ((Size_T)(-index) <= size))
|
|
4130
4046
|
{
|
|
4131
4047
|
index = size + index;
|
|
4132
4048
|
}
|
|
@@ -4170,7 +4086,7 @@ namespace Rice
|
|
|
4170
4086
|
}
|
|
4171
4087
|
|
|
4172
4088
|
// Wrap the vector
|
|
4173
|
-
detail::wrapConstructed<T>(self, Data_Type<T>::ruby_data_type(), data
|
|
4089
|
+
detail::wrapConstructed<T>(self, Data_Type<T>::ruby_data_type(), data);
|
|
4174
4090
|
});
|
|
4175
4091
|
}
|
|
4176
4092
|
|
|
@@ -4186,10 +4102,10 @@ namespace Rice
|
|
|
4186
4102
|
}
|
|
4187
4103
|
else
|
|
4188
4104
|
{
|
|
4189
|
-
klass_.define_method("resize", [](const T
|
|
4190
|
-
|
|
4191
|
-
|
|
4192
|
-
|
|
4105
|
+
klass_.define_method("resize", [](const T&, Size_T)
|
|
4106
|
+
{
|
|
4107
|
+
// Do nothing
|
|
4108
|
+
});
|
|
4193
4109
|
}
|
|
4194
4110
|
}
|
|
4195
4111
|
|
|
@@ -4246,7 +4162,7 @@ namespace Rice
|
|
|
4246
4162
|
return vector[index];
|
|
4247
4163
|
}
|
|
4248
4164
|
})
|
|
4249
|
-
.template define_method<Value_T*(T::*)()>("data", &T::data,
|
|
4165
|
+
.template define_method<Value_T*(T::*)()>("data", &T::data, ReturnBuffer());
|
|
4250
4166
|
}
|
|
4251
4167
|
else
|
|
4252
4168
|
{
|
|
@@ -4327,7 +4243,11 @@ namespace Rice
|
|
|
4327
4243
|
{
|
|
4328
4244
|
if constexpr (detail::is_comparable_v<T>)
|
|
4329
4245
|
{
|
|
4330
|
-
klass_.define_method("
|
|
4246
|
+
klass_.define_method("==", [](T& vector, T& other)->bool
|
|
4247
|
+
{
|
|
4248
|
+
return vector == other;
|
|
4249
|
+
})
|
|
4250
|
+
.define_method("delete", [](T& vector, Parameter_T element) -> std::optional<Value_T>
|
|
4331
4251
|
{
|
|
4332
4252
|
auto iter = std::find(vector.begin(), vector.end(), element);
|
|
4333
4253
|
if (iter == vector.end())
|
|
@@ -4361,21 +4281,22 @@ namespace Rice
|
|
|
4361
4281
|
return iter - vector.begin();
|
|
4362
4282
|
}
|
|
4363
4283
|
});
|
|
4284
|
+
rb_define_alias(klass_, "eql?", "==");
|
|
4364
4285
|
}
|
|
4365
4286
|
else
|
|
4366
4287
|
{
|
|
4367
|
-
klass_.define_method("delete", [](T
|
|
4368
|
-
|
|
4369
|
-
|
|
4370
|
-
|
|
4371
|
-
.define_method("include?", [](const T
|
|
4372
|
-
|
|
4373
|
-
|
|
4374
|
-
|
|
4375
|
-
.define_method("index", [](const T
|
|
4376
|
-
|
|
4377
|
-
|
|
4378
|
-
|
|
4288
|
+
klass_.define_method("delete", [](T&, Parameter_T) -> std::optional<Value_T>
|
|
4289
|
+
{
|
|
4290
|
+
return std::nullopt;
|
|
4291
|
+
})
|
|
4292
|
+
.define_method("include?", [](const T&, Parameter_T)
|
|
4293
|
+
{
|
|
4294
|
+
return false;
|
|
4295
|
+
})
|
|
4296
|
+
.define_method("index", [](const T&, Parameter_T) -> std::optional<Difference_T>
|
|
4297
|
+
{
|
|
4298
|
+
return std::nullopt;
|
|
4299
|
+
});
|
|
4379
4300
|
}
|
|
4380
4301
|
}
|
|
4381
4302
|
|
|
@@ -4400,7 +4321,7 @@ namespace Rice
|
|
|
4400
4321
|
})
|
|
4401
4322
|
.define_method("insert", [this](T& vector, Difference_T index, Parameter_T element) -> T&
|
|
4402
4323
|
{
|
|
4403
|
-
|
|
4324
|
+
size_t normalized = normalizeIndex(vector.size(), index, true);
|
|
4404
4325
|
// For a Ruby array a positive index means insert the element before the index. But
|
|
4405
4326
|
// a negative index means insert the element *after* the index. std::vector
|
|
4406
4327
|
// inserts *before* the index. So add 1 if this is a negative index.
|
|
@@ -4499,10 +4420,10 @@ namespace Rice
|
|
|
4499
4420
|
}
|
|
4500
4421
|
else
|
|
4501
4422
|
{
|
|
4502
|
-
klass_.define_method("to_s", [](const T&
|
|
4503
|
-
|
|
4504
|
-
|
|
4505
|
-
|
|
4423
|
+
klass_.define_method("to_s", [](const T&)
|
|
4424
|
+
{
|
|
4425
|
+
return "[Not printable]";
|
|
4426
|
+
});
|
|
4506
4427
|
}
|
|
4507
4428
|
}
|
|
4508
4429
|
|
|
@@ -4564,7 +4485,7 @@ namespace Rice
|
|
|
4564
4485
|
{
|
|
4565
4486
|
}
|
|
4566
4487
|
|
|
4567
|
-
|
|
4488
|
+
double is_convertible(VALUE value)
|
|
4568
4489
|
{
|
|
4569
4490
|
switch (rb_type(value))
|
|
4570
4491
|
{
|
|
@@ -4574,7 +4495,7 @@ namespace Rice
|
|
|
4574
4495
|
case RUBY_T_ARRAY:
|
|
4575
4496
|
if constexpr (std::is_default_constructible_v<T>)
|
|
4576
4497
|
{
|
|
4577
|
-
return Convertible::
|
|
4498
|
+
return Convertible::Exact;
|
|
4578
4499
|
}
|
|
4579
4500
|
default:
|
|
4580
4501
|
return Convertible::None;
|
|
@@ -4600,7 +4521,7 @@ namespace Rice
|
|
|
4600
4521
|
}
|
|
4601
4522
|
default:
|
|
4602
4523
|
{
|
|
4603
|
-
throw Exception(rb_eTypeError, "wrong argument type %s (expected %
|
|
4524
|
+
throw Exception(rb_eTypeError, "wrong argument type %s (expected %s)",
|
|
4604
4525
|
detail::protect(rb_obj_classname, value), "std::vector");
|
|
4605
4526
|
}
|
|
4606
4527
|
}
|
|
@@ -4620,7 +4541,7 @@ namespace Rice
|
|
|
4620
4541
|
{
|
|
4621
4542
|
}
|
|
4622
4543
|
|
|
4623
|
-
|
|
4544
|
+
double is_convertible(VALUE value)
|
|
4624
4545
|
{
|
|
4625
4546
|
switch (rb_type(value))
|
|
4626
4547
|
{
|
|
@@ -4630,7 +4551,7 @@ namespace Rice
|
|
|
4630
4551
|
case RUBY_T_ARRAY:
|
|
4631
4552
|
if constexpr (std::is_default_constructible_v<T>)
|
|
4632
4553
|
{
|
|
4633
|
-
return Convertible::
|
|
4554
|
+
return Convertible::Exact;
|
|
4634
4555
|
}
|
|
4635
4556
|
default:
|
|
4636
4557
|
return Convertible::None;
|
|
@@ -4657,7 +4578,7 @@ namespace Rice
|
|
|
4657
4578
|
}
|
|
4658
4579
|
default:
|
|
4659
4580
|
{
|
|
4660
|
-
throw Exception(rb_eTypeError, "wrong argument type %s (expected %
|
|
4581
|
+
throw Exception(rb_eTypeError, "wrong argument type %s (expected %s)",
|
|
4661
4582
|
detail::protect(rb_obj_classname, value), "std::vector");
|
|
4662
4583
|
}
|
|
4663
4584
|
}
|
|
@@ -4678,7 +4599,7 @@ namespace Rice
|
|
|
4678
4599
|
{
|
|
4679
4600
|
}
|
|
4680
4601
|
|
|
4681
|
-
|
|
4602
|
+
double is_convertible(VALUE value)
|
|
4682
4603
|
{
|
|
4683
4604
|
switch (rb_type(value))
|
|
4684
4605
|
{
|
|
@@ -4691,7 +4612,7 @@ namespace Rice
|
|
|
4691
4612
|
case RUBY_T_ARRAY:
|
|
4692
4613
|
if constexpr (std::is_default_constructible_v<T>)
|
|
4693
4614
|
{
|
|
4694
|
-
return Convertible::
|
|
4615
|
+
return Convertible::Exact;
|
|
4695
4616
|
}
|
|
4696
4617
|
default:
|
|
4697
4618
|
return Convertible::None;
|
|
@@ -4718,7 +4639,7 @@ namespace Rice
|
|
|
4718
4639
|
}
|
|
4719
4640
|
default:
|
|
4720
4641
|
{
|
|
4721
|
-
throw Exception(rb_eTypeError, "wrong argument type %s (expected %
|
|
4642
|
+
throw Exception(rb_eTypeError, "wrong argument type %s (expected %s)",
|
|
4722
4643
|
detail::protect(rb_obj_classname, value), "std::vector");
|
|
4723
4644
|
}
|
|
4724
4645
|
}
|
|
@@ -4739,7 +4660,7 @@ namespace Rice
|
|
|
4739
4660
|
public:
|
|
4740
4661
|
To_Ruby() = default;
|
|
4741
4662
|
|
|
4742
|
-
explicit To_Ruby(
|
|
4663
|
+
explicit To_Ruby(Arg* arg) : arg_(arg)
|
|
4743
4664
|
{
|
|
4744
4665
|
}
|
|
4745
4666
|
|
|
@@ -4749,7 +4670,7 @@ namespace Rice
|
|
|
4749
4670
|
}
|
|
4750
4671
|
|
|
4751
4672
|
private:
|
|
4752
|
-
|
|
4673
|
+
Arg* arg_ = nullptr;
|
|
4753
4674
|
};
|
|
4754
4675
|
}
|
|
4755
4676
|
}
|