rice 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) hide show
  1. data/COPYING +23 -0
  2. data/Doxyfile +1253 -0
  3. data/Makefile.am +26 -0
  4. data/Makefile.in +736 -0
  5. data/README +881 -0
  6. data/README.mingw +8 -0
  7. data/bootstrap +8 -0
  8. data/config.guess +1535 -0
  9. data/config.sub +1644 -0
  10. data/configure +7310 -0
  11. data/configure.ac +48 -0
  12. data/depcomp +584 -0
  13. data/doxygen.ac +314 -0
  14. data/doxygen.am +186 -0
  15. data/install-sh +507 -0
  16. data/missing +367 -0
  17. data/post-autoconf.rb +22 -0
  18. data/post-automake.rb +28 -0
  19. data/rice/Address_Registration_Guard.hpp +7 -0
  20. data/rice/Address_Registration_Guard.ipp +34 -0
  21. data/rice/Address_Registration_Guard_defn.hpp +65 -0
  22. data/rice/Allocation_Strategies.hpp +37 -0
  23. data/rice/Array.hpp +220 -0
  24. data/rice/Array.ipp +262 -0
  25. data/rice/Builtin_Object.hpp +8 -0
  26. data/rice/Builtin_Object.ipp +50 -0
  27. data/rice/Builtin_Object_defn.hpp +51 -0
  28. data/rice/Class.cpp +57 -0
  29. data/rice/Class.hpp +8 -0
  30. data/rice/Class.ipp +4 -0
  31. data/rice/Class_defn.hpp +83 -0
  32. data/rice/Constructor.hpp +189 -0
  33. data/rice/Critical_Guard.hpp +34 -0
  34. data/rice/Critical_Guard.ipp +20 -0
  35. data/rice/Data_Object.hpp +127 -0
  36. data/rice/Data_Object.ipp +129 -0
  37. data/rice/Data_Type.cpp +21 -0
  38. data/rice/Data_Type.hpp +8 -0
  39. data/rice/Data_Type.ipp +227 -0
  40. data/rice/Data_Type_defn.hpp +219 -0
  41. data/rice/Data_Type_fwd.hpp +12 -0
  42. data/rice/Enum.hpp +118 -0
  43. data/rice/Enum.ipp +246 -0
  44. data/rice/Exception.cpp +59 -0
  45. data/rice/Exception.hpp +69 -0
  46. data/rice/Exception_Base.hpp +30 -0
  47. data/rice/Exception_Base.ipp +11 -0
  48. data/rice/Hash.hpp +206 -0
  49. data/rice/Hash.ipp +336 -0
  50. data/rice/Identifier.cpp +8 -0
  51. data/rice/Identifier.hpp +50 -0
  52. data/rice/Identifier.ipp +33 -0
  53. data/rice/Jump_Tag.hpp +24 -0
  54. data/rice/Makefile.am +112 -0
  55. data/rice/Makefile.in +675 -0
  56. data/rice/Module.cpp +75 -0
  57. data/rice/Module.hpp +8 -0
  58. data/rice/Module.ipp +6 -0
  59. data/rice/Module_defn.hpp +87 -0
  60. data/rice/Module_impl.hpp +237 -0
  61. data/rice/Module_impl.ipp +302 -0
  62. data/rice/Object.cpp +153 -0
  63. data/rice/Object.hpp +8 -0
  64. data/rice/Object.ipp +19 -0
  65. data/rice/Object_defn.hpp +183 -0
  66. data/rice/Require_Guard.hpp +21 -0
  67. data/rice/String.cpp +93 -0
  68. data/rice/String.hpp +88 -0
  69. data/rice/Struct.cpp +117 -0
  70. data/rice/Struct.hpp +162 -0
  71. data/rice/Struct.ipp +26 -0
  72. data/rice/Symbol.cpp +25 -0
  73. data/rice/Symbol.hpp +66 -0
  74. data/rice/Symbol.ipp +44 -0
  75. data/rice/VM.cpp +79 -0
  76. data/rice/VM.hpp +27 -0
  77. data/rice/config.hpp +23 -0
  78. data/rice/config.hpp.in +22 -0
  79. data/rice/detail/Auto_Function_Wrapper.hpp +719 -0
  80. data/rice/detail/Auto_Function_Wrapper.ipp +1354 -0
  81. data/rice/detail/Auto_Member_Function_Wrapper.hpp +685 -0
  82. data/rice/detail/Auto_Member_Function_Wrapper.ipp +1435 -0
  83. data/rice/detail/Caster.hpp +61 -0
  84. data/rice/detail/Exception_Handler.hpp +118 -0
  85. data/rice/detail/Iterator_Definer.hpp +98 -0
  86. data/rice/detail/Not_Copyable.hpp +25 -0
  87. data/rice/detail/Wrapped_Function.hpp +33 -0
  88. data/rice/detail/check_ruby_type.cpp +21 -0
  89. data/rice/detail/check_ruby_type.hpp +23 -0
  90. data/rice/detail/creation_funcs.hpp +45 -0
  91. data/rice/detail/creation_funcs.ipp +62 -0
  92. data/rice/detail/default_allocation_func.hpp +23 -0
  93. data/rice/detail/default_allocation_func.ipp +11 -0
  94. data/rice/detail/define_method_and_auto_wrap.hpp +27 -0
  95. data/rice/detail/define_method_and_auto_wrap.ipp +20 -0
  96. data/rice/detail/env.hpp +13 -0
  97. data/rice/detail/from_ruby.hpp +43 -0
  98. data/rice/detail/from_ruby.ipp +74 -0
  99. data/rice/detail/method_data.cpp +105 -0
  100. data/rice/detail/method_data.hpp +33 -0
  101. data/rice/detail/node.hpp +13 -0
  102. data/rice/detail/object_call.hpp +85 -0
  103. data/rice/detail/object_call.ipp +147 -0
  104. data/rice/detail/protect.cpp +27 -0
  105. data/rice/detail/protect.hpp +34 -0
  106. data/rice/detail/remove_const.hpp +21 -0
  107. data/rice/detail/ruby.hpp +85 -0
  108. data/rice/detail/rubysig.hpp +13 -0
  109. data/rice/detail/st.hpp +56 -0
  110. data/rice/detail/to_ruby.hpp +16 -0
  111. data/rice/detail/to_ruby.ipp +10 -0
  112. data/rice/detail/win32.hpp +16 -0
  113. data/rice/detail/wrap_function.hpp +288 -0
  114. data/rice/detail/wrap_function.ipp +473 -0
  115. data/rice/generate_code.rb +1092 -0
  116. data/rice/global_function.hpp +16 -0
  117. data/rice/global_function.ipp +11 -0
  118. data/rice/protect.hpp +91 -0
  119. data/rice/protect.ipp +803 -0
  120. data/rice/ruby_try_catch.hpp +86 -0
  121. data/rice/to_from_ruby.hpp +8 -0
  122. data/rice/to_from_ruby.ipp +299 -0
  123. data/rice/to_from_ruby_defn.hpp +71 -0
  124. data/ruby.ac +105 -0
  125. data/ruby/Makefile.am +1 -0
  126. data/ruby/Makefile.in +493 -0
  127. data/ruby/lib/Makefile.am +3 -0
  128. data/ruby/lib/Makefile.in +369 -0
  129. data/ruby/lib/mkmf-rice.rb.in +199 -0
  130. data/sample/Makefile.am +47 -0
  131. data/sample/Makefile.in +375 -0
  132. data/sample/enum/extconf.rb +3 -0
  133. data/sample/enum/sample_enum.cpp +54 -0
  134. data/sample/enum/test.rb +8 -0
  135. data/sample/inheritance/animals.cpp +98 -0
  136. data/sample/inheritance/extconf.rb +3 -0
  137. data/sample/inheritance/test.rb +7 -0
  138. data/sample/map/extconf.rb +3 -0
  139. data/sample/map/map.cpp +81 -0
  140. data/sample/map/test.rb +7 -0
  141. data/test/Makefile.am +44 -0
  142. data/test/Makefile.in +575 -0
  143. data/test/test_Address_Registration_Guard.cpp +43 -0
  144. data/test/test_Allocation_Strategies.cpp +77 -0
  145. data/test/test_Array.cpp +241 -0
  146. data/test/test_Builtin_Object.cpp +72 -0
  147. data/test/test_Class.cpp +350 -0
  148. data/test/test_Constructor.cpp +30 -0
  149. data/test/test_Critical_Guard.cpp +47 -0
  150. data/test/test_Data_Object.cpp +235 -0
  151. data/test/test_Enum.cpp +162 -0
  152. data/test/test_Exception.cpp +46 -0
  153. data/test/test_Hash.cpp +195 -0
  154. data/test/test_Identifier.cpp +70 -0
  155. data/test/test_Jump_Tag.cpp +17 -0
  156. data/test/test_Module.cpp +253 -0
  157. data/test/test_Object.cpp +148 -0
  158. data/test/test_String.cpp +94 -0
  159. data/test/test_Struct.cpp +192 -0
  160. data/test/test_Symbol.cpp +63 -0
  161. data/test/test_To_From_Ruby.cpp +281 -0
  162. data/test/test_VM.cpp +26 -0
  163. data/test/test_rice.rb +30 -0
  164. data/test/unittest.cpp +136 -0
  165. data/test/unittest.hpp +292 -0
  166. metadata +209 -0
data/rice/Module.cpp ADDED
@@ -0,0 +1,75 @@
1
+ #include "Module.hpp"
2
+ #include "Symbol.hpp"
3
+ #include "Array.hpp"
4
+ #include "Exception.hpp"
5
+ #include "protect.hpp"
6
+
7
+ Rice::Module::
8
+ Module()
9
+ : Module_impl<Module_base, Module>(rb_cObject)
10
+ {
11
+ }
12
+
13
+ Rice::Module::
14
+ Module(VALUE v)
15
+ : Module_impl<Module_base, Module>(v)
16
+ {
17
+ if(::rb_type(v) != T_CLASS && ::rb_type(v) != T_MODULE)
18
+ {
19
+ throw Exception(
20
+ rb_eTypeError,
21
+ "Expected a Module but got a %s",
22
+ rb_class2name(CLASS_OF(v))); // TODO: might raise an exception
23
+ }
24
+ }
25
+
26
+ Rice::Object Rice::Module::
27
+ mod_name() const
28
+ {
29
+ return rb_mod_name(*this);
30
+ }
31
+
32
+ Rice::Module Rice::
33
+ define_module_under(
34
+ Rice::Object module,
35
+ char const * name)
36
+ {
37
+ VALUE v = rb_define_module_under(module, name);
38
+ return Module(v);
39
+ }
40
+
41
+ Rice::Module Rice::
42
+ define_module(
43
+ char const * name)
44
+ {
45
+ VALUE v = rb_define_module(name);
46
+ return Module(v);
47
+ }
48
+
49
+ Rice::Module Rice::
50
+ anonymous_module()
51
+ {
52
+ return Module(protect(rb_module_new));
53
+ }
54
+
55
+ void Rice::Module::
56
+ swap(Rice::Module & other)
57
+ {
58
+ std::swap(handler_, other.handler_);
59
+ Object::swap(other);
60
+ }
61
+
62
+ Rice::Array
63
+ Rice::Module::
64
+ ancestors() const
65
+ {
66
+ return protect(rb_mod_ancestors, *this);
67
+ }
68
+
69
+ Rice::Class
70
+ Rice::Module::
71
+ singleton_class() const
72
+ {
73
+ return CLASS_OF(value());
74
+ }
75
+
data/rice/Module.hpp ADDED
@@ -0,0 +1,8 @@
1
+ #ifndef Rice__builtin__Module__hpp_
2
+ #define Rice__builtin__Module__hpp_
3
+
4
+ #include "Module_defn.hpp"
5
+ #include "Module.ipp"
6
+
7
+ #endif // Rice__builtin__Module__hpp_
8
+
data/rice/Module.ipp ADDED
@@ -0,0 +1,6 @@
1
+ #ifndef Rice__Module__ipp_
2
+ #define Rice__Module__ipp_
3
+
4
+ #include "Module_impl.ipp"
5
+
6
+ #endif // Rice__Module__ipp_
@@ -0,0 +1,87 @@
1
+ #ifndef Rice__Module_defn__hpp_
2
+ #define Rice__Module_defn__hpp_
3
+
4
+ #include "Object_defn.hpp"
5
+ #include "Module_impl.hpp"
6
+ #include "to_from_ruby_defn.hpp"
7
+ #include <memory>
8
+
9
+ namespace Rice
10
+ {
11
+
12
+ class Array;
13
+ class Class;
14
+
15
+ //! A helper for defining a Module and its methods.
16
+ /*! This class provides a C++-style interface to ruby's Module class and
17
+ * for defining methods on that module.
18
+ *
19
+ * Many of the methods are defined in Module_impl.hpp so that they can
20
+ * return a reference to the most derived type.
21
+ */
22
+ class Module
23
+ // TODO: we can't inherit from Builtin_Object, because Class needs
24
+ // type T_CLASS and Module needs type T_MODULE
25
+ : public Module_impl<Module_base, Module>
26
+ {
27
+ public:
28
+ //! Default construct a Module and initialize it to rb_cObject.
29
+ Module();
30
+
31
+ //! Construct a Module from an existing Module object.
32
+ Module(VALUE v);
33
+
34
+ //! Return the name of the module.
35
+ Object mod_name() const;
36
+
37
+ //! Swap with another Module.
38
+ void swap(Module & other);
39
+
40
+ //! Return an array containing the Module's ancestors.
41
+ /*! You will need to include Array.hpp to use this function.
42
+ */
43
+ Array ancestors() const;
44
+
45
+ //! Return the module's singleton class.
46
+ /*! You will need to include Class.hpp to use this function.
47
+ */
48
+ Class singleton_class() const;
49
+ };
50
+
51
+ //! Define a new module in the namespace given by module.
52
+ /*! \param module the module in which to define the new module.
53
+ * \param name the name of the new module.
54
+ */
55
+ Module define_module_under(
56
+ Object module,
57
+ char const * name);
58
+
59
+ //! Define a new module in the default namespace.
60
+ /*! \param name the name of the new module.
61
+ */
62
+ Module define_module(
63
+ char const * name);
64
+
65
+ //! Create a new anonymous module.
66
+ /*! \return the new module.
67
+ */
68
+ Module anonymous_module();
69
+
70
+ } // namespace Rice
71
+
72
+ template<>
73
+ inline
74
+ Rice::Module from_ruby<Rice::Module>(Rice::Object x)
75
+ {
76
+ return Rice::Module(x);
77
+ }
78
+
79
+ template<>
80
+ inline
81
+ Rice::Object to_ruby<Rice::Module>(Rice::Module const & x)
82
+ {
83
+ return x;
84
+ }
85
+
86
+ #endif // Rice__Module_defn__hpp_
87
+
@@ -0,0 +1,237 @@
1
+ #ifndef Rice__Module_impl__hpp_
2
+ #define Rice__Module_impl__hpp_
3
+
4
+ #include "detail/Exception_Handler.hpp"
5
+ #include "detail/ruby.hpp"
6
+ #include "Object_defn.hpp"
7
+
8
+ namespace Rice
9
+ {
10
+
11
+ class Module;
12
+ class Class;
13
+ template<typename T> class Data_Type;
14
+
15
+ /*! Holds all member data of Module_impl so it only exists in one place
16
+ * in the hierarchy.
17
+ */
18
+ class Module_base
19
+ : public Object
20
+ {
21
+ public:
22
+ Module_base(VALUE v = rb_cObject);
23
+
24
+ protected: // TODO
25
+ // TODO: For now, we always leak the handler, but in the future, we
26
+ // should register it with the garbage collector.
27
+ detail::Exception_Handler const * handler_;
28
+ };
29
+
30
+ /*! An intermediate base class so we can always return the most-derived
31
+ * type (Module, Class, Data_Type, ...) without having to re-implement
32
+ * each function for each derived class.
33
+ */
34
+ template<typename Base_T, typename Derived_T>
35
+ class Module_impl
36
+ : public Base_T
37
+ {
38
+ public:
39
+ Module_impl();
40
+
41
+ template<typename T>
42
+ Module_impl(T const & arg);
43
+
44
+ //! Define an exception handler.
45
+ /*! Whenever an exception of type Exception_T is thrown from a
46
+ * function defined on this class, functor will be called to
47
+ * translate the exception into a ruby exception.
48
+ * \param Exception_T a template parameter indicating the type of
49
+ * exception to be translated.
50
+ * \param functor a functor to be called to translate the exception
51
+ * into a ruby exception. This functor should re-throw the exception
52
+ * as an Exception.
53
+ * Example:
54
+ * \code
55
+ * class MyException : public std::exception { };
56
+ * Data_Type<MyException> rb_cMyException;
57
+ * Class rb_cFoo;
58
+ *
59
+ * void translate_my_exception(MyException const & ex)
60
+ * {
61
+ * Data_Object<MyException> ex_(
62
+ * new MyException(ex),
63
+ * rb_cMyException);
64
+ * throw Exception(ex_);
65
+ * }
66
+ *
67
+ * extern "C"
68
+ * void Init_MyExtension()
69
+ * {
70
+ * rb_cMyException = define_class("MyException");
71
+ * rb_cFoo = define_class("Foo")
72
+ * .add_handler<MyException>(translate_my_exception);
73
+ * }
74
+ * \endcode
75
+ */
76
+ template<typename Exception_T, typename Functor_T>
77
+ Derived_T & add_handler(
78
+ Functor_T functor);
79
+
80
+ //! Define an instance method.
81
+ /*! The method's implementation can be any function or member
82
+ * function. A wrapper will be generated which will use from_ruby<>
83
+ * to convert the arguments from ruby types to C++ types before
84
+ * calling the function. The return value will be converted back to
85
+ * ruby by using to_ruby().
86
+ * \param name the name of the method
87
+ * \param func the implementation of the function, either a function
88
+ * pointer or a member function pointer.
89
+ * \return *this
90
+ */
91
+ template<typename Func_T>
92
+ Derived_T & define_method(
93
+ char const * name,
94
+ Func_T func);
95
+
96
+ //! Define a singleton method.
97
+ /*! The method's implementation can be any function or member
98
+ * function. A wrapper will be generated which will use from_ruby<>
99
+ * to convert the arguments from ruby types to C++ types before
100
+ * calling the function. The return value will be converted back to
101
+ * ruby by using to_ruby().
102
+ * \param name the name of the method
103
+ * \param func the implementation of the function, either a function
104
+ * pointer or a member function pointer.
105
+ * \return *this
106
+ */
107
+ template<typename Func_T>
108
+ Derived_T & define_singleton_method(
109
+ char const * name,
110
+ Func_T func);
111
+
112
+ //! Define a module function.
113
+ /*! A module function is a function that can be accessed either as a
114
+ * singleton method or as an instance method.
115
+ * The method's implementation can be any function or member
116
+ * function. A wrapper will be generated which will use from_ruby<>
117
+ * to convert the arguments from ruby types to C++ types before
118
+ * calling the function. The return value will be converted back to
119
+ * ruby by using to_ruby().
120
+ * \param name the name of the method
121
+ * \param func the implementation of the function, either a function
122
+ * pointer or a member function pointer.
123
+ * \return *this
124
+ */
125
+ template<typename Func_T>
126
+ Derived_T & define_module_function(
127
+ char const * name,
128
+ Func_T func);
129
+
130
+ //! Define an iterator.
131
+ /*! Essentially this is a conversion from a C++-style begin/end
132
+ * iterator to a Ruby-style \#each iterator.
133
+ * \param begin a member function pointer to a function that returns
134
+ * an iterator to the beginning of the sequence.
135
+ * \param end a member function pointer to a function that returns an
136
+ * iterator to the end of the sequence.
137
+ * \param name the name of the iterator.
138
+ * \return *this
139
+ */
140
+ template<typename T, typename Iterator_T>
141
+ Derived_T & define_iterator(
142
+ Iterator_T (T::*begin)(),
143
+ Iterator_T (T::*end)(),
144
+ char const * name = "each");
145
+
146
+ //! Include a module.
147
+ /*! \param inc the module to be included.
148
+ * \return *this
149
+ */
150
+ Derived_T & include_module(
151
+ Module const & inc);
152
+
153
+ //! Set a constant.
154
+ /*! \param name the name of the constant to set.
155
+ * \param value the value of the constant.
156
+ * \return *this
157
+ */
158
+ Derived_T & const_set(
159
+ Identifier name,
160
+ Object value);
161
+
162
+ //! Get a constant.
163
+ /*! \param name the name of the constant to get.
164
+ * \return the value of the constant.
165
+ */
166
+ Object const_get(
167
+ Identifier name) const;
168
+
169
+ //! Determine whether a constant is defined.
170
+ /*! \param name the name of the constant to check.
171
+ * \return true if the constant is defined in this module or false
172
+ * otherwise.
173
+ */
174
+ bool const_defined(
175
+ Identifier name) const;
176
+
177
+ //! Remove a constant.
178
+ /*! \param name the name of the constant to remove.
179
+ */
180
+ void remove_const(
181
+ Identifier name);
182
+
183
+ //! Define a module under this module.
184
+ /*! \param name the name of the module.
185
+ * \return the new class.
186
+ */
187
+ Module define_module(
188
+ char const * name);
189
+
190
+ //! Define a class under this module.
191
+ /*! \param name the name of the class.
192
+ * \param superclass the base class to use.
193
+ * \return the new class.
194
+ */
195
+ Class define_class(
196
+ char const * name,
197
+ Object superclass = rb_cObject);
198
+
199
+ //! Define a new data class under this module.
200
+ /*! The class will have a base class of Object.
201
+ * \param T the C++ type of the wrapped class.
202
+ * \return the new class.
203
+ */
204
+ // This function needs to be defined inline to work around a bug in
205
+ // g++ 3.3.3.
206
+ template<typename T>
207
+ Data_Type<T>
208
+ define_class(
209
+ char const * name)
210
+ {
211
+ return this->define_class_with_object_as_base<T>(name);
212
+ }
213
+
214
+ //! Define a new data class under this module.
215
+ /*! The class with have a base class determined by Base_T (specifically,
216
+ * Data_Type<Base_T>::klass). Therefore, the type Base_T must already
217
+ * have been registered using define_class<> or define_class_under<>.
218
+ * \param T the C++ type of the wrapped class.
219
+ * \return the new class.
220
+ */
221
+ template<typename T, typename T_Base_T>
222
+ Data_Type<T>
223
+ define_class(
224
+ char const * name);
225
+
226
+ private:
227
+ // Workaround for g++ 3.3.3 (see above).
228
+ template<typename T>
229
+ Data_Type<T>
230
+ define_class_with_object_as_base(
231
+ char const * name);
232
+ };
233
+
234
+ } // namespace Rice
235
+
236
+ #endif // Rice__Module_impl__hpp_
237
+
@@ -0,0 +1,302 @@
1
+ #include "detail/define_method_and_auto_wrap.hpp"
2
+ #include "Object.hpp"
3
+ #include "Data_Object.hpp"
4
+ #include "Data_Type.hpp"
5
+ #include "Symbol.hpp"
6
+ #include "protect.hpp"
7
+
8
+ #include "Module.hpp"
9
+ #include "Class.hpp"
10
+ #include "Data_Type.hpp"
11
+
12
+ #include "detail/ruby.hpp"
13
+ #include "detail/method_data.hpp"
14
+
15
+
16
+ inline
17
+ Rice::Module_base::
18
+ Module_base(VALUE v)
19
+ : Object(v)
20
+ , handler_(new Rice::detail::Default_Exception_Handler)
21
+ {
22
+ }
23
+
24
+ template<typename Base_T, typename Derived_T>
25
+ inline
26
+ Rice::Module_impl<Base_T, Derived_T>::
27
+ Module_impl()
28
+ : Base_T()
29
+ {
30
+ }
31
+
32
+ template<typename Base_T, typename Derived_T>
33
+ template<typename T>
34
+ inline
35
+ Rice::Module_impl<Base_T, Derived_T>::
36
+ Module_impl(T const & arg)
37
+ : Base_T(arg)
38
+ {
39
+ }
40
+
41
+ template<typename Base_T, typename Derived_T>
42
+ template<typename Exception_T, typename Functor_T>
43
+ inline
44
+ Derived_T &
45
+ Rice::Module_impl<Base_T, Derived_T>::
46
+ add_handler(
47
+ Functor_T functor)
48
+ {
49
+ this->handler_ =
50
+ new Rice::detail::
51
+ Functor_Exception_Handler<Exception_T, Functor_T>(
52
+ functor,
53
+ this->handler_);
54
+ return (Derived_T &)*this;
55
+ }
56
+
57
+ template<typename Base_T, typename Derived_T>
58
+ template<typename Func_T>
59
+ inline
60
+ Derived_T &
61
+ Rice::Module_impl<Base_T, Derived_T>::
62
+ define_method(
63
+ char const * name,
64
+ Func_T func)
65
+ {
66
+ detail::define_method_and_auto_wrap(
67
+ *this, name, func, this->handler_);
68
+ return (Derived_T &)*this;
69
+ }
70
+
71
+ template<typename Base_T, typename Derived_T>
72
+ template<typename T>
73
+ inline
74
+ Derived_T &
75
+ Rice::Module_impl<Base_T, Derived_T>::
76
+ define_singleton_method(
77
+ char const * name,
78
+ T func)
79
+ {
80
+ detail::define_method_and_auto_wrap(
81
+ rb_class_of(*this), name, func, this->handler_);
82
+ return (Derived_T &)*this;
83
+ }
84
+
85
+ template<typename Base_T, typename Derived_T>
86
+ template<typename T>
87
+ inline
88
+ Derived_T &
89
+ Rice::Module_impl<Base_T, Derived_T>::
90
+ define_module_function(
91
+ char const * name,
92
+ T func)
93
+ {
94
+ detail::define_method_and_auto_wrap(*this, name, func);
95
+ this->call("module_function", Symbol(name));
96
+ return (Derived_T &)*this;
97
+ }
98
+
99
+ namespace Rice
100
+ {
101
+
102
+ namespace detail
103
+ {
104
+
105
+ class Iterator
106
+ {
107
+ public:
108
+ virtual ~Iterator() { }
109
+
110
+ virtual VALUE call_impl(VALUE self) = 0;
111
+
112
+ static VALUE call(VALUE self)
113
+ {
114
+ void * data = Rice::detail::method_data();
115
+ Iterator * iterator = static_cast<Iterator *>(data);
116
+ return iterator->call_impl(self);
117
+ }
118
+ };
119
+
120
+ template<typename T, typename Iterator_T>
121
+ class Iterator_Impl
122
+ : public Iterator
123
+ {
124
+ public:
125
+ Iterator_Impl(
126
+ Iterator_T (T::*begin)(),
127
+ Iterator_T (T::*end)(),
128
+ Rice::Data_Type<T> data_type)
129
+ : begin_(begin)
130
+ , end_(end)
131
+ , data_type_(data_type)
132
+ {
133
+ }
134
+
135
+ virtual VALUE call_impl(VALUE self)
136
+ {
137
+ Rice::Data_Object<T> obj(self, data_type_);
138
+ Iterator_T it = obj->begin();
139
+ Iterator_T end = obj->end();
140
+ for(; it != end; ++it)
141
+ {
142
+ protect(rb_yield, to_ruby(*it));
143
+ }
144
+ return self;
145
+ }
146
+
147
+ private:
148
+ Iterator_T (T::*begin_)();
149
+ Iterator_T (T::*end_)();
150
+ Rice::Data_Type<T> data_type_;
151
+ };
152
+
153
+ } // namespace detail
154
+
155
+ } // namespace Rice
156
+
157
+ template<typename Base_T, typename Derived_T>
158
+ template<typename T, typename Iterator_T>
159
+ inline
160
+ Derived_T &
161
+ Rice::Module_impl<Base_T, Derived_T>::
162
+ define_iterator(
163
+ Iterator_T (T::*begin)(),
164
+ Iterator_T (T::*end)(),
165
+ char const * name)
166
+ {
167
+ // TODO: memory leak!!!!!!!
168
+ detail::Iterator * iterator =
169
+ new detail::Iterator_Impl<T, Iterator_T>(
170
+ begin,
171
+ end,
172
+ Data_Type<T>());
173
+ detail::define_method_with_data(
174
+ static_cast<VALUE>(*this),
175
+ name,
176
+ (RUBY_METHOD_FUNC)iterator->call,
177
+ 0,
178
+ iterator);
179
+ return (Derived_T &)*this;
180
+ }
181
+
182
+ namespace Rice
183
+ {
184
+
185
+ namespace detail
186
+ {
187
+
188
+ inline VALUE
189
+ include_module(VALUE mod, VALUE inc)
190
+ {
191
+ rb_include_module(mod, inc);
192
+ return Qnil;
193
+ }
194
+
195
+ inline VALUE
196
+ const_set(VALUE mod, ID name, VALUE value)
197
+ {
198
+ rb_const_set(mod, name, value);
199
+ return Qnil;
200
+ }
201
+
202
+ } // namespace detail
203
+
204
+ } // namespace Rice
205
+
206
+ template<typename Base_T, typename Derived_T>
207
+ inline
208
+ Derived_T &
209
+ Rice::Module_impl<Base_T, Derived_T>::
210
+ include_module(
211
+ Module const & inc)
212
+ {
213
+ protect(detail::include_module, *this, inc);
214
+ return (Derived_T &)*this;
215
+ }
216
+
217
+ template<typename Base_T, typename Derived_T>
218
+ inline
219
+ Derived_T &
220
+ Rice::Module_impl<Base_T, Derived_T>::
221
+ const_set(
222
+ Identifier name,
223
+ Object value)
224
+ {
225
+ protect(detail::const_set, *this, name, value);
226
+ return (Derived_T &)*this;
227
+ }
228
+
229
+ template<typename Base_T, typename Derived_T>
230
+ inline
231
+ Rice::Object
232
+ Rice::Module_impl<Base_T, Derived_T>::
233
+ const_get(
234
+ Identifier name) const
235
+ {
236
+ return protect(rb_const_get, *this, name);
237
+ }
238
+
239
+ template<typename Base_T, typename Derived_T>
240
+ inline
241
+ bool
242
+ Rice::Module_impl<Base_T, Derived_T>::
243
+ const_defined(Identifier name) const
244
+ {
245
+ int result = protect(rb_const_defined, *this, name);
246
+ return bool(result);
247
+ }
248
+
249
+ template<typename Base_T, typename Derived_T>
250
+ inline
251
+ void
252
+ Rice::Module_impl<Base_T, Derived_T>::
253
+ remove_const(Identifier name)
254
+ {
255
+ protect(rb_mod_remove_const, *this, Symbol(name));
256
+ }
257
+
258
+ template<typename Base_T, typename Derived_T>
259
+ inline
260
+ Rice::Module
261
+ Rice::Module_impl<Base_T, Derived_T>::
262
+ define_module(
263
+ char const * name)
264
+ {
265
+ return Rice::define_module_under(*this, name);
266
+ }
267
+
268
+ template<typename Base_T, typename Derived_T>
269
+ inline
270
+ Rice::Class
271
+ Rice::Module_impl<Base_T, Derived_T>::
272
+ define_class(
273
+ char const * name,
274
+ Object superclass)
275
+ {
276
+ return Rice::define_class_under(*this, name, superclass);
277
+ }
278
+
279
+ template<typename Base_T, typename Derived_T>
280
+ template<typename T>
281
+ inline
282
+ Rice::Data_Type<T>
283
+ Rice::Module_impl<Base_T, Derived_T>::
284
+ define_class_with_object_as_base(
285
+ char const * name)
286
+ {
287
+ return Rice::define_class_under<T>(*this, name);
288
+ }
289
+
290
+ template<typename Base_T, typename Derived_T>
291
+ template<typename T, typename T_Base_T>
292
+ inline
293
+ Rice::Data_Type<T>
294
+ Rice::Module_impl<Base_T, Derived_T>::
295
+ define_class(
296
+ char const * name)
297
+ {
298
+ return Rice::define_class_under<T, T_Base_T>(
299
+ *this,
300
+ name);
301
+ }
302
+