Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

to_from_ruby.hpp

00001 #ifndef Exc_Ruby__to_from_ruby__hpp_
00002 #define Exc_Ruby__to_from_ruby__hpp_
00003 
00004 #include "excruby/exceptional_ruby.hpp"
00005 
00006 #include <typeinfo>
00007 
00008 // TODO: Add default implementations for from_ruby and to_ruby that use
00009 // Ruby_Type to know the mapping between ruby and C++ type.
00010 template<typename T>
00011 T from_ruby(VALUE /* x */)
00012 {
00013   throw Exc_Ruby::Ruby_Exception(
00014       rb_eNotImpError,
00015       "No conversion from ruby defined for %s",
00016       typeid(T).name());
00017 }
00018 
00019 template<typename T>
00020 VALUE to_ruby(T const & /* x */)
00021 {
00022   throw Exc_Ruby::Ruby_Exception(
00023       rb_eNotImpError,
00024       "No conversion to ruby defined for %s",
00025       typeid(T).name());
00026 }
00027 
00028 // ---------------------------------------------------------------------
00029 template<>
00030 VALUE from_ruby<VALUE>(VALUE x)
00031 {
00032   return x;
00033 }
00034 
00035 template<>
00036 VALUE to_ruby<VALUE>(VALUE const & x)
00037 {
00038   return x;
00039 }
00040 
00041 // ---------------------------------------------------------------------
00042 template<>
00043 int from_ruby<int>(VALUE x)
00044 {
00045   return Exc_Ruby::CPP_NUM2LONG(x);
00046 }
00047 
00048 template<>
00049 VALUE to_ruby<int>(int const & x)
00050 {
00051   return INT2NUM(x);
00052 }
00053 
00054 // ---------------------------------------------------------------------
00055 template<>
00056 char const * from_ruby<char const *>(VALUE x)
00057 {
00058   return Exc_Ruby::CPP_STR2CSTR(x);
00059 }
00060 
00061 template<>
00062 VALUE to_ruby<char const *>(char const * const & x)
00063 {
00064   return rb_str_new2(x);
00065 }
00066 
00067 #endif // Exc_Ruby__to_from_ruby__hpp_

Generated on Sat Jan 1 12:02:20 2005 for Exceptional Ruby by doxygen 1.3.6