#ifndef Rice__Data_Object__ipp_ #define Rice__Data_Object__ipp_ #include "detail/check_ruby_type.hpp" #include "protect.hpp" #include template const typename Rice::Default_Mark_Function::Ruby_Data_Func Rice::Default_Mark_Function::mark = ruby_mark; namespace Rice { namespace detail { inline VALUE data_wrap_struct( VALUE klass, RUBY_DATA_FUNC mark, RUBY_DATA_FUNC free, void * obj) { return Data_Wrap_Struct(klass, mark, free, obj); } template inline VALUE wrap( VALUE klass, typename Data_Object::Ruby_Data_Func mark, typename Data_Object::Ruby_Data_Func free, T * obj) { // We cast to obj void* here before passing to Data_Wrap_Struct, // becuase otherwise compilation will fail if obj is const. It's safe // to do this, because unwrap() will always add the const back when // the object is unwrapped. return Rice::protect(data_wrap_struct, klass, reinterpret_cast(mark), reinterpret_cast(free), (void *)obj); } template inline VALUE data_get_struct(VALUE value, T * * obj) { Data_Get_Struct(value, T, *obj); return Qnil; } template inline T * unwrap(VALUE value) { T * obj; Rice::protect(data_get_struct, value, &obj); return obj; } } // namespace detail } // namespace Rice template inline Rice::Data_Object:: Data_Object( T * obj, VALUE klass, Ruby_Data_Func mark_func, Ruby_Data_Func free_func) : Object(detail::wrap(klass, mark_func, free_func, obj)) , obj_(obj) { } template inline Rice::Data_Object:: Data_Object( Object value) : Object(value) , obj_(detail::unwrap(value)) { Data_Type klass; check_cpp_type(klass); detail::check_ruby_type(value, klass, true); } template template inline Rice::Data_Object:: Data_Object( Object value, Data_Type const & klass) : Object(value) , obj_(detail::unwrap(value)) { check_cpp_type(klass); detail::check_ruby_type(value, klass, true); } template inline Rice::Data_Object:: Data_Object(Data_Object const & other) : Object(other.value()) , obj_(other.obj_) { } template template inline void Rice::Data_Object:: swap(Data_Object & ref) { std::swap(obj_, ref.obj_); Object::swap(ref); } template inline void Rice::Data_Object:: check_cpp_type(Data_Type const & /* klass */) { } template Rice::Object Rice::detail::to_ruby_ >:: convert(Rice::Data_Object const & x) { return x; } #endif // Rice__Data_Object__ipp_