wurlinc-rice 1.4.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +23 -0
- data/Doxyfile +1253 -0
- data/Makefile.am +26 -0
- data/README +1119 -0
- data/README.mingw +8 -0
- data/Rakefile +33 -0
- data/bootstrap +9 -0
- data/configure.ac +52 -0
- data/doxygen.ac +314 -0
- data/doxygen.am +186 -0
- data/extconf.rb +41 -0
- data/post-autoconf.rb +22 -0
- data/post-automake.rb +28 -0
- data/rice/Address_Registration_Guard.hpp +7 -0
- data/rice/Address_Registration_Guard.ipp +34 -0
- data/rice/Address_Registration_Guard_defn.hpp +65 -0
- data/rice/Allocation_Strategies.hpp +37 -0
- data/rice/Arg.hpp +8 -0
- data/rice/Arg_impl.hpp +127 -0
- data/rice/Arg_operators.cpp +21 -0
- data/rice/Arg_operators.hpp +19 -0
- data/rice/Array.hpp +220 -0
- data/rice/Array.ipp +263 -0
- data/rice/Builtin_Object.hpp +8 -0
- data/rice/Builtin_Object.ipp +50 -0
- data/rice/Builtin_Object_defn.hpp +51 -0
- data/rice/Class.cpp +57 -0
- data/rice/Class.hpp +8 -0
- data/rice/Class.ipp +6 -0
- data/rice/Class_defn.hpp +83 -0
- data/rice/Constructor.hpp +367 -0
- data/rice/Critical_Guard.hpp +40 -0
- data/rice/Critical_Guard.ipp +26 -0
- data/rice/Data_Object.hpp +8 -0
- data/rice/Data_Object.ipp +133 -0
- data/rice/Data_Object_defn.hpp +132 -0
- data/rice/Data_Type.cpp +54 -0
- data/rice/Data_Type.hpp +8 -0
- data/rice/Data_Type.ipp +365 -0
- data/rice/Data_Type_defn.hpp +261 -0
- data/rice/Data_Type_fwd.hpp +12 -0
- data/rice/Director.cpp +13 -0
- data/rice/Director.hpp +39 -0
- data/rice/Enum.hpp +117 -0
- data/rice/Enum.ipp +246 -0
- data/rice/Exception.cpp +59 -0
- data/rice/Exception.hpp +9 -0
- data/rice/Exception_Base.hpp +8 -0
- data/rice/Exception_Base.ipp +13 -0
- data/rice/Exception_Base_defn.hpp +27 -0
- data/rice/Exception_defn.hpp +69 -0
- data/rice/Hash.hpp +210 -0
- data/rice/Hash.ipp +338 -0
- data/rice/Identifier.cpp +8 -0
- data/rice/Identifier.hpp +50 -0
- data/rice/Identifier.ipp +33 -0
- data/rice/Jump_Tag.hpp +24 -0
- data/rice/Makefile.am +129 -0
- data/rice/Module.cpp +84 -0
- data/rice/Module.hpp +8 -0
- data/rice/Module.ipp +6 -0
- data/rice/Module_defn.hpp +88 -0
- data/rice/Module_impl.hpp +281 -0
- data/rice/Module_impl.ipp +348 -0
- data/rice/Object.cpp +160 -0
- data/rice/Object.hpp +8 -0
- data/rice/Object.ipp +19 -0
- data/rice/Object_defn.hpp +191 -0
- data/rice/Require_Guard.hpp +21 -0
- data/rice/String.cpp +94 -0
- data/rice/String.hpp +89 -0
- data/rice/Struct.cpp +117 -0
- data/rice/Struct.hpp +162 -0
- data/rice/Struct.ipp +26 -0
- data/rice/Symbol.cpp +25 -0
- data/rice/Symbol.hpp +66 -0
- data/rice/Symbol.ipp +44 -0
- data/rice/VM.cpp +92 -0
- data/rice/VM.hpp +32 -0
- data/rice/config.hpp.in +40 -0
- data/rice/detail/Arguments.hpp +118 -0
- data/rice/detail/Auto_Function_Wrapper.hpp +829 -0
- data/rice/detail/Auto_Function_Wrapper.ipp +3391 -0
- data/rice/detail/Auto_Member_Function_Wrapper.hpp +828 -0
- data/rice/detail/Auto_Member_Function_Wrapper.ipp +2503 -0
- data/rice/detail/Caster.hpp +103 -0
- data/rice/detail/Exception_Handler.hpp +8 -0
- data/rice/detail/Exception_Handler.ipp +68 -0
- data/rice/detail/Exception_Handler_defn.hpp +96 -0
- data/rice/detail/Iterator.hpp +93 -0
- data/rice/detail/Not_Copyable.hpp +25 -0
- data/rice/detail/Wrapped_Function.hpp +33 -0
- data/rice/detail/cfp.hpp +24 -0
- data/rice/detail/cfp.ipp +51 -0
- data/rice/detail/check_ruby_type.cpp +27 -0
- data/rice/detail/check_ruby_type.hpp +23 -0
- data/rice/detail/creation_funcs.hpp +37 -0
- data/rice/detail/creation_funcs.ipp +36 -0
- data/rice/detail/default_allocation_func.hpp +23 -0
- data/rice/detail/default_allocation_func.ipp +11 -0
- data/rice/detail/define_method_and_auto_wrap.hpp +31 -0
- data/rice/detail/define_method_and_auto_wrap.ipp +30 -0
- data/rice/detail/demangle.cpp +56 -0
- data/rice/detail/demangle.hpp +19 -0
- data/rice/detail/env.hpp +19 -0
- data/rice/detail/from_ruby.hpp +43 -0
- data/rice/detail/from_ruby.ipp +60 -0
- data/rice/detail/method_data.cpp +159 -0
- data/rice/detail/method_data.hpp +21 -0
- data/rice/detail/mininode.cpp +1220 -0
- data/rice/detail/mininode.hpp +320 -0
- data/rice/detail/node.hpp +13 -0
- data/rice/detail/object_call.hpp +68 -0
- data/rice/detail/object_call.ipp +131 -0
- data/rice/detail/protect.cpp +29 -0
- data/rice/detail/protect.hpp +34 -0
- data/rice/detail/ruby.hpp +93 -0
- data/rice/detail/ruby_version_code.hpp.in +6 -0
- data/rice/detail/rubysig.hpp +19 -0
- data/rice/detail/st.hpp +60 -0
- data/rice/detail/to_ruby.hpp +22 -0
- data/rice/detail/to_ruby.ipp +36 -0
- data/rice/detail/traits.hpp +43 -0
- data/rice/detail/win32.hpp +16 -0
- data/rice/detail/wrap_function.hpp +341 -0
- data/rice/detail/wrap_function.ipp +514 -0
- data/rice/global_function.hpp +33 -0
- data/rice/global_function.ipp +22 -0
- data/rice/protect.hpp +91 -0
- data/rice/protect.ipp +1133 -0
- data/rice/ruby_mark.hpp +13 -0
- data/rice/ruby_try_catch.hpp +86 -0
- data/rice/rubypp.rb +97 -0
- data/rice/to_from_ruby.hpp +8 -0
- data/rice/to_from_ruby.ipp +297 -0
- data/rice/to_from_ruby_defn.hpp +71 -0
- data/ruby/Makefile.am +1 -0
- data/ruby/lib/Makefile.am +3 -0
- data/ruby/lib/mkmf-rice.rb.in +216 -0
- data/ruby/lib/version.rb +3 -0
- data/ruby.ac +136 -0
- data/sample/Makefile.am +47 -0
- data/sample/enum/extconf.rb +3 -0
- data/sample/enum/sample_enum.cpp +54 -0
- data/sample/enum/test.rb +8 -0
- data/sample/inheritance/animals.cpp +98 -0
- data/sample/inheritance/extconf.rb +3 -0
- data/sample/inheritance/test.rb +7 -0
- data/sample/map/extconf.rb +3 -0
- data/sample/map/map.cpp +81 -0
- data/sample/map/test.rb +7 -0
- data/test/Makefile.am +78 -0
- data/test/ext/Makefile.am +43 -0
- data/test/ext/t1/Foo.hpp +10 -0
- data/test/ext/t1/extconf.rb +2 -0
- data/test/ext/t1/t1.cpp +15 -0
- data/test/ext/t2/extconf.rb +2 -0
- data/test/ext/t2/t2.cpp +11 -0
- data/test/test_Address_Registration_Guard.cpp +43 -0
- data/test/test_Allocation_Strategies.cpp +77 -0
- data/test/test_Array.cpp +241 -0
- data/test/test_Builtin_Object.cpp +72 -0
- data/test/test_Class.cpp +498 -0
- data/test/test_Constructor.cpp +128 -0
- data/test/test_Critical_Guard.cpp +51 -0
- data/test/test_Data_Object.cpp +275 -0
- data/test/test_Data_Type.cpp +348 -0
- data/test/test_Director.cpp +301 -0
- data/test/test_Enum.cpp +195 -0
- data/test/test_Exception.cpp +46 -0
- data/test/test_Hash.cpp +195 -0
- data/test/test_Identifier.cpp +70 -0
- data/test/test_Jump_Tag.cpp +17 -0
- data/test/test_Memory_Management.cpp +50 -0
- data/test/test_Module.cpp +481 -0
- data/test/test_Object.cpp +148 -0
- data/test/test_String.cpp +94 -0
- data/test/test_Struct.cpp +192 -0
- data/test/test_Symbol.cpp +63 -0
- data/test/test_To_From_Ruby.cpp +263 -0
- data/test/test_VM.cpp +26 -0
- data/test/test_global_functions.cpp +114 -0
- data/test/test_rice.rb +43 -0
- data/test/unittest.cpp +136 -0
- data/test/unittest.hpp +292 -0
- metadata +276 -0
data/rice/Array.ipp
ADDED
@@ -0,0 +1,263 @@
|
|
1
|
+
#ifndef Rice__Array__ipp_
|
2
|
+
#define Rice__Array__ipp_
|
3
|
+
|
4
|
+
#include "protect.hpp"
|
5
|
+
|
6
|
+
inline Rice::Array::
|
7
|
+
Array()
|
8
|
+
: Builtin_Object<RArray, T_ARRAY>(protect(rb_ary_new))
|
9
|
+
{
|
10
|
+
}
|
11
|
+
|
12
|
+
inline Rice::Array::
|
13
|
+
Array(Object v)
|
14
|
+
: Builtin_Object<RArray, T_ARRAY>(v)
|
15
|
+
{
|
16
|
+
}
|
17
|
+
|
18
|
+
inline Rice::Array::
|
19
|
+
Array(VALUE v)
|
20
|
+
: Builtin_Object<RArray, T_ARRAY>(v)
|
21
|
+
{
|
22
|
+
}
|
23
|
+
|
24
|
+
template<typename Iter_T>
|
25
|
+
inline Rice::Array::
|
26
|
+
Array(Iter_T it, Iter_T end)
|
27
|
+
: Builtin_Object<RArray, T_ARRAY>(protect(rb_ary_new))
|
28
|
+
{
|
29
|
+
for(; it != end; ++it)
|
30
|
+
{
|
31
|
+
push(*it);
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
35
|
+
template<typename T, size_t n>
|
36
|
+
inline Rice::Array::
|
37
|
+
Array(T const (& a)[n])
|
38
|
+
: Builtin_Object<RArray, T_ARRAY>(protect(rb_ary_new))
|
39
|
+
{
|
40
|
+
for(size_t j = 0; j < n; ++j)
|
41
|
+
{
|
42
|
+
push(a[j]);
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
inline size_t Rice::Array::
|
47
|
+
size() const
|
48
|
+
{
|
49
|
+
return RARRAY_LEN(this->value());
|
50
|
+
}
|
51
|
+
|
52
|
+
inline Rice::Object Rice::Array::
|
53
|
+
operator[](ptrdiff_t index) const
|
54
|
+
{
|
55
|
+
VALUE * ptr = RARRAY_PTR(this->value());
|
56
|
+
return ptr[position_of(index)];
|
57
|
+
}
|
58
|
+
|
59
|
+
inline Rice::Array::Proxy Rice::Array::
|
60
|
+
operator[](ptrdiff_t index)
|
61
|
+
{
|
62
|
+
return Proxy(*this, position_of(index));
|
63
|
+
}
|
64
|
+
|
65
|
+
template<typename T>
|
66
|
+
inline Rice::Object Rice::Array::
|
67
|
+
push(T const & obj)
|
68
|
+
{
|
69
|
+
return protect(rb_ary_push, value(), to_ruby(obj));
|
70
|
+
}
|
71
|
+
|
72
|
+
inline Rice::Object Rice::Array::
|
73
|
+
pop()
|
74
|
+
{
|
75
|
+
return protect(rb_ary_pop, value());
|
76
|
+
}
|
77
|
+
|
78
|
+
template<typename T>
|
79
|
+
inline Rice::Object Rice::Array::
|
80
|
+
unshift(T const & obj)
|
81
|
+
{
|
82
|
+
return protect(rb_ary_unshift, value(), to_ruby(obj));
|
83
|
+
}
|
84
|
+
|
85
|
+
inline Rice::Object Rice::Array::
|
86
|
+
shift()
|
87
|
+
{
|
88
|
+
return protect(rb_ary_shift, value());
|
89
|
+
}
|
90
|
+
|
91
|
+
inline VALUE * Rice::Array::
|
92
|
+
to_c_array()
|
93
|
+
{
|
94
|
+
return RARRAY_PTR(this->value());
|
95
|
+
}
|
96
|
+
|
97
|
+
inline size_t Rice::Array::
|
98
|
+
position_of(ptrdiff_t index) const
|
99
|
+
{
|
100
|
+
if(index < 0)
|
101
|
+
{
|
102
|
+
return size() + index;
|
103
|
+
}
|
104
|
+
else
|
105
|
+
{
|
106
|
+
return static_cast<size_t>(index);
|
107
|
+
}
|
108
|
+
}
|
109
|
+
|
110
|
+
inline Rice::Array::Proxy::
|
111
|
+
Proxy(Array array, size_t index)
|
112
|
+
: array_(array)
|
113
|
+
, index_(index)
|
114
|
+
{
|
115
|
+
}
|
116
|
+
|
117
|
+
inline Rice::Array::Proxy::
|
118
|
+
operator Rice::Object() const
|
119
|
+
{
|
120
|
+
return RARRAY_PTR(array_.value())[index_];
|
121
|
+
}
|
122
|
+
|
123
|
+
inline VALUE Rice::Array::Proxy::
|
124
|
+
value() const
|
125
|
+
{
|
126
|
+
return RARRAY_PTR(array_.value())[index_];
|
127
|
+
}
|
128
|
+
|
129
|
+
template<typename T>
|
130
|
+
Rice::Object Rice::Array::Proxy::
|
131
|
+
operator=(T const & value)
|
132
|
+
{
|
133
|
+
Object o = to_ruby(value);
|
134
|
+
RARRAY_PTR(array_.value())[index_] = o.value();
|
135
|
+
return o;
|
136
|
+
}
|
137
|
+
|
138
|
+
template<typename Array_Ref_T, typename Value_T>
|
139
|
+
inline Rice::Array::Iterator<Array_Ref_T, Value_T>::
|
140
|
+
Iterator(Array_Ref_T array, size_t index)
|
141
|
+
: array_(array)
|
142
|
+
, index_(index)
|
143
|
+
{
|
144
|
+
}
|
145
|
+
|
146
|
+
template<typename Array_Ref_T, typename Value_T>
|
147
|
+
template<typename Array_Ref_T_, typename Value_T_>
|
148
|
+
inline
|
149
|
+
Rice::Array::Iterator<Array_Ref_T, Value_T>::
|
150
|
+
Iterator(Iterator<Array_Ref_T_, Value_T_> const & rhs)
|
151
|
+
: array_(rhs.array())
|
152
|
+
, index_(rhs.index())
|
153
|
+
, tmp_()
|
154
|
+
{
|
155
|
+
}
|
156
|
+
|
157
|
+
template<typename Array_Ref_T, typename Value_T>
|
158
|
+
template<typename Array_Ref_T_, typename Value_T_>
|
159
|
+
inline Rice::Array::Iterator<Array_Ref_T, Value_T> &
|
160
|
+
Rice::Array::Iterator<Array_Ref_T, Value_T>::
|
161
|
+
operator=(Iterator<Array_Ref_T_, Value_T_> const & rhs)
|
162
|
+
{
|
163
|
+
array_ = rhs.array_;
|
164
|
+
index_ = rhs.index_;
|
165
|
+
return *this;
|
166
|
+
}
|
167
|
+
|
168
|
+
template<typename Array_Ref_T, typename Value_T>
|
169
|
+
inline Rice::Array::Iterator<Array_Ref_T, Value_T> &
|
170
|
+
Rice::Array::Iterator<Array_Ref_T, Value_T>::
|
171
|
+
operator++()
|
172
|
+
{
|
173
|
+
++index_;
|
174
|
+
return *this;
|
175
|
+
}
|
176
|
+
|
177
|
+
template<typename Array_Ref_T, typename Value_T>
|
178
|
+
inline Rice::Array::Iterator<Array_Ref_T, Value_T>
|
179
|
+
Rice::Array::Iterator<Array_Ref_T, Value_T>::
|
180
|
+
operator++(int)
|
181
|
+
{
|
182
|
+
Array copy(*this);
|
183
|
+
++(*this);
|
184
|
+
return *this;
|
185
|
+
}
|
186
|
+
|
187
|
+
template<typename Array_Ref_T, typename Value_T>
|
188
|
+
inline Value_T
|
189
|
+
Rice::Array::Iterator<Array_Ref_T, Value_T>::
|
190
|
+
operator*()
|
191
|
+
{
|
192
|
+
return array_[index_];
|
193
|
+
}
|
194
|
+
|
195
|
+
template<typename Array_Ref_T, typename Value_T>
|
196
|
+
inline Rice::Object *
|
197
|
+
Rice::Array::Iterator<Array_Ref_T, Value_T>::
|
198
|
+
operator->()
|
199
|
+
{
|
200
|
+
tmp_ = array_[index_];
|
201
|
+
return &tmp_;
|
202
|
+
}
|
203
|
+
|
204
|
+
template<typename Array_Ref_T, typename Value_T>
|
205
|
+
template<typename Array_Ref_T_, typename Value_T_>
|
206
|
+
inline bool
|
207
|
+
Rice::Array::Iterator<Array_Ref_T, Value_T>::
|
208
|
+
operator==(Iterator<Array_Ref_T_, Value_T_> const & rhs) const
|
209
|
+
{
|
210
|
+
return array_.value() == rhs.array_.value() && index_ == rhs.index_;
|
211
|
+
}
|
212
|
+
|
213
|
+
template<typename Array_Ref_T, typename Value_T>
|
214
|
+
template<typename Array_Ref_T_, typename Value_T_>
|
215
|
+
inline bool
|
216
|
+
Rice::Array::Iterator<Array_Ref_T, Value_T>::
|
217
|
+
operator!=(Iterator<Array_Ref_T_, Value_T_> const & rhs) const
|
218
|
+
{
|
219
|
+
return !(*this == rhs);
|
220
|
+
}
|
221
|
+
|
222
|
+
template<typename Array_Ref_T, typename Value_T>
|
223
|
+
Array_Ref_T
|
224
|
+
Rice::Array::Iterator<Array_Ref_T, Value_T>::
|
225
|
+
array() const
|
226
|
+
{
|
227
|
+
return array_;
|
228
|
+
}
|
229
|
+
|
230
|
+
template<typename Array_Ref_T, typename Value_T>
|
231
|
+
size_t
|
232
|
+
Rice::Array::Iterator<Array_Ref_T, Value_T>::
|
233
|
+
index() const
|
234
|
+
{
|
235
|
+
return index_;
|
236
|
+
}
|
237
|
+
|
238
|
+
inline Rice::Array::iterator Rice::Array::
|
239
|
+
begin()
|
240
|
+
{
|
241
|
+
return iterator(*this, 0);
|
242
|
+
}
|
243
|
+
|
244
|
+
inline Rice::Array::const_iterator Rice::Array::
|
245
|
+
begin() const
|
246
|
+
{
|
247
|
+
return const_iterator(*this, 0);
|
248
|
+
}
|
249
|
+
|
250
|
+
inline Rice::Array::iterator Rice::Array::
|
251
|
+
end()
|
252
|
+
{
|
253
|
+
return iterator(*this, size());
|
254
|
+
}
|
255
|
+
|
256
|
+
inline Rice::Array::const_iterator Rice::Array::
|
257
|
+
end() const
|
258
|
+
{
|
259
|
+
return const_iterator(*this, size());
|
260
|
+
}
|
261
|
+
|
262
|
+
#endif // Rice__Array__ipp_
|
263
|
+
|
@@ -0,0 +1,50 @@
|
|
1
|
+
#ifndef Rice__Builtin_Object__ipp_
|
2
|
+
#define Rice__Builtin_Object__ipp_
|
3
|
+
|
4
|
+
#include "Object.hpp"
|
5
|
+
#include "protect.hpp"
|
6
|
+
#include "detail/check_ruby_type.hpp"
|
7
|
+
|
8
|
+
#include <algorithm>
|
9
|
+
|
10
|
+
namespace Rice
|
11
|
+
{
|
12
|
+
|
13
|
+
namespace detail
|
14
|
+
{
|
15
|
+
inline VALUE check_type(Object value, int type)
|
16
|
+
{
|
17
|
+
rb_check_type(value, type);
|
18
|
+
return Qnil;
|
19
|
+
}
|
20
|
+
}
|
21
|
+
|
22
|
+
template<typename T, int Builtin_Type>
|
23
|
+
inline Builtin_Object<T, Builtin_Type>::
|
24
|
+
Builtin_Object(Object value)
|
25
|
+
: Object(value)
|
26
|
+
, obj_((T*)(value.value()))
|
27
|
+
{
|
28
|
+
protect(detail::check_type, value, Builtin_Type);
|
29
|
+
}
|
30
|
+
|
31
|
+
template<typename T, int Builtin_Type>
|
32
|
+
inline Builtin_Object<T, Builtin_Type>::
|
33
|
+
Builtin_Object(Builtin_Object<T, Builtin_Type> const & other)
|
34
|
+
: Object(other.value())
|
35
|
+
, obj_(other.obj_)
|
36
|
+
{
|
37
|
+
}
|
38
|
+
|
39
|
+
template<typename T, int Builtin_Type>
|
40
|
+
inline void Builtin_Object<T, Builtin_Type>::
|
41
|
+
swap(Builtin_Object<T, Builtin_Type> & ref)
|
42
|
+
{
|
43
|
+
std::swap(obj_, ref.obj_);
|
44
|
+
Object::swap(ref);
|
45
|
+
}
|
46
|
+
|
47
|
+
} // namespace Rice
|
48
|
+
|
49
|
+
#endif // Rice__Builtin_Object__ipp_
|
50
|
+
|
@@ -0,0 +1,51 @@
|
|
1
|
+
#ifndef Rice__Builtin_Object_defn__hpp_
|
2
|
+
#define Rice__Builtin_Object_defn__hpp_
|
3
|
+
|
4
|
+
#include "Object_defn.hpp"
|
5
|
+
#include "Allocation_Strategies.hpp"
|
6
|
+
#include "detail/ruby.hpp"
|
7
|
+
|
8
|
+
namespace Rice
|
9
|
+
{
|
10
|
+
|
11
|
+
//! A smartpointer-like wrapper for Ruby builtin objects.
|
12
|
+
/*! A builtin object is one of Ruby's internal types, e.g. RArray or
|
13
|
+
* RString. Every builtin type structure has a corresponding integer
|
14
|
+
* type number (e.g T_ARRAY for RArray or T_STRING for RString). This
|
15
|
+
* class is a wrapper for those types of objects, primarily useful as a
|
16
|
+
* base class for other wrapper classes like Array and Hash.
|
17
|
+
*/
|
18
|
+
template<typename T, int Builtin_Type>
|
19
|
+
class Builtin_Object
|
20
|
+
: public Object
|
21
|
+
{
|
22
|
+
public:
|
23
|
+
//! Wrap an already allocated Ruby object.
|
24
|
+
/*! Checks to see if the object is an object of type Builtin_Type; a
|
25
|
+
* C++ exception is thrown if this is not the case.
|
26
|
+
* \param value the object to be wrapped.
|
27
|
+
*/
|
28
|
+
Builtin_Object(Object value);
|
29
|
+
|
30
|
+
//! Make a copy of a Builtin_Object
|
31
|
+
/*! \param other the Builtin_Object to be copied.
|
32
|
+
*/
|
33
|
+
Builtin_Object(Builtin_Object const & other);
|
34
|
+
|
35
|
+
T & operator*() const { return *obj_; } //!< Return a reference to obj_
|
36
|
+
T * operator->() const { return obj_; } //!< Return a pointer to obj_
|
37
|
+
T * get() const { return obj_; } //!< Return a pointer to obj_
|
38
|
+
|
39
|
+
//! Swap with another builtin object of the same type
|
40
|
+
/*! \param ref the object with which to swap.
|
41
|
+
*/
|
42
|
+
void swap(Builtin_Object<T, Builtin_Type> & ref);
|
43
|
+
|
44
|
+
private:
|
45
|
+
T * obj_;
|
46
|
+
};
|
47
|
+
|
48
|
+
} // namespace Rice
|
49
|
+
|
50
|
+
#endif // Rice__Builtin_Object_defn__hpp_
|
51
|
+
|
data/rice/Class.cpp
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
#include "Class.hpp"
|
2
|
+
#include "Exception.hpp"
|
3
|
+
#include "detail/creation_funcs.hpp"
|
4
|
+
|
5
|
+
Rice::Class::
|
6
|
+
Class()
|
7
|
+
: Module_impl<Module, Class>()
|
8
|
+
{
|
9
|
+
}
|
10
|
+
|
11
|
+
Rice::Class::
|
12
|
+
Class(VALUE v)
|
13
|
+
: Module_impl<Module, Class>(v)
|
14
|
+
{
|
15
|
+
if(::rb_type(v) != T_CLASS)
|
16
|
+
{
|
17
|
+
throw Exception(
|
18
|
+
rb_eTypeError,
|
19
|
+
"Expected a Class but got a %s",
|
20
|
+
rb_class2name(CLASS_OF(v))); // TODO: might raise an exception
|
21
|
+
}
|
22
|
+
}
|
23
|
+
|
24
|
+
Rice::Class & Rice::Class::
|
25
|
+
undef_creation_funcs()
|
26
|
+
{
|
27
|
+
detail::undef_creation_funcs(*this);
|
28
|
+
return *this;
|
29
|
+
}
|
30
|
+
|
31
|
+
Rice::Class Rice::
|
32
|
+
define_class_under(
|
33
|
+
Rice::Object module,
|
34
|
+
char const * name,
|
35
|
+
Rice::Object superclass)
|
36
|
+
{
|
37
|
+
VALUE v = rb_define_class_under(module, name, superclass);
|
38
|
+
return Class(v);
|
39
|
+
}
|
40
|
+
|
41
|
+
Rice::Class Rice::
|
42
|
+
define_class(
|
43
|
+
char const * name,
|
44
|
+
Rice::Object superclass)
|
45
|
+
{
|
46
|
+
VALUE v = rb_define_class(name, superclass);
|
47
|
+
return Class(v);
|
48
|
+
}
|
49
|
+
|
50
|
+
Rice::Class Rice::
|
51
|
+
anonymous_class(
|
52
|
+
Rice::Object superclass)
|
53
|
+
{
|
54
|
+
VALUE v = Class(rb_cClass).call("new");
|
55
|
+
return Class(v);
|
56
|
+
}
|
57
|
+
|
data/rice/Class.hpp
ADDED
data/rice/Class.ipp
ADDED
data/rice/Class_defn.hpp
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
#ifndef Rice__Class_defn__hpp_
|
2
|
+
#define Rice__Class_defn__hpp_
|
3
|
+
|
4
|
+
#include "Object_defn.hpp"
|
5
|
+
#include "Module_impl.hpp"
|
6
|
+
#include "Module_defn.hpp"
|
7
|
+
#include "to_from_ruby_defn.hpp"
|
8
|
+
#include "Identifier.hpp"
|
9
|
+
|
10
|
+
/*!
|
11
|
+
* \example inheritance/animals.cpp
|
12
|
+
*/
|
13
|
+
|
14
|
+
namespace Rice
|
15
|
+
{
|
16
|
+
|
17
|
+
//! A helper for defining a Class and its methods.
|
18
|
+
/*! This class provides a C++-style interface to ruby's Class class and
|
19
|
+
* for defining methods on that class.
|
20
|
+
*/
|
21
|
+
class Class
|
22
|
+
: public Module_impl<Module, Class>
|
23
|
+
{
|
24
|
+
public:
|
25
|
+
//! Default construct a new class wrapper and initialize it to
|
26
|
+
//! rb_cObject.
|
27
|
+
Class();
|
28
|
+
|
29
|
+
//! Construct a new class wrapper from a ruby object of type T_CLASS.
|
30
|
+
Class(VALUE v);
|
31
|
+
|
32
|
+
//! Disallow creation of an instance from Ruby code.
|
33
|
+
/*! Undefines the singleton method allocate (or new, if using a
|
34
|
+
* version of ruby prior to 1.7) and the instance method initialize.
|
35
|
+
*/
|
36
|
+
Class & undef_creation_funcs();
|
37
|
+
};
|
38
|
+
|
39
|
+
//! Define a new class in the namespace given by module.
|
40
|
+
/*! \param module the Module in which to define the class.
|
41
|
+
* \param name the name of the class.
|
42
|
+
* \param superclass the base class to use.
|
43
|
+
* \return the new class.
|
44
|
+
*/
|
45
|
+
Class define_class_under(
|
46
|
+
Object module,
|
47
|
+
char const * name,
|
48
|
+
Object superclass = rb_cObject);
|
49
|
+
|
50
|
+
//! Define a new class in the default namespace.
|
51
|
+
/*! \param name the name of the class.
|
52
|
+
* \param superclass the base class to use.
|
53
|
+
* \return the new class.
|
54
|
+
*/
|
55
|
+
Class define_class(
|
56
|
+
char const * name,
|
57
|
+
Object superclass = rb_cObject);
|
58
|
+
|
59
|
+
//! Create a new anonymous class.
|
60
|
+
/*! \param superclass the base class to use.
|
61
|
+
* \return the new class.
|
62
|
+
*/
|
63
|
+
Class anonymous_class(
|
64
|
+
Object superclass = rb_cObject);
|
65
|
+
|
66
|
+
} // namespace Rice
|
67
|
+
|
68
|
+
template<>
|
69
|
+
inline
|
70
|
+
Rice::Class from_ruby<Rice::Class>(Rice::Object x)
|
71
|
+
{
|
72
|
+
return Rice::Class(x);
|
73
|
+
}
|
74
|
+
|
75
|
+
template<>
|
76
|
+
inline
|
77
|
+
Rice::Object to_ruby<Rice::Class>(Rice::Class const & x)
|
78
|
+
{
|
79
|
+
return x;
|
80
|
+
}
|
81
|
+
|
82
|
+
#endif // Rice__Class_defn__hpp_
|
83
|
+
|