wurlinc-rice 1.4.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (186) hide show
  1. data/COPYING +23 -0
  2. data/Doxyfile +1253 -0
  3. data/Makefile.am +26 -0
  4. data/README +1119 -0
  5. data/README.mingw +8 -0
  6. data/Rakefile +33 -0
  7. data/bootstrap +9 -0
  8. data/configure.ac +52 -0
  9. data/doxygen.ac +314 -0
  10. data/doxygen.am +186 -0
  11. data/extconf.rb +41 -0
  12. data/post-autoconf.rb +22 -0
  13. data/post-automake.rb +28 -0
  14. data/rice/Address_Registration_Guard.hpp +7 -0
  15. data/rice/Address_Registration_Guard.ipp +34 -0
  16. data/rice/Address_Registration_Guard_defn.hpp +65 -0
  17. data/rice/Allocation_Strategies.hpp +37 -0
  18. data/rice/Arg.hpp +8 -0
  19. data/rice/Arg_impl.hpp +127 -0
  20. data/rice/Arg_operators.cpp +21 -0
  21. data/rice/Arg_operators.hpp +19 -0
  22. data/rice/Array.hpp +220 -0
  23. data/rice/Array.ipp +263 -0
  24. data/rice/Builtin_Object.hpp +8 -0
  25. data/rice/Builtin_Object.ipp +50 -0
  26. data/rice/Builtin_Object_defn.hpp +51 -0
  27. data/rice/Class.cpp +57 -0
  28. data/rice/Class.hpp +8 -0
  29. data/rice/Class.ipp +6 -0
  30. data/rice/Class_defn.hpp +83 -0
  31. data/rice/Constructor.hpp +367 -0
  32. data/rice/Critical_Guard.hpp +40 -0
  33. data/rice/Critical_Guard.ipp +26 -0
  34. data/rice/Data_Object.hpp +8 -0
  35. data/rice/Data_Object.ipp +133 -0
  36. data/rice/Data_Object_defn.hpp +132 -0
  37. data/rice/Data_Type.cpp +54 -0
  38. data/rice/Data_Type.hpp +8 -0
  39. data/rice/Data_Type.ipp +365 -0
  40. data/rice/Data_Type_defn.hpp +261 -0
  41. data/rice/Data_Type_fwd.hpp +12 -0
  42. data/rice/Director.cpp +13 -0
  43. data/rice/Director.hpp +39 -0
  44. data/rice/Enum.hpp +117 -0
  45. data/rice/Enum.ipp +246 -0
  46. data/rice/Exception.cpp +59 -0
  47. data/rice/Exception.hpp +9 -0
  48. data/rice/Exception_Base.hpp +8 -0
  49. data/rice/Exception_Base.ipp +13 -0
  50. data/rice/Exception_Base_defn.hpp +27 -0
  51. data/rice/Exception_defn.hpp +69 -0
  52. data/rice/Hash.hpp +210 -0
  53. data/rice/Hash.ipp +338 -0
  54. data/rice/Identifier.cpp +8 -0
  55. data/rice/Identifier.hpp +50 -0
  56. data/rice/Identifier.ipp +33 -0
  57. data/rice/Jump_Tag.hpp +24 -0
  58. data/rice/Makefile.am +129 -0
  59. data/rice/Module.cpp +84 -0
  60. data/rice/Module.hpp +8 -0
  61. data/rice/Module.ipp +6 -0
  62. data/rice/Module_defn.hpp +88 -0
  63. data/rice/Module_impl.hpp +281 -0
  64. data/rice/Module_impl.ipp +348 -0
  65. data/rice/Object.cpp +160 -0
  66. data/rice/Object.hpp +8 -0
  67. data/rice/Object.ipp +19 -0
  68. data/rice/Object_defn.hpp +191 -0
  69. data/rice/Require_Guard.hpp +21 -0
  70. data/rice/String.cpp +94 -0
  71. data/rice/String.hpp +89 -0
  72. data/rice/Struct.cpp +117 -0
  73. data/rice/Struct.hpp +162 -0
  74. data/rice/Struct.ipp +26 -0
  75. data/rice/Symbol.cpp +25 -0
  76. data/rice/Symbol.hpp +66 -0
  77. data/rice/Symbol.ipp +44 -0
  78. data/rice/VM.cpp +92 -0
  79. data/rice/VM.hpp +32 -0
  80. data/rice/config.hpp.in +40 -0
  81. data/rice/detail/Arguments.hpp +118 -0
  82. data/rice/detail/Auto_Function_Wrapper.hpp +829 -0
  83. data/rice/detail/Auto_Function_Wrapper.ipp +3391 -0
  84. data/rice/detail/Auto_Member_Function_Wrapper.hpp +828 -0
  85. data/rice/detail/Auto_Member_Function_Wrapper.ipp +2503 -0
  86. data/rice/detail/Caster.hpp +103 -0
  87. data/rice/detail/Exception_Handler.hpp +8 -0
  88. data/rice/detail/Exception_Handler.ipp +68 -0
  89. data/rice/detail/Exception_Handler_defn.hpp +96 -0
  90. data/rice/detail/Iterator.hpp +93 -0
  91. data/rice/detail/Not_Copyable.hpp +25 -0
  92. data/rice/detail/Wrapped_Function.hpp +33 -0
  93. data/rice/detail/cfp.hpp +24 -0
  94. data/rice/detail/cfp.ipp +51 -0
  95. data/rice/detail/check_ruby_type.cpp +27 -0
  96. data/rice/detail/check_ruby_type.hpp +23 -0
  97. data/rice/detail/creation_funcs.hpp +37 -0
  98. data/rice/detail/creation_funcs.ipp +36 -0
  99. data/rice/detail/default_allocation_func.hpp +23 -0
  100. data/rice/detail/default_allocation_func.ipp +11 -0
  101. data/rice/detail/define_method_and_auto_wrap.hpp +31 -0
  102. data/rice/detail/define_method_and_auto_wrap.ipp +30 -0
  103. data/rice/detail/demangle.cpp +56 -0
  104. data/rice/detail/demangle.hpp +19 -0
  105. data/rice/detail/env.hpp +19 -0
  106. data/rice/detail/from_ruby.hpp +43 -0
  107. data/rice/detail/from_ruby.ipp +60 -0
  108. data/rice/detail/method_data.cpp +159 -0
  109. data/rice/detail/method_data.hpp +21 -0
  110. data/rice/detail/mininode.cpp +1220 -0
  111. data/rice/detail/mininode.hpp +320 -0
  112. data/rice/detail/node.hpp +13 -0
  113. data/rice/detail/object_call.hpp +68 -0
  114. data/rice/detail/object_call.ipp +131 -0
  115. data/rice/detail/protect.cpp +29 -0
  116. data/rice/detail/protect.hpp +34 -0
  117. data/rice/detail/ruby.hpp +93 -0
  118. data/rice/detail/ruby_version_code.hpp.in +6 -0
  119. data/rice/detail/rubysig.hpp +19 -0
  120. data/rice/detail/st.hpp +60 -0
  121. data/rice/detail/to_ruby.hpp +22 -0
  122. data/rice/detail/to_ruby.ipp +36 -0
  123. data/rice/detail/traits.hpp +43 -0
  124. data/rice/detail/win32.hpp +16 -0
  125. data/rice/detail/wrap_function.hpp +341 -0
  126. data/rice/detail/wrap_function.ipp +514 -0
  127. data/rice/global_function.hpp +33 -0
  128. data/rice/global_function.ipp +22 -0
  129. data/rice/protect.hpp +91 -0
  130. data/rice/protect.ipp +1133 -0
  131. data/rice/ruby_mark.hpp +13 -0
  132. data/rice/ruby_try_catch.hpp +86 -0
  133. data/rice/rubypp.rb +97 -0
  134. data/rice/to_from_ruby.hpp +8 -0
  135. data/rice/to_from_ruby.ipp +297 -0
  136. data/rice/to_from_ruby_defn.hpp +71 -0
  137. data/ruby/Makefile.am +1 -0
  138. data/ruby/lib/Makefile.am +3 -0
  139. data/ruby/lib/mkmf-rice.rb.in +216 -0
  140. data/ruby/lib/version.rb +3 -0
  141. data/ruby.ac +136 -0
  142. data/sample/Makefile.am +47 -0
  143. data/sample/enum/extconf.rb +3 -0
  144. data/sample/enum/sample_enum.cpp +54 -0
  145. data/sample/enum/test.rb +8 -0
  146. data/sample/inheritance/animals.cpp +98 -0
  147. data/sample/inheritance/extconf.rb +3 -0
  148. data/sample/inheritance/test.rb +7 -0
  149. data/sample/map/extconf.rb +3 -0
  150. data/sample/map/map.cpp +81 -0
  151. data/sample/map/test.rb +7 -0
  152. data/test/Makefile.am +78 -0
  153. data/test/ext/Makefile.am +43 -0
  154. data/test/ext/t1/Foo.hpp +10 -0
  155. data/test/ext/t1/extconf.rb +2 -0
  156. data/test/ext/t1/t1.cpp +15 -0
  157. data/test/ext/t2/extconf.rb +2 -0
  158. data/test/ext/t2/t2.cpp +11 -0
  159. data/test/test_Address_Registration_Guard.cpp +43 -0
  160. data/test/test_Allocation_Strategies.cpp +77 -0
  161. data/test/test_Array.cpp +241 -0
  162. data/test/test_Builtin_Object.cpp +72 -0
  163. data/test/test_Class.cpp +498 -0
  164. data/test/test_Constructor.cpp +128 -0
  165. data/test/test_Critical_Guard.cpp +51 -0
  166. data/test/test_Data_Object.cpp +275 -0
  167. data/test/test_Data_Type.cpp +348 -0
  168. data/test/test_Director.cpp +301 -0
  169. data/test/test_Enum.cpp +195 -0
  170. data/test/test_Exception.cpp +46 -0
  171. data/test/test_Hash.cpp +195 -0
  172. data/test/test_Identifier.cpp +70 -0
  173. data/test/test_Jump_Tag.cpp +17 -0
  174. data/test/test_Memory_Management.cpp +50 -0
  175. data/test/test_Module.cpp +481 -0
  176. data/test/test_Object.cpp +148 -0
  177. data/test/test_String.cpp +94 -0
  178. data/test/test_Struct.cpp +192 -0
  179. data/test/test_Symbol.cpp +63 -0
  180. data/test/test_To_From_Ruby.cpp +263 -0
  181. data/test/test_VM.cpp +26 -0
  182. data/test/test_global_functions.cpp +114 -0
  183. data/test/test_rice.rb +43 -0
  184. data/test/unittest.cpp +136 -0
  185. data/test/unittest.hpp +292 -0
  186. metadata +276 -0
@@ -0,0 +1,7 @@
1
+ #ifndef Rice__Address_Registration_Guard__hpp_
2
+ #define Rice__Address_Registration_Guard__hpp_
3
+
4
+ #include "Address_Registration_Guard_defn.hpp"
5
+ #include "Address_Registration_Guard.ipp"
6
+
7
+ #endif // Rice__Address_Registration_Guard__hpp_
@@ -0,0 +1,34 @@
1
+ #include "Object.hpp"
2
+ #include <algorithm>
3
+
4
+ inline Rice::Address_Registration_Guard::
5
+ Address_Registration_Guard(VALUE * address)
6
+ : address_(address)
7
+ {
8
+ rb_gc_register_address(address);
9
+ }
10
+
11
+ inline Rice::Address_Registration_Guard::
12
+ Address_Registration_Guard(Object * object)
13
+ : address_(const_cast<VALUE *>(&object->value()))
14
+ {
15
+ rb_gc_register_address(address_);
16
+ }
17
+
18
+ inline Rice::Address_Registration_Guard::
19
+ ~Address_Registration_Guard()
20
+ {
21
+ rb_gc_unregister_address(address_);
22
+ }
23
+
24
+ inline VALUE * Rice::Address_Registration_Guard::
25
+ address() const
26
+ {
27
+ return address_;
28
+ }
29
+
30
+ inline void Rice::Address_Registration_Guard::
31
+ swap(Rice::Address_Registration_Guard & other)
32
+ {
33
+ std::swap(address_, other.address_);
34
+ }
@@ -0,0 +1,65 @@
1
+ #ifndef Rice__Address_Registration_Guard_defn__hpp_
2
+ #define Rice__Address_Registration_Guard_defn__hpp_
3
+
4
+ #include "Object_defn.hpp"
5
+ #include "detail/ruby.hpp"
6
+ #include "detail/Not_Copyable.hpp"
7
+
8
+ namespace Rice
9
+ {
10
+
11
+ //! A guard to register a given address with the GC.
12
+ /*! Calls rb_gc_register_address upon construction and
13
+ * rb_gc_unregister_address upon destruction.
14
+ * For example:
15
+ * \code
16
+ * Class Foo
17
+ * {
18
+ * public:
19
+ * Foo()
20
+ * : string_(rb_str_new2())
21
+ * , guard_(&string_);
22
+ *
23
+ * private:
24
+ * VALUE string_;
25
+ * Address_Registration_Guard guard_;
26
+ * };
27
+ * \endcode
28
+ */
29
+ class Address_Registration_Guard
30
+ : private detail::Not_Copyable
31
+ {
32
+ public:
33
+ //! Register an address with the GC.
34
+ /* \param address The address to register with the GC. The address
35
+ * must point to a valid ruby object (RObject).
36
+ */
37
+ Address_Registration_Guard(VALUE * address);
38
+
39
+ //! Register an Object with the GC.
40
+ /*! \param object The Object to register with the GC. The object must
41
+ * not be destroyed before the Address_Registration_Guard is
42
+ * destroyed.
43
+ */
44
+ Address_Registration_Guard(Object * object);
45
+
46
+ //! Unregister an address/Object with the GC.
47
+ /*! Destruct an Address_Registration_Guard. The address registered
48
+ * with the Address_Registration_Guard when it was constructed will
49
+ * be unregistered from the GC.
50
+ */
51
+ ~Address_Registration_Guard();
52
+
53
+ //! Get the address that is registered with the GC.
54
+ VALUE * address() const;
55
+
56
+ //! Swap with another Address_Registration_Guard.
57
+ void swap(Address_Registration_Guard & other);
58
+
59
+ private:
60
+ VALUE * address_;
61
+ };
62
+
63
+ } // namespace Rice
64
+
65
+ #endif // Rice__Address_Registration_Guard_defn__hpp_
@@ -0,0 +1,37 @@
1
+ #ifndef Rice__Default_Allocation_Strategy__hpp_
2
+ #define Rice__Default_Allocation_Strategy__hpp_
3
+
4
+ #include "detail/ruby.hpp"
5
+
6
+ /*! \file
7
+ * \brief Strategies for allocation/deallocation of objects.
8
+ */
9
+
10
+ namespace Rice
11
+ {
12
+
13
+ template<typename T>
14
+ struct Default_Allocation_Strategy
15
+ {
16
+ //! Allocate an object using operator new.
17
+ static T * allocate() { return new T; }
18
+
19
+ //! Delete obj using the delete operator.
20
+ static void free(T * obj) { delete obj; }
21
+ };
22
+
23
+ template<typename T>
24
+ struct Xmalloc_Allocation_Strategy
25
+ {
26
+ //! Allocate an array of objects using operator new and xmalloc.
27
+ static T * allocate() { T * obj = static_cast<T *>(::xmalloc(sizeof(T))); new(obj) T; return obj; }
28
+
29
+ //! Delete obj by calling the destructor explicitly and calling xfree.
30
+ static void free(T * obj) { obj->~T(); ::xfree(obj); }
31
+ };
32
+
33
+ // TODO: array allocation
34
+
35
+ } // namespace Rice
36
+
37
+ #endif // Rice__Default_Allocation_Strategy__hpp_
data/rice/Arg.hpp ADDED
@@ -0,0 +1,8 @@
1
+ #ifndef Rice__Arg__hpp_
2
+ #define Rice__Arg__hpp_
3
+
4
+ #include "Arg_impl.hpp"
5
+ #include "detail/Arguments.hpp"
6
+ #include "Arg_operators.hpp"
7
+
8
+ #endif // Rice__Arg__hpp_
data/rice/Arg_impl.hpp ADDED
@@ -0,0 +1,127 @@
1
+ #ifndef Rice__Arg_Impl_hpp_
2
+ #define Rice__Arg_Impl_hpp_
3
+
4
+ namespace Rice {
5
+
6
+ //! Helper for defining default arguments of a method
7
+ /*! This class exposes the ability to define the default values of a
8
+ * wrapped method. Inspired by how Boost.Python handles keyword and
9
+ * default arguments, the syntax is simple:
10
+ *
11
+ * define_method(
12
+ * "method",
13
+ * &method,
14
+ * (Arg("arg1"), Arg("arg2") = 3, Arg("arg3") = true)
15
+ * );
16
+ *
17
+ * which means "for method &method, it takes 3 arguments
18
+ * [arg1, arg2, arg3]. Of these arguments, arg2's default is 3
19
+ * and arg3's default is true.
20
+ *
21
+ * It may be required to explicitly cast the type of the default
22
+ * value to prevent compilation errors.
23
+ */
24
+ class Arg
25
+ {
26
+ public:
27
+ //! Initialize a new Arg with the name of the argument
28
+ /*! We require the name of the argument because 1) it makes code
29
+ * easier to read and 2) hopefully Ruby gets keyword arguments
30
+ * in the future and this means Rice will be ready for it.
31
+ */
32
+ Arg(const char* name)
33
+ : name_(name)
34
+ , defaultValue(0)
35
+ {}
36
+
37
+ //! Copy Constructor
38
+ Arg(const Arg& other)
39
+ : name_(other.name()),
40
+ defaultValue(other.defaultValue ? other.defaultValue->clone() : 0)
41
+ {}
42
+
43
+ virtual ~Arg()
44
+ {
45
+ if(defaultValue) {
46
+ delete defaultValue;
47
+ }
48
+ }
49
+
50
+ //! Set the default value for this Arg
51
+ /*! Set the default value for this argument.
52
+ * If this isn't called on this Arg, then this
53
+ * Arg is required in the method call.
54
+ *
55
+ * \param val the value to store as default
56
+ */
57
+ template<typename Arg_Type>
58
+ Arg& operator=(Arg_Type val)
59
+ {
60
+ defaultValue = new type<Arg_Type>(val);
61
+ return *this;
62
+ }
63
+
64
+ //! Check if this Arg has a default value associated with it
65
+ bool hasDefaultValue() const {
66
+ return defaultValue != 0;
67
+ }
68
+
69
+ //! Return the default value associated with this Arg
70
+ /*! \return the type saved to this Arg
71
+ */
72
+ template<typename Arg_Type>
73
+ Arg_Type getDefaultValue()
74
+ {
75
+ return static_cast< type<Arg_Type>* >(defaultValue)->held;
76
+ }
77
+
78
+ //! Get the name of this Arg
79
+ const char* name() const
80
+ {
81
+ return name_;
82
+ }
83
+
84
+ private:
85
+
86
+ //! Name of the argument
87
+ const char* name_;
88
+
89
+ /**
90
+ * The following is a stripped down version of
91
+ * Boost.Any.
92
+ */
93
+
94
+ class type_base
95
+ {
96
+ public:
97
+ virtual ~type_base() {}
98
+ virtual type_base* clone() const = 0;
99
+ };
100
+
101
+ template<typename Type>
102
+ class type : public type_base
103
+ {
104
+ public:
105
+ type(Type value)
106
+ :held(value)
107
+ {}
108
+
109
+ virtual ~type() { }
110
+
111
+ virtual type_base* clone() const
112
+ {
113
+ return new type(held);
114
+ }
115
+
116
+ Type held;
117
+ };
118
+
119
+ public:
120
+
121
+ //! Our saved default value
122
+ type_base* defaultValue;
123
+ };
124
+
125
+ }
126
+
127
+ #endif // Rice__Arg_Impl_hpp_
@@ -0,0 +1,21 @@
1
+ #include "Arg_impl.hpp"
2
+ #include "detail/Arguments.hpp"
3
+ #include "Arg_operators.hpp"
4
+
5
+ namespace Rice {
6
+
7
+ Arguments* operator,(Arg arg1, Arg arg2)
8
+ {
9
+ Arguments* a = new Arguments();
10
+ a->add(arg1);
11
+ a->add(arg2);
12
+ return a;
13
+ }
14
+
15
+ Arguments* operator,(Arguments* arguments, Arg arg)
16
+ {
17
+ arguments->add(arg);
18
+ return arguments;
19
+ }
20
+
21
+ }
@@ -0,0 +1,19 @@
1
+ #ifndef Rice__Arg_Operators_hpp_
2
+ #define Rice__Arg_Operators_hpp_
3
+
4
+ namespace Rice
5
+ {
6
+
7
+ //! Build the list of Arg objects into an Arguments object
8
+ /*! Take a list of Arg objects and build up a single Argument
9
+ * object used later in method dispatch
10
+ */
11
+ Arguments* operator,(Arg arg1, Arg arg2);
12
+
13
+ /*! @see operator,(Arg, Arg)
14
+ */
15
+ Arguments* operator,(Arguments* arguments, Arg arg);
16
+
17
+ }
18
+
19
+ #endif // Rice__Arg_Operators_hpp_
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
+