Sha256: 256a95b7514e3984e7e1945c2a4083be3e55615be7a7d8e86d81a30bb6da0504

Contents?: true

Size: 1.8 KB

Versions: 17

Compression:

Stored size: 1.8 KB

Contents

#ifndef Rice__to_from_ruby_defn__hpp_
#define Rice__to_from_ruby_defn__hpp_

#include "Object_defn.hpp"
#include "detail/from_ruby.hpp"
#include "detail/to_ruby.hpp"

#include <typeinfo>
#include <string>
#include <stdexcept>

// ---------------------------------------------------------------------

//! Convert a Ruby object to C++.
/*! If the Ruby object can be converted to an immediate value, returns a
 *  copy of the Ruby object.  If the Ruby object is holding a C++
 *  object and the type specified is a pointer to that type, returns a
 *  pointer to that object.
 *
 *  Conversions from ruby to a pointer type are automatically generated
 *  when a type is bound using Data_Type.  If no conversion exists an
 *  exception is thrown.
 *
 *  \param T the C++ type to which to convert.
 *  \param x the Ruby object to convert.
 *  \return a C++ representation of the Ruby object.
 *
 *  Example:
 *  \code
 *    Object x = INT2NUM(42);
 *    std::cout << from_ruby<int>(x);
 *
 *    Data_Object<Foo> foo(new Foo);
 *    Object obj(foo);
 *    std::cout << *from_ruby<Foo *>(obj) << std::endl;
 *  \endcode
 */
template<typename T>
inline
typename Rice::detail::from_ruby_<T>::Retval_T from_ruby(Rice::Object x)
{
  return Rice::detail::from_ruby_<T>::convert(x);
}

//! Convert a C++ object to Ruby.
/*! If x is a pointer, wraps the pointee as a Ruby object.  If x is an
 *  Object, returns x.
 *
 *  If no conversion exists a compile-time error is generated.
 *
 *  \param x the object to convert.
 *  \return a Ruby representation of the C++ object.
 *
 *  Example:
 *  \code
 *    rb_p(to_ruby(42));
 *
 *    Foo * p_foo = new Foo();
 *    rb_p(to_ruby(p_foo));
 *  \endcode
 */
template<typename T>
inline
Rice::Object to_ruby(T const & x)
{
  return Rice::detail::to_ruby_<T>::convert(x);
}

#endif // Rice__to_from_ruby_defn__hpp_

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
rice-3.0.0 rice/to_from_ruby_defn.hpp
rice2-2.2.1 rice/to_from_ruby_defn.hpp
rice2-2.2.0 rice/to_from_ruby_defn.hpp
rice-2.2.0 rice/to_from_ruby_defn.hpp
rice-2.1.3 rice/to_from_ruby_defn.hpp
rice-2.1.2 rice/to_from_ruby_defn.hpp
rice-2.1.1 rice/to_from_ruby_defn.hpp
rice-2.1.0 rice/to_from_ruby_defn.hpp
rice-2.0.0 rice/to_from_ruby_defn.hpp
rice-1.7.0 rice/to_from_ruby_defn.hpp
rice-1.6.3 rice/to_from_ruby_defn.hpp
rice-1.6.2 rice/to_from_ruby_defn.hpp
rice-1.6.1 rice/to_from_ruby_defn.hpp
rice-1.6.0 rice/to_from_ruby_defn.hpp
rice-1.6.0.pre rice/to_from_ruby_defn.hpp
rice-1.5.3 rice/to_from_ruby_defn.hpp
rice-1.5.2 rice/to_from_ruby_defn.hpp