keyme-rice 1.5.1.keyme
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 +15 -0
- data/COPYING +23 -0
- data/Doxyfile +1253 -0
- data/Makefile.am +26 -0
- data/Makefile.in +853 -0
- data/README +1124 -0
- data/README.mingw +8 -0
- data/Rakefile +34 -0
- data/aclocal.m4 +971 -0
- data/bootstrap +8 -0
- data/config.guess +1530 -0
- data/config.sub +1773 -0
- data/configure +7121 -0
- data/configure.ac +52 -0
- data/depcomp +688 -0
- data/doxygen.ac +314 -0
- data/doxygen.am +186 -0
- data/extconf.rb +51 -0
- data/install-sh +527 -0
- data/missing +331 -0
- data/post-autoconf.rb +22 -0
- data/post-automake.rb +28 -0
- data/rice/Address_Registration_Guard.cpp +22 -0
- data/rice/Address_Registration_Guard.hpp +7 -0
- data/rice/Address_Registration_Guard.ipp +37 -0
- data/rice/Address_Registration_Guard_defn.hpp +75 -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 +50 -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 +368 -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 +138 -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 +227 -0
- data/rice/Hash.ipp +330 -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/Makefile.in +769 -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 +82 -0
- data/rice/VM.hpp +32 -0
- data/rice/config.hpp +44 -0
- data/rice/config.hpp.in +43 -0
- data/rice/detail/Arguments.hpp +118 -0
- data/rice/detail/Auto_Function_Wrapper.hpp +898 -0
- data/rice/detail/Auto_Function_Wrapper.ipp +3694 -0
- data/rice/detail/Auto_Member_Function_Wrapper.hpp +897 -0
- data/rice/detail/Auto_Member_Function_Wrapper.ipp +2774 -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 +69 -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 +84 -0
- data/rice/detail/ruby_version_code.hpp +6 -0
- data/rice/detail/ruby_version_code.hpp.in +6 -0
- data/rice/detail/rubysig.hpp +19 -0
- data/rice/detail/st.hpp +22 -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 +92 -0
- data/rice/protect.ipp +1134 -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 +294 -0
- data/rice/to_from_ruby_defn.hpp +71 -0
- data/ruby/Makefile.am +1 -0
- data/ruby/Makefile.in +569 -0
- data/ruby/lib/Makefile.am +3 -0
- data/ruby/lib/Makefile.in +423 -0
- data/ruby/lib/mkmf-rice.rb.in +213 -0
- data/ruby/lib/version.rb +3 -0
- data/ruby.ac +136 -0
- data/sample/Makefile.am +47 -0
- data/sample/Makefile.in +408 -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 +77 -0
- data/test/Makefile.in +820 -0
- data/test/ext/Makefile.am +43 -0
- data/test/ext/Makefile.in +404 -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_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 +303 -0
- data/test/test_Enum.cpp +195 -0
- data/test/test_Exception.cpp +46 -0
- data/test/test_Hash.cpp +198 -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 +497 -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 +321 -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 +294 -0
- metadata +259 -0
data/rice/Array.hpp
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
#ifndef Rice__Array__hpp_
|
|
2
|
+
#define Rice__Array__hpp_
|
|
3
|
+
|
|
4
|
+
#include "Builtin_Object.hpp"
|
|
5
|
+
#include "to_from_ruby_defn.hpp"
|
|
6
|
+
#include "detail/ruby.hpp"
|
|
7
|
+
#include <iterator>
|
|
8
|
+
|
|
9
|
+
namespace Rice
|
|
10
|
+
{
|
|
11
|
+
|
|
12
|
+
//! A wrapper for the ruby Array class.
|
|
13
|
+
/*! This class provides a C++-style interface to ruby's Array class and
|
|
14
|
+
* its associated rb_ary_* functions.
|
|
15
|
+
* Example:
|
|
16
|
+
* \code
|
|
17
|
+
* Array a;
|
|
18
|
+
* a.push(String("some string"));
|
|
19
|
+
* a.push(42);
|
|
20
|
+
* \endcode
|
|
21
|
+
*/
|
|
22
|
+
class Array
|
|
23
|
+
: public Builtin_Object<RArray, T_ARRAY>
|
|
24
|
+
{
|
|
25
|
+
public:
|
|
26
|
+
//! Construct a new array
|
|
27
|
+
Array();
|
|
28
|
+
|
|
29
|
+
//! Wrap an existing array
|
|
30
|
+
/*! \param v a ruby object, which must be of type T_ARRAY.
|
|
31
|
+
*/
|
|
32
|
+
Array(Object v);
|
|
33
|
+
|
|
34
|
+
//! Wrap an existing array
|
|
35
|
+
/*! \param v a ruby object, which must be of type T_ARRAY.
|
|
36
|
+
*/
|
|
37
|
+
Array(VALUE v);
|
|
38
|
+
|
|
39
|
+
//! Construct an array from a sequence.
|
|
40
|
+
/*! \param begin an iterator to the beginning of the sequence.
|
|
41
|
+
* \param end an iterator to the end of the sequence.
|
|
42
|
+
*/
|
|
43
|
+
template<typename Iter_T>
|
|
44
|
+
Array(Iter_T begin, Iter_T end);
|
|
45
|
+
|
|
46
|
+
//! Construct an Array from a C array.
|
|
47
|
+
/*! \param a a C array of type T and size n.
|
|
48
|
+
*/
|
|
49
|
+
template<typename T, size_t n>
|
|
50
|
+
Array(T const (& a)[n]);
|
|
51
|
+
|
|
52
|
+
public:
|
|
53
|
+
//! Return the size of the array.
|
|
54
|
+
size_t size() const;
|
|
55
|
+
|
|
56
|
+
//! Return the element at the given index.
|
|
57
|
+
/*! \param index The index of the desired element. The index may be
|
|
58
|
+
* negative, to indicate an offset from the end of the array. If the
|
|
59
|
+
* index is out of bounds, this function has undefined behavior.
|
|
60
|
+
* \return the element at the given index.
|
|
61
|
+
*/
|
|
62
|
+
Object operator[](ptrdiff_t index) const;
|
|
63
|
+
|
|
64
|
+
private:
|
|
65
|
+
//! A helper class so array[index]=value can work.
|
|
66
|
+
class Proxy;
|
|
67
|
+
|
|
68
|
+
public:
|
|
69
|
+
//! Return a reference to the element at the given index.
|
|
70
|
+
/*! \param index The index of the desired element. The index may be
|
|
71
|
+
* negative, to indicate an offset from the end of the array. If the
|
|
72
|
+
* index is out of bounds, this function has undefined behavior.
|
|
73
|
+
* \return the element at the given index.
|
|
74
|
+
*/
|
|
75
|
+
Proxy operator[](ptrdiff_t index);
|
|
76
|
+
|
|
77
|
+
//! Push an element onto the end of the array
|
|
78
|
+
/*! \param v an object to push onto the array.
|
|
79
|
+
* \return the object which was pushed onto the array.
|
|
80
|
+
*/
|
|
81
|
+
template<typename T>
|
|
82
|
+
Object push(T const & obj);
|
|
83
|
+
|
|
84
|
+
//! Pop an element from the end of the array
|
|
85
|
+
/*! \return the object which was popped from the array, or Qnil if
|
|
86
|
+
* the array was empty.
|
|
87
|
+
*/
|
|
88
|
+
Object pop();
|
|
89
|
+
|
|
90
|
+
//! Unshift an element onto the beginning of the array
|
|
91
|
+
/*! \param v an object to unshift onto the array.
|
|
92
|
+
* \return the object which was unshifted onto the array.
|
|
93
|
+
*/
|
|
94
|
+
template<typename T>
|
|
95
|
+
Object unshift(T const & obj);
|
|
96
|
+
|
|
97
|
+
//! Shift an element from the beginning of the array
|
|
98
|
+
/*! \return the object which was shifted from the array.
|
|
99
|
+
*/
|
|
100
|
+
Object shift();
|
|
101
|
+
|
|
102
|
+
//! Return a pointer to the beginning of the underlying C array.
|
|
103
|
+
//! Use with caution!
|
|
104
|
+
/*! \return a pointer to the beginning of the array.
|
|
105
|
+
*/
|
|
106
|
+
VALUE * to_c_array();
|
|
107
|
+
|
|
108
|
+
private:
|
|
109
|
+
template<typename Array_Ref_T, typename Value_T>
|
|
110
|
+
class Iterator;
|
|
111
|
+
|
|
112
|
+
size_t position_of(ptrdiff_t index) const;
|
|
113
|
+
|
|
114
|
+
public:
|
|
115
|
+
//! An iterator.
|
|
116
|
+
typedef Iterator<Array &, Proxy> iterator;
|
|
117
|
+
|
|
118
|
+
//! A const iterator.
|
|
119
|
+
typedef Iterator<Array const &, Object> const_iterator;
|
|
120
|
+
|
|
121
|
+
//! Return an iterator to the beginning of the array.
|
|
122
|
+
iterator begin();
|
|
123
|
+
|
|
124
|
+
//! Return a const iterator to the beginning of the array.
|
|
125
|
+
const_iterator begin() const;
|
|
126
|
+
|
|
127
|
+
//! Return an iterator to the end of the array.
|
|
128
|
+
iterator end();
|
|
129
|
+
|
|
130
|
+
//! Return a const iterator to the end of the array.
|
|
131
|
+
const_iterator end() const;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
//! A helper class so array[index]=value can work.
|
|
135
|
+
class Array::Proxy
|
|
136
|
+
{
|
|
137
|
+
public:
|
|
138
|
+
//! Construct a new Proxy
|
|
139
|
+
Proxy(Array array, size_t index);
|
|
140
|
+
|
|
141
|
+
//! Implicit conversion to Object.
|
|
142
|
+
operator Object() const;
|
|
143
|
+
|
|
144
|
+
//! Explicit conversion to VALUE.
|
|
145
|
+
VALUE value() const;
|
|
146
|
+
|
|
147
|
+
//! Assignment operator.
|
|
148
|
+
template<typename T>
|
|
149
|
+
Object operator=(T const & value);
|
|
150
|
+
|
|
151
|
+
private:
|
|
152
|
+
Array array_;
|
|
153
|
+
size_t index_;
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
//! A helper class for implementing iterators for a Array.
|
|
157
|
+
// TODO: This really should be a random-access iterator.
|
|
158
|
+
template<typename Array_Ref_T, typename Value_T>
|
|
159
|
+
class Array::Iterator
|
|
160
|
+
: public std::iterator<
|
|
161
|
+
std::forward_iterator_tag,
|
|
162
|
+
Value_T, // Type
|
|
163
|
+
ptrdiff_t, // Distance type
|
|
164
|
+
Object *, // Pointer type
|
|
165
|
+
Value_T &> // Reference type
|
|
166
|
+
{
|
|
167
|
+
public:
|
|
168
|
+
Iterator(Array_Ref_T array, size_t index);
|
|
169
|
+
|
|
170
|
+
template<typename Array_Ref_T_, typename Value_T_>
|
|
171
|
+
Iterator(Iterator<Array_Ref_T_, Value_T_> const & rhs);
|
|
172
|
+
|
|
173
|
+
template<typename Array_Ref_T_, typename Value_T_>
|
|
174
|
+
Iterator & operator=(Iterator<Array_Ref_T_, Value_T_> const & rhs);
|
|
175
|
+
|
|
176
|
+
Iterator & operator++();
|
|
177
|
+
Iterator operator++(int);
|
|
178
|
+
Value_T operator*();
|
|
179
|
+
Object * operator->();
|
|
180
|
+
|
|
181
|
+
template<typename Array_Ref_T_, typename Value_T_>
|
|
182
|
+
bool operator==(Iterator<Array_Ref_T_, Value_T_> const & rhs) const;
|
|
183
|
+
|
|
184
|
+
template<typename Array_Ref_T_, typename Value_T_>
|
|
185
|
+
bool operator!=(Iterator<Array_Ref_T_, Value_T_> const & rhs) const;
|
|
186
|
+
|
|
187
|
+
// Causes ICE on g++ 3.3.3
|
|
188
|
+
// template<typename Array_Ref_T_, typename Value_T_>
|
|
189
|
+
// friend class Iterator;
|
|
190
|
+
|
|
191
|
+
Array_Ref_T array() const;
|
|
192
|
+
size_t index() const;
|
|
193
|
+
|
|
194
|
+
private:
|
|
195
|
+
Array_Ref_T array_;
|
|
196
|
+
size_t index_;
|
|
197
|
+
|
|
198
|
+
Object tmp_;
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
} // namespace Rice
|
|
202
|
+
|
|
203
|
+
template<>
|
|
204
|
+
inline
|
|
205
|
+
Rice::Array from_ruby<Rice::Array>(Rice::Object x)
|
|
206
|
+
{
|
|
207
|
+
return Rice::Array(x);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
template<>
|
|
211
|
+
inline
|
|
212
|
+
Rice::Object to_ruby<Rice::Array>(Rice::Array const & x)
|
|
213
|
+
{
|
|
214
|
+
return x;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
#include "Array.ipp"
|
|
218
|
+
|
|
219
|
+
#endif // Rice__Array__hpp_
|
|
220
|
+
|
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,50 @@
|
|
|
1
|
+
#ifndef Rice__Builtin_Object_defn__hpp_
|
|
2
|
+
#define Rice__Builtin_Object_defn__hpp_
|
|
3
|
+
|
|
4
|
+
#include "Object_defn.hpp"
|
|
5
|
+
#include "detail/ruby.hpp"
|
|
6
|
+
|
|
7
|
+
namespace Rice
|
|
8
|
+
{
|
|
9
|
+
|
|
10
|
+
//! A smartpointer-like wrapper for Ruby builtin objects.
|
|
11
|
+
/*! A builtin object is one of Ruby's internal types, e.g. RArray or
|
|
12
|
+
* RString. Every builtin type structure has a corresponding integer
|
|
13
|
+
* type number (e.g T_ARRAY for RArray or T_STRING for RString). This
|
|
14
|
+
* class is a wrapper for those types of objects, primarily useful as a
|
|
15
|
+
* base class for other wrapper classes like Array and Hash.
|
|
16
|
+
*/
|
|
17
|
+
template<typename T, int Builtin_Type>
|
|
18
|
+
class Builtin_Object
|
|
19
|
+
: public Object
|
|
20
|
+
{
|
|
21
|
+
public:
|
|
22
|
+
//! Wrap an already allocated Ruby object.
|
|
23
|
+
/*! Checks to see if the object is an object of type Builtin_Type; a
|
|
24
|
+
* C++ exception is thrown if this is not the case.
|
|
25
|
+
* \param value the object to be wrapped.
|
|
26
|
+
*/
|
|
27
|
+
Builtin_Object(Object value);
|
|
28
|
+
|
|
29
|
+
//! Make a copy of a Builtin_Object
|
|
30
|
+
/*! \param other the Builtin_Object to be copied.
|
|
31
|
+
*/
|
|
32
|
+
Builtin_Object(Builtin_Object const & other);
|
|
33
|
+
|
|
34
|
+
T & operator*() const { return *obj_; } //!< Return a reference to obj_
|
|
35
|
+
T * operator->() const { return obj_; } //!< Return a pointer to obj_
|
|
36
|
+
T * get() const { return obj_; } //!< Return a pointer to obj_
|
|
37
|
+
|
|
38
|
+
//! Swap with another builtin object of the same type
|
|
39
|
+
/*! \param ref the object with which to swap.
|
|
40
|
+
*/
|
|
41
|
+
void swap(Builtin_Object<T, Builtin_Type> & ref);
|
|
42
|
+
|
|
43
|
+
private:
|
|
44
|
+
T * obj_;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
} // namespace Rice
|
|
48
|
+
|
|
49
|
+
#endif // Rice__Builtin_Object_defn__hpp_
|
|
50
|
+
|
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