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.
Files changed (202) hide show
  1. checksums.yaml +15 -0
  2. data/COPYING +23 -0
  3. data/Doxyfile +1253 -0
  4. data/Makefile.am +26 -0
  5. data/Makefile.in +853 -0
  6. data/README +1124 -0
  7. data/README.mingw +8 -0
  8. data/Rakefile +34 -0
  9. data/aclocal.m4 +971 -0
  10. data/bootstrap +8 -0
  11. data/config.guess +1530 -0
  12. data/config.sub +1773 -0
  13. data/configure +7121 -0
  14. data/configure.ac +52 -0
  15. data/depcomp +688 -0
  16. data/doxygen.ac +314 -0
  17. data/doxygen.am +186 -0
  18. data/extconf.rb +51 -0
  19. data/install-sh +527 -0
  20. data/missing +331 -0
  21. data/post-autoconf.rb +22 -0
  22. data/post-automake.rb +28 -0
  23. data/rice/Address_Registration_Guard.cpp +22 -0
  24. data/rice/Address_Registration_Guard.hpp +7 -0
  25. data/rice/Address_Registration_Guard.ipp +37 -0
  26. data/rice/Address_Registration_Guard_defn.hpp +75 -0
  27. data/rice/Arg.hpp +8 -0
  28. data/rice/Arg_impl.hpp +127 -0
  29. data/rice/Arg_operators.cpp +21 -0
  30. data/rice/Arg_operators.hpp +19 -0
  31. data/rice/Array.hpp +220 -0
  32. data/rice/Array.ipp +263 -0
  33. data/rice/Builtin_Object.hpp +8 -0
  34. data/rice/Builtin_Object.ipp +50 -0
  35. data/rice/Builtin_Object_defn.hpp +50 -0
  36. data/rice/Class.cpp +57 -0
  37. data/rice/Class.hpp +8 -0
  38. data/rice/Class.ipp +6 -0
  39. data/rice/Class_defn.hpp +83 -0
  40. data/rice/Constructor.hpp +368 -0
  41. data/rice/Critical_Guard.hpp +40 -0
  42. data/rice/Critical_Guard.ipp +26 -0
  43. data/rice/Data_Object.hpp +8 -0
  44. data/rice/Data_Object.ipp +133 -0
  45. data/rice/Data_Object_defn.hpp +138 -0
  46. data/rice/Data_Type.cpp +54 -0
  47. data/rice/Data_Type.hpp +8 -0
  48. data/rice/Data_Type.ipp +365 -0
  49. data/rice/Data_Type_defn.hpp +261 -0
  50. data/rice/Data_Type_fwd.hpp +12 -0
  51. data/rice/Director.cpp +13 -0
  52. data/rice/Director.hpp +39 -0
  53. data/rice/Enum.hpp +117 -0
  54. data/rice/Enum.ipp +246 -0
  55. data/rice/Exception.cpp +59 -0
  56. data/rice/Exception.hpp +9 -0
  57. data/rice/Exception_Base.hpp +8 -0
  58. data/rice/Exception_Base.ipp +13 -0
  59. data/rice/Exception_Base_defn.hpp +27 -0
  60. data/rice/Exception_defn.hpp +69 -0
  61. data/rice/Hash.hpp +227 -0
  62. data/rice/Hash.ipp +330 -0
  63. data/rice/Identifier.cpp +8 -0
  64. data/rice/Identifier.hpp +50 -0
  65. data/rice/Identifier.ipp +33 -0
  66. data/rice/Jump_Tag.hpp +24 -0
  67. data/rice/Makefile.am +129 -0
  68. data/rice/Makefile.in +769 -0
  69. data/rice/Module.cpp +84 -0
  70. data/rice/Module.hpp +8 -0
  71. data/rice/Module.ipp +6 -0
  72. data/rice/Module_defn.hpp +88 -0
  73. data/rice/Module_impl.hpp +281 -0
  74. data/rice/Module_impl.ipp +348 -0
  75. data/rice/Object.cpp +160 -0
  76. data/rice/Object.hpp +8 -0
  77. data/rice/Object.ipp +19 -0
  78. data/rice/Object_defn.hpp +191 -0
  79. data/rice/Require_Guard.hpp +21 -0
  80. data/rice/String.cpp +94 -0
  81. data/rice/String.hpp +89 -0
  82. data/rice/Struct.cpp +117 -0
  83. data/rice/Struct.hpp +162 -0
  84. data/rice/Struct.ipp +26 -0
  85. data/rice/Symbol.cpp +25 -0
  86. data/rice/Symbol.hpp +66 -0
  87. data/rice/Symbol.ipp +44 -0
  88. data/rice/VM.cpp +82 -0
  89. data/rice/VM.hpp +32 -0
  90. data/rice/config.hpp +44 -0
  91. data/rice/config.hpp.in +43 -0
  92. data/rice/detail/Arguments.hpp +118 -0
  93. data/rice/detail/Auto_Function_Wrapper.hpp +898 -0
  94. data/rice/detail/Auto_Function_Wrapper.ipp +3694 -0
  95. data/rice/detail/Auto_Member_Function_Wrapper.hpp +897 -0
  96. data/rice/detail/Auto_Member_Function_Wrapper.ipp +2774 -0
  97. data/rice/detail/Caster.hpp +103 -0
  98. data/rice/detail/Exception_Handler.hpp +8 -0
  99. data/rice/detail/Exception_Handler.ipp +68 -0
  100. data/rice/detail/Exception_Handler_defn.hpp +96 -0
  101. data/rice/detail/Iterator.hpp +93 -0
  102. data/rice/detail/Not_Copyable.hpp +25 -0
  103. data/rice/detail/Wrapped_Function.hpp +33 -0
  104. data/rice/detail/cfp.hpp +24 -0
  105. data/rice/detail/cfp.ipp +51 -0
  106. data/rice/detail/check_ruby_type.cpp +27 -0
  107. data/rice/detail/check_ruby_type.hpp +23 -0
  108. data/rice/detail/creation_funcs.hpp +37 -0
  109. data/rice/detail/creation_funcs.ipp +36 -0
  110. data/rice/detail/default_allocation_func.hpp +23 -0
  111. data/rice/detail/default_allocation_func.ipp +11 -0
  112. data/rice/detail/define_method_and_auto_wrap.hpp +31 -0
  113. data/rice/detail/define_method_and_auto_wrap.ipp +30 -0
  114. data/rice/detail/demangle.cpp +56 -0
  115. data/rice/detail/demangle.hpp +19 -0
  116. data/rice/detail/env.hpp +19 -0
  117. data/rice/detail/from_ruby.hpp +43 -0
  118. data/rice/detail/from_ruby.ipp +60 -0
  119. data/rice/detail/method_data.cpp +159 -0
  120. data/rice/detail/method_data.hpp +21 -0
  121. data/rice/detail/mininode.cpp +1220 -0
  122. data/rice/detail/mininode.hpp +320 -0
  123. data/rice/detail/node.hpp +13 -0
  124. data/rice/detail/object_call.hpp +69 -0
  125. data/rice/detail/object_call.ipp +131 -0
  126. data/rice/detail/protect.cpp +29 -0
  127. data/rice/detail/protect.hpp +34 -0
  128. data/rice/detail/ruby.hpp +84 -0
  129. data/rice/detail/ruby_version_code.hpp +6 -0
  130. data/rice/detail/ruby_version_code.hpp.in +6 -0
  131. data/rice/detail/rubysig.hpp +19 -0
  132. data/rice/detail/st.hpp +22 -0
  133. data/rice/detail/to_ruby.hpp +22 -0
  134. data/rice/detail/to_ruby.ipp +36 -0
  135. data/rice/detail/traits.hpp +43 -0
  136. data/rice/detail/win32.hpp +16 -0
  137. data/rice/detail/wrap_function.hpp +341 -0
  138. data/rice/detail/wrap_function.ipp +514 -0
  139. data/rice/global_function.hpp +33 -0
  140. data/rice/global_function.ipp +22 -0
  141. data/rice/protect.hpp +92 -0
  142. data/rice/protect.ipp +1134 -0
  143. data/rice/ruby_mark.hpp +13 -0
  144. data/rice/ruby_try_catch.hpp +86 -0
  145. data/rice/rubypp.rb +97 -0
  146. data/rice/to_from_ruby.hpp +8 -0
  147. data/rice/to_from_ruby.ipp +294 -0
  148. data/rice/to_from_ruby_defn.hpp +71 -0
  149. data/ruby/Makefile.am +1 -0
  150. data/ruby/Makefile.in +569 -0
  151. data/ruby/lib/Makefile.am +3 -0
  152. data/ruby/lib/Makefile.in +423 -0
  153. data/ruby/lib/mkmf-rice.rb.in +213 -0
  154. data/ruby/lib/version.rb +3 -0
  155. data/ruby.ac +136 -0
  156. data/sample/Makefile.am +47 -0
  157. data/sample/Makefile.in +408 -0
  158. data/sample/enum/extconf.rb +3 -0
  159. data/sample/enum/sample_enum.cpp +54 -0
  160. data/sample/enum/test.rb +8 -0
  161. data/sample/inheritance/animals.cpp +98 -0
  162. data/sample/inheritance/extconf.rb +3 -0
  163. data/sample/inheritance/test.rb +7 -0
  164. data/sample/map/extconf.rb +3 -0
  165. data/sample/map/map.cpp +81 -0
  166. data/sample/map/test.rb +7 -0
  167. data/test/Makefile.am +77 -0
  168. data/test/Makefile.in +820 -0
  169. data/test/ext/Makefile.am +43 -0
  170. data/test/ext/Makefile.in +404 -0
  171. data/test/ext/t1/Foo.hpp +10 -0
  172. data/test/ext/t1/extconf.rb +2 -0
  173. data/test/ext/t1/t1.cpp +15 -0
  174. data/test/ext/t2/extconf.rb +2 -0
  175. data/test/ext/t2/t2.cpp +11 -0
  176. data/test/test_Address_Registration_Guard.cpp +43 -0
  177. data/test/test_Array.cpp +241 -0
  178. data/test/test_Builtin_Object.cpp +72 -0
  179. data/test/test_Class.cpp +498 -0
  180. data/test/test_Constructor.cpp +128 -0
  181. data/test/test_Critical_Guard.cpp +51 -0
  182. data/test/test_Data_Object.cpp +275 -0
  183. data/test/test_Data_Type.cpp +348 -0
  184. data/test/test_Director.cpp +303 -0
  185. data/test/test_Enum.cpp +195 -0
  186. data/test/test_Exception.cpp +46 -0
  187. data/test/test_Hash.cpp +198 -0
  188. data/test/test_Identifier.cpp +70 -0
  189. data/test/test_Jump_Tag.cpp +17 -0
  190. data/test/test_Memory_Management.cpp +50 -0
  191. data/test/test_Module.cpp +497 -0
  192. data/test/test_Object.cpp +148 -0
  193. data/test/test_String.cpp +94 -0
  194. data/test/test_Struct.cpp +192 -0
  195. data/test/test_Symbol.cpp +63 -0
  196. data/test/test_To_From_Ruby.cpp +321 -0
  197. data/test/test_VM.cpp +26 -0
  198. data/test/test_global_functions.cpp +114 -0
  199. data/test/test_rice.rb +43 -0
  200. data/test/unittest.cpp +136 -0
  201. data/test/unittest.hpp +294 -0
  202. metadata +259 -0
@@ -0,0 +1,348 @@
1
+ #include "detail/define_method_and_auto_wrap.hpp"
2
+ #include "Object.hpp"
3
+ #include "Address_Registration_Guard.hpp"
4
+ #include "Data_Object.hpp"
5
+ #include "Data_Type.hpp"
6
+ #include "Symbol.hpp"
7
+ #include "Exception.hpp"
8
+ #include "protect.hpp"
9
+
10
+ #include "Module.hpp"
11
+ #include "Class.hpp"
12
+ #include "Data_Type.hpp"
13
+
14
+ #include "detail/ruby.hpp"
15
+ #include "detail/method_data.hpp"
16
+ #include "detail/Iterator.hpp"
17
+
18
+
19
+ inline
20
+ Rice::Module_base::
21
+ Module_base(VALUE v)
22
+ : Object(v)
23
+ , handler_(Qnil)
24
+ , handler_guard_(&handler_)
25
+ {
26
+ }
27
+
28
+ inline
29
+ Rice::Module_base::
30
+ Module_base(Module_base const & other)
31
+ : Object(other)
32
+ , handler_(other.handler_)
33
+ , handler_guard_(&handler_)
34
+ {
35
+ }
36
+
37
+ inline
38
+ Rice::Module_base &
39
+ Rice::Module_base::
40
+ operator=(Module_base const & other)
41
+ {
42
+ Module_base tmp(other);
43
+ swap(tmp);
44
+ return *this;
45
+ }
46
+
47
+ inline
48
+ void
49
+ Rice::Module_base::
50
+ swap(Module_base & other)
51
+ {
52
+ std::swap(handler_, other.handler_);
53
+ Object::swap(other);
54
+ }
55
+
56
+ template<typename Exception_T, typename Functor_T>
57
+ inline
58
+ void
59
+ Rice::Module_base::
60
+ add_handler(Functor_T functor)
61
+ {
62
+ Data_Object<detail::Exception_Handler> handler(
63
+ new detail::
64
+ Functor_Exception_Handler<Exception_T, Functor_T>(
65
+ functor,
66
+ this->handler()),
67
+ rb_cObject);
68
+ this->handler_.swap(handler);
69
+ }
70
+
71
+ inline
72
+ Rice::Object
73
+ Rice::Module_base::
74
+ handler() const
75
+ {
76
+ if(!handler_.test())
77
+ {
78
+ Data_Object<Rice::detail::Default_Exception_Handler> handler(
79
+ new Rice::detail::Default_Exception_Handler,
80
+ rb_cObject);
81
+ handler_.swap(handler);
82
+ }
83
+
84
+ return handler_;
85
+ }
86
+
87
+ template<typename Base_T, typename Derived_T>
88
+ inline
89
+ Rice::Module_impl<Base_T, Derived_T>::
90
+ Module_impl()
91
+ : Base_T()
92
+ {
93
+ }
94
+
95
+ template<typename Base_T, typename Derived_T>
96
+ template<typename T>
97
+ inline
98
+ Rice::Module_impl<Base_T, Derived_T>::
99
+ Module_impl(T const & arg)
100
+ : Base_T(arg)
101
+ {
102
+ }
103
+
104
+ template<typename Base_T, typename Derived_T>
105
+ template<typename Exception_T, typename Functor_T>
106
+ inline
107
+ Derived_T &
108
+ Rice::Module_impl<Base_T, Derived_T>::
109
+ add_handler(
110
+ Functor_T functor)
111
+ {
112
+ Module_base::add_handler<Exception_T>(functor);
113
+ return (Derived_T &)*this;
114
+ }
115
+
116
+ template<typename Base_T, typename Derived_T>
117
+ template<typename Func_T>
118
+ inline
119
+ Derived_T &
120
+ Rice::Module_impl<Base_T, Derived_T>::
121
+ define_method(
122
+ Identifier name,
123
+ Func_T func,
124
+ Arguments* arguments)
125
+ {
126
+ detail::define_method_and_auto_wrap(
127
+ *this, name, func, this->handler(), arguments);
128
+ return (Derived_T &)*this;
129
+ }
130
+
131
+ template<typename Base_T, typename Derived_T>
132
+ template<typename Func_T>
133
+ inline
134
+ Derived_T &
135
+ Rice::Module_impl<Base_T, Derived_T>::
136
+ define_method(
137
+ Identifier name,
138
+ Func_T func,
139
+ Arg const& arg)
140
+ {
141
+ Arguments* args = new Arguments();
142
+ args->add(arg);
143
+ return define_method(name, func, args);
144
+ }
145
+
146
+
147
+ template<typename Base_T, typename Derived_T>
148
+ template<typename Func_T>
149
+ inline
150
+ Derived_T &
151
+ Rice::Module_impl<Base_T, Derived_T>::
152
+ define_singleton_method(
153
+ Identifier name,
154
+ Func_T func,
155
+ Arguments* arguments)
156
+ {
157
+ detail::define_method_and_auto_wrap(
158
+ rb_singleton_class(*this), name, func, this->handler(), arguments);
159
+ return (Derived_T &)*this;
160
+ }
161
+
162
+ template<typename Base_T, typename Derived_T>
163
+ template<typename Func_T>
164
+ inline
165
+ Derived_T &
166
+ Rice::Module_impl<Base_T, Derived_T>::
167
+ define_singleton_method(
168
+ Identifier name,
169
+ Func_T func,
170
+ Arg const& arg)
171
+ {
172
+ Arguments* args = new Arguments();
173
+ args->add(arg);
174
+ return define_singleton_method(name, func, args);
175
+ }
176
+
177
+ template<typename Base_T, typename Derived_T>
178
+ template<typename Func_T>
179
+ inline
180
+ Derived_T &
181
+ Rice::Module_impl<Base_T, Derived_T>::
182
+ define_module_function(
183
+ Identifier name,
184
+ Func_T func,
185
+ Arguments* arguments)
186
+ {
187
+ if(this->rb_type() != T_MODULE)
188
+ {
189
+ throw Rice::Exception(
190
+ rb_eTypeError,
191
+ "can only define module functions for modules");
192
+ }
193
+
194
+ define_method(name, func, arguments);
195
+ define_singleton_method(name, func, arguments);
196
+ return (Derived_T &)*this;
197
+ }
198
+
199
+ template<typename Base_T, typename Derived_T>
200
+ template<typename Func_T>
201
+ inline
202
+ Derived_T &
203
+ Rice::Module_impl<Base_T, Derived_T>::
204
+ define_module_function(
205
+ Identifier name,
206
+ Func_T func,
207
+ Arg const& arg)
208
+ {
209
+ Arguments* args = new Arguments();
210
+ args->add(arg);
211
+ return define_module_function(name, func, args);
212
+ }
213
+
214
+ template<typename Base_T, typename Derived_T>
215
+ template<typename T, typename Iterator_T>
216
+ inline
217
+ Derived_T &
218
+ Rice::Module_impl<Base_T, Derived_T>::
219
+ define_iterator(
220
+ Iterator_T (T::*begin)(),
221
+ Iterator_T (T::*end)(),
222
+ Identifier name)
223
+ {
224
+ detail::define_iterator(*this, name, begin, end);
225
+ return (Derived_T &)*this;
226
+ }
227
+
228
+ namespace Rice
229
+ {
230
+
231
+ namespace detail
232
+ {
233
+
234
+ inline VALUE
235
+ include_module(VALUE mod, VALUE inc)
236
+ {
237
+ rb_include_module(mod, inc);
238
+ return Qnil;
239
+ }
240
+
241
+ inline VALUE
242
+ const_set(VALUE mod, ID name, VALUE value)
243
+ {
244
+ rb_const_set(mod, name, value);
245
+ return Qnil;
246
+ }
247
+
248
+ } // namespace detail
249
+
250
+ } // namespace Rice
251
+
252
+ template<typename Base_T, typename Derived_T>
253
+ inline
254
+ Derived_T &
255
+ Rice::Module_impl<Base_T, Derived_T>::
256
+ include_module(
257
+ Module const & inc)
258
+ {
259
+ protect(detail::include_module, *this, inc);
260
+ return (Derived_T &)*this;
261
+ }
262
+
263
+ template<typename Base_T, typename Derived_T>
264
+ inline
265
+ Derived_T &
266
+ Rice::Module_impl<Base_T, Derived_T>::
267
+ const_set(
268
+ Identifier name,
269
+ Object value)
270
+ {
271
+ protect(detail::const_set, *this, name, value);
272
+ return (Derived_T &)*this;
273
+ }
274
+
275
+ template<typename Base_T, typename Derived_T>
276
+ inline
277
+ Rice::Object
278
+ Rice::Module_impl<Base_T, Derived_T>::
279
+ const_get(
280
+ Identifier name) const
281
+ {
282
+ return protect(rb_const_get, *this, name);
283
+ }
284
+
285
+ template<typename Base_T, typename Derived_T>
286
+ inline
287
+ bool
288
+ Rice::Module_impl<Base_T, Derived_T>::
289
+ const_defined(Identifier name) const
290
+ {
291
+ int result = protect(rb_const_defined, *this, name);
292
+ return bool(result);
293
+ }
294
+
295
+ template<typename Base_T, typename Derived_T>
296
+ inline
297
+ void
298
+ Rice::Module_impl<Base_T, Derived_T>::
299
+ remove_const(Identifier name)
300
+ {
301
+ protect(rb_mod_remove_const, *this, name.to_sym());
302
+ }
303
+
304
+ template<typename Base_T, typename Derived_T>
305
+ inline
306
+ Rice::Module
307
+ Rice::Module_impl<Base_T, Derived_T>::
308
+ define_module(
309
+ char const * name)
310
+ {
311
+ return Rice::define_module_under(*this, name);
312
+ }
313
+
314
+ template<typename Base_T, typename Derived_T>
315
+ inline
316
+ Rice::Class
317
+ Rice::Module_impl<Base_T, Derived_T>::
318
+ define_class(
319
+ char const * name,
320
+ Object superclass)
321
+ {
322
+ return Rice::define_class_under(*this, name, superclass);
323
+ }
324
+
325
+ template<typename Base_T, typename Derived_T>
326
+ template<typename T>
327
+ inline
328
+ Rice::Data_Type<T>
329
+ Rice::Module_impl<Base_T, Derived_T>::
330
+ define_class_with_object_as_base(
331
+ char const * name)
332
+ {
333
+ return Rice::define_class_under<T>(*this, name);
334
+ }
335
+
336
+ template<typename Base_T, typename Derived_T>
337
+ template<typename T, typename T_Base_T>
338
+ inline
339
+ Rice::Data_Type<T>
340
+ Rice::Module_impl<Base_T, Derived_T>::
341
+ define_class(
342
+ char const * name)
343
+ {
344
+ return Rice::define_class_under<T, T_Base_T>(
345
+ *this,
346
+ name);
347
+ }
348
+
data/rice/Object.cpp ADDED
@@ -0,0 +1,160 @@
1
+ #include "Object.hpp"
2
+ #include "Class.hpp"
3
+ #include "String.hpp"
4
+ #include "Array.hpp"
5
+
6
+ #include <algorithm>
7
+ #include <iostream>
8
+
9
+ namespace Rice
10
+ {
11
+
12
+ Object const Nil(Qnil);
13
+ Object const True(Qtrue);
14
+ Object const False(Qfalse);
15
+ Object const Undef(Qundef);
16
+
17
+ }
18
+
19
+ Rice::Class Rice::Object::
20
+ class_of() const {
21
+ return rb_class_of(value_);
22
+ }
23
+
24
+ int Rice::Object::
25
+ compare(Object const & other) const
26
+ {
27
+ Object result = call("<=>", other);
28
+ return from_ruby<int>(result);
29
+ }
30
+
31
+ void Rice::Object::
32
+ freeze()
33
+ {
34
+ protect(rb_obj_freeze, value());
35
+ }
36
+
37
+ bool Rice::Object::
38
+ is_frozen() const
39
+ {
40
+ return bool(OBJ_FROZEN(value()));
41
+ }
42
+
43
+ Rice::String Rice::Object::
44
+ to_s() const {
45
+ return call("to_s");
46
+ }
47
+
48
+ Rice::String Rice::Object::
49
+ inspect() const {
50
+ return call("inspect");
51
+ }
52
+
53
+ void Rice::Object::
54
+ swap(Rice::Object & other)
55
+ {
56
+ std::swap(value_, other.value_);
57
+ }
58
+
59
+ Rice::Object Rice::Object::
60
+ instance_eval(String const & s)
61
+ {
62
+ VALUE argv[] = { s.value() };
63
+ return protect(rb_obj_instance_eval, 1, &argv[0], *this);
64
+ }
65
+
66
+ int Rice::Object::
67
+ rb_type() const
68
+ {
69
+ return ::rb_type(*this);
70
+ }
71
+
72
+ bool Rice::Object::
73
+ is_a(Object klass) const
74
+ {
75
+ Object result = protect(rb_obj_is_kind_of, *this, klass);
76
+ return result.test();
77
+ }
78
+
79
+ bool Rice::Object::
80
+ respond_to(Identifier id) const
81
+ {
82
+ return bool(rb_respond_to(*this, id));
83
+ }
84
+
85
+ bool Rice::Object::
86
+ is_instance_of(Object klass) const
87
+ {
88
+ Object result = protect(rb_obj_is_instance_of, *this, klass);
89
+ return result.test();
90
+ }
91
+
92
+ Rice::Object Rice::Object::
93
+ iv_get(
94
+ Identifier name) const
95
+ {
96
+ return protect(rb_ivar_get, *this, name.id());
97
+ }
98
+
99
+ Rice::Object Rice::Object::
100
+ attr_get(
101
+ Identifier name) const
102
+ {
103
+ return protect(rb_attr_get, *this, name.id());
104
+ }
105
+
106
+ Rice::Object Rice::Object::
107
+ vcall(
108
+ Identifier id,
109
+ Array args)
110
+ {
111
+ return protect(rb_funcall3, *this, id, args.size(), args.to_c_array());
112
+ }
113
+
114
+ void Rice::Object::
115
+ mark() const
116
+ {
117
+ rb_gc_mark(*this);
118
+ }
119
+
120
+ void Rice::Object::
121
+ set_value(VALUE v)
122
+ {
123
+ value_ = v;
124
+ }
125
+
126
+ std::ostream & Rice::
127
+ operator<<(std::ostream & out, Rice::Object const & obj)
128
+ {
129
+ String s(obj.to_s());
130
+ out << s.c_str();
131
+ return out;
132
+ }
133
+
134
+ bool Rice::
135
+ operator==(Rice::Object const & lhs, Rice::Object const & rhs)
136
+ {
137
+ Object result = lhs.call("==", rhs);
138
+ return result.test();
139
+ }
140
+
141
+ bool Rice::
142
+ operator!=(Rice::Object const & lhs, Rice::Object const & rhs)
143
+ {
144
+ return !(lhs == rhs);
145
+ }
146
+
147
+ bool Rice::
148
+ operator<(Rice::Object const & lhs, Rice::Object const & rhs)
149
+ {
150
+ Object result = lhs.call("<", rhs);
151
+ return result.test();
152
+ }
153
+
154
+ bool Rice::
155
+ operator>(Rice::Object const & lhs, Rice::Object const & rhs)
156
+ {
157
+ Object result = lhs.call(">", rhs);
158
+ return result.test();
159
+ }
160
+
data/rice/Object.hpp ADDED
@@ -0,0 +1,8 @@
1
+ #ifndef Rice__Object__hpp_
2
+ #define Rice__Object__hpp_
3
+
4
+ #include "Object_defn.hpp"
5
+ #include "Object.ipp"
6
+
7
+ #endif // Rice__Object__hpp_
8
+
data/rice/Object.ipp ADDED
@@ -0,0 +1,19 @@
1
+ #ifndef Rice__Object__ipp_
2
+ #define Rice__Object__ipp_
3
+
4
+ #include "protect.hpp"
5
+ #include "detail/ruby.hpp"
6
+
7
+ #include "detail/object_call.ipp"
8
+
9
+ template<typename T>
10
+ void Rice::Object::
11
+ iv_set(
12
+ Identifier name,
13
+ T const & value)
14
+ {
15
+ protect(rb_ivar_set, *this, name.id(), to_ruby(value));
16
+ }
17
+
18
+ #endif // Rice__Object__ipp_
19
+
@@ -0,0 +1,191 @@
1
+ #ifndef Rice__Object_defn__hpp_
2
+ #define Rice__Object_defn__hpp_
3
+
4
+ /*! \file Object.hpp
5
+ */
6
+
7
+ #include "Identifier.hpp"
8
+ #include "detail/ruby.hpp"
9
+
10
+ #include <iosfwd>
11
+
12
+ namespace Rice
13
+ {
14
+
15
+ class Class;
16
+ class String;
17
+ class Array;
18
+
19
+ //! The base class for all Objects
20
+ /*! Perhaps the name "Object" is a misnomer, because this class really
21
+ * holds an object reference, not an object.
22
+ */
23
+ class Object
24
+ {
25
+ public:
26
+ //! Encapsulate an existing ruby object.
27
+ Object(VALUE value = Qnil) : value_(value) { }
28
+
29
+ //! Copy constructor
30
+ Object(Object const & other) : value_(other.value()) { }
31
+
32
+ //! Destructor
33
+ virtual ~Object() { }
34
+
35
+ //! Returns false if the object is nil or false; returns true
36
+ //! otherwise.
37
+ // Having this conversion also prevents accidental conversion to
38
+ // undesired integral types (e.g. long or int) by making the
39
+ // conversion ambiguous.
40
+ bool test() const { return RTEST(value_); }
41
+
42
+ //! Returns false if the object is nil or false; returns true
43
+ //! otherwise.
44
+ operator bool() const { return test(); }
45
+
46
+ //! Returns true if the object is nil, false otherwise.
47
+ bool is_nil() const { return NIL_P(value_); }
48
+
49
+ //! Implicit conversion to VALUE.
50
+ operator VALUE() const { return value_; }
51
+
52
+ //! Explicitly get the encapsulated VALUE.
53
+ // Returns a const ref so that Address_Registration_Guard can access
54
+ // the address where the VALUE is stored
55
+ VALUE const volatile & value() const { return value_; }
56
+
57
+ //! Get the class of an object.
58
+ /*! \return the object's Class.
59
+ */
60
+ Class class_of() const;
61
+
62
+ //! Compare this object to another object.
63
+ /*! Gets the result of self <=> other and returns the result. The
64
+ * result will be less than zero if self < other, greater than zero
65
+ * if self > other, and equal to zero if self == other.
66
+ */
67
+ int compare(Object const & other) const;
68
+
69
+ //! Return a string representation of an object.
70
+ /*! \return the result of calling to_s on the object. A String is not
71
+ * returned, because it is not possible to return an instance of a
72
+ * derived class.
73
+ */
74
+ String to_s() const;
75
+
76
+ //! Inspect the object.
77
+ /*! \return the result of calling inspect on the object. A String is
78
+ * not returned, because it is not possible to return an instance of
79
+ * a derived class.
80
+ */
81
+ String inspect() const;
82
+
83
+ //! Freeze the object.
84
+ void freeze();
85
+
86
+ //! Determine if the object is frozen.
87
+ /*! \return true if the object is frozen, false otherwise.
88
+ */
89
+ bool is_frozen() const;
90
+
91
+ //! Swap with another Object.
92
+ void swap(Object & other);
93
+
94
+ //! Evaluate the given string in the context of the object.
95
+ /*! This is equivalant to calling obj.instance_eval(s) from inside the
96
+ * interpreter.
97
+ * \return the result of the expression.
98
+ */
99
+ Object instance_eval(String const & s);
100
+
101
+ //! Return the type of the underlying C object.
102
+ /*! This is equivalent to calling rb_type(obj).
103
+ * \return the type of the underlying C object (e.g. T_DATA, T_ARRAY,
104
+ * etc.).
105
+ */
106
+ int rb_type() const;
107
+
108
+ //! Determine whether the object is an instance of a class/module.
109
+ /*! \param klass a class or module.
110
+ * \return true if the object is an instance of the given
111
+ * class/module or one of its descendants.
112
+ */
113
+ bool is_a(Object klass) const;
114
+
115
+ //! Determine if the objects responds to a method.
116
+ /*! \param id the name of the method
117
+ * \return true if the objects responds to the method, false
118
+ * otherwise.
119
+ */
120
+ bool respond_to(Identifier id) const;
121
+
122
+ //! Determine whether class is the object's class.
123
+ /*! \param klass a class.
124
+ * \return true if the object is an instance of the given class.
125
+ */
126
+ bool is_instance_of(Object klass) const;
127
+
128
+ //! Set an instance variable.
129
+ /*! \param name the name of the instance variable to set (including
130
+ * the leading @ sign)
131
+ * \param value the value of the variable, which will be converted to
132
+ * a Ruby type if necessary.
133
+ */
134
+ template<typename T>
135
+ void iv_set(
136
+ Identifier name,
137
+ T const & value);
138
+
139
+ //! Get the value of an instance variable.
140
+ /*! \param name the name of the instance variable to get
141
+ * \return the value of the instance variable
142
+ */
143
+ Object iv_get(
144
+ Identifier name) const;
145
+
146
+ //! Get the value of an instance variable, but don't warn if it is
147
+ //unset.
148
+ /*! \param name the name of the instance variable to get
149
+ * \return the value of the instance variable
150
+ */
151
+ Object attr_get(
152
+ Identifier name) const;
153
+
154
+ #include "detail/object_call.hpp"
155
+
156
+ //! Vectorized call.
157
+ /*! Calls the method identified by id with the list of arguments
158
+ * identified by args.
159
+ * \param id the name of the method to call
160
+ * \param args the arguments to the method
161
+ * \return the return value of the method call
162
+ */
163
+ Object vcall(Identifier id, Array args);
164
+
165
+ //! Mark the object with the garbage collector.
166
+ void mark() const;
167
+
168
+ protected:
169
+ //! Set the encapsulated value.
170
+ void set_value(VALUE v);
171
+
172
+ private:
173
+ volatile VALUE value_;
174
+ };
175
+
176
+ std::ostream & operator<<(std::ostream & out, Object const & obj);
177
+
178
+ bool operator==(Object const & lhs, Object const & rhs);
179
+ bool operator!=(Object const & lhs, Object const & rhs);
180
+ bool operator<(Object const & lhs, Object const & rhs);
181
+ bool operator>(Object const & lhs, Object const & rhs);
182
+
183
+ extern Object const Nil;
184
+ extern Object const True;
185
+ extern Object const False;
186
+ extern Object const Undef;
187
+
188
+ } // namespace Rice
189
+
190
+ #endif // Rice__Object_defn__hpp_
191
+