Skip to content

Commit 373e28c

Browse files
committed
Move RubyType<T>::klass to Type<T>::rubyKlass() to have a single system to map C++ classes to Ruby classes.
1 parent ec739dd commit 373e28c

File tree

9 files changed

+282
-101
lines changed

9 files changed

+282
-101
lines changed

rice/Buffer.ipp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ namespace Rice
7979
if (Data_Type<std::remove_cv_t<T>>::is_descendant(value))
8080
{
8181
this->m_size = 1;
82-
this->m_buffer = new T[this->m_size]();
83-
(std::remove_cv_t<T>)this->m_buffer[0] = *detail::unwrap<T>(value, Data_Type<std::remove_cv_t<T>>::ruby_data_type(), false);
82+
T* instance = detail::unwrap<T>(value, Data_Type<std::remove_cv_t<T>>::ruby_data_type(), false);
83+
this->m_buffer = new T[this->m_size]{*instance};
8484
this->m_owner = false;
8585
break;
8686
}

rice/detail/Native.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ namespace Rice::detail
4848
virtual std::string name() = 0;
4949
virtual NativeKind kind() = 0;
5050
virtual VALUE returnKlass() = 0;
51-
5251
std::vector<const ParameterAbstract*> parameters();
5352

5453
protected:

rice/detail/Parameter.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace Rice::detail
1717

1818
virtual Convertible matches(std::optional<VALUE>& valueOpt) = 0;
1919
virtual std::string cppTypeName() = 0;
20-
virtual VALUE rubyKlass() = 0;
20+
virtual VALUE klass() = 0;
2121

2222
public:
2323
Arg* arg = nullptr;
@@ -37,7 +37,7 @@ namespace Rice::detail
3737
T convertToNative(std::optional<VALUE>& valueOpt);
3838
Convertible matches(std::optional<VALUE>& valueOpt) override;
3939
std::string cppTypeName() override;
40-
VALUE rubyKlass() override;
40+
VALUE klass() override;
4141

4242
// std::string typeName() override;
4343
private:

rice/detail/Parameter.ipp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ namespace Rice::detail
9797
}
9898

9999
template<typename T>
100-
inline VALUE Parameter<T>::rubyKlass()
100+
inline VALUE Parameter<T>::klass()
101101
{
102102
TypeMapper<T> typeMapper;
103103
return typeMapper.rubyKlass();

rice/detail/RubyType.ipp

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ namespace Rice::detail
1212
static inline std::set<ruby_value_type> Narrowable = { };
1313
static inline std::string packTemplate = "not supported";
1414
static inline std::string name = "bool";
15-
static inline VALUE klass = rb_cTrueClass;
1615
};
1716

1817
template<>
@@ -27,7 +26,6 @@ namespace Rice::detail
2726
static inline std::set<ruby_value_type> Narrowable = { RUBY_T_FIXNUM };
2827
static inline std::string packTemplate = CHAR_MIN < 0 ? "c*" : "C*";
2928
static inline std::string name = "String";
30-
static inline VALUE klass = rb_cString;
3129
};
3230

3331
template<>
@@ -43,7 +41,6 @@ namespace Rice::detail
4341
static inline std::set<ruby_value_type> Narrowable = { RUBY_T_FIXNUM };
4442
static inline std::string packTemplate = "c*";
4543
static inline std::string name = "String";
46-
static inline VALUE klass = rb_cString;
4744
};
4845

4946
template<>
@@ -59,10 +56,6 @@ namespace Rice::detail
5956
static inline std::set<ruby_value_type> Narrowable = { RUBY_T_FIXNUM };
6057
static inline std::string packTemplate = "C*";
6158
static inline std::string name = "String";
62-
static inline VALUE klass()
63-
{
64-
return rb_cString;
65-
}
6659
};
6760

6861
template<>
@@ -77,10 +70,6 @@ namespace Rice::detail
7770
static inline std::set<ruby_value_type> Narrowable = { RUBY_T_FIXNUM };
7871
static inline std::string packTemplate = "s*";
7972
static inline std::string name = "Integer";
80-
static inline VALUE klass()
81-
{
82-
return rb_cInteger;
83-
}
8473
};
8574

8675
template<>
@@ -95,10 +84,6 @@ namespace Rice::detail
9584
static inline std::set<ruby_value_type> Narrowable = { RUBY_T_FIXNUM };
9685
static inline std::string packTemplate = "S*";
9786
static inline std::string name = "Integer";
98-
static inline VALUE klass()
99-
{
100-
return rb_cInteger;
101-
}
10287
};
10388

10489
template<>
@@ -115,10 +100,6 @@ namespace Rice::detail
115100
static inline std::set<ruby_value_type> Narrowable = { RUBY_T_BIGNUM };
116101
static inline std::string packTemplate = "i*";
117102
static inline std::string name = "Integer";
118-
static inline VALUE klass()
119-
{
120-
return rb_cInteger;
121-
}
122103
};
123104

124105
template<>
@@ -135,10 +116,6 @@ namespace Rice::detail
135116
static inline std::set<ruby_value_type> Narrowable = { RUBY_T_BIGNUM };
136117
static inline std::string packTemplate = "I*";
137118
static inline std::string name = "Integer";
138-
static inline VALUE klass()
139-
{
140-
return rb_cInteger;
141-
}
142119
};
143120

144121
template<>
@@ -153,10 +130,6 @@ namespace Rice::detail
153130
static inline std::set<ruby_value_type> Narrowable = { RUBY_T_BIGNUM };
154131
static inline std::string packTemplate = "l_*";
155132
static inline std::string name = "Integer";
156-
static inline VALUE klass()
157-
{
158-
return rb_cInteger;
159-
}
160133
};
161134

162135
template<>
@@ -171,10 +144,6 @@ namespace Rice::detail
171144
static inline std::set<ruby_value_type> Narrowable = { RUBY_T_BIGNUM};
172145
static inline std::string packTemplate = "L_*";
173146
static inline std::string name = "Integer";
174-
static inline VALUE klass()
175-
{
176-
return rb_cInteger;
177-
}
178147
};
179148

180149
template<>
@@ -189,10 +158,6 @@ namespace Rice::detail
189158
static inline std::set<ruby_value_type> Narrowable = { };
190159
static inline std::string packTemplate = "q_*";
191160
static inline std::string name = "Integer";
192-
static inline VALUE klass()
193-
{
194-
return rb_cInteger;
195-
}
196161
};
197162

198163
template<>
@@ -207,10 +172,6 @@ namespace Rice::detail
207172
static inline std::set<ruby_value_type> Narrowable = { };
208173
static inline std::string packTemplate = "Q_*";
209174
static inline std::string name = "Integer";
210-
static inline VALUE klass()
211-
{
212-
return rb_cInteger;
213-
}
214175
};
215176

216177
template<>
@@ -225,10 +186,6 @@ namespace Rice::detail
225186
static inline std::set<ruby_value_type> Narrowable = { RUBY_T_FLOAT };
226187
static inline std::string packTemplate = "f*";
227188
static inline std::string name = "Float";
228-
static inline VALUE klass()
229-
{
230-
return rb_cFloat;
231-
}
232189
};
233190

234191
template<>
@@ -243,10 +200,6 @@ namespace Rice::detail
243200
static inline std::set<ruby_value_type> Narrowable = { };
244201
static inline std::string packTemplate = "d*";
245202
static inline std::string name = "Float";
246-
static inline VALUE klass()
247-
{
248-
return rb_cFloat;
249-
}
250203
};
251204

252205
template<>
@@ -257,10 +210,6 @@ namespace Rice::detail
257210
static inline std::set<ruby_value_type> Castable = { };
258211
static inline std::set<ruby_value_type> Narrowable = { };
259212
static inline std::string name = "void";
260-
static inline VALUE klass()
261-
{
262-
return rb_cNilClass;
263-
}
264213
};
265214
}
266215

0 commit comments

Comments
 (0)