Rice  1.5.2
 All Classes Files Functions Variables Typedefs Friends Pages
Data_Object_defn.hpp
Go to the documentation of this file.
1 #ifndef Rice__Data_Object_defn__hpp_
2 #define Rice__Data_Object_defn__hpp_
3 
4 #include "Object_defn.hpp"
5 #include "Data_Type_fwd.hpp"
6 #include "ruby_mark.hpp"
7 #include "detail/to_ruby.hpp"
8 #include "detail/ruby.hpp"
9 
15 namespace Rice
16 {
17 
18 template<typename T>
20 {
21  typedef void (*Ruby_Data_Func)(T * obj);
22  static const Ruby_Data_Func mark;
23 };
24 
25 template<typename T>
27 {
28  static void free(T * obj) { delete obj; }
29 };
30 
31 
33 
56 template<typename T>
58  : public Object
59 {
60 public:
62  typedef void (*Ruby_Data_Func)(T * obj);
63 
65 
79  T * obj,
80  VALUE klass = Data_Type<T>::klass(),
83 
85 
90  Object value);
91 
93 
99  template<typename U>
100  Data_Object(
101  Object value,
102  Data_Type<U> const & klass = Data_Type<T>::klass());
103 
105 
107  Data_Object(Data_Object const & other);
108 
109  T & operator*() const { return *obj_; }
110  T * operator->() const { return obj_; }
111  T * get() const { return obj_; }
112 
114 
116  template<typename U>
117  void swap(Data_Object<U> & ref);
118 
119 private:
120  static void check_cpp_type(Data_Type<T> const & klass);
121 
122 private:
123  T * obj_;
124 };
125 
126 namespace detail
127 {
128  template<typename T>
129  struct to_ruby_<Data_Object<T> >
130  {
131  static Rice::Object convert(Data_Object<T> const & x);
132  };
133 }
134 
135 } // namespace Rice
136 
137 #endif // Rice__Data_Object_defn__hpp_
138 
A mechanism for binding ruby types to C++ types.
Definition: Data_Type_defn.hpp:110
T * operator->() const
Return a pointer to obj_.
Definition: Data_Object_defn.hpp:110
Definition: Data_Object_defn.hpp:19
T & operator*() const
Return a reference to obj_.
Definition: Data_Object_defn.hpp:109
Definition: Data_Object_defn.hpp:26
VALUE const volatile & value() const
Explicitly get the encapsulated VALUE.
Definition: Object_defn.hpp:55
The base class for all Objects.
Definition: Object_defn.hpp:23
void(* Ruby_Data_Func)(T *obj)
A function that takes a T* and returns void.
Definition: Data_Object_defn.hpp:62
void swap(Data_Object< U > &ref)
Swap with another data object of the same type.
Data_Object(T *obj, VALUE klass=Data_Type< T >::klass(), Ruby_Data_Func mark_func=Default_Mark_Function< T >::mark, Ruby_Data_Func free_func=Default_Free_Function< T >::free)
Wrap a C++ object.
A smartpointer-like wrapper for Ruby data objects.
Definition: Data_Object_defn.hpp:57