Rice  1.5.2
 All Classes Files Functions Variables Typedefs Friends Pages
Data_Type_defn.hpp
1 #ifndef Rice__Data_Type_defn__hpp_
2 #define Rice__Data_Type_defn__hpp_
3 
4 #include "Class_defn.hpp"
5 #include "Data_Type_fwd.hpp"
6 #include "detail/ruby.hpp"
7 #include <memory>
8 #include <map>
9 #include <set>
10 
15 namespace Rice
16 {
17 
18 namespace detail
19 {
20  class Abstract_Caster;
21 }
22 
23 class Module;
24 
27  : public Module_impl<Class, Data_Type_Base>
28 {
29 public:
32 
34  Data_Type_Base(VALUE v);
35 
37  virtual ~Data_Type_Base() = 0;
38 
39  // Must be public to workaround gcc 3.3
40  typedef std::map<VALUE, detail::Abstract_Caster *> Casters;
41 
42  virtual detail::Abstract_Caster * caster() const = 0;
43 
44  static Casters & casters();
45 
46 private:
47  static Casters * casters_;
48 };
49 
51 
56 template<typename T>
57 Rice::Data_Type<T> define_class_under(
58  Object module,
59  char const * name);
60 
62 
69 template<typename T, typename Base_T>
70 Rice::Data_Type<T> define_class_under(
71  Object module,
72  char const * name);
73 
75 
79 template<typename T>
80 Rice::Data_Type<T> define_class(
81  char const * name);
82 
84 
91 template<typename T, typename Base_T>
92 Rice::Data_Type<T> define_class(
93  char const * name);
94 
96 
102 template<typename From_T, typename To_T>
103 void define_implicit_cast();
104 
106 
109 template<typename T>
111  : public Module_impl<Data_Type_Base, Data_Type<T> >
112 {
113 public:
115  typedef T Type;
116 
118 
121  Data_Type();
122 
124 
128  Data_Type(Module const & v);
129 
131  virtual ~Data_Type();
132 
134 
136  static Module klass();
137 
139 
143  virtual Data_Type & operator=(Module const & klass);
144 
146 
160  template<typename Constructor_T>
162  Constructor_T constructor,
163  Arguments * arguments = 0);
164 
165  template<typename Constructor_T>
167  Constructor_T constructor,
168  Arg const& arg);
169 
171 
191  template<typename Director_T>
193 
195 
198  static T * from_ruby(Object x);
199 
201 
203  static bool is_bound();
204 
205  virtual detail::Abstract_Caster * caster() const;
206 
207  static std::auto_ptr<detail::Abstract_Caster> caster_;
208 
209 protected:
211 
217  template<typename Base_T>
218  static Data_Type bind(Module const & klass);
219 
220  template<typename T_>
222  Object module,
223  char const * name);
224 
225  template<typename T_, typename Base_T_>
227  Object module,
228  char const * name);
229 
230  template<typename T_>
231  friend Rice::Data_Type<T_> Rice::define_class(
232  char const * name);
233 
234  template<typename T_, typename Base_T_>
236  char const * name);
237 
238 private:
239  template<typename T_>
240  friend class Data_Type;
241 
242  static void check_is_bound();
243 
244  static VALUE klass_;
245 
246  typedef std::set<Data_Type<T> *> Instances;
247 
248  static Instances & unbound_instances()
249  {
250  static Instances unbound_instances;
251  return unbound_instances;
252  }
253 };
254 
255 
256 } // namespace Rice
257 
258 #include "Data_Type.ipp"
259 
260 #endif // Rice__Data_Type_defn__hpp_
261 
Definition: Module_impl.hpp:47
T Type
The C++ type being held.
Definition: Data_Type_defn.hpp:115
The base class for all instantiations of Data_Type.
Definition: Data_Type_defn.hpp:26
A mechanism for binding ruby types to C++ types.
Definition: Data_Type_defn.hpp:110
Data_Type< T > & define_director()
Register a Director class for this class.
Data_Type_Base()
Default constructor.
String name() const
Return the name of the module.
virtual ~Data_Type()
Destructor.
static Module klass()
Explictly return the Ruby type.
Data_Type< T > & define_constructor(Constructor_T constructor, Arguments *arguments=0)
Define a constructor for the class.
static T * from_ruby(Object x)
Convert ruby object x to type T.
virtual Data_Type & operator=(Module const &klass)
Assignment operator which takes a Module.
friend Rice::Data_Type< T_ > define_class_under(Object module, char const *name)
Define a new data class in the namespace given by module.
A helper for defining a Module and its methods.
Definition: Module_defn.hpp:23
friend Rice::Data_Type< T_ > define_class(char const *name)
Define a new data class in the default namespace.
The base class for all Objects.
Definition: Object_defn.hpp:23
Data_Type()
Default constructor which does not bind.
static Data_Type bind(Module const &klass)
Bind a Data_Type to a VALUE.
static bool is_bound()
Determine if the type is bound.
Helper for defining default arguments of a method.
Definition: Arg_impl.hpp:26
virtual ~Data_Type_Base()=0
Destructor.