rice 4.6.0 → 4.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/include/rice/stl.hpp CHANGED
@@ -3771,68 +3771,67 @@ namespace Rice
3771
3771
  }
3772
3772
  })
3773
3773
  .define_method("last", [](const T& vector) -> std::optional<Value_T>
3774
+ {
3775
+ if (vector.size() > 0)
3774
3776
  {
3775
- if (vector.size() > 0)
3776
- {
3777
- return vector.back();
3778
- }
3779
- else
3780
- {
3781
- return std::nullopt;
3782
- }
3783
- })
3777
+ return vector.back();
3778
+ }
3779
+ else
3780
+ {
3781
+ return std::nullopt;
3782
+ }
3783
+ })
3784
3784
  .define_method("[]", [this](const T& vector, Difference_T index) -> std::optional<Value_T>
3785
+ {
3786
+ index = normalizeIndex(vector.size(), index);
3787
+ if (index < 0 || index >= (Difference_T)vector.size())
3785
3788
  {
3786
- index = normalizeIndex(vector.size(), index);
3787
- if (index < 0 || index >= (Difference_T)vector.size())
3788
- {
3789
- return std::nullopt;
3790
- }
3791
- else
3792
- {
3793
- return vector[index];
3794
- }
3795
- })
3789
+ return std::nullopt;
3790
+ }
3791
+ else
3792
+ {
3793
+ return vector[index];
3794
+ }
3795
+ })
3796
3796
  .define_method("[]", [this](const T& vector, Difference_T start, Difference_T length) -> VALUE
3797
+ {
3798
+ start = normalizeIndex(vector.size(), start);
3799
+ if (start < 0 || start >= (Difference_T)vector.size())
3800
+ {
3801
+ return rb_ary_new();
3802
+ }
3803
+ else
3797
3804
  {
3798
- start = normalizeIndex(vector.size(), start);
3799
- if (start < 0 || start >= (Difference_T)vector.size())
3805
+ auto begin = vector.begin() + start;
3806
+
3807
+ // Ruby does not throw an exception when the length is too long
3808
+ Difference_T size = (Difference_T)vector.size();
3809
+ if (start + length > size)
3800
3810
  {
3801
- return rb_ary_new();
3811
+ length = size - start;
3802
3812
  }
3803
- else
3804
- {
3805
- auto begin = vector.begin() + start;
3806
-
3807
- // Ruby does not throw an exception when the length is too long
3808
- Difference_T size = (Difference_T)vector.size();
3809
- if (start + length > size)
3810
- {
3811
- length = size - start;
3812
- }
3813
3813
 
3814
- auto finish = vector.begin() + start + length;
3815
- T slice(begin, finish);
3814
+ auto finish = vector.begin() + start + length;
3815
+ T slice(begin, finish);
3816
3816
 
3817
- VALUE result = rb_ary_new();
3818
- std::for_each(slice.begin(), slice.end(), [&result](const Reference_T element)
3819
- {
3820
- VALUE value = detail::To_Ruby<Parameter_T>().convert(element);
3821
- rb_ary_push(result, value);
3822
- });
3823
-
3824
- return result;
3825
- }
3826
- }, Return().setValue());
3817
+ VALUE result = rb_ary_new();
3818
+ std::for_each(slice.begin(), slice.end(), [&result](const Reference_T element)
3819
+ {
3820
+ VALUE value = detail::To_Ruby<Parameter_T>().convert(element);
3821
+ rb_ary_push(result, value);
3822
+ });
3827
3823
 
3828
- if constexpr (!std::is_same_v<Value_T, bool>)
3829
- {
3830
- define_buffer<Value_T>();
3831
- define_buffer<Value_T*>();
3832
- klass_.template define_method<Value_T*(T::*)()>("data", &T::data);
3824
+ return result;
3833
3825
  }
3826
+ }, Return().setValue());
3827
+
3828
+ if constexpr (!std::is_same_v<Value_T, bool>)
3829
+ {
3830
+ define_buffer<Value_T>();
3831
+ klass_.template define_method<Value_T*(T::*)()>("data", &T::data);
3832
+ }
3834
3833
 
3835
- rb_define_alias(klass_, "at", "[]");
3834
+ rb_define_alias(klass_, "at", "[]");
3836
3835
  }
3837
3836
 
3838
3837
  // Methods that require Value_T to support operator==
data/lib/rice/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rice
2
- VERSION = "4.6.0"
2
+ VERSION = "4.6.1"
3
3
  end
data/rice/Buffer.hpp CHANGED
@@ -3,11 +3,14 @@
3
3
 
4
4
  namespace Rice
5
5
  {
6
+ template<typename T, typename = void>
7
+ class Buffer;
8
+
6
9
  template<typename T>
7
- class Buffer
10
+ class Buffer<T, std::enable_if_t<!std::is_pointer_v<T>>>
8
11
  {
9
12
  public:
10
- using type = T;
13
+ using Element_T = T;
11
14
 
12
15
  Buffer(T* pointer);
13
16
  Buffer(T* pointer, size_t size);
@@ -20,6 +23,7 @@ namespace Rice
20
23
 
21
24
  Buffer& operator=(const Buffer& other) = delete;
22
25
  Buffer& operator=(Buffer&& other);
26
+ T& operator[](size_t index);
23
27
 
24
28
  T* ptr();
25
29
  T& reference();
@@ -29,7 +33,7 @@ namespace Rice
29
33
  void setSize(size_t value);
30
34
 
31
35
  // Ruby API
32
- // VALUE toString() const;
36
+ VALUE toString() const;
33
37
 
34
38
  VALUE bytes() const;
35
39
  VALUE bytes(size_t count) const;
@@ -37,15 +41,12 @@ namespace Rice
37
41
  Array toArray() const;
38
42
  Array toArray(size_t count) const;
39
43
 
40
- T get(size_t index) const;
41
- void set(size_t index, T value);
42
-
43
44
  bool isOwner() const;
44
45
  void setOwner(bool value);
45
46
 
46
47
  private:
47
- void fromRubyType(VALUE value);
48
- void fromDataType(VALUE value);
48
+ void fromBuiltinType(VALUE value);
49
+ void fromWrappedType(VALUE value);
49
50
 
50
51
  bool m_owner = false;
51
52
  size_t m_size = 0;
@@ -54,10 +55,10 @@ namespace Rice
54
55
  };
55
56
 
56
57
  template<typename T>
57
- class Buffer<T*>
58
+ class Buffer<T*, std::enable_if_t<!detail::is_wrapped_v<T>>>
58
59
  {
59
60
  public:
60
- using type = T*;
61
+ using Element_T = Buffer<T>;
61
62
 
62
63
  Buffer(T** pointer);
63
64
  Buffer(T** pointer, size_t size);
@@ -71,7 +72,7 @@ namespace Rice
71
72
  Buffer& operator=(const Buffer& other) = delete;
72
73
  Buffer& operator=(Buffer&& other);
73
74
 
74
- const Buffer<T>& operator[](size_t index);
75
+ Element_T& operator[](size_t index);
75
76
 
76
77
  T** ptr();
77
78
  void release();
@@ -80,7 +81,7 @@ namespace Rice
80
81
  void setSize(size_t value);
81
82
 
82
83
  // Ruby API
83
- // VALUE toString() const;
84
+ VALUE toString() const;
84
85
 
85
86
  VALUE bytes() const;
86
87
  VALUE bytes(size_t count) const;
@@ -98,6 +99,50 @@ namespace Rice
98
99
  std::vector<Buffer<T>> m_inner;
99
100
  };
100
101
 
102
+ template<typename T>
103
+ class Buffer<T*, std::enable_if_t<detail::is_wrapped_v<T>>>
104
+ {
105
+ public:
106
+ using Element_T = T*;
107
+
108
+ Buffer(T** pointer);
109
+ Buffer(T** pointer, size_t size);
110
+ Buffer(VALUE value);
111
+
112
+ ~Buffer();
113
+
114
+ Buffer(const Buffer& other) = delete;
115
+ Buffer(Buffer&& other);
116
+
117
+ Buffer& operator=(const Buffer& other) = delete;
118
+ Buffer& operator=(Buffer&& other);
119
+
120
+ Element_T& operator[](size_t index);
121
+
122
+ T** ptr();
123
+ void release();
124
+
125
+ size_t size() const;
126
+ void setSize(size_t value);
127
+
128
+ // Ruby API
129
+ VALUE toString() const;
130
+
131
+ VALUE bytes() const;
132
+ VALUE bytes(size_t count) const;
133
+
134
+ Array toArray() const;
135
+ Array toArray(size_t count) const;
136
+
137
+ void setOwner(bool value);
138
+ bool isOwner() const;
139
+
140
+ private:
141
+ bool m_owner = false;
142
+ size_t m_size = 0;
143
+ T** m_buffer = nullptr;
144
+ };
145
+
101
146
  template<>
102
147
  class Buffer<void>
103
148
  {