Rice  1.5.2
 All Classes Files Functions Variables Typedefs Friends Pages
Module_impl.hpp
1 #ifndef Rice__Module_impl__hpp_
2 #define Rice__Module_impl__hpp_
3 
4 #include "detail/Exception_Handler_defn.hpp"
5 #include "detail/ruby.hpp"
6 #include "Object_defn.hpp"
7 #include "Address_Registration_Guard_defn.hpp"
8 #include "Arg.hpp"
9 
10 namespace Rice
11 {
12 
13 class Module;
14 class Class;
15 template<typename T> class Data_Type;
16 
21  : public Object
22 {
23 public:
24  Module_base(VALUE v = rb_cObject);
25  Module_base(Module_base const & other);
26 
27  Module_base & operator=(Module_base const & other);
28 
29  void swap(Module_base & other);
30 
31 protected:
32  template<typename Exception_T, typename Functor_T>
33  void add_handler(Functor_T functor);
34 
35  Object handler() const;
36 
37 private:
38  Object mutable handler_;
39  Address_Registration_Guard handler_guard_;
40 };
41 
46 template<typename Base_T, typename Derived_T>
48  : public Base_T
49 {
50 public:
51  Module_impl();
52 
53  template<typename T>
54  Module_impl(T const & arg);
55 
57 
88  template<typename Exception_T, typename Functor_T>
89  Derived_T & add_handler(
90  Functor_T functor);
91 
93 
105  template<typename Func_T>
106  Derived_T & define_method(
107  Identifier name,
108  Func_T func,
109  Arguments* arguments = 0);
110 
111  // FIXME There's GOT to be a better way to
112  // do this. Handles the case where there is a single
113  // argument defined for this method
114  template<typename Func_T>
115  Derived_T & define_method(
116  Identifier name,
117  Func_T func,
118  Arg const& arg);
119 
121 
133  template<typename Func_T>
134  Derived_T & define_singleton_method(
135  Identifier name,
136  Func_T func,
137  Arguments* arguments = 0);
138 
139  // FIXME: See define_method with Arg above
140  template<typename Func_T>
141  Derived_T & define_singleton_method(
142  Identifier name,
143  Func_T func,
144  Arg const& arg);
145 
147 
161  template<typename Func_T>
162  Derived_T & define_module_function(
163  Identifier name,
164  Func_T func,
165  Arguments* arguments = 0);
166 
167  // FIXME: See define_method with Arg above
168  template<typename Func_T>
169  Derived_T & define_module_function(
170  Identifier name,
171  Func_T func,
172  Arg const& arg);
173 
175 
184  template<typename T, typename Iterator_T>
185  Derived_T & define_iterator(
186  Iterator_T (T::*begin)(),
187  Iterator_T (T::*end)(),
188  Identifier name = "each");
189 
191 
194  Derived_T & include_module(
195  Module const & inc);
196 
198 
202  Derived_T & const_set(
203  Identifier name,
204  Object value);
205 
207 
211  Identifier name) const;
212 
214 
218  bool const_defined(
219  Identifier name) const;
220 
222 
224  void remove_const(
225  Identifier name);
226 
228 
232  char const * name);
233 
235 
240  char const * name,
241  Object superclass = rb_cObject);
242 
244 
248  // This function needs to be defined inline to work around a bug in
249  // g++ 3.3.3.
250  template<typename T>
253  char const * name)
254  {
255  return this->define_class_with_object_as_base<T>(name);
256  }
257 
259 
265  template<typename T, typename T_Base_T>
267  define_class(
268  char const * name);
269 
270 private:
271  // Workaround for g++ 3.3.3 (see above).
272  template<typename T>
274  define_class_with_object_as_base(
275  char const * name);
276 };
277 
278 } // namespace Rice
279 
280 #endif // Rice__Module_impl__hpp_
281 
bool const_defined(Identifier name) const
Determine whether a constant is defined.
Definition: Module_impl.hpp:47
A wrapper for the ID type.
Definition: Identifier.hpp:15
A mechanism for binding ruby types to C++ types.
Definition: Data_Type_defn.hpp:110
Derived_T & define_singleton_method(Identifier name, Func_T func, Arguments *arguments=0)
Define a singleton method.
Derived_T & include_module(Module const &inc)
Include a module.
Module define_module(char const *name)
Define a module under this module.
Definition: Module_impl.hpp:20
Class define_class(char const *name, Object superclass=rb_cObject)
Define a class under this module.
Derived_T & define_method(Identifier name, Func_T func, Arguments *arguments=0)
Define an instance method.
Data_Type< T > define_class(char const *name)
Define a new data class under this module.
Definition: Module_impl.hpp:252
A helper for defining a Module and its methods.
Definition: Module_defn.hpp:23
A helper for defining a Class and its methods.
Definition: Class_defn.hpp:21
A guard to register a given address with the GC.
Definition: Address_Registration_Guard_defn.hpp:29
The base class for all Objects.
Definition: Object_defn.hpp:23
Derived_T & const_set(Identifier name, Object value)
Set a constant.
Derived_T & add_handler(Functor_T functor)
Define an exception handler.
void remove_const(Identifier name)
Remove a constant.
Object const_get(Identifier name) const
Get a constant.
Helper for defining default arguments of a method.
Definition: Arg_impl.hpp:26
Derived_T & define_iterator(Iterator_T(T::*begin)(), Iterator_T(T::*end)(), Identifier name="each")
Define an iterator.
Derived_T & define_module_function(Identifier name, Func_T func, Arguments *arguments=0)
Define a module function.