rice 4.11.0 → 4.11.2
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 +54 -24
- data/include/rice/rice.hpp +252 -55
- data/lib/rice/version.rb +1 -1
- data/rice/Data_Type.ipp +1 -3
- data/rice/cpp_api/Object.hpp +10 -5
- data/rice/cpp_api/Object.ipp +39 -31
- data/rice/cpp_api/String.ipp +4 -4
- data/rice/cpp_api/shared_methods.hpp +4 -4
- data/rice/detail/Parameter.ipp +4 -0
- data/rice/detail/RubyType.ipp +11 -0
- data/rice/detail/TypeRegistry.ipp +6 -0
- data/rice/detail/Types.ipp +29 -0
- data/rice/detail/from_ruby.ipp +80 -0
- data/rice/detail/to_ruby.ipp +56 -0
- data/test/test_Object.cpp +2 -12
- metadata +1 -1
data/include/rice/rice.hpp
CHANGED
|
@@ -1859,6 +1859,12 @@ namespace Rice
|
|
|
1859
1859
|
Object(Object&& other) = default;
|
|
1860
1860
|
Object& operator=(Object&& other) = default;
|
|
1861
1861
|
|
|
1862
|
+
//! Implicit conversion to VALUE.
|
|
1863
|
+
operator VALUE() const;
|
|
1864
|
+
|
|
1865
|
+
//! Explicitly get the encapsulated VALUE.
|
|
1866
|
+
VALUE value() const;
|
|
1867
|
+
|
|
1862
1868
|
//! Returns false if the object is nil or false; returns true
|
|
1863
1869
|
//! otherwise.
|
|
1864
1870
|
explicit operator bool() const;
|
|
@@ -1866,11 +1872,6 @@ namespace Rice
|
|
|
1866
1872
|
//! Returns true if the object is nil, false otherwise.
|
|
1867
1873
|
bool is_nil() const;
|
|
1868
1874
|
|
|
1869
|
-
//! Implicit conversion to VALUE.
|
|
1870
|
-
operator VALUE() const;
|
|
1871
|
-
|
|
1872
|
-
//! Explicitly get the encapsulated VALUE.
|
|
1873
|
-
VALUE value() const;
|
|
1874
1875
|
|
|
1875
1876
|
//! Get the class of an object.
|
|
1876
1877
|
/*! \return the object's Class.
|
|
@@ -2071,6 +2072,10 @@ namespace Rice
|
|
|
2071
2072
|
void remove_const(Identifier name);
|
|
2072
2073
|
|
|
2073
2074
|
protected:
|
|
2075
|
+
//! Checks the encapsulated VALUE is not nil and returns it. If it is nil
|
|
2076
|
+
//! an exception is thrown.
|
|
2077
|
+
VALUE validated_value() const;
|
|
2078
|
+
|
|
2074
2079
|
//! Set the encapsulated value.
|
|
2075
2080
|
void set_value(VALUE value);
|
|
2076
2081
|
|
|
@@ -2700,7 +2705,7 @@ namespace Rice
|
|
|
2700
2705
|
*/
|
|
2701
2706
|
inline auto& include_module(Module const& inc)
|
|
2702
2707
|
{
|
|
2703
|
-
detail::protect(rb_include_module, this->
|
|
2708
|
+
detail::protect(rb_include_module, this->validated_value(), inc.value());
|
|
2704
2709
|
return *this;
|
|
2705
2710
|
}
|
|
2706
2711
|
|
|
@@ -2724,7 +2729,7 @@ inline auto& include_module(Module const& inc)
|
|
|
2724
2729
|
template<typename Method_T, typename...Arg_Ts>
|
|
2725
2730
|
inline auto& define_method(std::string name, Method_T&& method, const Arg_Ts&...args)
|
|
2726
2731
|
{
|
|
2727
|
-
this->wrap_native_method(this->
|
|
2732
|
+
this->wrap_native_method(this->validated_value(), name, std::forward<Method_T>(method), args...);
|
|
2728
2733
|
return *this;
|
|
2729
2734
|
}
|
|
2730
2735
|
|
|
@@ -2742,7 +2747,7 @@ inline auto& define_method(std::string name, Method_T&& method, const Arg_Ts&...
|
|
|
2742
2747
|
template<typename Function_T, typename...Arg_Ts>
|
|
2743
2748
|
inline auto& define_function(std::string name, Function_T&& func, const Arg_Ts&...args)
|
|
2744
2749
|
{
|
|
2745
|
-
this->wrap_native_function(this->
|
|
2750
|
+
this->wrap_native_function(this->validated_value(), name, std::forward<Function_T>(func), args...);
|
|
2746
2751
|
return *this;
|
|
2747
2752
|
}
|
|
2748
2753
|
|
|
@@ -2816,7 +2821,7 @@ template<typename Constant_T>
|
|
|
2816
2821
|
inline auto& define_constant(std::string name, Constant_T value)
|
|
2817
2822
|
{
|
|
2818
2823
|
using Base_T = detail::remove_cv_recursive_t<Constant_T>;
|
|
2819
|
-
detail::protect(rb_define_const, this->
|
|
2824
|
+
detail::protect(rb_define_const, this->validated_value(), name.c_str(), detail::To_Ruby<Base_T>().convert(value));
|
|
2820
2825
|
return *this;
|
|
2821
2826
|
}
|
|
2822
2827
|
protected:
|
|
@@ -2898,7 +2903,7 @@ namespace Rice
|
|
|
2898
2903
|
*/
|
|
2899
2904
|
inline auto& include_module(Module const& inc)
|
|
2900
2905
|
{
|
|
2901
|
-
detail::protect(rb_include_module, this->
|
|
2906
|
+
detail::protect(rb_include_module, this->validated_value(), inc.value());
|
|
2902
2907
|
return *this;
|
|
2903
2908
|
}
|
|
2904
2909
|
|
|
@@ -2922,7 +2927,7 @@ inline auto& include_module(Module const& inc)
|
|
|
2922
2927
|
template<typename Method_T, typename...Arg_Ts>
|
|
2923
2928
|
inline auto& define_method(std::string name, Method_T&& method, const Arg_Ts&...args)
|
|
2924
2929
|
{
|
|
2925
|
-
this->wrap_native_method(this->
|
|
2930
|
+
this->wrap_native_method(this->validated_value(), name, std::forward<Method_T>(method), args...);
|
|
2926
2931
|
return *this;
|
|
2927
2932
|
}
|
|
2928
2933
|
|
|
@@ -2940,7 +2945,7 @@ inline auto& define_method(std::string name, Method_T&& method, const Arg_Ts&...
|
|
|
2940
2945
|
template<typename Function_T, typename...Arg_Ts>
|
|
2941
2946
|
inline auto& define_function(std::string name, Function_T&& func, const Arg_Ts&...args)
|
|
2942
2947
|
{
|
|
2943
|
-
this->wrap_native_function(this->
|
|
2948
|
+
this->wrap_native_function(this->validated_value(), name, std::forward<Function_T>(func), args...);
|
|
2944
2949
|
return *this;
|
|
2945
2950
|
}
|
|
2946
2951
|
|
|
@@ -3014,7 +3019,7 @@ template<typename Constant_T>
|
|
|
3014
3019
|
inline auto& define_constant(std::string name, Constant_T value)
|
|
3015
3020
|
{
|
|
3016
3021
|
using Base_T = detail::remove_cv_recursive_t<Constant_T>;
|
|
3017
|
-
detail::protect(rb_define_const, this->
|
|
3022
|
+
detail::protect(rb_define_const, this->validated_value(), name.c_str(), detail::To_Ruby<Base_T>().convert(value));
|
|
3018
3023
|
return *this;
|
|
3019
3024
|
}
|
|
3020
3025
|
};
|
|
@@ -3363,7 +3368,7 @@ namespace Rice
|
|
|
3363
3368
|
*/
|
|
3364
3369
|
inline auto& include_module(Module const& inc)
|
|
3365
3370
|
{
|
|
3366
|
-
detail::protect(rb_include_module, this->
|
|
3371
|
+
detail::protect(rb_include_module, this->validated_value(), inc.value());
|
|
3367
3372
|
return *this;
|
|
3368
3373
|
}
|
|
3369
3374
|
|
|
@@ -3387,7 +3392,7 @@ inline auto& include_module(Module const& inc)
|
|
|
3387
3392
|
template<typename Method_T, typename...Arg_Ts>
|
|
3388
3393
|
inline auto& define_method(std::string name, Method_T&& method, const Arg_Ts&...args)
|
|
3389
3394
|
{
|
|
3390
|
-
this->wrap_native_method(this->
|
|
3395
|
+
this->wrap_native_method(this->validated_value(), name, std::forward<Method_T>(method), args...);
|
|
3391
3396
|
return *this;
|
|
3392
3397
|
}
|
|
3393
3398
|
|
|
@@ -3405,7 +3410,7 @@ inline auto& define_method(std::string name, Method_T&& method, const Arg_Ts&...
|
|
|
3405
3410
|
template<typename Function_T, typename...Arg_Ts>
|
|
3406
3411
|
inline auto& define_function(std::string name, Function_T&& func, const Arg_Ts&...args)
|
|
3407
3412
|
{
|
|
3408
|
-
this->wrap_native_function(this->
|
|
3413
|
+
this->wrap_native_function(this->validated_value(), name, std::forward<Function_T>(func), args...);
|
|
3409
3414
|
return *this;
|
|
3410
3415
|
}
|
|
3411
3416
|
|
|
@@ -3479,7 +3484,7 @@ template<typename Constant_T>
|
|
|
3479
3484
|
inline auto& define_constant(std::string name, Constant_T value)
|
|
3480
3485
|
{
|
|
3481
3486
|
using Base_T = detail::remove_cv_recursive_t<Constant_T>;
|
|
3482
|
-
detail::protect(rb_define_const, this->
|
|
3487
|
+
detail::protect(rb_define_const, this->validated_value(), name.c_str(), detail::To_Ruby<Base_T>().convert(value));
|
|
3483
3488
|
return *this;
|
|
3484
3489
|
}
|
|
3485
3490
|
protected:
|
|
@@ -3792,6 +3797,17 @@ namespace Rice::detail
|
|
|
3792
3797
|
static inline std::string name = "Float";
|
|
3793
3798
|
};
|
|
3794
3799
|
|
|
3800
|
+
template<>
|
|
3801
|
+
class RubyType<long double>
|
|
3802
|
+
{
|
|
3803
|
+
public:
|
|
3804
|
+
using FromRuby_T = double(*)(VALUE);
|
|
3805
|
+
|
|
3806
|
+
static inline FromRuby_T fromRuby = rb_num2dbl;
|
|
3807
|
+
static inline std::string packTemplate = "d*";
|
|
3808
|
+
static inline std::string name = "Float";
|
|
3809
|
+
};
|
|
3810
|
+
|
|
3795
3811
|
template<>
|
|
3796
3812
|
class RubyType<void>
|
|
3797
3813
|
{
|
|
@@ -4527,6 +4543,10 @@ namespace Rice::detail
|
|
|
4527
4543
|
T defaultValue = this->arg()->template defaultValue<T>();
|
|
4528
4544
|
return this->toRuby_.convert(defaultValue);
|
|
4529
4545
|
}
|
|
4546
|
+
else
|
|
4547
|
+
{
|
|
4548
|
+
throw std::runtime_error("Default value not allowed for parameter " + this->arg()->name);
|
|
4549
|
+
}
|
|
4530
4550
|
}
|
|
4531
4551
|
else
|
|
4532
4552
|
{
|
|
@@ -6064,6 +6084,35 @@ namespace Rice::detail
|
|
|
6064
6084
|
}
|
|
6065
6085
|
};
|
|
6066
6086
|
|
|
6087
|
+
template<>
|
|
6088
|
+
struct Type<long double>
|
|
6089
|
+
{
|
|
6090
|
+
static bool verify()
|
|
6091
|
+
{
|
|
6092
|
+
return true;
|
|
6093
|
+
}
|
|
6094
|
+
|
|
6095
|
+
static VALUE rubyKlass()
|
|
6096
|
+
{
|
|
6097
|
+
return rb_cFloat;
|
|
6098
|
+
}
|
|
6099
|
+
};
|
|
6100
|
+
|
|
6101
|
+
template<int N>
|
|
6102
|
+
struct Type<long double[N]>
|
|
6103
|
+
{
|
|
6104
|
+
static bool verify()
|
|
6105
|
+
{
|
|
6106
|
+
define_buffer<long double>();
|
|
6107
|
+
return true;
|
|
6108
|
+
}
|
|
6109
|
+
|
|
6110
|
+
static VALUE rubyKlass()
|
|
6111
|
+
{
|
|
6112
|
+
return rb_cString;
|
|
6113
|
+
}
|
|
6114
|
+
};
|
|
6115
|
+
|
|
6067
6116
|
template<>
|
|
6068
6117
|
struct Type<void>
|
|
6069
6118
|
{
|
|
@@ -6592,6 +6641,62 @@ namespace Rice
|
|
|
6592
6641
|
Arg* arg_ = nullptr;
|
|
6593
6642
|
};
|
|
6594
6643
|
|
|
6644
|
+
// =========== long double ============
|
|
6645
|
+
template<>
|
|
6646
|
+
class To_Ruby<long double>
|
|
6647
|
+
{
|
|
6648
|
+
public:
|
|
6649
|
+
To_Ruby() = default;
|
|
6650
|
+
|
|
6651
|
+
explicit To_Ruby(Arg* arg) : arg_(arg)
|
|
6652
|
+
{}
|
|
6653
|
+
|
|
6654
|
+
VALUE convert(const long double& native)
|
|
6655
|
+
{
|
|
6656
|
+
return protect(rb_float_new, native);
|
|
6657
|
+
}
|
|
6658
|
+
|
|
6659
|
+
private:
|
|
6660
|
+
Arg* arg_ = nullptr;
|
|
6661
|
+
};
|
|
6662
|
+
|
|
6663
|
+
template<>
|
|
6664
|
+
class To_Ruby<long double&>
|
|
6665
|
+
{
|
|
6666
|
+
public:
|
|
6667
|
+
To_Ruby() = default;
|
|
6668
|
+
|
|
6669
|
+
explicit To_Ruby(Arg* arg) : arg_(arg)
|
|
6670
|
+
{}
|
|
6671
|
+
|
|
6672
|
+
VALUE convert(const long double& native)
|
|
6673
|
+
{
|
|
6674
|
+
return protect(rb_float_new, native);
|
|
6675
|
+
}
|
|
6676
|
+
|
|
6677
|
+
private:
|
|
6678
|
+
Arg* arg_ = nullptr;
|
|
6679
|
+
};
|
|
6680
|
+
|
|
6681
|
+
template<int N>
|
|
6682
|
+
class To_Ruby<long double[N]>
|
|
6683
|
+
{
|
|
6684
|
+
public:
|
|
6685
|
+
To_Ruby() = default;
|
|
6686
|
+
|
|
6687
|
+
explicit To_Ruby(Arg* arg) : arg_(arg)
|
|
6688
|
+
{}
|
|
6689
|
+
|
|
6690
|
+
VALUE convert(long double data[N])
|
|
6691
|
+
{
|
|
6692
|
+
Buffer<long double> buffer(data, N);
|
|
6693
|
+
Data_Object<Buffer<long double>> dataObject(std::move(buffer));
|
|
6694
|
+
return dataObject.value();
|
|
6695
|
+
}
|
|
6696
|
+
private:
|
|
6697
|
+
Arg* arg_ = nullptr;
|
|
6698
|
+
};
|
|
6699
|
+
|
|
6595
6700
|
// =========== float ============
|
|
6596
6701
|
template<>
|
|
6597
6702
|
class To_Ruby<float>
|
|
@@ -7870,6 +7975,86 @@ namespace Rice::detail
|
|
|
7870
7975
|
Reference<double> reference_;
|
|
7871
7976
|
};
|
|
7872
7977
|
|
|
7978
|
+
// =========== long double ============
|
|
7979
|
+
template<>
|
|
7980
|
+
class From_Ruby<long double>
|
|
7981
|
+
{
|
|
7982
|
+
public:
|
|
7983
|
+
From_Ruby() = default;
|
|
7984
|
+
|
|
7985
|
+
explicit From_Ruby(Arg* arg) : arg_(arg)
|
|
7986
|
+
{}
|
|
7987
|
+
|
|
7988
|
+
long double is_convertible(VALUE value)
|
|
7989
|
+
{
|
|
7990
|
+
return FromRubyFundamental<long double>::is_convertible(value);
|
|
7991
|
+
}
|
|
7992
|
+
|
|
7993
|
+
long double convert(VALUE value)
|
|
7994
|
+
{
|
|
7995
|
+
return FromRubyFundamental<long double>::convert(value);
|
|
7996
|
+
}
|
|
7997
|
+
|
|
7998
|
+
private:
|
|
7999
|
+
Arg* arg_ = nullptr;
|
|
8000
|
+
};
|
|
8001
|
+
|
|
8002
|
+
template<>
|
|
8003
|
+
class From_Ruby<long double&>
|
|
8004
|
+
{
|
|
8005
|
+
public:
|
|
8006
|
+
using Reference_T = Reference<long double>;
|
|
8007
|
+
|
|
8008
|
+
From_Ruby() = default;
|
|
8009
|
+
|
|
8010
|
+
explicit From_Ruby(Arg* arg) : arg_(arg)
|
|
8011
|
+
{}
|
|
8012
|
+
|
|
8013
|
+
long double is_convertible(VALUE value)
|
|
8014
|
+
{
|
|
8015
|
+
switch (rb_type(value))
|
|
8016
|
+
{
|
|
8017
|
+
case RUBY_T_DATA:
|
|
8018
|
+
{
|
|
8019
|
+
if (Data_Type<Reference_T>::is_descendant(value))
|
|
8020
|
+
{
|
|
8021
|
+
return Convertible::Exact;
|
|
8022
|
+
}
|
|
8023
|
+
[[fallthrough]];
|
|
8024
|
+
}
|
|
8025
|
+
default:
|
|
8026
|
+
{
|
|
8027
|
+
return FromRubyFundamental<long double>::is_convertible(value);
|
|
8028
|
+
}
|
|
8029
|
+
}
|
|
8030
|
+
}
|
|
8031
|
+
|
|
8032
|
+
long double& convert(VALUE value)
|
|
8033
|
+
{
|
|
8034
|
+
switch (rb_type(value))
|
|
8035
|
+
{
|
|
8036
|
+
case RUBY_T_DATA:
|
|
8037
|
+
{
|
|
8038
|
+
if (Data_Type<Reference_T>::is_descendant(value))
|
|
8039
|
+
{
|
|
8040
|
+
Reference_T* reference = unwrap<Reference_T>(value, Data_Type<Reference_T>::ruby_data_type(), false);
|
|
8041
|
+
return reference->get();
|
|
8042
|
+
}
|
|
8043
|
+
[[fallthrough]];
|
|
8044
|
+
}
|
|
8045
|
+
default:
|
|
8046
|
+
{
|
|
8047
|
+
this->reference_ = Reference<long double>(value);
|
|
8048
|
+
return this->reference_.get();
|
|
8049
|
+
}
|
|
8050
|
+
}
|
|
8051
|
+
}
|
|
8052
|
+
|
|
8053
|
+
private:
|
|
8054
|
+
Arg* arg_ = nullptr;
|
|
8055
|
+
Reference<long double> reference_;
|
|
8056
|
+
};
|
|
8057
|
+
|
|
7873
8058
|
// =========== float ============
|
|
7874
8059
|
template<>
|
|
7875
8060
|
class From_Ruby<float>
|
|
@@ -8964,6 +9149,12 @@ namespace Rice::detail
|
|
|
8964
9149
|
{
|
|
8965
9150
|
return std::type_index(typeid(T));
|
|
8966
9151
|
}
|
|
9152
|
+
else if constexpr (std::is_reference_v<T>)
|
|
9153
|
+
{
|
|
9154
|
+
// For incomplete reference types, strip the reference and use pointer.
|
|
9155
|
+
// Can't form T* when T is a reference type (pointer-to-reference is illegal).
|
|
9156
|
+
return std::type_index(typeid(std::remove_reference_t<T>*));
|
|
9157
|
+
}
|
|
8967
9158
|
else
|
|
8968
9159
|
{
|
|
8969
9160
|
return std::type_index(typeid(T*));
|
|
@@ -12568,16 +12759,9 @@ namespace Rice
|
|
|
12568
12759
|
{
|
|
12569
12760
|
}
|
|
12570
12761
|
|
|
12571
|
-
inline Object::
|
|
12572
|
-
{
|
|
12573
|
-
// Bypass getter to not raise exception
|
|
12574
|
-
return RTEST(this->value_.value());
|
|
12575
|
-
}
|
|
12576
|
-
|
|
12577
|
-
inline bool Object::is_nil() const
|
|
12762
|
+
inline VALUE Object::value() const
|
|
12578
12763
|
{
|
|
12579
|
-
|
|
12580
|
-
return NIL_P(this->value_.value());
|
|
12764
|
+
return this->value_.value();
|
|
12581
12765
|
}
|
|
12582
12766
|
|
|
12583
12767
|
inline Object::operator VALUE() const
|
|
@@ -12585,9 +12769,9 @@ namespace Rice
|
|
|
12585
12769
|
return this->value();
|
|
12586
12770
|
}
|
|
12587
12771
|
|
|
12588
|
-
inline VALUE Object::
|
|
12772
|
+
inline VALUE Object::validated_value() const
|
|
12589
12773
|
{
|
|
12590
|
-
VALUE result = this->
|
|
12774
|
+
VALUE result = this->value();
|
|
12591
12775
|
|
|
12592
12776
|
if (result == Qnil)
|
|
12593
12777
|
{
|
|
@@ -12598,6 +12782,16 @@ namespace Rice
|
|
|
12598
12782
|
return result;
|
|
12599
12783
|
}
|
|
12600
12784
|
|
|
12785
|
+
inline Object::operator bool() const
|
|
12786
|
+
{
|
|
12787
|
+
return RTEST(this->value());
|
|
12788
|
+
}
|
|
12789
|
+
|
|
12790
|
+
inline bool Object::is_nil() const
|
|
12791
|
+
{
|
|
12792
|
+
return NIL_P(this->value());
|
|
12793
|
+
}
|
|
12794
|
+
|
|
12601
12795
|
template<typename ...Parameter_Ts>
|
|
12602
12796
|
inline Object Object::call(Identifier id, Parameter_Ts... args) const
|
|
12603
12797
|
{
|
|
@@ -12609,7 +12803,7 @@ namespace Rice
|
|
|
12609
12803
|
easy to duplicate by setting GC.stress to true and calling a constructor
|
|
12610
12804
|
that takes multiple values like a std::pair wrapper. */
|
|
12611
12805
|
std::array<VALUE, sizeof...(Parameter_Ts)> values = { detail::To_Ruby<detail::remove_cv_recursive_t<Parameter_Ts>>().convert(std::forward<Parameter_Ts>(args))... };
|
|
12612
|
-
return detail::protect(rb_funcallv,
|
|
12806
|
+
return detail::protect(rb_funcallv, this->validated_value(), id.id(), (int)values.size(), (const VALUE*)values.data());
|
|
12613
12807
|
}
|
|
12614
12808
|
|
|
12615
12809
|
template<typename ...Parameter_Ts>
|
|
@@ -12617,13 +12811,13 @@ namespace Rice
|
|
|
12617
12811
|
{
|
|
12618
12812
|
/* IMPORTANT - See call() above */
|
|
12619
12813
|
std::array<VALUE, sizeof...(Parameter_Ts)> values = { detail::To_Ruby<detail::remove_cv_recursive_t<Parameter_Ts>>().convert(args)... };
|
|
12620
|
-
return detail::protect(rb_funcallv_kw,
|
|
12814
|
+
return detail::protect(rb_funcallv_kw, this->validated_value(), id.id(), (int)values.size(), (const VALUE*)values.data(), RB_PASS_KEYWORDS);
|
|
12621
12815
|
}
|
|
12622
12816
|
|
|
12623
12817
|
template<typename T>
|
|
12624
12818
|
inline void Object::iv_set(Identifier name, T const& value)
|
|
12625
12819
|
{
|
|
12626
|
-
detail::protect(rb_ivar_set, this->
|
|
12820
|
+
detail::protect(rb_ivar_set, this->validated_value(), name.id(), detail::To_Ruby<T>().convert(value));
|
|
12627
12821
|
}
|
|
12628
12822
|
|
|
12629
12823
|
inline int Object::compare(Object const& other) const
|
|
@@ -12639,66 +12833,71 @@ namespace Rice
|
|
|
12639
12833
|
return this->is_nil() && other.is_nil();
|
|
12640
12834
|
}
|
|
12641
12835
|
|
|
12642
|
-
VALUE result = detail::protect(rb_equal, this->
|
|
12836
|
+
VALUE result = detail::protect(rb_equal, this->validated_value(), other.validated_value());
|
|
12643
12837
|
return RB_TEST(result);
|
|
12644
12838
|
}
|
|
12645
12839
|
|
|
12646
12840
|
inline bool Object::is_eql(const Object& other) const
|
|
12647
12841
|
{
|
|
12648
|
-
|
|
12842
|
+
if (this->is_nil() || other.is_nil())
|
|
12843
|
+
{
|
|
12844
|
+
return this->is_nil() && other.is_nil();
|
|
12845
|
+
}
|
|
12846
|
+
|
|
12847
|
+
VALUE result = detail::protect(rb_eql, this->validated_value(), other.validated_value());
|
|
12649
12848
|
return RB_TEST(result);
|
|
12650
12849
|
}
|
|
12651
12850
|
|
|
12652
12851
|
inline void Object::freeze()
|
|
12653
12852
|
{
|
|
12654
|
-
detail::protect(rb_obj_freeze,
|
|
12853
|
+
detail::protect(rb_obj_freeze, this->validated_value());
|
|
12655
12854
|
}
|
|
12656
12855
|
|
|
12657
12856
|
inline bool Object::is_frozen() const
|
|
12658
12857
|
{
|
|
12659
|
-
return RB_OBJ_FROZEN(
|
|
12858
|
+
return RB_OBJ_FROZEN(this->validated_value());
|
|
12660
12859
|
}
|
|
12661
12860
|
|
|
12662
12861
|
inline int Object::rb_type() const
|
|
12663
12862
|
{
|
|
12664
|
-
return ::rb_type(this->
|
|
12863
|
+
return ::rb_type(this->validated_value());
|
|
12665
12864
|
}
|
|
12666
12865
|
|
|
12667
12866
|
inline VALUE Object::object_id() const
|
|
12668
12867
|
{
|
|
12669
|
-
return detail::protect(rb_obj_id, this->
|
|
12868
|
+
return detail::protect(rb_obj_id, this->validated_value());
|
|
12670
12869
|
}
|
|
12671
12870
|
|
|
12672
12871
|
inline bool Object::is_a(Object klass) const
|
|
12673
12872
|
{
|
|
12674
|
-
VALUE result = detail::protect(rb_obj_is_kind_of, this->
|
|
12873
|
+
VALUE result = detail::protect(rb_obj_is_kind_of, this->validated_value(), klass.validated_value());
|
|
12675
12874
|
return RB_TEST(result);
|
|
12676
12875
|
}
|
|
12677
12876
|
|
|
12678
12877
|
inline void Object::extend(Module const& mod)
|
|
12679
12878
|
{
|
|
12680
|
-
detail::protect(rb_extend_object, this->
|
|
12879
|
+
detail::protect(rb_extend_object, this->validated_value(), mod.validated_value());
|
|
12681
12880
|
}
|
|
12682
12881
|
|
|
12683
12882
|
inline bool Object::respond_to(Identifier id) const
|
|
12684
12883
|
{
|
|
12685
|
-
return bool(rb_respond_to(this->
|
|
12884
|
+
return bool(rb_respond_to(this->validated_value(), id.id()));
|
|
12686
12885
|
}
|
|
12687
12886
|
|
|
12688
12887
|
inline bool Object::is_instance_of(Object klass) const
|
|
12689
12888
|
{
|
|
12690
|
-
VALUE result = detail::protect(rb_obj_is_instance_of, this->
|
|
12889
|
+
VALUE result = detail::protect(rb_obj_is_instance_of, this->validated_value(), klass.validated_value());
|
|
12691
12890
|
return RB_TEST(result);
|
|
12692
12891
|
}
|
|
12693
12892
|
|
|
12694
12893
|
inline Object Object::iv_get(Identifier name) const
|
|
12695
12894
|
{
|
|
12696
|
-
return detail::protect(rb_ivar_get, this->
|
|
12895
|
+
return detail::protect(rb_ivar_get, this->validated_value(), name.id());
|
|
12697
12896
|
}
|
|
12698
12897
|
|
|
12699
12898
|
inline Object Object::attr_get(Identifier name) const
|
|
12700
12899
|
{
|
|
12701
|
-
return detail::protect(rb_attr_get, this->
|
|
12900
|
+
return detail::protect(rb_attr_get, this->validated_value(), name.id());
|
|
12702
12901
|
}
|
|
12703
12902
|
|
|
12704
12903
|
inline void Object::set_value(VALUE value)
|
|
@@ -12708,20 +12907,20 @@ namespace Rice
|
|
|
12708
12907
|
|
|
12709
12908
|
inline Object Object::const_get(Identifier name) const
|
|
12710
12909
|
{
|
|
12711
|
-
return detail::protect(rb_const_get, this->
|
|
12910
|
+
return detail::protect(rb_const_get, this->validated_value(), name.id());
|
|
12712
12911
|
}
|
|
12713
12912
|
|
|
12714
12913
|
inline bool Object::const_defined(Identifier name) const
|
|
12715
12914
|
{
|
|
12716
|
-
size_t result = detail::protect(rb_const_defined, this->
|
|
12915
|
+
size_t result = detail::protect(rb_const_defined, this->validated_value(), name.id());
|
|
12717
12916
|
return bool(result);
|
|
12718
12917
|
}
|
|
12719
12918
|
|
|
12720
12919
|
inline Object Object::const_set(Identifier name, Object value)
|
|
12721
12920
|
{
|
|
12722
12921
|
// We will allow setting constants to Qnil, or the decimal value of 4. This happens
|
|
12723
|
-
// in C++ libraries with enums. Thus
|
|
12724
|
-
detail::protect(rb_const_set, this->
|
|
12922
|
+
// in C++ libraries with enums. Thus use value() instead of validated_value
|
|
12923
|
+
detail::protect(rb_const_set, this->validated_value(), name.id(), value.value());
|
|
12725
12924
|
return value;
|
|
12726
12925
|
}
|
|
12727
12926
|
|
|
@@ -12736,7 +12935,7 @@ namespace Rice
|
|
|
12736
12935
|
|
|
12737
12936
|
inline void Object::remove_const(Identifier name)
|
|
12738
12937
|
{
|
|
12739
|
-
detail::protect(rb_mod_remove_const, this->
|
|
12938
|
+
detail::protect(rb_mod_remove_const, this->validated_value(), name.to_sym());
|
|
12740
12939
|
}
|
|
12741
12940
|
|
|
12742
12941
|
inline bool operator==(Object const& lhs, Object const& rhs)
|
|
@@ -12898,22 +13097,22 @@ namespace Rice
|
|
|
12898
13097
|
|
|
12899
13098
|
inline size_t String::length() const
|
|
12900
13099
|
{
|
|
12901
|
-
return RSTRING_LEN(value());
|
|
13100
|
+
return RSTRING_LEN(this->value());
|
|
12902
13101
|
}
|
|
12903
13102
|
|
|
12904
13103
|
inline char String::operator[](ptrdiff_t index) const
|
|
12905
13104
|
{
|
|
12906
|
-
return RSTRING_PTR(value())[index];
|
|
13105
|
+
return RSTRING_PTR(this->value())[index];
|
|
12907
13106
|
}
|
|
12908
13107
|
|
|
12909
13108
|
inline char const* String::c_str() const
|
|
12910
13109
|
{
|
|
12911
|
-
return RSTRING_PTR(value());
|
|
13110
|
+
return RSTRING_PTR(this->value());
|
|
12912
13111
|
}
|
|
12913
13112
|
|
|
12914
13113
|
inline std::string String::str() const
|
|
12915
13114
|
{
|
|
12916
|
-
return std::string(RSTRING_PTR(value()), length());
|
|
13115
|
+
return std::string(RSTRING_PTR(this->value()), length());
|
|
12917
13116
|
}
|
|
12918
13117
|
|
|
12919
13118
|
template<typename T>
|
|
@@ -14820,7 +15019,7 @@ namespace Rice
|
|
|
14820
15019
|
template <typename Attribute_T, typename Access_T, typename...Arg_Ts>
|
|
14821
15020
|
inline Data_Type<T>& Data_Type<T>::define_singleton_attr(std::string name, Attribute_T attribute, Access_T access, const Arg_Ts&...args)
|
|
14822
15021
|
{
|
|
14823
|
-
VALUE singleton = detail::protect(rb_singleton_class, this->
|
|
15022
|
+
VALUE singleton = detail::protect(rb_singleton_class, this->validated_value());
|
|
14824
15023
|
return this->define_attr_internal<Attribute_T, Access_T>(singleton, name, std::forward<Attribute_T>(attribute), access, args...);
|
|
14825
15024
|
}
|
|
14826
15025
|
|
|
@@ -14828,8 +15027,6 @@ namespace Rice
|
|
|
14828
15027
|
template <typename Attribute_T, typename Access_T, typename...Arg_Ts>
|
|
14829
15028
|
inline Data_Type<T>& Data_Type<T>::define_attr_internal(VALUE klass, std::string name, Attribute_T attribute, Access_T, const Arg_Ts&...args)
|
|
14830
15029
|
{
|
|
14831
|
-
using Attr_T = typename detail::attribute_traits<Attribute_T>::attr_type;
|
|
14832
|
-
|
|
14833
15030
|
// Define attribute getter
|
|
14834
15031
|
if constexpr (std::is_same_v<Access_T, AttrAccess::ReadWriteType> || std::is_same_v<Access_T, AttrAccess::ReadType>)
|
|
14835
15032
|
{
|
data/lib/rice/version.rb
CHANGED
data/rice/Data_Type.ipp
CHANGED
|
@@ -368,7 +368,7 @@ namespace Rice
|
|
|
368
368
|
template <typename Attribute_T, typename Access_T, typename...Arg_Ts>
|
|
369
369
|
inline Data_Type<T>& Data_Type<T>::define_singleton_attr(std::string name, Attribute_T attribute, Access_T access, const Arg_Ts&...args)
|
|
370
370
|
{
|
|
371
|
-
VALUE singleton = detail::protect(rb_singleton_class, this->
|
|
371
|
+
VALUE singleton = detail::protect(rb_singleton_class, this->validated_value());
|
|
372
372
|
return this->define_attr_internal<Attribute_T, Access_T>(singleton, name, std::forward<Attribute_T>(attribute), access, args...);
|
|
373
373
|
}
|
|
374
374
|
|
|
@@ -376,8 +376,6 @@ namespace Rice
|
|
|
376
376
|
template <typename Attribute_T, typename Access_T, typename...Arg_Ts>
|
|
377
377
|
inline Data_Type<T>& Data_Type<T>::define_attr_internal(VALUE klass, std::string name, Attribute_T attribute, Access_T, const Arg_Ts&...args)
|
|
378
378
|
{
|
|
379
|
-
using Attr_T = typename detail::attribute_traits<Attribute_T>::attr_type;
|
|
380
|
-
|
|
381
379
|
// Define attribute getter
|
|
382
380
|
if constexpr (std::is_same_v<Access_T, AttrAccess::ReadWriteType> || std::is_same_v<Access_T, AttrAccess::ReadType>)
|
|
383
381
|
{
|
data/rice/cpp_api/Object.hpp
CHANGED
|
@@ -37,6 +37,12 @@ namespace Rice
|
|
|
37
37
|
Object(Object&& other) = default;
|
|
38
38
|
Object& operator=(Object&& other) = default;
|
|
39
39
|
|
|
40
|
+
//! Implicit conversion to VALUE.
|
|
41
|
+
operator VALUE() const;
|
|
42
|
+
|
|
43
|
+
//! Explicitly get the encapsulated VALUE.
|
|
44
|
+
VALUE value() const;
|
|
45
|
+
|
|
40
46
|
//! Returns false if the object is nil or false; returns true
|
|
41
47
|
//! otherwise.
|
|
42
48
|
explicit operator bool() const;
|
|
@@ -44,11 +50,6 @@ namespace Rice
|
|
|
44
50
|
//! Returns true if the object is nil, false otherwise.
|
|
45
51
|
bool is_nil() const;
|
|
46
52
|
|
|
47
|
-
//! Implicit conversion to VALUE.
|
|
48
|
-
operator VALUE() const;
|
|
49
|
-
|
|
50
|
-
//! Explicitly get the encapsulated VALUE.
|
|
51
|
-
VALUE value() const;
|
|
52
53
|
|
|
53
54
|
//! Get the class of an object.
|
|
54
55
|
/*! \return the object's Class.
|
|
@@ -249,6 +250,10 @@ namespace Rice
|
|
|
249
250
|
void remove_const(Identifier name);
|
|
250
251
|
|
|
251
252
|
protected:
|
|
253
|
+
//! Checks the encapsulated VALUE is not nil and returns it. If it is nil
|
|
254
|
+
//! an exception is thrown.
|
|
255
|
+
VALUE validated_value() const;
|
|
256
|
+
|
|
252
257
|
//! Set the encapsulated value.
|
|
253
258
|
void set_value(VALUE value);
|
|
254
259
|
|