<|start_filename|>test/test_Address_Registration_Guard.cpp<|end_filename|>
#include "unittest.hpp"
#include "rice/Address_Registration_Guard.hpp"

using namespace Rice;

TESTSUITE(Address_Registration_Guard);

SETUP(Address_Registration_Guard)
{
  ruby_init();
}

TESTCASE(register_address)
{
  VALUE v = Qnil;
  Address_Registration_Guard g(&v);
}

TESTCASE(register_object)
{
  Object o;
  Address_Registration_Guard g(&o);
}

TESTCASE(get_address)
{
  VALUE v = Qnil;
  Address_Registration_Guard g(&v);
  ASSERT_EQUAL(&v, g.address());
}

TESTCASE(swap)
{
  VALUE v = Qnil;
  VALUE v2 = Qnil;
  Address_Registration_Guard g(&v);
  Address_Registration_Guard g2(&v2);
  g.swap(g2);
  ASSERT_EQUAL(&v, g2.address());
  ASSERT_EQUAL(&v2, g.address());
  // TODO: ensure addresses are still registered
}



<|start_filename|>rice/detail/protect.hpp<|end_filename|>
#ifndef Rice__detail__protect__hpp_
#define Rice__detail__protect__hpp_

#include "ruby.hpp"

/*! \file
 *  \brief Functions for making exception-safe calls into Ruby code.
 *  These are the building blocks for building other exception-safe
 *  helper functions.
 */

namespace Rice
{

namespace detail
{

//! Call the given function, converting Ruby exceptions to C++
//! exceptions.
/*! Call the function f with the parameter arg  If f raises a Ruby
 * exception, then the exception is re-thrown as an Exception.  If f
 * exits with any other non-zero tag (e.g. a Symbol is thrown), then the
 * tag is re-thrown as a Jump_Tag.
 */
VALUE protect(
    RUBY_VALUE_FUNC f,
    VALUE arg);

} // namespace detail

} // namespace Rice

#endif // Rice__detail__protect__hpp_



<|start_filename|>rice/Data_Type.hpp<|end_filename|>
#ifndef Rice__Data_Type__hpp_
#define Rice__Data_Type__hpp_

#include "Data_Type_defn.hpp"
#include "Data_Type.ipp"

#endif // Rice__Data_Type__hpp_



<|start_filename|>rice/Director.hpp<|end_filename|>
#ifndef Rice__Director__hpp_
#define Rice__Director__hpp_

#include "Object.hpp"

namespace Rice {

  /**
   * A Director works exactly as a SWIG %director works (thus the name).
   * You use this class to help build proxy classes so that polymorphism
   * works from C++ into Ruby.
   */
  class Director 
  {
    public:
      //! Construct new Director. Needs the Ruby object so that the 
      //  proxy class can call methods on that object.
      Director(Object self);

      virtual ~Director() { }

      //! Raise a ruby exception when a call comes through for a pure virtual method
      /*! If a Ruby script calls 'super' on a method that's otherwise a pure virtual
       *  method, use this method to throw an exception in this case. 
       */
      void raisePureVirtual() const;

      //! Get the Ruby object linked to this C++ instance
      Object getSelf() const { return self_; }

    private:

      // Save the Ruby object related to the instance of this class
      Object self_;

  };
}

#endif // Rice__Director__hpp_


<|start_filename|>rice/detail/rubysig.hpp<|end_filename|>
#ifndef Rice__detail__rubysig__hpp_
#define Rice__detail__rubysig__hpp_

#include "ruby_version_code.hpp"

/**
 * Helper header for the rubysig.h ruby include file, which does
 * not have extern "C"
 */

#if RICE__RUBY_VERSION_CODE < 190

extern "C" {
  #include "rubysig.h"
}

#endif

#endif


<|start_filename|>rice/Symbol.hpp<|end_filename|>
#ifndef Rice__Symbol__hpp_
#define Rice__Symbol__hpp_

#include "Identifier.hpp"
#include "Object.hpp"
#include "detail/ruby.hpp"
#include <string>

namespace Rice
{

//! A wrapper for ruby's Symbol class.
/*! Symbols are internal identifiers in ruby.  They are singletons and
 *  can be thought of as frozen strings.  They differ from an Identifier
 *  in that they are in fact real Objects, but they can be converted
 *  back and forth between Identifier and Symbol.
 */
class Symbol
  : public Object
{
public:
  //! Wrap an existing symbol.
  Symbol(VALUE v);

  //! Wrap an existing symbol.
  Symbol(Object v);

  //! Construct a Symbol from an Identifier.
  Symbol(Identifier id);

  //! Construct a Symbol from a null-terminated C string.
  Symbol(char const * s = "");

  //! Construct a Symbol from an std::string.
  Symbol(std::string const & s);

  //! Return a string representation of the Symbol.
  char const * c_str() const;

  //! Return a string representation of the Symbol.
  std::string str() const;

  //! Return the Symbol as an Identifier.
  Identifier to_id() const;
};

} // namespace Rice

template<>
inline
Rice::Symbol from_ruby<Rice::Symbol>(Rice::Object x)
{
  return Rice::Symbol(x);
}

template<>
inline
Rice::Object to_ruby<Rice::Symbol>(Rice::Symbol const & x)
{
  return x;
}

#include "Symbol.ipp"

#endif // Rice__Symbol__hpp_



<|start_filename|>rice/detail/Exception_Handler_defn.hpp<|end_filename|>
#ifndef Rice__detail__Exception_Handler_defn__hpp_
#define Rice__detail__Exception_Handler_defn__hpp_

#include "ruby.h"
#undef TYPE

#include "Not_Copyable.hpp"
#include "../Address_Registration_Guard_defn.hpp"
#include "../Data_Object_defn.hpp"

namespace Rice
{

namespace detail
{

// A class for converting C++ exceptions to ruby exceptions.  It's used
// like this:
//
//   try
//   {
//   }
//   catch(...)
//   {
//     handler->handle_exception();
//   }
//
// If an exception is thrown the handler will pass the exception up the
// chain, then the last handler in the chain will throw the exception
// down the chain until a lower handler can handle it, e.g.:
//
//   try
//   {
//     return call_next_exception_handler();
//   }
//   catch(MyException const & ex)
//   {
//     throw Rice::Exception(rb_cMyException, "%s", ex.what());
//   }
//
class Exception_Handler
  : public Rice::detail::Not_Copyable
{
public:
  Exception_Handler(
      Data_Object<Exception_Handler> next_exception_handler);

  virtual ~Exception_Handler();

  virtual VALUE handle_exception() const = 0;

  VALUE call_next_exception_handler() const;

private:
  Data_Object<Exception_Handler> next_exception_handler_;
  Address_Registration_Guard next_exception_handler_guard_;
};

// The default exception handler just rethrows the exception.  If there
// are other handlers in the chain, they will try to handle the rethrown
// exception.
class Default_Exception_Handler
  : public Exception_Handler
{
public:
  Default_Exception_Handler();

  virtual VALUE handle_exception() const;
};

// An exception handler that takes a functor as an argument.  The
// functor should throw a Rice::Exception to handle the exception.  If
// the functor does not handle the exception, the exception will be
// re-thrown.
template <typename Exception_T, typename Functor_T>
class Functor_Exception_Handler
  : public Exception_Handler
{
public:
  Functor_Exception_Handler(
      Functor_T handler,
      Data_Object<Exception_Handler> next_exception_handler);

private:
  virtual VALUE handle_exception() const;

private:
  Functor_T handler_;
};

} // namespace detail

} // namespace Rice

#endif // Rice__detail__Exception_Handler_defn__hpp_



<|start_filename|>rice/detail/default_allocation_func.hpp<|end_filename|>
#ifndef Rice__detail__default_allocation_func__hpp_
#define Rice__detail__default_allocation_func__hpp_

namespace Rice
{

namespace detail
{

//! A default implementation of an allocate_func.  This function does no
//! actual allocation; the initialize_func can later do the real
//! allocation with: DATA_PTR(self) = new Type(arg1, arg2, ...)
template<typename T>
VALUE default_allocation_func(VALUE klass);

} // detail

} // Rice

#include "default_allocation_func.ipp"

#endif // Rice__detail__default_allocation_func__hpp_



<|start_filename|>rice/Critical_Guard.hpp<|end_filename|>
#ifndef Rice__ruby_Critical_Guard__hpp_
#define Rice__ruby_Critical_Guard__hpp_

#include "detail/ruby_version_code.hpp"

#if RICE__RUBY_VERSION_CODE < 190

namespace Rice
{

//! A guard to prevent Ruby from switching threads.
/*! Sets rb_thread_critical to 1 upon construction and back to its
 *  original value upon destruction.  This prevents the scheduler from
 *  changing threads.  This does not work on YARV, however, which has a
 *  different threading model.
 */
class Critical_Guard
{
public:
  //! Prevent ruby from switching threads.
  /*! Prevent the ruby scheduler from switching threads by setting
   *  rb_thread_critical to 1.
   */
  Critical_Guard();

  //! Allow ruby to switch threads.
  /*! Allow the ruby scheduler to switch threads by setting
   *  rb_thread_critical to 0.
   */
  ~Critical_Guard();
};

}

#endif

#include "Critical_Guard.ipp"

#endif // Rice__ruby_Critical_Guard__hpp_



<|start_filename|>rice/Address_Registration_Guard.cpp<|end_filename|>
#include "Address_Registration_Guard.hpp"

bool Rice::Address_Registration_Guard::enabled = true;
bool Rice::Address_Registration_Guard::exit_handler_registered = false;

static void disable_all_guards(VALUE)
{
    Rice::Address_Registration_Guard::disable();
}

void Rice::Address_Registration_Guard::registerExitHandler()
{
    if (exit_handler_registered) return;
    rb_set_end_proc(&disable_all_guards, Qnil);
    exit_handler_registered = true;
}

void Rice::Address_Registration_Guard::disable()
{
    enabled = false;
}



<|start_filename|>rice/Module.cpp<|end_filename|>
#include "Module.hpp"
#include "Symbol.hpp"
#include "String.hpp"
#include "Array.hpp"
#include "Exception.hpp"
#include "protect.hpp"

Rice::Module::
Module()
  : Module_impl<Module_base, Module>(rb_cObject)
{
}

Rice::Module::
Module(VALUE v)
  : Module_impl<Module_base, Module>(v)
{
  if(::rb_type(v) != T_CLASS && ::rb_type(v) != T_MODULE)
  {
    throw Exception(
        rb_eTypeError,
        "Expected a Module but got a %s",
        rb_class2name(CLASS_OF(v))); // TODO: might raise an exception
  }
}

Rice::String Rice::Module::
name() const
{
  Object name = rb_mod_name(*this);
  if(name.is_nil())
  {
    // 1.9
    return String("");
  }
  else
  {
    return name;
  }
}

Rice::Module Rice::
define_module_under(
    Rice::Object module,
    char const * name)
{
  VALUE v = rb_define_module_under(module, name);
  return Module(v);
}

Rice::Module Rice::
define_module(
    char const * name)
{
  VALUE v = rb_define_module(name);
  return Module(v);
}

Rice::Module Rice::
anonymous_module()
{
  return Module(protect(rb_module_new));
}

void Rice::Module::
swap(Rice::Module & other)
{
  Module_base::swap(other);
}

Rice::Array
Rice::Module::
ancestors() const
{
  return protect(rb_mod_ancestors, *this);
}

Rice::Class
Rice::Module::
singleton_class() const
{
  return CLASS_OF(value());
}



<|start_filename|>rice/Builtin_Object.ipp<|end_filename|>
#ifndef Rice__Builtin_Object__ipp_
#define Rice__Builtin_Object__ipp_

#include "Object.hpp"
#include "protect.hpp"
#include "detail/check_ruby_type.hpp"

#include <algorithm>

namespace Rice
{

namespace detail
{
  inline VALUE check_type(Object value, int type)
  {
    rb_check_type(value, type);
    return Qnil;
  }
}

template<typename T, int Builtin_Type>
inline Builtin_Object<T, Builtin_Type>::
Builtin_Object(Object value)
  : Object(value)
  , obj_((T*)(value.value()))
{
  protect(detail::check_type, value, Builtin_Type);
}

template<typename T, int Builtin_Type>
inline Builtin_Object<T, Builtin_Type>::
Builtin_Object(Builtin_Object<T, Builtin_Type> const & other)
  : Object(other.value())
  , obj_(other.obj_)
{
}

template<typename T, int Builtin_Type>
inline void Builtin_Object<T, Builtin_Type>::
swap(Builtin_Object<T, Builtin_Type> & ref)
{
  std::swap(obj_, ref.obj_);
  Object::swap(ref);
}

} // namespace Rice

#endif // Rice__Builtin_Object__ipp_



<|start_filename|>rice/Data_Type_defn.hpp<|end_filename|>
#ifndef Rice__Data_Type_defn__hpp_
#define Rice__Data_Type_defn__hpp_

#include "Class_defn.hpp"
#include "Data_Type_fwd.hpp"
#include "detail/ruby.hpp"
#include <memory>
#include <map>
#include <set>

/*!
 *  \example map/map.cpp
 */

namespace Rice
{

namespace detail
{
  class Abstract_Caster;
}

class Module;

//! The base class for all instantiations of Data_Type.
class Data_Type_Base
  : public Module_impl<Class, Data_Type_Base>
{
public:
  //! Default constructor.
  Data_Type_Base();

  //! Constructor.
  Data_Type_Base(VALUE v);

  //! Destructor.
  virtual ~Data_Type_Base() = 0;

  // Must be public to workaround gcc 3.3
  typedef std::map<VALUE, detail::Abstract_Caster *> Casters;

  virtual detail::Abstract_Caster * caster() const = 0;

  static Casters & casters();

private:
  static Casters * casters_;
};

//! Define a new data class in the namespace given by module.
/*! The class will have a base class of Object.
 *  \param T the C++ type of the wrapped class.
 *  \param module the the Module in which to define the class.
 *  \return the new class.
 */
template<typename T>
Rice::Data_Type<T> define_class_under(
    Object module,
    char const * name);

//! Define a new data class in the namespace given by module.
/*! The class with have a base class determined by Base_T (specifically,
 *  Data_Type<Base_T>::klass).  Therefore, the type Base_T must already
 *  have been registered using define_class<> or define_class_under<>.
 *  \param T the C++ type of the wrapped class.
 *  \param module the the Module in which to define the class.
 *  \return the new class.
 */
template<typename T, typename Base_T>
Rice::Data_Type<T> define_class_under(
    Object module,
    char const * name);

//! Define a new data class in the default namespace.
/*! The class will have a base class of Object.
 *  \param T the C++ type of the wrapped class.
 *  \return the new class.
 */
template<typename T>
Rice::Data_Type<T> define_class(
    char const * name);

//! Define a new data class in the default namespace.
/*! The class with have a base class determined by Base_T (specifically,
 *  Data_Type<Base_T>::klass).  Therefore, the type Base_T must already
 *  have been registered using define_class<> or define_class_under<>.
 *  \param T the C++ type of the wrapped class.
 *  \param module the the Module in which to define the class.
 *  \return the new class.
 */
template<typename T, typename Base_T>
Rice::Data_Type<T> define_class(
    char const * name);

//! Define an implicit conversion rule between two types.
/*! Given two types, which can be custom types already 
 *  wrapped into Rice or fundamental C++ types, this
 *  tells Rice that the two types can be used interchangably.
 *  \param From_T The type to convert from
 *  \param To_T The type to convert to
 */
template<typename From_T, typename To_T>
void define_implicit_cast();

//! A mechanism for binding ruby types to C++ types.
/*! This class binds run-time types (Ruby VALUEs) to compile-time types
 *  (C++ types).  The binding can occur only once.
 */
template<typename T>
class Data_Type
  : public Module_impl<Data_Type_Base, Data_Type<T> >
{
public:
  //! The C++ type being held.
  typedef T Type;

  //! Default constructor which does not bind.
  /*! No member functions must be called on this Data_Type except bind,
   *  until the type is bound.
   */
  Data_Type();

  //! Constructor which takes a Module.
  /*! Binds the type to the given VALUE according to the rules given
   *  above.
   *  \param klass the module to which to bind.
   */
  Data_Type(Module const & v);

  //! Destructor.
  virtual ~Data_Type();
 
  //! Explictly return the Ruby type.
  /*! \return the ruby class to which the type is bound.
   */
  static Module klass();

  //! Assignment operator which takes a Module
  /*! \param klass must be the class to which this data type is already
   *  bound.
   *  \return *this
   */
  virtual Data_Type & operator=(Module const & klass);

  //! Define a constructor for the class.
  /*! Creates a singleton method allocate and an instance method called
   *  initialize which together create a new instance of the class.  The
   *  allocate method allocates memory for the object reference and the
   *  initialize method constructs the object.
   *  \param constructor an object that has a static member function
   *  construct() that constructs a new instance of T and sets the object's data
   *  member to point to the new instance.  A helper class Constructor
   *  is provided that does precisely this.
   *  For example:
   *  \code
   *    define_class<Foo>("Foo")
   *      .define_constructor(Constructor<Foo>());
   *  \endcode
   */
  template<typename Constructor_T>
  Data_Type<T> & define_constructor(
      Constructor_T constructor,
      Arguments * arguments = 0);

  template<typename Constructor_T>
  Data_Type<T> & define_constructor(
      Constructor_T constructor,
      Arg const& arg);

  //! Register a Director class for this class.
  /*! For any class that uses Rice::Director to enable polymorphism
   *  across the languages, you need to register that director proxy
   *  class with this method. Not doing so will cause the resulting 
   *  library to die at run time when it tries to convert the base
   *  type into the Director proxy type, and cannot find an appropriate Caster.
   *
   *  This method takes no arguments, just needs the type of the
   *  Director proxy class.
   *
   *  For example:
   *  \code
   *    class FooDirector : public Foo, public Rice::Director {
   *      ...
   *    };
   *
   *    define_class<Foo>("Foo")
   *      .define_director<FooDirector>()
   *      .define_constructor(Constructor<FooDirector, Rice::Object>());
   *  \endcode
   */
  template<typename Director_T>
  Data_Type<T>& define_director();

  //! Convert ruby object x to type T.
  /*! \param x the object to convert.
   *  \return the C++ object wrapped inside object x.
   */
  static T * from_ruby(Object x);

  //! Determine if the type is bound.
  /*! \return true if the object is bound, false otherwise.
   */
  static bool is_bound();

  virtual detail::Abstract_Caster * caster() const;

  static std::auto_ptr<detail::Abstract_Caster> caster_;

protected:
  //! Bind a Data_Type to a VALUE.
  /*! Throws an exception if the Data_Type is already bound to a
   *  different class.  Any existing instances of the Data_Type will be
   *  bound after this function returns.
   *  \param klass the ruby type to which to bind.
   *  \return *this
   */
  template<typename Base_T>
  static Data_Type bind(Module const & klass);

  template<typename T_>
  friend Rice::Data_Type<T_> define_class_under(
      Object module,
      char const * name);

  template<typename T_, typename Base_T_>
  friend Rice::Data_Type<T_> define_class_under(
      Object module,
      char const * name);

  template<typename T_>
  friend Rice::Data_Type<T_> Rice::define_class(
      char const * name);

  template<typename T_, typename Base_T_>
  friend Rice::Data_Type<T_> define_class(
      char const * name);

private:
  template<typename T_>
  friend class Data_Type;

  static void check_is_bound();

  static VALUE klass_;

  typedef std::set<Data_Type<T> *> Instances;

  static Instances & unbound_instances()
  {
    static Instances unbound_instances;
    return unbound_instances;
  }
};


} // namespace Rice

#include "Data_Type.ipp"

#endif // Rice__Data_Type_defn__hpp_



<|start_filename|>rice/Class.cpp<|end_filename|>
#include "Class.hpp"
#include "Exception.hpp"
#include "detail/creation_funcs.hpp"

Rice::Class::
Class()
  : Module_impl<Module, Class>()
{
}

Rice::Class::
Class(VALUE v)
  : Module_impl<Module, Class>(v)
{
  if(::rb_type(v) != T_CLASS)
  {
    throw Exception(
        rb_eTypeError,
        "Expected a Class but got a %s",
        rb_class2name(CLASS_OF(v))); // TODO: might raise an exception
  }
}

Rice::Class & Rice::Class::
undef_creation_funcs()
{
  detail::undef_creation_funcs(*this);
  return *this;
}

Rice::Class Rice::
define_class_under(
    Rice::Object module,
    char const * name,
    Rice::Object superclass)
{
  VALUE v = rb_define_class_under(module, name, superclass);
  return Class(v);
}

Rice::Class Rice::
define_class(
    char const * name,
    Rice::Object superclass)
{
  VALUE v = rb_define_class(name, superclass);
  return Class(v);
}

Rice::Class Rice::
anonymous_class(
    Rice::Object superclass)
{
  VALUE v = Class(rb_cClass).call("new");
  return Class(v);
}



<|start_filename|>rice/Require_Guard.hpp<|end_filename|>
#ifndef Rice__Require_Guard__hpp_
#define Rice__Require_Guard__hpp_

/*! \def RICE_REQUIRE_GUARD
 *  \brief Put this inside your Init_module function to keep it from
 *         being required more than once with the same name (if you use
 *         Rice, and your module is initialized more than once, an
 *         exception will be thrown).
 */
#define RICE_REQUIRE_GUARD \
  static bool Rice__module_initialized = false; \
  if(Rice__module_initialized) \
  { \
    return; \
  } \
  /* TODO: If module initialization fails, it's not possible to */ \
  /* retry */ \
  Rice__module_initialized = true

#endif // Rice__Require_Guard__hpp_



<|start_filename|>rice/Identifier.hpp<|end_filename|>
#ifndef Rice__Identifier__hpp_
#define Rice__Identifier__hpp_

#include "detail/ruby.hpp"
#include <string>

namespace Rice
{

class Symbol;

//! A wrapper for the ID type
/*! An ID is ruby's internal representation of a Symbol object.
 */
class Identifier
{
public:
  //! Construct a new Identifier from an ID.
  Identifier(ID id);

  //! Construct a new Identifier from a Symbol.
  Identifier(Symbol const & symbol);

  //! Construct a new Identifier from a string.
  Identifier(char const * s = "");

  //! Return a string representation of the Identifier.
  char const * c_str() const;

  //! Return a string representation of the Identifier.
  std::string str() const;

  //! Return the underlying ID
  ID id() const { return id_; }

  //! Return the underlying ID
  operator ID() const { return id_; }

  //! Return the ID as a Symbol
  VALUE to_sym() const;

private:
  ID id_;
};

} // namespace Rice

#include "Identifier.ipp"

#endif // Rice__Identifier__hpp_


<|start_filename|>rice/Data_Type.cpp<|end_filename|>
#include "Data_Type.hpp"

Rice::Data_Type_Base::Casters * Rice::Data_Type_Base::casters_ = 0;

Rice::Data_Type_Base::
Data_Type_Base()
  : Module_impl<Class, Data_Type_Base>()
{
}

Rice::Data_Type_Base::
Data_Type_Base(VALUE v)
  : Module_impl<Class, Data_Type_Base>(v)
{
}

Rice::Data_Type_Base::
~Data_Type_Base()
{
}

Rice::Data_Type_Base::Casters &
Rice::Data_Type_Base::
casters()
{
  // Initialize the casters_ if it is null
  if (!casters_)
  {
    // First, see if it has been previously registered with the
    // interpreter (possibly by another extension)
    Class object(rb_cObject);
    Object casters_object(object.attr_get("__rice_casters__"));

    if (casters_object.is_nil())
    {
      // If it is unset, then set it for the first time
      Data_Object<Casters> casters(
          new Casters,
          rb_cObject);
      object.iv_set("__rice_casters__", casters);
      casters_ = casters.get();
    }
    else
    {
      // If it is set, then use the existing value
      Data_Object<Casters> casters(
          casters_object);
      casters_ = casters.get();
    }
  }

  return *casters_;
}



<|start_filename|>rice/Builtin_Object.hpp<|end_filename|>
#ifndef Rice__Builtin_Object__hpp_
#define Rice__Builtin_Object__hpp_

#include "Builtin_Object_defn.hpp"
#include "Builtin_Object.ipp"

#endif // Rice__Builtin_Object__hpp_



<|start_filename|>test/test_Critical_Guard.cpp<|end_filename|>
#include "unittest.hpp"
#include "rice/Critical_Guard.hpp"
#include <stdexcept>

#if RICE__RUBY_VERSION_CODE < 190

using namespace Rice;

TESTSUITE(Critical_Guard);

SETUP(Critical_Guard)
{
  ruby_init();
}

TESTCASE(normal_path)
{
  rb_thread_critical = 1;
  {
    Critical_Guard g;
    ASSERT(rb_thread_critical);
  }
  ASSERT(!rb_thread_critical);
}

TESTCASE(unset_thread_critical_on_destruction)
{
  rb_thread_critical = 1;
  {
    Critical_Guard g;
    ASSERT(rb_thread_critical);
  }
  ASSERT(!rb_thread_critical);
}

TESTCASE(exception)
{
  rb_thread_critical = 1;
  try
  {
    Critical_Guard g;
    throw std::runtime_error("testing");
  }
  catch(...)
  {
  }
  ASSERT(!rb_thread_critical);
}

#endif



<|start_filename|>test/test_String.cpp<|end_filename|>
#include "unittest.hpp"
#include "rice/String.hpp"

using namespace Rice;

TESTSUITE(String);

SETUP(String)
{
  ruby_init();
}

TESTCASE(default_construct)
{
  String s;
  ASSERT_EQUAL(T_STRING, rb_type(s));
  ASSERT_EQUAL("", RSTRING_PTR(s.value()));
}

TESTCASE(construct_from_value)
{
  String s(rb_str_new2("foo"));
  ASSERT_EQUAL(T_STRING, rb_type(s));
  ASSERT_EQUAL("foo", RSTRING_PTR(s.value()));
}

TESTCASE(construct_from_object)
{
  Object o(rb_str_new2("foo"));
  String s(o);
  ASSERT_EQUAL(T_STRING, rb_type(s));
  ASSERT_EQUAL("foo", RSTRING_PTR(s.value()));
}

TESTCASE(construct_from_identifier)
{
  String s(Identifier("foo"));
  ASSERT_EQUAL(T_STRING, rb_type(s));
  ASSERT_EQUAL("foo", RSTRING_PTR(s.value()));
}

TESTCASE(construct_from_c_string)
{
  String s("foo");
  ASSERT_EQUAL(T_STRING, rb_type(s));
  ASSERT_EQUAL("foo", RSTRING_PTR(s.value()));
}

TESTCASE(construct_from_std_string)
{
  String s(std::string("foo"));
  ASSERT_EQUAL(T_STRING, rb_type(s));
  ASSERT_EQUAL("foo", RSTRING_PTR(s.value()));
}

TESTCASE(format)
{
  String s(String::format("%s %d", "foo", 42));
  ASSERT_EQUAL(T_STRING, rb_type(s));
  ASSERT_EQUAL("foo 42", RSTRING_PTR(s.value()));
}

TESTCASE(length)
{
  String s("foo");
  ASSERT_EQUAL(3u, s.length());
}

TESTCASE(bracket)
{
  String s("foo");
  ASSERT_EQUAL('f', s[0]);
  ASSERT_EQUAL('o', s[1]);
  ASSERT_EQUAL('o', s[2]);
}

TESTCASE(c_str)
{
  String s("foo");
  ASSERT_EQUAL(RSTRING_PTR(s.value()), s.c_str());
}

TESTCASE(str)
{
  String s("foo");
  ASSERT_EQUAL(std::string("foo"), s.str());
}

TESTCASE(intern)
{
  String s("foo");
  ASSERT_EQUAL(Identifier("foo"), s.intern());
}



<|start_filename|>rice/detail/method_data.hpp<|end_filename|>
#ifndef Rice__detail__method_data__hpp
#define Rice__detail__method_data__hpp

#include "ruby.hpp"

namespace Rice
{

namespace detail
{

VALUE define_method_with_data(
    VALUE klass, ID id, VALUE (*cfunc)(ANYARGS), int arity, VALUE data);

VALUE method_data();

} // namespace detail

} // namespace Rice

#endif // Rice__detail__method_data__hpp


<|start_filename|>rice/to_from_ruby.hpp<|end_filename|>
#ifndef Rice__to_from_ruby__hpp_
#define Rice__to_from_ruby__hpp_

#include "to_from_ruby_defn.hpp"
#include "to_from_ruby.ipp"

#endif // Rice__to_from_ruby__hpp_



<|start_filename|>rice/detail/env.hpp<|end_filename|>
#ifndef Rice__detail__env__hpp_
#define Rice__detail__env__hpp_

/**
 * Helper header for the env.h ruby include file, which does
 * not have extern "C"
 */

// TODO: Won't work on ruby 1.9

#include "ruby_version_code.hpp"

#if RICE__RUBY_VERSION_CODE < 190
extern "C" {
  #include "env.h"
}
#endif

#endif


<|start_filename|>rice/detail/check_ruby_type.cpp<|end_filename|>
#include "check_ruby_type.hpp"
#include "../Exception.hpp"

void Rice::detail::
check_ruby_type(
    VALUE value,
    VALUE klass,
    bool include_super
    )
{ 
  if( !rb_obj_is_kind_of(value, klass) ||
     (!include_super && rb_obj_class(value) != klass))
  {
    // Not sure why this stuff can't be chained
    VALUE gotV = protect(rb_mod_name, rb_obj_class(value));
    char* got = StringValuePtr(gotV);
    VALUE exptV = protect(rb_mod_name, klass);
    char* expected = StringValuePtr(exptV);

    throw Exception(
        rb_eTypeError,
        "wrong argument type %s (expected %s)",
        got, expected
      );
  }                                 
}



<|start_filename|>rice/detail/demangle.cpp<|end_filename|>
#include "demangle.hpp"

#ifdef __GNUC__
#include <cxxabi.h>
#include <cstdlib>
#include <cstring>
#endif

std::string
Rice::detail::
demangle(char const * mangled_name)
{
#ifdef __GNUC__
    struct Helper
  {
    Helper(
        char const * mangled_name)
      : name_(0)
    {
      int status = 0;
      name_ = abi::__cxa_demangle(mangled_name, 0, 0, &status);
    }

    ~Helper()
    {
      std::free(name_);
    }

    char * name_;

  private:
    Helper(Helper const &);
    void operator=(Helper const &);
  };

  Helper helper(mangled_name);
  if(helper.name_)
  {
    return helper.name_;
  }
  else
  {
    return mangled_name;
  }
#else
  return mangled_name;
#endif
}


std::string
Rice::detail::
demangle(std::string const & mangled_name)
{
  return demangle(mangled_name.c_str());
}


<|start_filename|>test/test_VM.cpp<|end_filename|>
#include "unittest.hpp"
#include "rice/VM.hpp"
#include "rice/Object.hpp"
#include <memory>

using namespace Rice;

std::auto_ptr<VM> vm;

TESTSUITE(VM);

SETUP(VM)
{
  std::vector<const char *> args;
  args.push_back("test_VM");
  args.push_back("-e");
  args.push_back("puts \"HELLO\"");
  vm.reset(new VM(args));
}

TESTCASE(create_object)
{
  Object o;
  o.call("to_s");
}



<|start_filename|>rice/Data_Type_fwd.hpp<|end_filename|>
#ifndef Rice__Data_Type_fwd__hpp_
#define Rice__Data_Type_fwd__hpp_

namespace Rice
{

  template<typename T>
  class Data_Type;

} // Rice

#endif // Rice__Data_Type_fwd__hpp_


<|start_filename|>rice/Director.cpp<|end_filename|>
#include "Director.hpp"

namespace Rice {

  Director::Director(Object self) {
    self_ = self;
  }

  void Director::raisePureVirtual() const {
    rb_raise(rb_eNotImpError, "Cannot call super() into a pure-virtual C++ method");
  }

}


<|start_filename|>rice/detail/creation_funcs.ipp<|end_filename|>
#ifndef Rice__detail__creation_funcs__ipp_
#define Rice__detail__creation_funcs__ipp_

namespace Rice
{

namespace detail
{

template<typename Initialize_Func_T>
inline void define_creation_funcs(
    Class const & klass,
    RUBY_VALUE_FUNC allocate_func,
    Initialize_Func_T initialize_func)
{
  rb_define_alloc_func(klass, allocate_func);
  klass.define_method("initialize", initialize_func);
}

inline void undef_alloc_func(Class const & klass)
{
  rb_undef_alloc_func(klass);
}

inline void undef_creation_funcs(Class const & klass)
{
  undef_alloc_func(klass);
  rb_undef_method(klass, "initialize");
}

} // namespace detail

} // namespace Rice

#endif // Rice__detail__creation_funcs__ipp_



<|start_filename|>rice/Exception_Base_defn.hpp<|end_filename|>
#ifndef Rice__Exception_Base_defn__hpp_
#define Rice__Exception_Base_defn__hpp_

#include "Object_defn.hpp"

namespace Rice
{

//! An abstract interface for Exception
/*! This class exists to prevent a circular reference between
 *  Exception.hpp and ruby_try_catch.hpp
 */
class Exception_Base
  : public std::exception
  , public Object
{
public:
  Exception_Base(VALUE v);

  virtual ~Exception_Base() throw() = 0;

  virtual char const * what() const throw() = 0;
};

} // Rice

#endif // Rice__Exception_Base_defn__hpp_


<|start_filename|>rice/Symbol.ipp<|end_filename|>
#ifndef Rice__Symbol__ipp_
#define Rice__Symbol__ipp_

#include "protect.hpp"
#include "detail/ruby.hpp"

inline Rice::Symbol::
Symbol(char const * s)
  : Object(ID2SYM(rb_intern(s)))
{
}

inline Rice::Symbol::
Symbol(std::string const & s)
  : Object(ID2SYM(rb_intern(s.c_str())))
{
}

inline Rice::Symbol::
Symbol(Identifier id)
  : Object(ID2SYM(id))
{
}

inline char const * Rice::Symbol::
c_str() const
{
  return to_id().c_str();
}

inline std::string Rice::Symbol::
str() const
{
  return to_id().str();
}

inline Rice::Identifier Rice::Symbol::
to_id() const
{
  return rb_to_id(value());
}

#endif // Rice__Symbol__ipp_



<|start_filename|>rice/detail/from_ruby.hpp<|end_filename|>
#ifndef Rice__detail__from_ruby__hpp_
#define Rice__detail__from_ruby__hpp_

namespace Rice
{
  namespace detail
  {
    template<typename T>
    struct from_ruby_
    {
      typedef T Retval_T;

      static T convert(Rice::Object x);
    };

    template<typename T>
    struct from_ruby_<T *>
    {
      typedef T * Retval_T;

      static T * convert(Rice::Object x);
    };

    template<typename T>
    struct from_ruby_<T const *>
    {
      typedef T const * Retval_T;

      static T const * convert(Rice::Object x);
    };

    template<typename T>
    struct from_ruby_<T &>
    {
      typedef T & Retval_T;

      static T & convert(Rice::Object x);
    };
  } // detail
} // Rice

#endif // Rice__detail__from_ruby__hpp_



<|start_filename|>rice/Exception_defn.hpp<|end_filename|>
#ifndef Rice__Exception_defn__hpp_
#define Rice__Exception_defn__hpp_

#include "Exception_Base_defn.hpp"
#include "String.hpp"
#include "Address_Registration_Guard_defn.hpp"

#include <stdexcept>
#include "detail/ruby.hpp"

namespace Rice
{

//! A placeholder for Ruby exceptions.
/*! You can use this to safely throw a Ruby exception using C++ syntax:
 *  \code
 *    VALUE foo(VALUE self) {
 *      RUBY_TRY {
 *        throw Rice::Exception(rb_eMyException, "uh oh!");
 *      RUBY_CATCH
 *    }
 *  \endcode
 */
class Exception
  : public Exception_Base
{
public:
  //! Construct a Exception with the exception e.
  explicit Exception(VALUE e);

  //! Copy constructor.
  Exception(Exception const & other);

  //! Construct a Exception with printf-style formatting.
  /*! \param exc either an exception object or a class that inherits
   *  from Exception.
   *  \param fmt a printf-style format string
   *  \param ... the arguments to the format string.
   */
  Exception(Object exc, char const * fmt, ...);

  //! Destructor
  virtual ~Exception() throw() { }

  //! Get the message the exception holds
  /*! \return the result of calling message() on the underlying
   *  exception object.
   */
  String message() const;

  //! Get message as a char const *.
  /*! If message is a non-string object, then this function will attempt
   *  to throw an exception (which it can't do because of the no-throw
   *  specification).
   *  \return the underlying C pointer of the underlying message object.
   */
  virtual char const * what() const throw();

private:
  // Keep message around in case someone calls what() and then the GC
  // gets invoked.
  mutable VALUE message_;
  Address_Registration_Guard message_guard_;
};

} // namespace Rice

#endif // Rice__Exception_defn__hpp_



<|start_filename|>rice/Address_Registration_Guard.hpp<|end_filename|>
#ifndef Rice__Address_Registration_Guard__hpp_
#define Rice__Address_Registration_Guard__hpp_

#include "Address_Registration_Guard_defn.hpp"
#include "Address_Registration_Guard.ipp"

#endif // Rice__Address_Registration_Guard__hpp_


<|start_filename|>rice/detail/Not_Copyable.hpp<|end_filename|>
#ifndef Rice__Not_Copyable__hpp_
#define Rice__Not_Copyable__hpp_

namespace Rice
{

namespace detail
{

// Inherit from Not_Copyable to prevent copying instances of a class.
class Not_Copyable
{
public:
  Not_Copyable() { }

private:
  Not_Copyable(Not_Copyable const &);
  Not_Copyable & operator=(Not_Copyable const &);
};

} // namespace detail

} // namespace Rice

#endif // Rice__Not_Copyable__hpp_


<|start_filename|>rice/detail/cfp.ipp<|end_filename|>
namespace detail
{

struct rb_thread_struct
{
    VALUE self;
    void *vm;
    VALUE *stack;
    unsigned long stack_size;
    VALUE *cfp;
    /* ... */
};

typedef struct rb_thread_struct rb_thread_t;

} // namespace detail

extern "C" detail::rb_thread_t * ruby_current_thread;

inline
VALUE *
Rice::detail::
cfp()
{
  return ruby_current_thread->cfp;
}

inline
VALUE &
Rice::detail::
cfp_data_memo_node_and_pc(VALUE * cfp)
{
  return cfp[0];
}

inline
VALUE &
Rice::detail::
cfp_self(VALUE * cfp)
{
  return cfp[5];
}

inline
VALUE &
Rice::detail::
cfp_method_class(VALUE * cfp)
{
  return cfp[11];
}



<|start_filename|>rice/Arg_operators.hpp<|end_filename|>
#ifndef Rice__Arg_Operators_hpp_
#define Rice__Arg_Operators_hpp_

namespace Rice
{

  //! Build the list of Arg objects into an Arguments object
  /*! Take a list of Arg objects and build up a single Argument
   *  object used later in method dispatch
   */
  Arguments* operator,(Arg arg1, Arg arg2);

  /*! @see operator,(Arg, Arg)
   */
  Arguments* operator,(Arguments* arguments, Arg arg);

}

#endif // Rice__Arg_Operators_hpp_


<|start_filename|>rice/detail/mininode.cpp<|end_filename|>
// TODO: This is silly, autoconf...
#undef PACKAGE_NAME
#undef PACKAGE_STRING
#undef PACKAGE_TARNAME
#undef PACKAGE_VERSION

#include "../config.hpp"

// TODO: This is silly, autoconf...
#undef PACKAGE_NAME
#undef PACKAGE_STRING
#undef PACKAGE_TARNAME
#undef PACKAGE_VERSION

#if !defined(HAVE_NODE_H) && !defined(REALLY_HAVE_RUBY_NODE_H)

#include "mininode.hpp"
#include <cstring>

extern "C"
char const * ruby_node_name(int node);

namespace
{

int node_value(char const * name)
{
  /* TODO: any way to end the block? */
  int j;
  for(j = 0; ; ++j)
  {
    if(!std::strcmp(name, ruby_node_name(j)))
    {
      return j;
    }
  }
}

} // namespace

static int NODE_METHOD_ = -1;

int Rice::detail::Mininode::get_NODE_METHOD()
{
  if(NODE_METHOD_ == -1)
  {
    NODE_METHOD_ = node_value("NODE_METHOD");
  }

  return NODE_METHOD_;
}
static int NODE_FBODY_ = -1;

int Rice::detail::Mininode::get_NODE_FBODY()
{
  if(NODE_FBODY_ == -1)
  {
    NODE_FBODY_ = node_value("NODE_FBODY");
  }

  return NODE_FBODY_;
}
static int NODE_CFUNC_ = -1;

int Rice::detail::Mininode::get_NODE_CFUNC()
{
  if(NODE_CFUNC_ == -1)
  {
    NODE_CFUNC_ = node_value("NODE_CFUNC");
  }

  return NODE_CFUNC_;
}
static int NODE_SCOPE_ = -1;

int Rice::detail::Mininode::get_NODE_SCOPE()
{
  if(NODE_SCOPE_ == -1)
  {
    NODE_SCOPE_ = node_value("NODE_SCOPE");
  }

  return NODE_SCOPE_;
}
static int NODE_BLOCK_ = -1;

int Rice::detail::Mininode::get_NODE_BLOCK()
{
  if(NODE_BLOCK_ == -1)
  {
    NODE_BLOCK_ = node_value("NODE_BLOCK");
  }

  return NODE_BLOCK_;
}
static int NODE_IF_ = -1;

int Rice::detail::Mininode::get_NODE_IF()
{
  if(NODE_IF_ == -1)
  {
    NODE_IF_ = node_value("NODE_IF");
  }

  return NODE_IF_;
}
static int NODE_CASE_ = -1;

int Rice::detail::Mininode::get_NODE_CASE()
{
  if(NODE_CASE_ == -1)
  {
    NODE_CASE_ = node_value("NODE_CASE");
  }

  return NODE_CASE_;
}
static int NODE_WHEN_ = -1;

int Rice::detail::Mininode::get_NODE_WHEN()
{
  if(NODE_WHEN_ == -1)
  {
    NODE_WHEN_ = node_value("NODE_WHEN");
  }

  return NODE_WHEN_;
}
static int NODE_OPT_N_ = -1;

int Rice::detail::Mininode::get_NODE_OPT_N()
{
  if(NODE_OPT_N_ == -1)
  {
    NODE_OPT_N_ = node_value("NODE_OPT_N");
  }

  return NODE_OPT_N_;
}
static int NODE_WHILE_ = -1;

int Rice::detail::Mininode::get_NODE_WHILE()
{
  if(NODE_WHILE_ == -1)
  {
    NODE_WHILE_ = node_value("NODE_WHILE");
  }

  return NODE_WHILE_;
}
static int NODE_UNTIL_ = -1;

int Rice::detail::Mininode::get_NODE_UNTIL()
{
  if(NODE_UNTIL_ == -1)
  {
    NODE_UNTIL_ = node_value("NODE_UNTIL");
  }

  return NODE_UNTIL_;
}
static int NODE_ITER_ = -1;

int Rice::detail::Mininode::get_NODE_ITER()
{
  if(NODE_ITER_ == -1)
  {
    NODE_ITER_ = node_value("NODE_ITER");
  }

  return NODE_ITER_;
}
static int NODE_FOR_ = -1;

int Rice::detail::Mininode::get_NODE_FOR()
{
  if(NODE_FOR_ == -1)
  {
    NODE_FOR_ = node_value("NODE_FOR");
  }

  return NODE_FOR_;
}
static int NODE_BREAK_ = -1;

int Rice::detail::Mininode::get_NODE_BREAK()
{
  if(NODE_BREAK_ == -1)
  {
    NODE_BREAK_ = node_value("NODE_BREAK");
  }

  return NODE_BREAK_;
}
static int NODE_NEXT_ = -1;

int Rice::detail::Mininode::get_NODE_NEXT()
{
  if(NODE_NEXT_ == -1)
  {
    NODE_NEXT_ = node_value("NODE_NEXT");
  }

  return NODE_NEXT_;
}
static int NODE_REDO_ = -1;

int Rice::detail::Mininode::get_NODE_REDO()
{
  if(NODE_REDO_ == -1)
  {
    NODE_REDO_ = node_value("NODE_REDO");
  }

  return NODE_REDO_;
}
static int NODE_RETRY_ = -1;

int Rice::detail::Mininode::get_NODE_RETRY()
{
  if(NODE_RETRY_ == -1)
  {
    NODE_RETRY_ = node_value("NODE_RETRY");
  }

  return NODE_RETRY_;
}
static int NODE_BEGIN_ = -1;

int Rice::detail::Mininode::get_NODE_BEGIN()
{
  if(NODE_BEGIN_ == -1)
  {
    NODE_BEGIN_ = node_value("NODE_BEGIN");
  }

  return NODE_BEGIN_;
}
static int NODE_RESCUE_ = -1;

int Rice::detail::Mininode::get_NODE_RESCUE()
{
  if(NODE_RESCUE_ == -1)
  {
    NODE_RESCUE_ = node_value("NODE_RESCUE");
  }

  return NODE_RESCUE_;
}
static int NODE_RESBODY_ = -1;

int Rice::detail::Mininode::get_NODE_RESBODY()
{
  if(NODE_RESBODY_ == -1)
  {
    NODE_RESBODY_ = node_value("NODE_RESBODY");
  }

  return NODE_RESBODY_;
}
static int NODE_ENSURE_ = -1;

int Rice::detail::Mininode::get_NODE_ENSURE()
{
  if(NODE_ENSURE_ == -1)
  {
    NODE_ENSURE_ = node_value("NODE_ENSURE");
  }

  return NODE_ENSURE_;
}
static int NODE_AND_ = -1;

int Rice::detail::Mininode::get_NODE_AND()
{
  if(NODE_AND_ == -1)
  {
    NODE_AND_ = node_value("NODE_AND");
  }

  return NODE_AND_;
}
static int NODE_OR_ = -1;

int Rice::detail::Mininode::get_NODE_OR()
{
  if(NODE_OR_ == -1)
  {
    NODE_OR_ = node_value("NODE_OR");
  }

  return NODE_OR_;
}
static int NODE_MASGN_ = -1;

int Rice::detail::Mininode::get_NODE_MASGN()
{
  if(NODE_MASGN_ == -1)
  {
    NODE_MASGN_ = node_value("NODE_MASGN");
  }

  return NODE_MASGN_;
}
static int NODE_LASGN_ = -1;

int Rice::detail::Mininode::get_NODE_LASGN()
{
  if(NODE_LASGN_ == -1)
  {
    NODE_LASGN_ = node_value("NODE_LASGN");
  }

  return NODE_LASGN_;
}
static int NODE_DASGN_ = -1;

int Rice::detail::Mininode::get_NODE_DASGN()
{
  if(NODE_DASGN_ == -1)
  {
    NODE_DASGN_ = node_value("NODE_DASGN");
  }

  return NODE_DASGN_;
}
static int NODE_DASGN_CURR_ = -1;

int Rice::detail::Mininode::get_NODE_DASGN_CURR()
{
  if(NODE_DASGN_CURR_ == -1)
  {
    NODE_DASGN_CURR_ = node_value("NODE_DASGN_CURR");
  }

  return NODE_DASGN_CURR_;
}
static int NODE_GASGN_ = -1;

int Rice::detail::Mininode::get_NODE_GASGN()
{
  if(NODE_GASGN_ == -1)
  {
    NODE_GASGN_ = node_value("NODE_GASGN");
  }

  return NODE_GASGN_;
}
static int NODE_IASGN_ = -1;

int Rice::detail::Mininode::get_NODE_IASGN()
{
  if(NODE_IASGN_ == -1)
  {
    NODE_IASGN_ = node_value("NODE_IASGN");
  }

  return NODE_IASGN_;
}
static int NODE_IASGN2_ = -1;

int Rice::detail::Mininode::get_NODE_IASGN2()
{
  if(NODE_IASGN2_ == -1)
  {
    NODE_IASGN2_ = node_value("NODE_IASGN2");
  }

  return NODE_IASGN2_;
}
static int NODE_CDECL_ = -1;

int Rice::detail::Mininode::get_NODE_CDECL()
{
  if(NODE_CDECL_ == -1)
  {
    NODE_CDECL_ = node_value("NODE_CDECL");
  }

  return NODE_CDECL_;
}
static int NODE_CVDECL_ = -1;

int Rice::detail::Mininode::get_NODE_CVDECL()
{
  if(NODE_CVDECL_ == -1)
  {
    NODE_CVDECL_ = node_value("NODE_CVDECL");
  }

  return NODE_CVDECL_;
}
static int NODE_OP_ASGN1_ = -1;

int Rice::detail::Mininode::get_NODE_OP_ASGN1()
{
  if(NODE_OP_ASGN1_ == -1)
  {
    NODE_OP_ASGN1_ = node_value("NODE_OP_ASGN1");
  }

  return NODE_OP_ASGN1_;
}
static int NODE_OP_ASGN2_ = -1;

int Rice::detail::Mininode::get_NODE_OP_ASGN2()
{
  if(NODE_OP_ASGN2_ == -1)
  {
    NODE_OP_ASGN2_ = node_value("NODE_OP_ASGN2");
  }

  return NODE_OP_ASGN2_;
}
static int NODE_OP_ASGN_AND_ = -1;

int Rice::detail::Mininode::get_NODE_OP_ASGN_AND()
{
  if(NODE_OP_ASGN_AND_ == -1)
  {
    NODE_OP_ASGN_AND_ = node_value("NODE_OP_ASGN_AND");
  }

  return NODE_OP_ASGN_AND_;
}
static int NODE_OP_ASGN_OR_ = -1;

int Rice::detail::Mininode::get_NODE_OP_ASGN_OR()
{
  if(NODE_OP_ASGN_OR_ == -1)
  {
    NODE_OP_ASGN_OR_ = node_value("NODE_OP_ASGN_OR");
  }

  return NODE_OP_ASGN_OR_;
}
static int NODE_CALL_ = -1;

int Rice::detail::Mininode::get_NODE_CALL()
{
  if(NODE_CALL_ == -1)
  {
    NODE_CALL_ = node_value("NODE_CALL");
  }

  return NODE_CALL_;
}
static int NODE_FCALL_ = -1;

int Rice::detail::Mininode::get_NODE_FCALL()
{
  if(NODE_FCALL_ == -1)
  {
    NODE_FCALL_ = node_value("NODE_FCALL");
  }

  return NODE_FCALL_;
}
static int NODE_VCALL_ = -1;

int Rice::detail::Mininode::get_NODE_VCALL()
{
  if(NODE_VCALL_ == -1)
  {
    NODE_VCALL_ = node_value("NODE_VCALL");
  }

  return NODE_VCALL_;
}
static int NODE_SUPER_ = -1;

int Rice::detail::Mininode::get_NODE_SUPER()
{
  if(NODE_SUPER_ == -1)
  {
    NODE_SUPER_ = node_value("NODE_SUPER");
  }

  return NODE_SUPER_;
}
static int NODE_ZSUPER_ = -1;

int Rice::detail::Mininode::get_NODE_ZSUPER()
{
  if(NODE_ZSUPER_ == -1)
  {
    NODE_ZSUPER_ = node_value("NODE_ZSUPER");
  }

  return NODE_ZSUPER_;
}
static int NODE_ARRAY_ = -1;

int Rice::detail::Mininode::get_NODE_ARRAY()
{
  if(NODE_ARRAY_ == -1)
  {
    NODE_ARRAY_ = node_value("NODE_ARRAY");
  }

  return NODE_ARRAY_;
}
static int NODE_ZARRAY_ = -1;

int Rice::detail::Mininode::get_NODE_ZARRAY()
{
  if(NODE_ZARRAY_ == -1)
  {
    NODE_ZARRAY_ = node_value("NODE_ZARRAY");
  }

  return NODE_ZARRAY_;
}
static int NODE_VALUES_ = -1;

int Rice::detail::Mininode::get_NODE_VALUES()
{
  if(NODE_VALUES_ == -1)
  {
    NODE_VALUES_ = node_value("NODE_VALUES");
  }

  return NODE_VALUES_;
}
static int NODE_HASH_ = -1;

int Rice::detail::Mininode::get_NODE_HASH()
{
  if(NODE_HASH_ == -1)
  {
    NODE_HASH_ = node_value("NODE_HASH");
  }

  return NODE_HASH_;
}
static int NODE_RETURN_ = -1;

int Rice::detail::Mininode::get_NODE_RETURN()
{
  if(NODE_RETURN_ == -1)
  {
    NODE_RETURN_ = node_value("NODE_RETURN");
  }

  return NODE_RETURN_;
}
static int NODE_YIELD_ = -1;

int Rice::detail::Mininode::get_NODE_YIELD()
{
  if(NODE_YIELD_ == -1)
  {
    NODE_YIELD_ = node_value("NODE_YIELD");
  }

  return NODE_YIELD_;
}
static int NODE_LVAR_ = -1;

int Rice::detail::Mininode::get_NODE_LVAR()
{
  if(NODE_LVAR_ == -1)
  {
    NODE_LVAR_ = node_value("NODE_LVAR");
  }

  return NODE_LVAR_;
}
static int NODE_DVAR_ = -1;

int Rice::detail::Mininode::get_NODE_DVAR()
{
  if(NODE_DVAR_ == -1)
  {
    NODE_DVAR_ = node_value("NODE_DVAR");
  }

  return NODE_DVAR_;
}
static int NODE_GVAR_ = -1;

int Rice::detail::Mininode::get_NODE_GVAR()
{
  if(NODE_GVAR_ == -1)
  {
    NODE_GVAR_ = node_value("NODE_GVAR");
  }

  return NODE_GVAR_;
}
static int NODE_IVAR_ = -1;

int Rice::detail::Mininode::get_NODE_IVAR()
{
  if(NODE_IVAR_ == -1)
  {
    NODE_IVAR_ = node_value("NODE_IVAR");
  }

  return NODE_IVAR_;
}
static int NODE_CONST_ = -1;

int Rice::detail::Mininode::get_NODE_CONST()
{
  if(NODE_CONST_ == -1)
  {
    NODE_CONST_ = node_value("NODE_CONST");
  }

  return NODE_CONST_;
}
static int NODE_CVAR_ = -1;

int Rice::detail::Mininode::get_NODE_CVAR()
{
  if(NODE_CVAR_ == -1)
  {
    NODE_CVAR_ = node_value("NODE_CVAR");
  }

  return NODE_CVAR_;
}
static int NODE_NTH_REF_ = -1;

int Rice::detail::Mininode::get_NODE_NTH_REF()
{
  if(NODE_NTH_REF_ == -1)
  {
    NODE_NTH_REF_ = node_value("NODE_NTH_REF");
  }

  return NODE_NTH_REF_;
}
static int NODE_BACK_REF_ = -1;

int Rice::detail::Mininode::get_NODE_BACK_REF()
{
  if(NODE_BACK_REF_ == -1)
  {
    NODE_BACK_REF_ = node_value("NODE_BACK_REF");
  }

  return NODE_BACK_REF_;
}
static int NODE_MATCH_ = -1;

int Rice::detail::Mininode::get_NODE_MATCH()
{
  if(NODE_MATCH_ == -1)
  {
    NODE_MATCH_ = node_value("NODE_MATCH");
  }

  return NODE_MATCH_;
}
static int NODE_MATCH2_ = -1;

int Rice::detail::Mininode::get_NODE_MATCH2()
{
  if(NODE_MATCH2_ == -1)
  {
    NODE_MATCH2_ = node_value("NODE_MATCH2");
  }

  return NODE_MATCH2_;
}
static int NODE_MATCH3_ = -1;

int Rice::detail::Mininode::get_NODE_MATCH3()
{
  if(NODE_MATCH3_ == -1)
  {
    NODE_MATCH3_ = node_value("NODE_MATCH3");
  }

  return NODE_MATCH3_;
}
static int NODE_LIT_ = -1;

int Rice::detail::Mininode::get_NODE_LIT()
{
  if(NODE_LIT_ == -1)
  {
    NODE_LIT_ = node_value("NODE_LIT");
  }

  return NODE_LIT_;
}
static int NODE_STR_ = -1;

int Rice::detail::Mininode::get_NODE_STR()
{
  if(NODE_STR_ == -1)
  {
    NODE_STR_ = node_value("NODE_STR");
  }

  return NODE_STR_;
}
static int NODE_DSTR_ = -1;

int Rice::detail::Mininode::get_NODE_DSTR()
{
  if(NODE_DSTR_ == -1)
  {
    NODE_DSTR_ = node_value("NODE_DSTR");
  }

  return NODE_DSTR_;
}
static int NODE_XSTR_ = -1;

int Rice::detail::Mininode::get_NODE_XSTR()
{
  if(NODE_XSTR_ == -1)
  {
    NODE_XSTR_ = node_value("NODE_XSTR");
  }

  return NODE_XSTR_;
}
static int NODE_DXSTR_ = -1;

int Rice::detail::Mininode::get_NODE_DXSTR()
{
  if(NODE_DXSTR_ == -1)
  {
    NODE_DXSTR_ = node_value("NODE_DXSTR");
  }

  return NODE_DXSTR_;
}
static int NODE_EVSTR_ = -1;

int Rice::detail::Mininode::get_NODE_EVSTR()
{
  if(NODE_EVSTR_ == -1)
  {
    NODE_EVSTR_ = node_value("NODE_EVSTR");
  }

  return NODE_EVSTR_;
}
static int NODE_DREGX_ = -1;

int Rice::detail::Mininode::get_NODE_DREGX()
{
  if(NODE_DREGX_ == -1)
  {
    NODE_DREGX_ = node_value("NODE_DREGX");
  }

  return NODE_DREGX_;
}
static int NODE_DREGX_ONCE_ = -1;

int Rice::detail::Mininode::get_NODE_DREGX_ONCE()
{
  if(NODE_DREGX_ONCE_ == -1)
  {
    NODE_DREGX_ONCE_ = node_value("NODE_DREGX_ONCE");
  }

  return NODE_DREGX_ONCE_;
}
static int NODE_ARGS_ = -1;

int Rice::detail::Mininode::get_NODE_ARGS()
{
  if(NODE_ARGS_ == -1)
  {
    NODE_ARGS_ = node_value("NODE_ARGS");
  }

  return NODE_ARGS_;
}
static int NODE_ARGS_AUX_ = -1;

int Rice::detail::Mininode::get_NODE_ARGS_AUX()
{
  if(NODE_ARGS_AUX_ == -1)
  {
    NODE_ARGS_AUX_ = node_value("NODE_ARGS_AUX");
  }

  return NODE_ARGS_AUX_;
}
static int NODE_OPT_ARG_ = -1;

int Rice::detail::Mininode::get_NODE_OPT_ARG()
{
  if(NODE_OPT_ARG_ == -1)
  {
    NODE_OPT_ARG_ = node_value("NODE_OPT_ARG");
  }

  return NODE_OPT_ARG_;
}
static int NODE_POSTARG_ = -1;

int Rice::detail::Mininode::get_NODE_POSTARG()
{
  if(NODE_POSTARG_ == -1)
  {
    NODE_POSTARG_ = node_value("NODE_POSTARG");
  }

  return NODE_POSTARG_;
}
static int NODE_ARGSCAT_ = -1;

int Rice::detail::Mininode::get_NODE_ARGSCAT()
{
  if(NODE_ARGSCAT_ == -1)
  {
    NODE_ARGSCAT_ = node_value("NODE_ARGSCAT");
  }

  return NODE_ARGSCAT_;
}
static int NODE_ARGSPUSH_ = -1;

int Rice::detail::Mininode::get_NODE_ARGSPUSH()
{
  if(NODE_ARGSPUSH_ == -1)
  {
    NODE_ARGSPUSH_ = node_value("NODE_ARGSPUSH");
  }

  return NODE_ARGSPUSH_;
}
static int NODE_SPLAT_ = -1;

int Rice::detail::Mininode::get_NODE_SPLAT()
{
  if(NODE_SPLAT_ == -1)
  {
    NODE_SPLAT_ = node_value("NODE_SPLAT");
  }

  return NODE_SPLAT_;
}
static int NODE_TO_ARY_ = -1;

int Rice::detail::Mininode::get_NODE_TO_ARY()
{
  if(NODE_TO_ARY_ == -1)
  {
    NODE_TO_ARY_ = node_value("NODE_TO_ARY");
  }

  return NODE_TO_ARY_;
}
static int NODE_BLOCK_ARG_ = -1;

int Rice::detail::Mininode::get_NODE_BLOCK_ARG()
{
  if(NODE_BLOCK_ARG_ == -1)
  {
    NODE_BLOCK_ARG_ = node_value("NODE_BLOCK_ARG");
  }

  return NODE_BLOCK_ARG_;
}
static int NODE_BLOCK_PASS_ = -1;

int Rice::detail::Mininode::get_NODE_BLOCK_PASS()
{
  if(NODE_BLOCK_PASS_ == -1)
  {
    NODE_BLOCK_PASS_ = node_value("NODE_BLOCK_PASS");
  }

  return NODE_BLOCK_PASS_;
}
static int NODE_DEFN_ = -1;

int Rice::detail::Mininode::get_NODE_DEFN()
{
  if(NODE_DEFN_ == -1)
  {
    NODE_DEFN_ = node_value("NODE_DEFN");
  }

  return NODE_DEFN_;
}
static int NODE_ALIAS_ = -1;

int Rice::detail::Mininode::get_NODE_ALIAS()
{
  if(NODE_ALIAS_ == -1)
  {
    NODE_ALIAS_ = node_value("NODE_ALIAS");
  }

  return NODE_ALIAS_;
}
static int NODE_VALIAS_ = -1;

int Rice::detail::Mininode::get_NODE_VALIAS()
{
  if(NODE_VALIAS_ == -1)
  {
    NODE_VALIAS_ = node_value("NODE_VALIAS");
  }

  return NODE_VALIAS_;
}
static int NODE_UNDEF_ = -1;

int Rice::detail::Mininode::get_NODE_UNDEF()
{
  if(NODE_UNDEF_ == -1)
  {
    NODE_UNDEF_ = node_value("NODE_UNDEF");
  }

  return NODE_UNDEF_;
}
static int NODE_CLASS_ = -1;

int Rice::detail::Mininode::get_NODE_CLASS()
{
  if(NODE_CLASS_ == -1)
  {
    NODE_CLASS_ = node_value("NODE_CLASS");
  }

  return NODE_CLASS_;
}
static int NODE_MODULE_ = -1;

int Rice::detail::Mininode::get_NODE_MODULE()
{
  if(NODE_MODULE_ == -1)
  {
    NODE_MODULE_ = node_value("NODE_MODULE");
  }

  return NODE_MODULE_;
}
static int NODE_SCLASS_ = -1;

int Rice::detail::Mininode::get_NODE_SCLASS()
{
  if(NODE_SCLASS_ == -1)
  {
    NODE_SCLASS_ = node_value("NODE_SCLASS");
  }

  return NODE_SCLASS_;
}
static int NODE_COLON2_ = -1;

int Rice::detail::Mininode::get_NODE_COLON2()
{
  if(NODE_COLON2_ == -1)
  {
    NODE_COLON2_ = node_value("NODE_COLON2");
  }

  return NODE_COLON2_;
}
static int NODE_COLON3_ = -1;

int Rice::detail::Mininode::get_NODE_COLON3()
{
  if(NODE_COLON3_ == -1)
  {
    NODE_COLON3_ = node_value("NODE_COLON3");
  }

  return NODE_COLON3_;
}
static int NODE_DOT2_ = -1;

int Rice::detail::Mininode::get_NODE_DOT2()
{
  if(NODE_DOT2_ == -1)
  {
    NODE_DOT2_ = node_value("NODE_DOT2");
  }

  return NODE_DOT2_;
}
static int NODE_DOT3_ = -1;

int Rice::detail::Mininode::get_NODE_DOT3()
{
  if(NODE_DOT3_ == -1)
  {
    NODE_DOT3_ = node_value("NODE_DOT3");
  }

  return NODE_DOT3_;
}
static int NODE_FLIP2_ = -1;

int Rice::detail::Mininode::get_NODE_FLIP2()
{
  if(NODE_FLIP2_ == -1)
  {
    NODE_FLIP2_ = node_value("NODE_FLIP2");
  }

  return NODE_FLIP2_;
}
static int NODE_FLIP3_ = -1;

int Rice::detail::Mininode::get_NODE_FLIP3()
{
  if(NODE_FLIP3_ == -1)
  {
    NODE_FLIP3_ = node_value("NODE_FLIP3");
  }

  return NODE_FLIP3_;
}
static int NODE_ATTRSET_ = -1;

int Rice::detail::Mininode::get_NODE_ATTRSET()
{
  if(NODE_ATTRSET_ == -1)
  {
    NODE_ATTRSET_ = node_value("NODE_ATTRSET");
  }

  return NODE_ATTRSET_;
}
static int NODE_SELF_ = -1;

int Rice::detail::Mininode::get_NODE_SELF()
{
  if(NODE_SELF_ == -1)
  {
    NODE_SELF_ = node_value("NODE_SELF");
  }

  return NODE_SELF_;
}
static int NODE_NIL_ = -1;

int Rice::detail::Mininode::get_NODE_NIL()
{
  if(NODE_NIL_ == -1)
  {
    NODE_NIL_ = node_value("NODE_NIL");
  }

  return NODE_NIL_;
}
static int NODE_TRUE_ = -1;

int Rice::detail::Mininode::get_NODE_TRUE()
{
  if(NODE_TRUE_ == -1)
  {
    NODE_TRUE_ = node_value("NODE_TRUE");
  }

  return NODE_TRUE_;
}
static int NODE_FALSE_ = -1;

int Rice::detail::Mininode::get_NODE_FALSE()
{
  if(NODE_FALSE_ == -1)
  {
    NODE_FALSE_ = node_value("NODE_FALSE");
  }

  return NODE_FALSE_;
}
static int NODE_ERRINFO_ = -1;

int Rice::detail::Mininode::get_NODE_ERRINFO()
{
  if(NODE_ERRINFO_ == -1)
  {
    NODE_ERRINFO_ = node_value("NODE_ERRINFO");
  }

  return NODE_ERRINFO_;
}
static int NODE_DEFINED_ = -1;

int Rice::detail::Mininode::get_NODE_DEFINED()
{
  if(NODE_DEFINED_ == -1)
  {
    NODE_DEFINED_ = node_value("NODE_DEFINED");
  }

  return NODE_DEFINED_;
}
static int NODE_POSTEXE_ = -1;

int Rice::detail::Mininode::get_NODE_POSTEXE()
{
  if(NODE_POSTEXE_ == -1)
  {
    NODE_POSTEXE_ = node_value("NODE_POSTEXE");
  }

  return NODE_POSTEXE_;
}
static int NODE_ALLOCA_ = -1;

int Rice::detail::Mininode::get_NODE_ALLOCA()
{
  if(NODE_ALLOCA_ == -1)
  {
    NODE_ALLOCA_ = node_value("NODE_ALLOCA");
  }

  return NODE_ALLOCA_;
}
static int NODE_BMETHOD_ = -1;

int Rice::detail::Mininode::get_NODE_BMETHOD()
{
  if(NODE_BMETHOD_ == -1)
  {
    NODE_BMETHOD_ = node_value("NODE_BMETHOD");
  }

  return NODE_BMETHOD_;
}
static int NODE_MEMO_ = -1;

int Rice::detail::Mininode::get_NODE_MEMO()
{
  if(NODE_MEMO_ == -1)
  {
    NODE_MEMO_ = node_value("NODE_MEMO");
  }

  return NODE_MEMO_;
}
static int NODE_IFUNC_ = -1;

int Rice::detail::Mininode::get_NODE_IFUNC()
{
  if(NODE_IFUNC_ == -1)
  {
    NODE_IFUNC_ = node_value("NODE_IFUNC");
  }

  return NODE_IFUNC_;
}
static int NODE_DSYM_ = -1;

int Rice::detail::Mininode::get_NODE_DSYM()
{
  if(NODE_DSYM_ == -1)
  {
    NODE_DSYM_ = node_value("NODE_DSYM");
  }

  return NODE_DSYM_;
}
static int NODE_ATTRASGN_ = -1;

int Rice::detail::Mininode::get_NODE_ATTRASGN()
{
  if(NODE_ATTRASGN_ == -1)
  {
    NODE_ATTRASGN_ = node_value("NODE_ATTRASGN");
  }

  return NODE_ATTRASGN_;
}
static int NODE_PRELUDE_ = -1;

int Rice::detail::Mininode::get_NODE_PRELUDE()
{
  if(NODE_PRELUDE_ == -1)
  {
    NODE_PRELUDE_ = node_value("NODE_PRELUDE");
  }

  return NODE_PRELUDE_;
}
static int NODE_LAMBDA_ = -1;

int Rice::detail::Mininode::get_NODE_LAMBDA()
{
  if(NODE_LAMBDA_ == -1)
  {
    NODE_LAMBDA_ = node_value("NODE_LAMBDA");
  }

  return NODE_LAMBDA_;
}
static int NODE_OPTBLOCK_ = -1;

int Rice::detail::Mininode::get_NODE_OPTBLOCK()
{
  if(NODE_OPTBLOCK_ == -1)
  {
    NODE_OPTBLOCK_ = node_value("NODE_OPTBLOCK");
  }

  return NODE_OPTBLOCK_;
}
static int NODE_LAST_ = -1;

int Rice::detail::Mininode::get_NODE_LAST()
{
  if(NODE_LAST_ == -1)
  {
    NODE_LAST_ = node_value("NODE_LAST");
  }

  return NODE_LAST_;
}

#endif



<|start_filename|>rice/Class.ipp<|end_filename|>
#ifndef Rice__Class__ipp_
#define Rice__Class__ipp_

#include "Module.ipp"

#endif // Rice__Class__ipp_


<|start_filename|>rice/detail/traits.hpp<|end_filename|>
#ifndef Rice__detail__traits__hpp_
#define Rice__detail__traits__hpp_

namespace Rice
{
namespace detail
{

/**
 * Remove const from a type
 */
template<typename T>
struct remove_const { typedef T Type; };

template<typename T>
struct remove_const<const T> { typedef T Type; };

/**
 * Remove a reference from a type
 */
template<typename T>
struct remove_ref { typedef T Type; };

template<typename T>
struct remove_ref<T &> { typedef T Type; };

/**
 * Do both of the above in one easy step
 */
template<typename T>
struct sanitize
{
  typedef T Type;
  //typedef typename remove_const< 
    //typename remove_ref<T>::Type 
    //>::Type Type;
};

}
}


#endif // Rice__detail__traits__hpp_


<|start_filename|>rice/String.hpp<|end_filename|>
#ifndef Rice__String__hpp_
#define Rice__String__hpp_

#include "Identifier.hpp"
#include "Builtin_Object_defn.hpp"
#include "to_from_ruby_defn.hpp"
#include "detail/ruby.hpp"
#include <string>

namespace Rice
{

//! A Wraper for the ruby String class.
/*! This class provides a C++-style interface to ruby's String class and
 *  its associated rb_str_* functions.
 *
 *  Example:
 *  \code
 *    String s(String::format("%s: %d", "foo", 42));
 *    std::cout << s.length() << std::endl;
 *  \endcode
 */
class String
  : public Builtin_Object<RString, T_STRING>
{
public:
  //! Construct a new string.
  String();

  //! Wrap an existing string.
  String(VALUE v);

  //! Wrap an existing string.
  String(Object v);

  //! Construct a String from an Identifier.
  String(Identifier id);

  //! Construct a String from a null-terminated C string.
  String(char const * s);

  //! Construct a String from an std::string.
  String(std::string const & s);

  //! Format a string using printf-style formatting.
  static String format(char const * s, ...);

  //! Get the length of the String.
  /*! \return the length of the string.
   */
  size_t length() const;

  //! Get the character at the given index.
  /*! \param index the desired index.
   *  \return the character at the given index.
   */
  char operator[](ptrdiff_t index) const;

  //! Return a pointer to the beginning of the underlying C string.
  char const * c_str() const;

  //! Return a copy of the string as an std::string.
  std::string str() const;

  //! Create an Identifier from the String.
  /*! Calls rb_intern to create an ID.
   *  \return an Identifier holding the ID returned from rb_intern.
   */
  Identifier intern() const;
};

} // namespace Rice

template<>
inline
Rice::String from_ruby<Rice::String>(Rice::Object x)
{
  return Rice::String(x);
}

template<>
inline
Rice::Object to_ruby<Rice::String>(Rice::String const & x)
{
  return x;
}

#endif // Rice__String__hpp_



<|start_filename|>rice/Struct.ipp<|end_filename|>
namespace Rice
{

template<typename T>
inline Object Struct::Instance::
operator[](T index)
{
  return rb_struct_aref(value(), ULONG2NUM(index));
}

template<>
inline Object Struct::Instance::
operator[]<Identifier>(Identifier member)
{
  size_t index = type_.offset_of(member);
  return (*this)[index];
}

template<>
inline Object Struct::Instance::
operator[]<char const *>(char const * name)
{
  return (*this)[Identifier(name)];
}

} // Rice


<|start_filename|>rice/detail/win32.hpp<|end_filename|>
#ifndef Rice__detail__win32__hpp_
#define Rice__detail__win32__hpp_

/*! \file
 * \brief Undefine all the evil macros that are defined in win32.h
 */

// None of these macros are used in Ruby header files
#undef bind
#undef read
#undef write
#undef send
#undef recv
#undef times

#endif // Rice__detail__win32__hpp_


<|start_filename|>rice/Exception_Base.hpp<|end_filename|>
#ifndef Rice__Exception_Base__hpp_
#define Rice__Exception_Base__hpp_

#include "Exception_Base_defn.hpp"
#include "Exception_Base.ipp"

#endif // Rice__Exception_Base__hpp_



<|start_filename|>rice/detail/Exception_Handler.ipp<|end_filename|>
#include "../Data_Type_defn.hpp"

inline
Rice::detail::Exception_Handler::
Exception_Handler(
    Data_Object<Exception_Handler> next_exception_handler)
  : next_exception_handler_(next_exception_handler)
  , next_exception_handler_guard_(&next_exception_handler_)
{
}

inline
Rice::detail::Exception_Handler::
~Exception_Handler()
{
}

inline
VALUE
Rice::detail::Exception_Handler::
call_next_exception_handler() const
{
  return next_exception_handler_->handle_exception();
}

inline Rice::detail::Default_Exception_Handler::
Default_Exception_Handler()
  : Exception_Handler(
      Data_Object<Exception_Handler>(0, rb_cObject))
{
}

inline
VALUE
Rice::detail::Default_Exception_Handler::
handle_exception() const
{
  throw;
}

template <typename Exception_T, typename Functor_T>
inline
Rice::detail::Functor_Exception_Handler<Exception_T, Functor_T>::
Functor_Exception_Handler(
    Functor_T handler,
    Data_Object<Exception_Handler> next_exception_handler)
  : Exception_Handler(next_exception_handler)
  , handler_(handler)
{
}

template <typename Exception_T, typename Functor_T>
inline
VALUE
Rice::detail::Functor_Exception_Handler<Exception_T, Functor_T>::
handle_exception() const
{
  try
  {
    return call_next_exception_handler();
  }
  catch(Exception_T const & ex)
  {
    handler_(ex);
    throw;
  }
}



<|start_filename|>rice/VM.hpp<|end_filename|>
#ifndef VM__hpp
#define VM__hpp

#include <vector>
#include "detail/ruby_version_code.hpp"

namespace Rice
{

class VM
{
public:
  VM(char * app_name);
  VM(int argc, char * argv[]);
  VM(std::vector<const char *> const & args);
  ~VM();

  void init_stack();
  void run();

private:
  void check_not_initialized() const;
  void init(int argc, char * argv[]);

#if RICE__RUBY_VERSION_CODE >= 190
  void * node_;
#endif
};

}

#endif // VM__hpp


<|start_filename|>rice/detail/node.hpp<|end_filename|>
#ifndef Rice__detail__node__hpp_
#define Rice__detail__node__hpp_

/**
 * Helper header for the node.h ruby include file, which does
 * not have extern "C"
 */

extern "C" {
  #include "node.h"
}

#endif


<|start_filename|>sample/map/map.cpp<|end_filename|>
#include "rice/Data_Type.hpp"
#include "rice/Constructor.hpp"

#include <map>

using namespace Rice;

namespace
{

class Map
{
private:
  struct Ruby_Value_Compare
  {
    bool operator()(Object lhs, Object rhs) const
    {
      Object result = lhs.call("<", rhs);
      return result.test();
    }
  };

  typedef std::map<Object, Object, Ruby_Value_Compare> Value_Map;

public:
  Object bracket(Object k)
  {
    Value_Map::iterator it = map_.find(k);
    return it == map_.end() ? Object(Qnil) : it->second;
  }

  Object bracket_equals(Object k, Object v)
  {
    map_[k] = v;
    return Qnil;
  }

  Value_Map::iterator begin() { return map_.begin(); }
  Value_Map::iterator end() { return map_.end(); }

  typedef Value_Map::value_type value_type;
  typedef Value_Map::iterator iterator;

private:
  Value_Map map_;
};

Data_Type<Map> rb_cMap;

} // namespace

template<>
Object to_ruby<Map::value_type>(Map::value_type const & p)
{
  return protect(rb_assoc_new, p.first, p.second);
}

#include <iostream>
extern "C"
void Init_map(void)
{
  RUBY_TRY
  {
    Map::iterator (Map::*begin)() = &Map::begin;
    Map::iterator (Map::*end)() = &Map::end;
    Rice::Module rb_mStd = define_module("Std");

    // TODO: no delete method on the map, because I'm not sure how to
    // make delete work properly while iterating
    rb_cMap =
      define_class_under<Map>(rb_mStd, "Map")
      .define_constructor(Constructor<Map>())
      .define_method("[]", &Map::bracket)
      .define_method("[]=", &Map::bracket_equals)
      .define_iterator(begin, end)
      .include_module(rb_mEnumerable)
      ;
  }
  RUBY_CATCH
}



<|start_filename|>rice/Data_Object.hpp<|end_filename|>
#ifndef Rice__Data_Object__hpp_
#define Rice__Data_Object__hpp_

#include "Data_Object_defn.hpp"
#include "Data_Object.ipp"

#endif // Rice__Data_Object__hpp_



<|start_filename|>rice/Identifier.ipp<|end_filename|>
inline Rice::Identifier::
Identifier(ID id)
  : id_(id)
{
}

inline Rice::Identifier::
Identifier(char const * s)
  : id_(rb_intern(s))
{
}

inline char const *
Rice::Identifier::
c_str() const
{
  return rb_id2name(id_);
}

inline std::string
Rice::Identifier::
str() const
{
  return c_str();
}

inline VALUE
Rice::Identifier::
to_sym() const
{
  return ID2SYM(id_);
}



<|start_filename|>test/test_Constructor.cpp<|end_filename|>
#include "unittest.hpp"
#include "rice/Constructor.hpp"
#include "rice/Data_Type.hpp"

#include "rice/detail/env.hpp"

#include <iostream>
using namespace std;

using namespace Rice;

TESTSUITE(Constructor);

namespace
{
  class Default_Constructible
  {
  public:
    Default_Constructible()
    {
    }
  };
}

TESTCASE(default_constructor)
{
  Data_Type<Default_Constructible> rb_cDefault_Constructible(
      anonymous_class());
  rb_cDefault_Constructible
    .define_constructor(Constructor<Default_Constructible>());
  Object o = rb_cDefault_Constructible.call("new");
  ASSERT_EQUAL(rb_cDefault_Constructible, o.class_of());
}


namespace
{
  class Non_Default_Constructible
  {
  public:
    Non_Default_Constructible(int i)
      : i_(i)
    {
    }

    int i() const
    {
      return i_;
    }

  private:
    int i_;
  };
}

TESTCASE(non_default_constructor)
{
  Data_Type<Non_Default_Constructible> rb_cNon_Default_Constructible(
      anonymous_class());
  rb_cNon_Default_Constructible
    .define_constructor(Constructor<Non_Default_Constructible, int>());
  Data_Object<Non_Default_Constructible> o =
    rb_cNon_Default_Constructible.call("new", 42);
  ASSERT_EQUAL(rb_cNon_Default_Constructible, o.class_of());
  ASSERT_EQUAL(42, o->i());
}

namespace
{
  int withArgsX;
  float withArgsY;
  bool withArgsYes;

  class WithDefaultArgs
  {
    public:
      WithDefaultArgs(int x, float y = 2.0, bool yes = false)
      {
        withArgsX = x;
        withArgsY = y;
        withArgsYes = yes;
      }
  };

  int withArgX;
  class WithOneArg
  {
    public:
      WithOneArg(int x = 14) {
        withArgX = x;
      }
  };
}

TESTCASE(constructor_supports_default_arguments)
{
  Class klass = define_class<WithDefaultArgs>("WithDefaultArgs").
    define_constructor(Constructor<WithDefaultArgs, int, float, bool>(),
          ( Arg("x"), Arg("y") = (float)2.0, Arg("yes") = (bool)false ));

  klass.call("new", 4);
  ASSERT_EQUAL(4, withArgsX);
  ASSERT_EQUAL(2.0, withArgsY);
  ASSERT_EQUAL(false, withArgsYes);

  klass.call("new", 5, 3.0);
  ASSERT_EQUAL(5, withArgsX);
  ASSERT_EQUAL(3.0, withArgsY);
  ASSERT_EQUAL(false, withArgsYes);

  klass.call("new", 7, 12.0, true);
  ASSERT_EQUAL(7, withArgsX);
  ASSERT_EQUAL(12.0, withArgsY);
  ASSERT_EQUAL(true, withArgsYes);
}

TESTCASE(constructor_supports_single_default_argument)
{
  Class klass = define_class<WithOneArg>("WithOneArg").
    define_constructor(Constructor<WithOneArg, int>(),
          ( Arg("x") = 14 ));

  klass.call("new");
  ASSERT_EQUAL(14, withArgX);

  klass.call("new", 6);
  ASSERT_EQUAL(6, withArgX);
}


<|start_filename|>rice/global_function.ipp<|end_filename|>
#include "detail/define_method_and_auto_wrap.hpp"

template<typename Func_T>
void Rice::define_global_function(
    char const * name,
    Func_T func,
    Arguments* arguments)
{
  Module(rb_mKernel).define_module_function(name, func, arguments);
}

template<typename Func_T>
void Rice::define_global_function(
    char const * name,
    Func_T func,
    Arg const& arg)
{
  Arguments* args = new Arguments();
  args->add(arg);
  define_global_function(name, func, args);
}



<|start_filename|>rice/detail/demangle.hpp<|end_filename|>
#ifndef Rice__detail__demangle__hpp_
#define Rice__detail__demangle__hpp_

#include <string>

namespace Rice
{

namespace detail
{

std::string demangle(char const * mangled_name);
std::string demangle(std::string const & mangled_name);

} // detail

} // Rice

#endif // Rice__detail__demangle__hpp_


<|start_filename|>rice/Critical_Guard.ipp<|end_filename|>
#ifndef Rice__ruby_Critical_Guard__ipp_
#define Rice__ruby_Critical_Guard__ipp_

#include "detail/ruby_version_code.hpp"

#if RICE__RUBY_VERSION_CODE < 190

#include "detail/ruby.hpp"
#include "detail/rubysig.hpp"

inline Rice::Critical_Guard::
Critical_Guard()
{
  rb_thread_critical = 1;
}

inline Rice::Critical_Guard::
~Critical_Guard()
{
  rb_thread_critical = 0;
}

#endif

#endif // Rice__ruby_Critical_Guard__ipp_



<|start_filename|>rice/ruby_try_catch.hpp<|end_filename|>
#ifndef Rice__ruby_try_catch__hpp_
#define Rice__ruby_try_catch__hpp_

#include "Exception_Base_defn.hpp"
#include "Jump_Tag.hpp"
#include "detail/ruby.hpp"
#include <stdexcept>

/*! \def RUBY_TRY
 *  \brief Start a block to catch Ruby exceptions and rethrow them.
 */
// Goto is used here to avoid having to use a second try/catch block (we
// can't rb_exc_raise directly out of the catch blocks below, since the
// exceptions will not get properly cleaned up).
// The labels are located before the try and not after it so the function can't
// "fall through" into the exception-handling code accidentally.
#define RUBY_TRY \
  VALUE Rice__ruby_exc = Qnil; \
  int Rice__ruby_jump_tag = 0; \
  \
  goto start_of_RUBY_TRY; \
  \
  Rice__ruby_exception: \
    rb_exc_raise(Rice__ruby_exc); \
  Rice__ruby_jump_tag: \
    rb_jump_tag(Rice__ruby_jump_tag); \
  \
  start_of_RUBY_TRY: \
  try

/*! \def RUBY_RETHROW(ex)
 *  \brief Given a Ruby exception as a VALUE, safely raise the exception as a
 *         Ruby exception.  This should be used inside a RUBY_TRY/RUBY_CATCH
 *         block.
 */
#define RUBY_RETHROW(ex) \
  Rice__ruby_exc = ex; \
  goto Rice__ruby_exception;

/*! \def RUBY_CATCH
 *  \brief End a RUBY_TRY block.
 */
#define RUBY_CATCH \
  catch(::Rice::Exception_Base const & ex) \
  { \
    RUBY_RETHROW(ex.value()); \
  } \
  catch(::Rice::Jump_Tag const & ex) \
  { \
    Rice__ruby_jump_tag = ex.tag; \
    goto Rice__ruby_jump_tag; \
  } \
  catch(std::bad_alloc const & ex) \
  { \
    /* This won't work quite right if the rb_exc_new2 fails; not    */ \
    /* much we can do about that, since Ruby doesn't give us access */ \
    /* to a pre-allocated NoMemoryError object                      */ \
    RUBY_RETHROW(rb_exc_new2(rb_eNoMemError, ex.what())); \
  } \
  catch(std::invalid_argument const & ex) \
  { \
    /* This can raise a NoMemoryError in VERY rare circumstances    */ \
    RUBY_RETHROW(rb_exc_new2(rb_eArgError, ex.what())); \
  } \
  catch(std::domain_error const & ex) \
  { \
    /* This can raise a NoMemoryError in VERY rare circumstances    */ \
    RUBY_RETHROW(rb_exc_new2(rb_eFloatDomainError, ex.what())); \
  } \
  catch(std::out_of_range const & ex) \
  { \
    /* This can raise a NoMemoryError in VERY rare circumstances    */ \
    RUBY_RETHROW(rb_exc_new2(rb_eRangeError, ex.what())); \
  } \
  catch(std::exception const & ex) \
  { \
    /* This can raise a NoMemoryError in VERY rare circumstances    */ \
    RUBY_RETHROW(rb_exc_new2(rb_eRuntimeError, ex.what())); \
  } \
  catch(...) \
  { \
    RUBY_RETHROW(rb_exc_new2(rb_eRuntimeError, "unknown C++ exception thrown")); \
  } \

#endif // Rice__ruby_try_catch__hpp_



<|start_filename|>rice/detail/creation_funcs.hpp<|end_filename|>
#ifndef Rice__detail__creation_funcs__hpp_
#define Rice__detail__creation_funcs__hpp_

namespace Rice
{

class Class;

namespace detail
{

//! Like define_alloc_func, but allows the user to define an
//! "initialize" method too.
template<typename Initialize_Func_T>
void define_creation_funcs(
    Class const & klass,
    RUBY_VALUE_FUNC allocate_func,
    Initialize_Func_T initialize_func);

//! This is just the opposite of define_alloc_func.  It can be
//! used to create a class that cannot be instantiated by the user.
void undef_alloc_func(
    Class const & klass);

//! This is just the opposite of define_creation_func.  It can be
//! used to create a class that cannot be instantiated by the user.
void undef_creation_funcs(
    Class const & klass);

} // namespace detail

} // namespace Rice

#include "creation_funcs.ipp"

#endif // Rice__detail__creation_funcs__hpp_



<|start_filename|>sample/enum/sample_enum.cpp<|end_filename|>
#include "rice/Enum.hpp"
#include "rice/ruby_try_catch.hpp"

using namespace Rice;

namespace
{

enum Sample_Enum
{
  SE_FOO = 1,
  SE_BAR = 42,
  SE_BAZ = 100,
};

Rice::Enum<Sample_Enum> sample_enum_type;

char const * description(Sample_Enum e)
{
  switch(e)
  {
    case SE_FOO: return "Fairly Ordinary Object";
    case SE_BAR: return "Beginner's All-purpose Ratchet";
    case SE_BAZ: return "Better than A Zebra";
  }
  return "???";
}

} // namespace

template<>
Sample_Enum from_ruby<Sample_Enum>(Object x)
{
  Data_Object<Sample_Enum> d(x, sample_enum_type);
  return *d;
}

extern "C"
void Init_sample_enum()
{
  RUBY_TRY
  {
    sample_enum_type =
      define_enum<Sample_Enum>("Sample_Enum")
      .define_value("FOO", SE_FOO)
      .define_value("BAR", SE_BAR)
      .define_value("BAZ", SE_BAZ);
     
    sample_enum_type
      .define_method("description", description);
  }
  RUBY_CATCH
}



<|start_filename|>rice/detail/method_data.cpp<|end_filename|>
#include "method_data.hpp"
#include "ruby.hpp"

// TODO: This is silly, autoconf...
#undef PACKAGE_NAME
#undef PACKAGE_STRING
#undef PACKAGE_TARNAME
#undef PACKAGE_VERSION
#include "../config.hpp"

#ifndef RUBY_VM
/* pre-YARV */
#include <node.h>
#include "env.hpp"
#endif

/* 1.8.6 compatibility */
#ifndef RCLASS_M_TBL
#define RCLASS_M_TBL(x) (RCLASS(x)->m_tbl)
#endif

namespace
{

VALUE DATA_MAGIC = rb_fix_new(0xDA7A);

} // namespace

#ifdef RUBY_VM

VALUE
Rice::detail::
method_data()
{
  ID id;
  VALUE origin;
  if (!rb_frame_method_id_and_class(&id, &origin))
  {
    rb_raise(
        rb_eRuntimeError,
        "Cannot get method id and class for function");
  }

  VALUE memo = rb_ivar_get(origin, 0);

  if(rb_type(memo) != T_ARRAY && RARRAY_PTR(memo)[0] != DATA_MAGIC)
  {
    /* This can happen for module functions that are created after
     * the stub function */
    rb_raise(
        rb_eRuntimeError,
        "Cannot find method data for module function");
  }

  return RARRAY_PTR(memo)[1];
}

#else

/* pre-YARV */

VALUE
Rice::detail::
method_data()
{
  VALUE origin = ruby_frame->last_class;
  VALUE memo = rb_ivar_get(origin, 0);
  return RARRAY_PTR(memo)[1];
}

#endif

// Define a method and attach data to it.
// The method looks to ruby like a normal aliased CFUNC, with a modified
// origin class.
//
// How this works:
//
// To store method data and have it registered with the GC, we need a
// "slot" to put it in.  This "slot" must be recognized and marked by
// the garbage collector.  There happens to be such a place we can put
// data, and it has to do with aliased methods.  When Ruby creates an
// alias for a method, it stores a reference to the original class in
// the method entry.  The form of the method entry differs from ruby
// version to ruby version, but the concept is the same across all of
// them.
// 
// In Rice, we make use of this by defining a method on a dummy class,
// then attaching that method to our real class.  The method is a real
// method in our class, but its origin class is our dummy class.
// 
// When Ruby makes a method call, it stores the origin class in the
// current stack frame.  When Ruby calls into Rice, we grab the origin
// class from the stack frame, then pull the data out of the origin
// class.  The data item is then used to determine how to convert
// arguments and return type, how to handle exceptions, etc.
//
// It used to be the case that Rice would "fix" the call frame so that
// the modified origin class was not visible to the called function (it
// would appear to the callee that the origin class was the same as the
// class it was defined on).  However, this required modifying the call
// frame directly, and the layout of that frame varies from version to
// version.  To keep things simple (and as a side effect improve
// performance), Rice no longer hides the modified origin class this way.
//
// Functions that make use of "last_class" (1.8) or
// "rb_frame_method_id_and_class" (1.9) will therefore not get the
// results they expect.
VALUE
Rice::detail::
define_method_with_data(
    VALUE klass, ID id, VALUE (*cfunc)(ANYARGS), int arity, VALUE data)
{
  VALUE origin = rb_class_boot(klass);

  // Create the memo object with a magic number so we can detect if
  // we're getting the origin class we expect (this can happen if the
  // module_function method is called on a Rice function on ruby 1.9).
  VALUE memo = rb_assoc_new(DATA_MAGIC, data);

  // Set the class name of our modified origin class to something
  // obvious in case someone tries to inspect it.
  VALUE real_class_name = rb_class_name(klass);
  VALUE origin_class_name = rb_str_plus(
      real_class_name,
      rb_str_new2("<data wrapper>"));

  // Create the modified origin class
  FL_SET(origin, FL_SINGLETON);
  rb_singleton_class_attached(origin, klass);
  rb_name_class(origin, SYM2ID(rb_str_intern(origin_class_name)));

  // Attach our "memo" to the origin class
  rb_ivar_set(origin, 0, memo);

  // Create the aliased method on the origin class
  rb_define_method(
      origin,
      rb_id2name(id),
      cfunc,
      arity);

  // Alias the method in the origin class so we can copy it to another
  // class with the origin class intact as part of the method entry
  rb_alias(
      origin,
      rb_intern("dummy"),
      id);

  // Copy the method entry to the real class
  st_data_t dummy_entry;
  st_lookup(RCLASS_M_TBL(origin), rb_intern("dummy"), &dummy_entry);
  st_insert(RCLASS_M_TBL(klass), id, dummy_entry);

  // Clear the table so we don't try to double-free the method entry
  RCLASS_M_TBL(origin) = st_init_numtable();

  return Qnil;
}


<|start_filename|>rice/to_from_ruby_defn.hpp<|end_filename|>
#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));
 *
 *    Data_Object<Foo> foo(new Foo);
 *    Foo * p_foo = foo.get();
 *    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_



<|start_filename|>rice/detail/Wrapped_Function.hpp<|end_filename|>
#ifndef Rice__detail__Wrapped_Function__hpp_
#define Rice__detail__Wrapped_Function__hpp_

#include "ruby.hpp"

namespace Rice
{

namespace detail
{

class Wrapped_Function
{
public:
  Wrapped_Function(RUBY_METHOD_FUNC func, int arity)
    : func_(func)
    , arity_(arity)
  {
  }

  RUBY_METHOD_FUNC func() const { return func_; }
  int arity() const { return arity_; }

private:
  RUBY_METHOD_FUNC func_;
  int arity_;
};

} // detail

} // Rice

#endif // Rice__detail__Wrapped_Function__hpp_


<|start_filename|>rice/detail/default_allocation_func.ipp<|end_filename|>
#include "../Data_Object.hpp"

template<typename T>
VALUE Rice::detail::
default_allocation_func(VALUE klass)
{
  Data_Object<T> m(static_cast<T*>(0), klass);
  return m.value();
} 




<|start_filename|>rice/detail/check_ruby_type.hpp<|end_filename|>
#ifndef Rice__detail__check_ruby_type__hpp_
#define Rice__detail__check_ruby_type__hpp_

#include "ruby.hpp"

namespace Rice
{

namespace detail
{

// Throws an exception if the given object is not of type klass.
void check_ruby_type(
    VALUE value,
    VALUE klass,
    bool include_super);

} // namespace detail

} // namespace Rice

#endif // Rice__detail__check_ruby_type__hpp_



<|start_filename|>rice/Module_impl.hpp<|end_filename|>
#ifndef Rice__Module_impl__hpp_
#define Rice__Module_impl__hpp_

#include "detail/Exception_Handler_defn.hpp"
#include "detail/ruby.hpp"
#include "Object_defn.hpp"
#include "Address_Registration_Guard_defn.hpp"
#include "Arg.hpp"

namespace Rice
{

class Module;
class Class;
template<typename T> class Data_Type;

/*! Holds all member data of Module_impl so it only exists in one place
 *  in the hierarchy.
 */
class Module_base
  : public Object
{
public:
  Module_base(VALUE v = rb_cObject);
  Module_base(Module_base const & other);

  Module_base & operator=(Module_base const & other);

  void swap(Module_base & other);

protected:
  template<typename Exception_T, typename Functor_T>
  void add_handler(Functor_T functor);

  Object handler() const;

private:
  Object mutable handler_;
  Address_Registration_Guard handler_guard_;
};

/*! An intermediate base class so we can always return the most-derived
 *  type (Module, Class, Data_Type, ...) without having to re-implement
 *  each function for each derived class.
 */
template<typename Base_T, typename Derived_T>
class Module_impl
  : public Base_T
{
public:
  Module_impl();

  template<typename T>
  Module_impl(T const & arg);

  //! Define an exception handler.
  /*! Whenever an exception of type Exception_T is thrown from a
   *  function defined on this class, functor will be called to
   *  translate the exception into a ruby exception.
   *  \param Exception_T a template parameter indicating the type of
   *  exception to be translated.
   *  \param functor a functor to be called to translate the exception
   *  into a ruby exception.  This functor should re-throw the exception
   *  as an Exception.
   *  Example:
   *  \code
   *    class MyException : public std::exception { };
   *    Data_Type<MyException> rb_cMyException;
   *    Class rb_cFoo;
   *
   *    void translate_my_exception(MyException const & ex)
   *    {
   *      Data_Object<MyException> ex_(
   *          new MyException(ex),
   *          rb_cMyException);
   *      throw Exception(ex_);
   *    }
   *
   *    extern "C"
   *    void Init_MyExtension()
   *    {
   *      rb_cMyException = define_class("MyException");
   *      rb_cFoo = define_class("Foo")
   *        .add_handler<MyException>(translate_my_exception);
   *    }
   *  \endcode
   */
  template<typename Exception_T, typename Functor_T>
  Derived_T & add_handler(
      Functor_T functor);

  //! Define an instance method.
  /*! The method's implementation can be any function or member
   *  function.  A wrapper will be generated which will use from_ruby<>
   *  to convert the arguments from ruby types to C++ types before
   *  calling the function.  The return value will be converted back to
   *  ruby by using to_ruby().
   *  \param name the name of the method
   *  \param func the implementation of the function, either a function
   *  pointer or a member function pointer.
   *  \param arguments the list of arguments of this function, used for
   *  defining default parameters (optional)
   *  \return *this
   */
  template<typename Func_T>
  Derived_T & define_method(
      Identifier name,
      Func_T func,
      Arguments* arguments = 0);

  // FIXME There's GOT to be a better way to
  // do this. Handles the case where there is a single
  // argument defined for this method
  template<typename Func_T>
  Derived_T & define_method(
      Identifier name,
      Func_T func,
      Arg const& arg);

  //! Define a singleton method.
  /*! The method's implementation can be any function or member
   *  function.  A wrapper will be generated which will use from_ruby<>
   *  to convert the arguments from ruby types to C++ types before
   *  calling the function.  The return value will be converted back to
   *  ruby by using to_ruby().
   *  \param name the name of the method
   *  \param func the implementation of the function, either a function
   *  pointer or a member function pointer.
   *  \param arguments the list of arguments of this function, used for
   *  defining default parameters (optional)
   *  \return *this
   */
  template<typename Func_T>
  Derived_T & define_singleton_method(
      Identifier name,
      Func_T func,
      Arguments* arguments = 0);

  // FIXME: See define_method with Arg above
  template<typename Func_T>
  Derived_T & define_singleton_method(
      Identifier name,
      Func_T func,
      Arg const& arg);

  //! Define a module function.
  /*! A module function is a function that can be accessed either as a
   *  singleton method or as an instance method.
   *  The method's implementation can be any function or member
   *  function.  A wrapper will be generated which will use from_ruby<>
   *  to convert the arguments from ruby types to C++ types before
   *  calling the function.  The return value will be converted back to
   *  ruby by using to_ruby().
   *  \param name the name of the method
   *  \param func the implementation of the function, either a function
   *  pointer or a member function pointer.
   *  \param arguments the list of arguments of this function, used for
   *  defining default parameters (optional)
   *  \return *this
   */
  template<typename Func_T>
  Derived_T & define_module_function(
      Identifier name,
      Func_T func,
      Arguments* arguments = 0);

  // FIXME: See define_method with Arg above
  template<typename Func_T>
  Derived_T & define_module_function(
      Identifier name,
      Func_T func,
      Arg const& arg);

  //! Define an iterator.
  /*! Essentially this is a conversion from a C++-style begin/end
   *  iterator to a Ruby-style \#each iterator.
   *  \param begin a member function pointer to a function that returns
   *  an iterator to the beginning of the sequence.
   *  \param end a member function pointer to a function that returns an
   *  iterator to the end of the sequence.
   *  \param name the name of the iterator.
   *  \return *this
   */
  template<typename T, typename Iterator_T>
  Derived_T & define_iterator(
      Iterator_T (T::*begin)(),
      Iterator_T (T::*end)(),
      Identifier name = "each");

  //! Include a module.
  /*! \param inc the module to be included.
   *  \return *this
   */
  Derived_T & include_module(
      Module const & inc);

  //! Set a constant.
  /*! \param name the name of the constant to set.
   *  \param value the value of the constant.
   *  \return *this
   */
  Derived_T & const_set(
      Identifier name,
      Object value);

  //! Get a constant.
  /*! \param name the name of the constant to get.
   *  \return the value of the constant.
   */
  Object const_get(
      Identifier name) const;

  //! Determine whether a constant is defined.
  /*! \param name the name of the constant to check.
   *  \return true if the constant is defined in this module or false
   *  otherwise.
   */
  bool const_defined(
      Identifier name) const;

  //! Remove a constant.
  /*! \param name the name of the constant to remove.
   */
  void remove_const(
      Identifier name);

  //! Define a module under this module.
  /*! \param name the name of the module.
   *  \return the new class.
   */
  Module define_module(
      char const * name);

  //! Define a class under this module.
  /*! \param name the name of the class.
   *  \param superclass the base class to use.
   *  \return the new class.
   */
  Class define_class(
      char const * name,
      Object superclass = rb_cObject);

  //! Define a new data class under this module.
  /*! The class will have a base class of Object.
   *  \param T the C++ type of the wrapped class.
   *  \return the new class.
   */
  // This function needs to be defined inline to work around a bug in
  // g++ 3.3.3.
  template<typename T>
  Data_Type<T>
  define_class(
      char const * name)
  {
    return this->define_class_with_object_as_base<T>(name);
  }

  //! Define a new data class under this module.
  /*! The class with have a base class determined by Base_T (specifically,
   *  Data_Type<Base_T>::klass).  Therefore, the type Base_T must already
   *  have been registered using define_class<> or define_class_under<>.
   *  \param T the C++ type of the wrapped class.
   *  \return the new class.
   */
  template<typename T, typename T_Base_T>
  Data_Type<T>
  define_class(
      char const * name);

private:
  // Workaround for g++ 3.3.3 (see above).
  template<typename T>
  Data_Type<T>
  define_class_with_object_as_base(
      char const * name);
};

} // namespace Rice

#endif // Rice__Module_impl__hpp_



<|start_filename|>rice/Data_Type.ipp<|end_filename|>
#ifndef Rice__Data_Type__ipp_
#define Rice__Data_Type__ipp_

#include "Class.hpp"
#include "String.hpp"
#include "Data_Object.hpp"
#include "detail/default_allocation_func.hpp"
#include "detail/creation_funcs.hpp"
#include "detail/method_data.hpp"
#include "detail/Caster.hpp"
#include "detail/demangle.hpp"

#include <stdexcept>
#include <typeinfo>

template<typename T>
VALUE Rice::Data_Type<T>::klass_ = Qnil;

template<typename T>
std::auto_ptr<Rice::detail::Abstract_Caster> Rice::Data_Type<T>::caster_;

template<typename T>
template<typename Base_T>
inline Rice::Data_Type<T> Rice::Data_Type<T>::
bind(Module const & klass)
{
  if(klass.value() == klass_)
  {
    return Data_Type<T>();
  }

  if(is_bound())
  {
    std::string s;
    s = "Data type ";
    s += detail::demangle(typeid(T).name());
    s += " is already bound to a different type";
    throw std::runtime_error(s.c_str());
  }

  // TODO: Make sure base type is bound; throw an exception otherwise.
  // We can't do this just yet, because we don't have a specialization
  // for binding to void.
  klass_ = klass;

  // TODO: do we need to unregister when the program exits?  we have to
  // be careful if we do, because the ruby interpreter might have
  // already shut down.  The correct behavior is probably to register an
  // exit proc with the interpreter, so the proc gets called before the
  // GC shuts down.
  rb_gc_register_address(&klass_);

  for(typename Instances::iterator it = unbound_instances().begin(),
      end = unbound_instances().end();
      it != end;
      unbound_instances().erase(it++))
  {
    (*it)->set_value(klass);
  }

  detail::Abstract_Caster * base_caster = Data_Type<Base_T>().caster();
  caster_.reset(new detail::Caster<T, Base_T>(base_caster, klass));
  Data_Type_Base::casters().insert(std::make_pair(klass, caster_.get()));
  return Data_Type<T>();
}

template<typename T>
inline Rice::Data_Type<T>::
Data_Type()
  : Module_impl<Data_Type_Base, Data_Type<T> >(
      klass_ == Qnil ? rb_cObject : klass_)
{
  if(!is_bound())
  {
    unbound_instances().insert(this);
  }
}

template<typename T>
inline Rice::Data_Type<T>::
Data_Type(Module const & klass)
  : Module_impl<Data_Type_Base, Data_Type<T> >(
      klass)
{
  this->bind<void>(klass);
}

template<typename T>
inline Rice::Data_Type<T>::
~Data_Type()
{
  unbound_instances().erase(this);
}

template<typename T>
Rice::Module
Rice::Data_Type<T>::
klass() {
  if(is_bound())
  {
    return klass_;
  }
  else
  {
    std::string s;
    s += detail::demangle(typeid(T *).name());
    s += " is unbound";
    throw std::runtime_error(s.c_str());
  }
}

template<typename T>
Rice::Data_Type<T> & Rice::Data_Type<T>::
operator=(Module const & klass)
{
  this->bind<void>(klass);
  return *this;
}

template<typename T>
template<typename Constructor_T>
inline Rice::Data_Type<T> & Rice::Data_Type<T>::
define_constructor(
    Constructor_T /* constructor */,
    Arguments* arguments)
{
  check_is_bound();

  // Normal constructor pattern with new/initialize
  rb_define_alloc_func(
      static_cast<VALUE>(*this),
      detail::default_allocation_func<T>);
  this->define_method(
      "initialize",
      &Constructor_T::construct,
      arguments
      );

  return *this;
}

template<typename T>
template<typename Constructor_T>
inline Rice::Data_Type<T> & Rice::Data_Type<T>::
define_constructor(
    Constructor_T constructor,
    Arg const& arg)
{
  Arguments* args = new Arguments();
  args->add(arg);
  return define_constructor(constructor, args);
}


template<typename T>
template<typename Director_T>
inline Rice::Data_Type<T>& Rice::Data_Type<T>::
define_director()
{
  Rice::Data_Type<Director_T>::template bind<T>(*this);
  return *this;
}

template<typename T>
inline T * Rice::Data_Type<T>::
from_ruby(Object x)
{
  check_is_bound();

  void * v = DATA_PTR(x.value());
  Class klass = x.class_of();

  if(klass.value() == klass_)
  {
    // Great, not converting to a base/derived type
    Data_Type<T> data_klass;
    Data_Object<T> obj(x, data_klass);
    return obj.get();
  }

  Data_Type_Base::Casters::const_iterator it = Data_Type_Base::casters().begin();
  Data_Type_Base::Casters::const_iterator end = Data_Type_Base::casters().end();
   
  // Finding the bound type that relates to the given klass is
  // a two step process. We iterate over the list of known type casters,
  // looking for:
  //
  // 1) casters that handle this direct type
  // 2) casters that handle types that are ancestors of klass
  //
  // Step 2 allows us to handle the case where a Rice-wrapped class
  // is subclassed in Ruby but then an instance of that class is passed
  // back into C++ (say, in a Listener / callback construction)
  //

  VALUE ancestors = rb_mod_ancestors(klass.value());

  long earliest = RARRAY_LEN(ancestors) + 1;

  int index;
  VALUE indexFound;
  Data_Type_Base::Casters::const_iterator toUse = end;

  for(; it != end; it++) {
    // Do we match directly?
    if(klass.value() == it->first) {
      toUse = it;
      break;
    }

    // Check for ancestors. Trick is, we need to find the lowest
    // ancestor that does have a Caster to make sure that we're casting
    // to the closest C++ type that the Ruby class is subclassing. 
    // There might be multiple ancestors that are also wrapped in
    // the extension, so find the earliest in the list and use that one.
    indexFound = rb_funcall(ancestors, rb_intern("index"), 1, it->first);

    if(indexFound != Qnil) {
      index = NUM2INT(indexFound);

      if(index < earliest) {
        earliest = index;
        toUse = it;
      }
    }
  }
  
  if(toUse == end)
  {
    std::string s = "Class ";
    s += klass.name().str();
    s += " is not registered/bound in Rice";
    throw std::runtime_error(s);
  }

  detail::Abstract_Caster * caster = toUse->second;
  if(caster)
  {
    T * result = static_cast<T *>(caster->cast_to_base(v, klass_));
    return result;
  }
  else
  {
    return static_cast<T *>(v);
  }
}

template<typename T>
inline bool Rice::Data_Type<T>::
is_bound()
{
  return klass_ != Qnil;
}

template<typename T>
inline Rice::detail::Abstract_Caster * Rice::Data_Type<T>::
caster() const
{
  check_is_bound();
  return caster_.get();
}

namespace Rice
{

template<>
inline detail::Abstract_Caster * Data_Type<void>::
caster() const
{
  return 0;
}

template<typename T>
void Data_Type<T>::
check_is_bound()
{
  if(!is_bound())
  {
    std::string s;
    s = "Data type ";
    s += detail::demangle(typeid(T).name());
    s += " is not bound";
    throw std::runtime_error(s.c_str());
  }
}

} // Rice

template<typename T>
inline Rice::Data_Type<T> Rice::
define_class_under(
    Object module,
    char const * name)
{
  Class c(define_class_under(module, name, rb_cObject));
  c.undef_creation_funcs();
  return Data_Type<T>::template bind<void>(c);
}

template<typename T, typename Base_T>
inline Rice::Data_Type<T> Rice::
define_class_under(
    Object module,
    char const * name)
{
  Data_Type<Base_T> base_dt;
  Class c(define_class_under(module, name, base_dt));
  c.undef_creation_funcs();
  return Data_Type<T>::template bind<Base_T>(c);
}

template<typename T>
inline Rice::Data_Type<T> Rice::
define_class(
    char const * name)
{
  Class c(define_class(name, rb_cObject));
  c.undef_creation_funcs();
  return Data_Type<T>::template bind<void>(c);
}

template<typename T, typename Base_T>
inline Rice::Data_Type<T> Rice::
define_class(
    char const * name)
{
  Data_Type<Base_T> base_dt;
  Class c(define_class(name, base_dt));
  c.undef_creation_funcs();
  return Data_Type<T>::template bind<Base_T>(c);
}

template<typename From_T, typename To_T>
inline void 
Rice::define_implicit_cast()
{
  // As Rice currently expects only one entry into
  // this list for a given klass VALUE, we need to get
  // the current caster for From_T and insert in our
  // new caster as the head of the caster list

  Class from_class = Data_Type<From_T>::klass().value();
  Class to_class = Data_Type<To_T>::klass().value();

  detail::Abstract_Caster* from_caster = 
    Data_Type<From_T>::caster_.release();

  detail::Abstract_Caster* new_caster = 
    new detail::Implicit_Caster<To_T, From_T>(from_caster, to_class);

  // Insert our new caster into the list for the from class
  Data_Type_Base::casters().erase(from_class);
  Data_Type_Base::casters().insert(
    std::make_pair(
      from_class,
      new_caster
    )
  );

  // And make sure the from_class has direct access to the
  // updated caster list
  Data_Type<From_T>::caster_.reset(new_caster);
}

#endif // Rice__Data_Type__ipp_


<|start_filename|>test/ext/t1/t1.cpp<|end_filename|>
#include "Foo.hpp"

#include "rice/Data_Type.hpp"
#include "rice/Constructor.hpp"

using namespace Rice;

extern "C"
void Init_t1()
{
  define_class<Foo>("Foo")
    .define_constructor(Constructor<Foo>())
    .define_method("foo", &Foo::foo);
}



<|start_filename|>rice/detail/object_call.ipp<|end_filename|>
// This is a generated file.  DO NOT EDIT!!
#include "../protect.hpp"
#include "../to_from_ruby.hpp"

inline Rice::Object Rice::Object::
call(Identifier id) const
{
  VALUE args[] = {  };
  return protect(rb_funcall2, value(), id, 0, args);
}

template<typename T0>
inline Rice::Object Rice::Object::
call(Identifier id, T0 arg0) const
{
  VALUE args[] = { to_ruby(arg0) };
  return protect(rb_funcall2, value(), id, 1, args);
}

template<typename T0, typename T1>
inline Rice::Object Rice::Object::
call(Identifier id, T0 arg0, T1 arg1) const
{
  VALUE args[] = { to_ruby(arg0), to_ruby(arg1) };
  return protect(rb_funcall2, value(), id, 2, args);
}

template<typename T0, typename T1, typename T2>
inline Rice::Object Rice::Object::
call(Identifier id, T0 arg0, T1 arg1, T2 arg2) const
{
  VALUE args[] = { to_ruby(arg0), to_ruby(arg1), to_ruby(arg2) };
  return protect(rb_funcall2, value(), id, 3, args);
}

template<typename T0, typename T1, typename T2, typename T3>
inline Rice::Object Rice::Object::
call(Identifier id, T0 arg0, T1 arg1, T2 arg2, T3 arg3) const
{
  VALUE args[] = { to_ruby(arg0), to_ruby(arg1), to_ruby(arg2), to_ruby(arg3) };
  return protect(rb_funcall2, value(), id, 4, args);
}

template<typename T0, typename T1, typename T2, typename T3, typename T4>
inline Rice::Object Rice::Object::
call(Identifier id, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) const
{
  VALUE args[] = { to_ruby(arg0), to_ruby(arg1), to_ruby(arg2), to_ruby(arg3), to_ruby(arg4) };
  return protect(rb_funcall2, value(), id, 5, args);
}

template<typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
inline Rice::Object Rice::Object::
call(Identifier id, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) const
{
  VALUE args[] = { to_ruby(arg0), to_ruby(arg1), to_ruby(arg2), to_ruby(arg3), to_ruby(arg4), to_ruby(arg5) };
  return protect(rb_funcall2, value(), id, 6, args);
}

template<typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
inline Rice::Object Rice::Object::
call(Identifier id, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) const
{
  VALUE args[] = { to_ruby(arg0), to_ruby(arg1), to_ruby(arg2), to_ruby(arg3), to_ruby(arg4), to_ruby(arg5), to_ruby(arg6) };
  return protect(rb_funcall2, value(), id, 7, args);
}

template<typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
inline Rice::Object Rice::Object::
call(Identifier id, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) const
{
  VALUE args[] = { to_ruby(arg0), to_ruby(arg1), to_ruby(arg2), to_ruby(arg3), to_ruby(arg4), to_ruby(arg5), to_ruby(arg6), to_ruby(arg7) };
  return protect(rb_funcall2, value(), id, 8, args);
}

template<typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
inline Rice::Object Rice::Object::
call(Identifier id, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) const
{
  VALUE args[] = { to_ruby(arg0), to_ruby(arg1), to_ruby(arg2), to_ruby(arg3), to_ruby(arg4), to_ruby(arg5), to_ruby(arg6), to_ruby(arg7), to_ruby(arg8) };
  return protect(rb_funcall2, value(), id, 9, args);
}

template<typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
inline Rice::Object Rice::Object::
call(Identifier id, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) const
{
  VALUE args[] = { to_ruby(arg0), to_ruby(arg1), to_ruby(arg2), to_ruby(arg3), to_ruby(arg4), to_ruby(arg5), to_ruby(arg6), to_ruby(arg7), to_ruby(arg8), to_ruby(arg9) };
  return protect(rb_funcall2, value(), id, 10, args);
}

template<typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10>
inline Rice::Object Rice::Object::
call(Identifier id, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10) const
{
  VALUE args[] = { to_ruby(arg0), to_ruby(arg1), to_ruby(arg2), to_ruby(arg3), to_ruby(arg4), to_ruby(arg5), to_ruby(arg6), to_ruby(arg7), to_ruby(arg8), to_ruby(arg9), to_ruby(arg10) };
  return protect(rb_funcall2, value(), id, 11, args);
}

template<typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11>
inline Rice::Object Rice::Object::
call(Identifier id, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11) const
{
  VALUE args[] = { to_ruby(arg0), to_ruby(arg1), to_ruby(arg2), to_ruby(arg3), to_ruby(arg4), to_ruby(arg5), to_ruby(arg6), to_ruby(arg7), to_ruby(arg8), to_ruby(arg9), to_ruby(arg10), to_ruby(arg11) };
  return protect(rb_funcall2, value(), id, 12, args);
}

template<typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12>
inline Rice::Object Rice::Object::
call(Identifier id, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12) const
{
  VALUE args[] = { to_ruby(arg0), to_ruby(arg1), to_ruby(arg2), to_ruby(arg3), to_ruby(arg4), to_ruby(arg5), to_ruby(arg6), to_ruby(arg7), to_ruby(arg8), to_ruby(arg9), to_ruby(arg10), to_ruby(arg11), to_ruby(arg12) };
  return protect(rb_funcall2, value(), id, 13, args);
}

template<typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13>
inline Rice::Object Rice::Object::
call(Identifier id, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13) const
{
  VALUE args[] = { to_ruby(arg0), to_ruby(arg1), to_ruby(arg2), to_ruby(arg3), to_ruby(arg4), to_ruby(arg5), to_ruby(arg6), to_ruby(arg7), to_ruby(arg8), to_ruby(arg9), to_ruby(arg10), to_ruby(arg11), to_ruby(arg12), to_ruby(arg13) };
  return protect(rb_funcall2, value(), id, 14, args);
}

template<typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, typename T14>
inline Rice::Object Rice::Object::
call(Identifier id, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14) const
{
  VALUE args[] = { to_ruby(arg0), to_ruby(arg1), to_ruby(arg2), to_ruby(arg3), to_ruby(arg4), to_ruby(arg5), to_ruby(arg6), to_ruby(arg7), to_ruby(arg8), to_ruby(arg9), to_ruby(arg10), to_ruby(arg11), to_ruby(arg12), to_ruby(arg13), to_ruby(arg14) };
  return protect(rb_funcall2, value(), id, 15, args);
}



<|start_filename|>rice/Module.hpp<|end_filename|>
#ifndef Rice__builtin__Module__hpp_
#define Rice__builtin__Module__hpp_

#include "Module_defn.hpp"
#include "Module.ipp"

#endif // Rice__builtin__Module__hpp_



<|start_filename|>rice/detail/wrap_function.ipp<|end_filename|>
#ifndef Rice__detail__wrap_function__ipp_
#define Rice__detail__wrap_function__ipp_

// This is a generated file.  DO NOT EDIT!!


// This causes problems with certain C++ libraries
#undef TYPE

#include "Auto_Function_Wrapper.hpp"
#include "Auto_Member_Function_Wrapper.hpp"
namespace Rice
{

namespace detail
{

template<typename Ret_T>
Wrapped_Function * wrap_function(
    Ret_T (*func)(),
    Data_Object<Exception_Handler> handler,
    Arguments* arguments)
{
  typedef Ret_T (*Func)();
  return new Auto_Function_Wrapper<Func, Ret_T>(func, handler, arguments);
}

template<typename Ret_T, typename Arg0_T>
Wrapped_Function * wrap_function(
    Ret_T (*func)(Arg0_T),
    Data_Object<Exception_Handler> handler,
    Arguments* arguments)
{
  typedef Ret_T (*Func)(Arg0_T);
  return new Auto_Function_Wrapper<Func, Ret_T, Arg0_T>(func, handler, arguments);
}

template<typename Ret_T, typename Self_T>
Wrapped_Function * wrap_function(
    Ret_T (Self_T::*func)(),
    Data_Object<Exception_Handler> handler,
    Arguments* arguments)
{
  typedef Ret_T (Self_T::*Func)();
  return new Auto_Member_Function_Wrapper<Func, Ret_T, Self_T>(func, handler, arguments);
}

template<typename Ret_T, typename Self_T>
Wrapped_Function * wrap_function(
    Ret_T (Self_T::*func)() const,
    Data_Object<Exception_Handler> handler,
    Arguments* arguments)
{
  typedef Ret_T (Self_T::*Func)() const;
  return new Auto_Member_Function_Wrapper<Func, Ret_T, Self_T>(func, handler, arguments);
}

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

template<typename Ret_T, typename Arg0_T, typename Arg1_T>
Wrapped_Function * wrap_function(
    Ret_T (*func)(Arg0_T, Arg1_T),
    Data_Object<Exception_Handler> handler,
    Arguments* arguments)
{
  typedef Ret_T (*Func)(Arg0_T, Arg1_T);
  return new Auto_Function_Wrapper<Func, Ret_T, Arg0_T, Arg1_T>(func, handler, arguments);
}

template<typename Ret_T, typename Self_T, typename Arg0_T>
Wrapped_Function * wrap_function(
    Ret_T (Self_T::*func)(Arg0_T),
    Data_Object<Exception_Handler> handler,
    Arguments* arguments)
{
  typedef Ret_T (Self_T::*Func)(Arg0_T);
  return new Auto_Member_Function_Wrapper<Func, Ret_T, Self_T, Arg0_T>(func, handler, arguments);
}

template<typename Ret_T, typename Self_T, typename Arg0_T>
Wrapped_Function * wrap_function(
    Ret_T (Self_T::*func)(Arg0_T) const,
    Data_Object<Exception_Handler> handler,
    Arguments* arguments)
{
  typedef Ret_T (Self_T::*Func)(Arg0_T) const;
  return new Auto_Member_Function_Wrapper<Func, Ret_T, Self_T, Arg0_T>(func, handler, arguments);
}

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

template<typename Ret_T, typename Arg0_T, typename Arg1_T, typename Arg2_T>
Wrapped_Function * wrap_function(
    Ret_T (*func)(Arg0_T, Arg1_T, Arg2_T),
    Data_Object<Exception_Handler> handler,
    Arguments* arguments)
{
  typedef Ret_T (*Func)(Arg0_T, Arg1_T, Arg2_T);
  return new Auto_Function_Wrapper<Func, Ret_T, Arg0_T, Arg1_T, Arg2_T>(func, handler, arguments);
}

template<typename Ret_T, typename Self_T, typename Arg0_T, typename Arg1_T>
Wrapped_Function * wrap_function(
    Ret_T (Self_T::*func)(Arg0_T, Arg1_T),
    Data_Object<Exception_Handler> handler,
    Arguments* arguments)
{
  typedef Ret_T (Self_T::*Func)(Arg0_T, Arg1_T);
  return new Auto_Member_Function_Wrapper<Func, Ret_T, Self_T, Arg0_T, Arg1_T>(func, handler, arguments);
}

template<typename Ret_T, typename Self_T, typename Arg0_T, typename Arg1_T>
Wrapped_Function * wrap_function(
    Ret_T (Self_T::*func)(Arg0_T, Arg1_T) const,
    Data_Object<Exception_Handler> handler,
    Arguments* arguments)
{
  typedef Ret_T (Self_T::*Func)(Arg0_T, Arg1_T) const;
  return new Auto_Member_Function_Wrapper<Func, Ret_T, Self_T, Arg0_T, Arg1_T>(func, handler, arguments);
}

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

template<typename Ret_T, typename Arg0_T, typename Arg1_T, typename Arg2_T, typename Arg3_T>
Wrapped_Function * wrap_function(
    Ret_T (*func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T),
    Data_Object<Exception_Handler> handler,
    Arguments* arguments)
{
  typedef Ret_T (*Func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T);
  return new Auto_Function_Wrapper<Func, Ret_T, Arg0_T, Arg1_T, Arg2_T, Arg3_T>(func, handler, arguments);
}

template<typename Ret_T, typename Self_T, typename Arg0_T, typename Arg1_T, typename Arg2_T>
Wrapped_Function * wrap_function(
    Ret_T (Self_T::*func)(Arg0_T, Arg1_T, Arg2_T),
    Data_Object<Exception_Handler> handler,
    Arguments* arguments)
{
  typedef Ret_T (Self_T::*Func)(Arg0_T, Arg1_T, Arg2_T);
  return new Auto_Member_Function_Wrapper<Func, Ret_T, Self_T, Arg0_T, Arg1_T, Arg2_T>(func, handler, arguments);
}

template<typename Ret_T, typename Self_T, typename Arg0_T, typename Arg1_T, typename Arg2_T>
Wrapped_Function * wrap_function(
    Ret_T (Self_T::*func)(Arg0_T, Arg1_T, Arg2_T) const,
    Data_Object<Exception_Handler> handler,
    Arguments* arguments)
{
  typedef Ret_T (Self_T::*Func)(Arg0_T, Arg1_T, Arg2_T) const;
  return new Auto_Member_Function_Wrapper<Func, Ret_T, Self_T, Arg0_T, Arg1_T, Arg2_T>(func, handler, arguments);
}

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

template<typename Ret_T, typename Arg0_T, typename Arg1_T, typename Arg2_T, typename Arg3_T, typename Arg4_T>
Wrapped_Function * wrap_function(
    Ret_T (*func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T),
    Data_Object<Exception_Handler> handler,
    Arguments* arguments)
{
  typedef Ret_T (*Func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T);
  return new Auto_Function_Wrapper<Func, Ret_T, Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T>(func, handler, arguments);
}

template<typename Ret_T, typename Self_T, typename Arg0_T, typename Arg1_T, typename Arg2_T, typename Arg3_T>
Wrapped_Function * wrap_function(
    Ret_T (Self_T::*func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T),
    Data_Object<Exception_Handler> handler,
    Arguments* arguments)
{
  typedef Ret_T (Self_T::*Func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T);
  return new Auto_Member_Function_Wrapper<Func, Ret_T, Self_T, Arg0_T, Arg1_T, Arg2_T, Arg3_T>(func, handler, arguments);
}

template<typename Ret_T, typename Self_T, typename Arg0_T, typename Arg1_T, typename Arg2_T, typename Arg3_T>
Wrapped_Function * wrap_function(
    Ret_T (Self_T::*func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T) const,
    Data_Object<Exception_Handler> handler,
    Arguments* arguments)
{
  typedef Ret_T (Self_T::*Func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T) const;
  return new Auto_Member_Function_Wrapper<Func, Ret_T, Self_T, Arg0_T, Arg1_T, Arg2_T, Arg3_T>(func, handler, arguments);
}

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

template<typename Ret_T, typename Arg0_T, typename Arg1_T, typename Arg2_T, typename Arg3_T, typename Arg4_T, typename Arg5_T>
Wrapped_Function * wrap_function(
    Ret_T (*func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T),
    Data_Object<Exception_Handler> handler,
    Arguments* arguments)
{
  typedef Ret_T (*Func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T);
  return new Auto_Function_Wrapper<Func, Ret_T, Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T>(func, handler, arguments);
}

template<typename Ret_T, typename Self_T, typename Arg0_T, typename Arg1_T, typename Arg2_T, typename Arg3_T, typename Arg4_T>
Wrapped_Function * wrap_function(
    Ret_T (Self_T::*func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T),
    Data_Object<Exception_Handler> handler,
    Arguments* arguments)
{
  typedef Ret_T (Self_T::*Func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T);
  return new Auto_Member_Function_Wrapper<Func, Ret_T, Self_T, Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T>(func, handler, arguments);
}

template<typename Ret_T, typename Self_T, typename Arg0_T, typename Arg1_T, typename Arg2_T, typename Arg3_T, typename Arg4_T>
Wrapped_Function * wrap_function(
    Ret_T (Self_T::*func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T) const,
    Data_Object<Exception_Handler> handler,
    Arguments* arguments)
{
  typedef Ret_T (Self_T::*Func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T) const;
  return new Auto_Member_Function_Wrapper<Func, Ret_T, Self_T, Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T>(func, handler, arguments);
}

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

template<typename Ret_T, typename Arg0_T, typename Arg1_T, typename Arg2_T, typename Arg3_T, typename Arg4_T, typename Arg5_T, typename Arg6_T>
Wrapped_Function * wrap_function(
    Ret_T (*func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T),
    Data_Object<Exception_Handler> handler,
    Arguments* arguments)
{
  typedef Ret_T (*Func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T);
  return new Auto_Function_Wrapper<Func, Ret_T, Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T>(func, handler, arguments);
}

template<typename Ret_T, typename Self_T, typename Arg0_T, typename Arg1_T, typename Arg2_T, typename Arg3_T, typename Arg4_T, typename Arg5_T>
Wrapped_Function * wrap_function(
    Ret_T (Self_T::*func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T),
    Data_Object<Exception_Handler> handler,
    Arguments* arguments)
{
  typedef Ret_T (Self_T::*Func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T);
  return new Auto_Member_Function_Wrapper<Func, Ret_T, Self_T, Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T>(func, handler, arguments);
}

template<typename Ret_T, typename Self_T, typename Arg0_T, typename Arg1_T, typename Arg2_T, typename Arg3_T, typename Arg4_T, typename Arg5_T>
Wrapped_Function * wrap_function(
    Ret_T (Self_T::*func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T) const,
    Data_Object<Exception_Handler> handler,
    Arguments* arguments)
{
  typedef Ret_T (Self_T::*Func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T) const;
  return new Auto_Member_Function_Wrapper<Func, Ret_T, Self_T, Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T>(func, handler, arguments);
}

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

template<typename Ret_T, typename Arg0_T, typename Arg1_T, typename Arg2_T, typename Arg3_T, typename Arg4_T, typename Arg5_T, typename Arg6_T, typename Arg7_T>
Wrapped_Function * wrap_function(
    Ret_T (*func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T),
    Data_Object<Exception_Handler> handler,
    Arguments* arguments)
{
  typedef Ret_T (*Func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T);
  return new Auto_Function_Wrapper<Func, Ret_T, Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T>(func, handler, arguments);
}

template<typename Ret_T, typename Self_T, typename Arg0_T, typename Arg1_T, typename Arg2_T, typename Arg3_T, typename Arg4_T, typename Arg5_T, typename Arg6_T>
Wrapped_Function * wrap_function(
    Ret_T (Self_T::*func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T),
    Data_Object<Exception_Handler> handler,
    Arguments* arguments)
{
  typedef Ret_T (Self_T::*Func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T);
  return new Auto_Member_Function_Wrapper<Func, Ret_T, Self_T, Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T>(func, handler, arguments);
}

template<typename Ret_T, typename Self_T, typename Arg0_T, typename Arg1_T, typename Arg2_T, typename Arg3_T, typename Arg4_T, typename Arg5_T, typename Arg6_T>
Wrapped_Function * wrap_function(
    Ret_T (Self_T::*func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T) const,
    Data_Object<Exception_Handler> handler,
    Arguments* arguments)
{
  typedef Ret_T (Self_T::*Func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T) const;
  return new Auto_Member_Function_Wrapper<Func, Ret_T, Self_T, Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T>(func, handler, arguments);
}

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

template<typename Ret_T, typename Arg0_T, typename Arg1_T, typename Arg2_T, typename Arg3_T, typename Arg4_T, typename Arg5_T, typename Arg6_T, typename Arg7_T, typename Arg8_T>
Wrapped_Function * wrap_function(
    Ret_T (*func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T),
    Data_Object<Exception_Handler> handler,
    Arguments* arguments)
{
  typedef Ret_T (*Func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T);
  return new Auto_Function_Wrapper<Func, Ret_T, Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T>(func, handler, arguments);
}

template<typename Ret_T, typename Self_T, typename Arg0_T, typename Arg1_T, typename Arg2_T, typename Arg3_T, typename Arg4_T, typename Arg5_T, typename Arg6_T, typename Arg7_T>
Wrapped_Function * wrap_function(
    Ret_T (Self_T::*func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T),
    Data_Object<Exception_Handler> handler,
    Arguments* arguments)
{
  typedef Ret_T (Self_T::*Func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T);
  return new Auto_Member_Function_Wrapper<Func, Ret_T, Self_T, Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T>(func, handler, arguments);
}

template<typename Ret_T, typename Self_T, typename Arg0_T, typename Arg1_T, typename Arg2_T, typename Arg3_T, typename Arg4_T, typename Arg5_T, typename Arg6_T, typename Arg7_T>
Wrapped_Function * wrap_function(
    Ret_T (Self_T::*func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T) const,
    Data_Object<Exception_Handler> handler,
    Arguments* arguments)
{
  typedef Ret_T (Self_T::*Func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T) const;
  return new Auto_Member_Function_Wrapper<Func, Ret_T, Self_T, Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T>(func, handler, arguments);
}

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

template<typename Ret_T, typename Arg0_T, typename Arg1_T, typename Arg2_T, typename Arg3_T, typename Arg4_T, typename Arg5_T, typename Arg6_T, typename Arg7_T, typename Arg8_T, typename Arg9_T>
Wrapped_Function * wrap_function(
    Ret_T (*func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T, Arg9_T),
    Data_Object<Exception_Handler> handler,
    Arguments* arguments)
{
  typedef Ret_T (*Func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T, Arg9_T);
  return new Auto_Function_Wrapper<Func, Ret_T, Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T, Arg9_T>(func, handler, arguments);
}

template<typename Ret_T, typename Self_T, typename Arg0_T, typename Arg1_T, typename Arg2_T, typename Arg3_T, typename Arg4_T, typename Arg5_T, typename Arg6_T, typename Arg7_T, typename Arg8_T>
Wrapped_Function * wrap_function(
    Ret_T (Self_T::*func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T),
    Data_Object<Exception_Handler> handler,
    Arguments* arguments)
{
  typedef Ret_T (Self_T::*Func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T);
  return new Auto_Member_Function_Wrapper<Func, Ret_T, Self_T, Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T>(func, handler, arguments);
}

template<typename Ret_T, typename Self_T, typename Arg0_T, typename Arg1_T, typename Arg2_T, typename Arg3_T, typename Arg4_T, typename Arg5_T, typename Arg6_T, typename Arg7_T, typename Arg8_T>
Wrapped_Function * wrap_function(
    Ret_T (Self_T::*func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T) const,
    Data_Object<Exception_Handler> handler,
    Arguments* arguments)
{
  typedef Ret_T (Self_T::*Func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T) const;
  return new Auto_Member_Function_Wrapper<Func, Ret_T, Self_T, Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T>(func, handler, arguments);
}

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

template<typename Ret_T, typename Arg0_T, typename Arg1_T, typename Arg2_T, typename Arg3_T, typename Arg4_T, typename Arg5_T, typename Arg6_T, typename Arg7_T, typename Arg8_T, typename Arg9_T, typename Arg10_T>
Wrapped_Function * wrap_function(
    Ret_T (*func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T, Arg9_T, Arg10_T),
    Data_Object<Exception_Handler> handler,
    Arguments* arguments)
{
  typedef Ret_T (*Func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T, Arg9_T, Arg10_T);
  return new Auto_Function_Wrapper<Func, Ret_T, Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T, Arg9_T, Arg10_T>(func, handler, arguments);
}

template<typename Ret_T, typename Self_T, typename Arg0_T, typename Arg1_T, typename Arg2_T, typename Arg3_T, typename Arg4_T, typename Arg5_T, typename Arg6_T, typename Arg7_T, typename Arg8_T, typename Arg9_T>
Wrapped_Function * wrap_function(
    Ret_T (Self_T::*func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T, Arg9_T),
    Data_Object<Exception_Handler> handler,
    Arguments* arguments)
{
  typedef Ret_T (Self_T::*Func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T, Arg9_T);
  return new Auto_Member_Function_Wrapper<Func, Ret_T, Self_T, Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T, Arg9_T>(func, handler, arguments);
}

template<typename Ret_T, typename Self_T, typename Arg0_T, typename Arg1_T, typename Arg2_T, typename Arg3_T, typename Arg4_T, typename Arg5_T, typename Arg6_T, typename Arg7_T, typename Arg8_T, typename Arg9_T>
Wrapped_Function * wrap_function(
    Ret_T (Self_T::*func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T, Arg9_T) const,
    Data_Object<Exception_Handler> handler,
    Arguments* arguments)
{
  typedef Ret_T (Self_T::*Func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T, Arg9_T) const;
  return new Auto_Member_Function_Wrapper<Func, Ret_T, Self_T, Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T, Arg9_T>(func, handler, arguments);
}

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

template<typename Ret_T, typename Arg0_T, typename Arg1_T, typename Arg2_T, typename Arg3_T, typename Arg4_T, typename Arg5_T, typename Arg6_T, typename Arg7_T, typename Arg8_T, typename Arg9_T, typename Arg10_T, typename Arg11_T>
Wrapped_Function * wrap_function(
    Ret_T (*func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T, Arg9_T, Arg10_T, Arg11_T),
    Data_Object<Exception_Handler> handler,
    Arguments* arguments)
{
  typedef Ret_T (*Func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T, Arg9_T, Arg10_T, Arg11_T);
  return new Auto_Function_Wrapper<Func, Ret_T, Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T, Arg9_T, Arg10_T, Arg11_T>(func, handler, arguments);
}

template<typename Ret_T, typename Self_T, typename Arg0_T, typename Arg1_T, typename Arg2_T, typename Arg3_T, typename Arg4_T, typename Arg5_T, typename Arg6_T, typename Arg7_T, typename Arg8_T, typename Arg9_T, typename Arg10_T>
Wrapped_Function * wrap_function(
    Ret_T (Self_T::*func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T, Arg9_T, Arg10_T),
    Data_Object<Exception_Handler> handler,
    Arguments* arguments)
{
  typedef Ret_T (Self_T::*Func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T, Arg9_T, Arg10_T);
  return new Auto_Member_Function_Wrapper<Func, Ret_T, Self_T, Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T, Arg9_T, Arg10_T>(func, handler, arguments);
}

template<typename Ret_T, typename Self_T, typename Arg0_T, typename Arg1_T, typename Arg2_T, typename Arg3_T, typename Arg4_T, typename Arg5_T, typename Arg6_T, typename Arg7_T, typename Arg8_T, typename Arg9_T, typename Arg10_T>
Wrapped_Function * wrap_function(
    Ret_T (Self_T::*func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T, Arg9_T, Arg10_T) const,
    Data_Object<Exception_Handler> handler,
    Arguments* arguments)
{
  typedef Ret_T (Self_T::*Func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T, Arg9_T, Arg10_T) const;
  return new Auto_Member_Function_Wrapper<Func, Ret_T, Self_T, Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T, Arg9_T, Arg10_T>(func, handler, arguments);
}

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

template<typename Ret_T, typename Arg0_T, typename Arg1_T, typename Arg2_T, typename Arg3_T, typename Arg4_T, typename Arg5_T, typename Arg6_T, typename Arg7_T, typename Arg8_T, typename Arg9_T, typename Arg10_T, typename Arg11_T, typename Arg12_T>
Wrapped_Function * wrap_function(
    Ret_T (*func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T, Arg9_T, Arg10_T, Arg11_T, Arg12_T),
    Data_Object<Exception_Handler> handler,
    Arguments* arguments)
{
  typedef Ret_T (*Func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T, Arg9_T, Arg10_T, Arg11_T, Arg12_T);
  return new Auto_Function_Wrapper<Func, Ret_T, Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T, Arg9_T, Arg10_T, Arg11_T, Arg12_T>(func, handler, arguments);
}

template<typename Ret_T, typename Self_T, typename Arg0_T, typename Arg1_T, typename Arg2_T, typename Arg3_T, typename Arg4_T, typename Arg5_T, typename Arg6_T, typename Arg7_T, typename Arg8_T, typename Arg9_T, typename Arg10_T, typename Arg11_T>
Wrapped_Function * wrap_function(
    Ret_T (Self_T::*func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T, Arg9_T, Arg10_T, Arg11_T),
    Data_Object<Exception_Handler> handler,
    Arguments* arguments)
{
  typedef Ret_T (Self_T::*Func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T, Arg9_T, Arg10_T, Arg11_T);
  return new Auto_Member_Function_Wrapper<Func, Ret_T, Self_T, Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T, Arg9_T, Arg10_T, Arg11_T>(func, handler, arguments);
}

template<typename Ret_T, typename Self_T, typename Arg0_T, typename Arg1_T, typename Arg2_T, typename Arg3_T, typename Arg4_T, typename Arg5_T, typename Arg6_T, typename Arg7_T, typename Arg8_T, typename Arg9_T, typename Arg10_T, typename Arg11_T>
Wrapped_Function * wrap_function(
    Ret_T (Self_T::*func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T, Arg9_T, Arg10_T, Arg11_T) const,
    Data_Object<Exception_Handler> handler,
    Arguments* arguments)
{
  typedef Ret_T (Self_T::*Func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T, Arg9_T, Arg10_T, Arg11_T) const;
  return new Auto_Member_Function_Wrapper<Func, Ret_T, Self_T, Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T, Arg9_T, Arg10_T, Arg11_T>(func, handler, arguments);
}

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

template<typename Ret_T, typename Arg0_T, typename Arg1_T, typename Arg2_T, typename Arg3_T, typename Arg4_T, typename Arg5_T, typename Arg6_T, typename Arg7_T, typename Arg8_T, typename Arg9_T, typename Arg10_T, typename Arg11_T, typename Arg12_T, typename Arg13_T>
Wrapped_Function * wrap_function(
    Ret_T (*func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T, Arg9_T, Arg10_T, Arg11_T, Arg12_T, Arg13_T),
    Data_Object<Exception_Handler> handler,
    Arguments* arguments)
{
  typedef Ret_T (*Func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T, Arg9_T, Arg10_T, Arg11_T, Arg12_T, Arg13_T);
  return new Auto_Function_Wrapper<Func, Ret_T, Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T, Arg9_T, Arg10_T, Arg11_T, Arg12_T, Arg13_T>(func, handler, arguments);
}

template<typename Ret_T, typename Self_T, typename Arg0_T, typename Arg1_T, typename Arg2_T, typename Arg3_T, typename Arg4_T, typename Arg5_T, typename Arg6_T, typename Arg7_T, typename Arg8_T, typename Arg9_T, typename Arg10_T, typename Arg11_T, typename Arg12_T>
Wrapped_Function * wrap_function(
    Ret_T (Self_T::*func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T, Arg9_T, Arg10_T, Arg11_T, Arg12_T),
    Data_Object<Exception_Handler> handler,
    Arguments* arguments)
{
  typedef Ret_T (Self_T::*Func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T, Arg9_T, Arg10_T, Arg11_T, Arg12_T);
  return new Auto_Member_Function_Wrapper<Func, Ret_T, Self_T, Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T, Arg9_T, Arg10_T, Arg11_T, Arg12_T>(func, handler, arguments);
}

template<typename Ret_T, typename Self_T, typename Arg0_T, typename Arg1_T, typename Arg2_T, typename Arg3_T, typename Arg4_T, typename Arg5_T, typename Arg6_T, typename Arg7_T, typename Arg8_T, typename Arg9_T, typename Arg10_T, typename Arg11_T, typename Arg12_T>
Wrapped_Function * wrap_function(
    Ret_T (Self_T::*func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T, Arg9_T, Arg10_T, Arg11_T, Arg12_T) const,
    Data_Object<Exception_Handler> handler,
    Arguments* arguments)
{
  typedef Ret_T (Self_T::*Func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T, Arg9_T, Arg10_T, Arg11_T, Arg12_T) const;
  return new Auto_Member_Function_Wrapper<Func, Ret_T, Self_T, Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T, Arg9_T, Arg10_T, Arg11_T, Arg12_T>(func, handler, arguments);
}

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

template<typename Ret_T, typename Arg0_T, typename Arg1_T, typename Arg2_T, typename Arg3_T, typename Arg4_T, typename Arg5_T, typename Arg6_T, typename Arg7_T, typename Arg8_T, typename Arg9_T, typename Arg10_T, typename Arg11_T, typename Arg12_T, typename Arg13_T, typename Arg14_T>
Wrapped_Function * wrap_function(
    Ret_T (*func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T, Arg9_T, Arg10_T, Arg11_T, Arg12_T, Arg13_T, Arg14_T),
    Data_Object<Exception_Handler> handler,
    Arguments* arguments)
{
  typedef Ret_T (*Func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T, Arg9_T, Arg10_T, Arg11_T, Arg12_T, Arg13_T, Arg14_T);
  return new Auto_Function_Wrapper<Func, Ret_T, Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T, Arg9_T, Arg10_T, Arg11_T, Arg12_T, Arg13_T, Arg14_T>(func, handler, arguments);
}

template<typename Ret_T, typename Self_T, typename Arg0_T, typename Arg1_T, typename Arg2_T, typename Arg3_T, typename Arg4_T, typename Arg5_T, typename Arg6_T, typename Arg7_T, typename Arg8_T, typename Arg9_T, typename Arg10_T, typename Arg11_T, typename Arg12_T, typename Arg13_T>
Wrapped_Function * wrap_function(
    Ret_T (Self_T::*func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T, Arg9_T, Arg10_T, Arg11_T, Arg12_T, Arg13_T),
    Data_Object<Exception_Handler> handler,
    Arguments* arguments)
{
  typedef Ret_T (Self_T::*Func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T, Arg9_T, Arg10_T, Arg11_T, Arg12_T, Arg13_T);
  return new Auto_Member_Function_Wrapper<Func, Ret_T, Self_T, Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T, Arg9_T, Arg10_T, Arg11_T, Arg12_T, Arg13_T>(func, handler, arguments);
}

template<typename Ret_T, typename Self_T, typename Arg0_T, typename Arg1_T, typename Arg2_T, typename Arg3_T, typename Arg4_T, typename Arg5_T, typename Arg6_T, typename Arg7_T, typename Arg8_T, typename Arg9_T, typename Arg10_T, typename Arg11_T, typename Arg12_T, typename Arg13_T>
Wrapped_Function * wrap_function(
    Ret_T (Self_T::*func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T, Arg9_T, Arg10_T, Arg11_T, Arg12_T, Arg13_T) const,
    Data_Object<Exception_Handler> handler,
    Arguments* arguments)
{
  typedef Ret_T (Self_T::*Func)(Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T, Arg9_T, Arg10_T, Arg11_T, Arg12_T, Arg13_T) const;
  return new Auto_Member_Function_Wrapper<Func, Ret_T, Self_T, Arg0_T, Arg1_T, Arg2_T, Arg3_T, Arg4_T, Arg5_T, Arg6_T, Arg7_T, Arg8_T, Arg9_T, Arg10_T, Arg11_T, Arg12_T, Arg13_T>(func, handler, arguments);
}

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

} // namespace detail

} // namespace Rice


#endif // Rice__detail__wrap_function__ipp_



<|start_filename|>rice/detail/Arguments.hpp<|end_filename|>
#ifndef Rice__Arguments__hpp_
#define Rice__Arguments__hpp_

#include "../Arg_impl.hpp"
#include <sstream>
#include <vector>
#include "../to_from_ruby_defn.hpp"

namespace Rice {

  class Arguments
  {
    public:
      Arguments() {
        required_ = 0;
        optional_ = 0;
      }

      ~Arguments() {
      }

      /**
       * Get the full argument count of this
       * list of arguments.
       * Returns -1 no defined arguments
       */
      int count() {
        if(required_ == 0 && optional_ == 0) {
          return -1;
        } else {
          return required_ + optional_;
        }
      }

      /**
       * Get the rb_scan_args format string for this
       * list of arguments.
       * In the case of no Args (default case), this
       * method uses the passed in full argument count
       */
      std::string formatString(int fullArgCount)
      {
        std::stringstream s;
        if(required_ == 0 && optional_ == 0)
        {
          s << fullArgCount << 0;
        }
        else
        {
          s << required_ << optional_;
        }

        return s.str();
      }

      /**
       * Add a defined Arg to this list of Arguments
       */
      void add(const Arg& arg)
      {
        args_.push_back(arg);

        if(arg.hasDefaultValue())
        {
          optional_++;
        }
        else
        {
          required_++;
        }
      }

      /**
       * Is the argument at the request location an optional
       * argument?
       */
      bool isOptional(unsigned int pos)
      {
        if(required_ == 0 && optional_ == 0)
        {
          return false;
        }
        if(pos >= args_.size())
        {
          return false;
        }
        return args_[pos].hasDefaultValue();
      }

      /**
       * Given a position, a type, and a ruby VALUE, figure out
       * what argument value we need to return according to
       * defaults and if that VALUE is nil or not
       */
      template<typename Arg_T>
      Arg_T getArgumentOrDefault(int pos, VALUE in)
      {
        if(isOptional(pos) && NIL_P(in))
        {
          return args_[pos].getDefaultValue<Arg_T>();
        }
        else
        {
          return from_ruby<Arg_T>(in);
        }
      }

    private:
      std::vector<Arg> args_;

      /** Keep counts of required and optional parameters */
      int required_;
      int optional_;
  };

}

#endif // Rice__Arguments__hpp_


<|start_filename|>rice/Object.hpp<|end_filename|>
#ifndef Rice__Object__hpp_
#define Rice__Object__hpp_

#include "Object_defn.hpp"
#include "Object.ipp"

#endif // Rice__Object__hpp_



<|start_filename|>rice/detail/cfp.hpp<|end_filename|>
#ifndef Rice__detail__cfp__hpp_
#define Rice__detail__cfp__hpp_

#include "ruby.hpp"

namespace Rice
{

namespace detail
{

VALUE * cfp();

VALUE & cfp_data_memo_node_and_pc(VALUE * cfp);
VALUE & cfp_self(VALUE * cfp);
VALUE & cfp_method_class(VALUE * cfp);

} // detail

} // Rice

#include "cfp.ipp"

#endif // Rice__detail__cfp__hpp_


<|start_filename|>rice/detail/from_ruby.ipp<|end_filename|>
#ifndef Rice__detail__from_ruby__ipp_
#define Rice__detail__from_ruby__ipp_

#include "../Data_Type.hpp"
#include "../String.hpp"
#include "demangle.hpp"
#include <typeinfo>

template<typename T>
T Rice::detail::from_ruby_<T>::
convert(Rice::Object x)
{
  if(rb_type(x.value()) == T_DATA)
  {
    return *Data_Type<T>::from_ruby(x);
  }
  else
  {
    std::string s("Unable to convert ");
    s += x.class_of().name().c_str();
    s += " to ";
    s += demangle(typeid(T).name());
    throw std::invalid_argument(s.c_str());
  }
}

template<typename T>
T * Rice::detail::from_ruby_<T *>::
convert(Rice::Object x)
{
  if(rb_type(x.value()) == T_DATA)
  {
    return Data_Type<T>::from_ruby(x);
  }
  else
  {
    std::string s("Unable to convert ");
    s += x.class_of().name().c_str();
    s += " to ";
    s += demangle(typeid(T *).name());
    throw std::invalid_argument(s.c_str());
  }
}

template<typename T>
T const * Rice::detail::from_ruby_<T const *>::
convert(Rice::Object x)
{
  return from_ruby<T *>(x);
}

template<typename T>
T & Rice::detail::from_ruby_<T &>::
convert(Rice::Object x)
{
  return *from_ruby<T *>(x);
}

#endif // Rice__detail__from_ruby__ipp_



<|start_filename|>rice/Array.ipp<|end_filename|>
#ifndef Rice__Array__ipp_
#define Rice__Array__ipp_

#include "protect.hpp"

inline Rice::Array::
Array()
  : Builtin_Object<RArray, T_ARRAY>(protect(rb_ary_new))
{
}

inline Rice::Array::
Array(Object v)
  : Builtin_Object<RArray, T_ARRAY>(v)
{
}

inline Rice::Array::
Array(VALUE v)
  : Builtin_Object<RArray, T_ARRAY>(v)
{
}

template<typename Iter_T>
inline Rice::Array::
Array(Iter_T it, Iter_T end)
  : Builtin_Object<RArray, T_ARRAY>(protect(rb_ary_new))
{
  for(; it != end; ++it)
  {
    push(*it);
  }
}

template<typename T, size_t n>
inline Rice::Array::
Array(T const (& a)[n])
  : Builtin_Object<RArray, T_ARRAY>(protect(rb_ary_new))
{
  for(size_t j = 0; j < n; ++j)
  {
    push(a[j]);
  }
}

inline size_t Rice::Array::
size() const
{
  return RARRAY_LEN(this->value());
}

inline Rice::Object Rice::Array::
operator[](ptrdiff_t index) const
{
  VALUE * ptr = RARRAY_PTR(this->value());
  return ptr[position_of(index)];
}

inline Rice::Array::Proxy Rice::Array::
operator[](ptrdiff_t index)
{
  return Proxy(*this, position_of(index));
}

template<typename T>
inline Rice::Object Rice::Array::
push(T const & obj)
{
  return protect(rb_ary_push, value(), to_ruby(obj));
}

inline Rice::Object Rice::Array::
pop()
{
  return protect(rb_ary_pop, value());
}

template<typename T>
inline Rice::Object Rice::Array::
unshift(T const & obj)
{
  return protect(rb_ary_unshift, value(), to_ruby(obj));
}

inline Rice::Object Rice::Array::
shift()
{
  return protect(rb_ary_shift, value());
}

inline VALUE * Rice::Array::
to_c_array()
{
  return RARRAY_PTR(this->value());
}

inline size_t Rice::Array::
position_of(ptrdiff_t index) const
{
  if(index < 0)
  {
    return size() + index;
  }
  else
  {
    return static_cast<size_t>(index);
  }
}

inline Rice::Array::Proxy::
Proxy(Array array, size_t index)
  : array_(array)
  , index_(index)
{
}

inline Rice::Array::Proxy::
operator Rice::Object() const
{
  return RARRAY_PTR(array_.value())[index_];
}

inline VALUE Rice::Array::Proxy::
value() const
{
  return RARRAY_PTR(array_.value())[index_];
}

template<typename T>
Rice::Object Rice::Array::Proxy::
operator=(T const & value)
{
  Object o = to_ruby(value);
  RARRAY_PTR(array_.value())[index_] = o.value();
  return o;
}

template<typename Array_Ref_T, typename Value_T>
inline Rice::Array::Iterator<Array_Ref_T, Value_T>::
Iterator(Array_Ref_T array, size_t index)
  : array_(array)
  , index_(index)
{
}

template<typename Array_Ref_T, typename Value_T>
template<typename Array_Ref_T_, typename Value_T_>
inline
Rice::Array::Iterator<Array_Ref_T, Value_T>::
Iterator(Iterator<Array_Ref_T_, Value_T_> const & rhs)
  : array_(rhs.array())
  , index_(rhs.index())
  , tmp_()
{
}

template<typename Array_Ref_T, typename Value_T>
template<typename Array_Ref_T_, typename Value_T_>
inline Rice::Array::Iterator<Array_Ref_T, Value_T> &
Rice::Array::Iterator<Array_Ref_T, Value_T>::
operator=(Iterator<Array_Ref_T_, Value_T_> const & rhs)
{
  array_ = rhs.array_;
  index_ = rhs.index_;
  return *this;
}

template<typename Array_Ref_T, typename Value_T>
inline Rice::Array::Iterator<Array_Ref_T, Value_T> &
Rice::Array::Iterator<Array_Ref_T, Value_T>::
operator++()
{
  ++index_;
  return *this;
}

template<typename Array_Ref_T, typename Value_T>
inline Rice::Array::Iterator<Array_Ref_T, Value_T>
Rice::Array::Iterator<Array_Ref_T, Value_T>::
operator++(int)
{
  Array copy(*this);
  ++(*this);
  return *this;
}

template<typename Array_Ref_T, typename Value_T>
inline Value_T
Rice::Array::Iterator<Array_Ref_T, Value_T>::
operator*()
{
  return array_[index_];
}

template<typename Array_Ref_T, typename Value_T>
inline Rice::Object *
Rice::Array::Iterator<Array_Ref_T, Value_T>::
operator->()
{
  tmp_ = array_[index_];
  return &tmp_;
}

template<typename Array_Ref_T, typename Value_T>
template<typename Array_Ref_T_, typename Value_T_>
inline bool
Rice::Array::Iterator<Array_Ref_T, Value_T>::
operator==(Iterator<Array_Ref_T_, Value_T_> const & rhs) const
{
  return array_.value() == rhs.array_.value() && index_ == rhs.index_;
}

template<typename Array_Ref_T, typename Value_T>
template<typename Array_Ref_T_, typename Value_T_>
inline bool
Rice::Array::Iterator<Array_Ref_T, Value_T>::
operator!=(Iterator<Array_Ref_T_, Value_T_> const & rhs) const
{
  return !(*this == rhs);
}

template<typename Array_Ref_T, typename Value_T>
Array_Ref_T
Rice::Array::Iterator<Array_Ref_T, Value_T>::
array() const
{
  return array_;
}

template<typename Array_Ref_T, typename Value_T>
size_t
Rice::Array::Iterator<Array_Ref_T, Value_T>::
index() const
{
  return index_;
}

inline Rice::Array::iterator Rice::Array::
begin()
{
  return iterator(*this, 0);
}

inline Rice::Array::const_iterator Rice::Array::
begin() const
{
  return const_iterator(*this, 0);
}

inline Rice::Array::iterator Rice::Array::
end()
{
  return iterator(*this, size());
}

inline Rice::Array::const_iterator Rice::Array::
end() const
{
  return const_iterator(*this, size());
}

#endif // Rice__Array__ipp_



<|start_filename|>rice/detail/Exception_Handler.hpp<|end_filename|>
#ifndef Rice__detail__Exception_Handler__hpp_
#define Rice__detail__Exception_Handler__hpp_

#include "Exception_Handler_defn.hpp"
#include "Exception_Handler.ipp"

#endif // Rice__detail__Exception_Handler__hpp_



<|start_filename|>test/test_Identifier.cpp<|end_filename|>
#include "unittest.hpp"
#include "rice/Identifier.hpp"
#include "rice/Symbol.hpp"

using namespace Rice;

TESTSUITE(Identifier);

SETUP(Identifier)
{
  ruby_init();
}

TESTCASE(construct_from_id)
{
  ID id = rb_intern("foo");
  Identifier identifier(id);
  ASSERT_EQUAL(id, identifier.id());
}

TESTCASE(construct_from_symbol)
{
  Symbol symbol("FOO");
  Identifier identifier(symbol);
  ASSERT_EQUAL(rb_intern("FOO"), identifier.id());
}

TESTCASE(construct_from_c_string)
{
  Identifier identifier("Foo");
  ASSERT_EQUAL(rb_intern("Foo"), identifier.id());
}

TESTCASE(default_construct)
{
  Identifier identifier;
  ASSERT_EQUAL(rb_intern(""), identifier.id());
}

TESTCASE(copy_construct)
{
  Identifier identifier1("Foo");
  Identifier identifier2(identifier1);
  ASSERT_EQUAL(rb_intern("Foo"), identifier2.id());
}

TESTCASE(c_str)
{
  Identifier identifier("Foo");
  ASSERT_EQUAL("Foo", identifier.c_str());
}

TESTCASE(str)
{
  Identifier identifier("Foo");
  ASSERT_EQUAL(std::string("Foo"), identifier.str());
}

TESTCASE(implicit_conversion_to_id)
{
  Identifier identifier("Foo");
  ASSERT_EQUAL(rb_intern("Foo"), static_cast<ID>(identifier));
}

TESTCASE(to_sym)
{
  Identifier identifier("Foo");
  ASSERT_EQUAL(Symbol("Foo"), Symbol(identifier.to_sym()));
}



<|start_filename|>rice/Enum.ipp<|end_filename|>
#ifndef Rice__Enum__ipp_
#define Rice__Enum__ipp_

#include "Data_Object.hpp"
#include "Class.hpp"
#include "String.hpp"
#include "protect.hpp"
#include <memory>

template<typename Enum_T>
long Rice::Default_Enum_Traits<Enum_T>::as_long(Enum_T value)
{
  return static_cast<long>(value);
}

template<typename Enum_T, typename Enum_Traits>
Rice::Enum<Enum_T, Enum_Traits>::
Enum()
  : Module_impl<Data_Type<Enum_T>, Enum<Enum_T, Enum_Traits> >()
  , enums_()
  , enums_guard_(&enums_)
  , names_()
  , names_guard_(&names_)
{
}

template<typename Enum_T, typename Enum_Traits>
Rice::Enum<Enum_T, Enum_Traits>::
Enum(
    char const * name,
    Module module)
  : Module_impl<Data_Type<Enum_T>, Enum<Enum_T, Enum_Traits> >()
  , enums_()
  , enums_guard_(&enums_)
  , names_()
  , names_guard_(&names_)
{
  this->template bind<void>(initialize(name, module));
}

template<typename Enum_T, typename Enum_Traits>
Rice::Enum<Enum_T, Enum_Traits>::
Enum(Enum<Enum_T, Enum_Traits> const & other)
  : Module_impl<Data_Type<Enum_T>, Enum<Enum_T, Enum_Traits> >(other)
  , enums_(other.enums_)
  , enums_guard_(&enums_)
  , names_(other.names_)
  , names_guard_(&names_)
{
}

template<typename Enum_T, typename Enum_Traits>
Rice::Enum<Enum_T, Enum_Traits> & Rice::Enum<Enum_T, Enum_Traits>::
operator=(Rice::Enum<Enum_T, Enum_Traits> const & other)
{
  Rice::Enum<Enum_T, Enum_Traits> tmp(other);
  this->swap(tmp);
  return *this;
}

template<typename Enum_T, typename Enum_Traits>
Rice::Enum<Enum_T, Enum_Traits>::
~Enum()
{
}

template<typename Enum_T, typename Enum_Traits>
Rice::Enum<Enum_T, Enum_Traits> & Rice::Enum<Enum_T, Enum_Traits>::
initialize(
    char const * name,
    Module module)
{
  Class c = Rice::define_class_under<Enum_T>(module, name)
    .define_method("to_s", to_s)
    .define_method("to_i", to_i)
    .define_method("inspect", inspect)
    .define_method("<=>", compare)
    //.define_method("hash", hash)
    .define_method("eql?", eql)
    .define_method("==", eql)
    .define_method("===", eql)
    .define_singleton_method("each", each)
    .define_singleton_method("from_int", from_int)
    .include_module(rb_mComparable);

  // TODO: This should be unnecessary (it should be taken care of when
  // define_class_under binds the C++ and ruby types)
  this->set_value(c);

  protect(rb_iv_set, c, "enums", enums_);
  protect(rb_iv_set, c, "names", names_);

  return *this;
}

template<typename Enum_T, typename Enum_Traits>
Rice::Enum<Enum_T, Enum_Traits> & Rice::Enum<Enum_T, Enum_Traits>::
define_value(
    char const * name,
    Enum_T value)
{
  std::auto_ptr<Enum_T> copy(new Enum_T(value));
  Rice::Data_Object<Enum_T> m(copy.get(), *this);
  copy.release();
  names_[m] = String(name);
  this->const_set(name, m);
  enums_.push(m);

  return *this;
}


template<typename Enum_T, typename Enum_Traits>
void Rice::Enum<Enum_T, Enum_Traits>::
swap(Enum<Enum_T, Enum_Traits> & other)
{
  Data_Type<Enum_T>::swap(other);
  enums_.swap(other.enums_);
  names_.swap(other.names_);
}

template<typename Enum_T, typename Enum_Traits>
Rice::Object Rice::Enum<Enum_T, Enum_Traits>::
each(Object self)
{
  VALUE enums_v = rb_iv_get(self, "enums");
  Check_Type(enums_v, T_ARRAY);
  Array enums(enums_v);
  for(size_t j = 0; j < enums.size(); ++j)
  {
    rb_yield(enums[j].value());
  }
  return Qnil;
}

template<typename Enum_T, typename Enum_Traits>
Rice::Object Rice::Enum<Enum_T, Enum_Traits>::
to_s(Object self)
{
  Data_Type<Enum_T> klass;
  Rice::Data_Object<Enum_T> m(self, klass);
  Object enum_class = rb_class_of(m);
  Hash names(rb_iv_get(enum_class, "names"));
  Object name = names[m];
  if(name.is_nil())
  {
    return String::format("INVALID(%d)", Enum_Traits::as_long(*m));
  }
  else
  {
    return String(name);
  }
}

template<typename Enum_T, typename Enum_Traits>
Rice::Object Rice::Enum<Enum_T, Enum_Traits>::
inspect(Object self)
{
  return String::format(
      "#<%s::%s>",
      String(self.class_of().name()).c_str(),
      String(to_s(self)).c_str());
}

template<typename Enum_T, typename Enum_Traits>
Rice::Object Rice::Enum<Enum_T, Enum_Traits>::
compare(Object lhs, Object rhs)
{
  if(lhs.class_of() != rhs.class_of())
  {
    String lhs_name(lhs.class_of().name());
    String rhs_name(rhs.class_of().name());
    rb_raise(
        rb_eTypeError,
        "Cannot compare %s to %s",
        lhs_name.c_str(),
        rhs_name.c_str());
  }

  Data_Type<Enum_T> klass;
  Rice::Data_Object<Enum_T> l(lhs, klass);
  Rice::Data_Object<Enum_T> r(rhs, klass);

  Enum_T left(*l);
  Enum_T right(*r);  

  if(left == right)
  {
    return INT2NUM(0);
  }
  else if(Enum_Traits::as_long(left) < Enum_Traits::as_long(right))
  {
    return INT2NUM(-1);
  }
  else
  {
    return INT2NUM(1);
  }
}

template<typename Enum_T, typename Enum_Traits>
Rice::Object Rice::Enum<Enum_T, Enum_Traits>::
eql(Object lhs, Object rhs)
{
  using ::from_ruby; // Workaround for g++ 3.3.3
  bool is_equal = from_ruby<int>(compare(lhs, rhs)) == 0; 
  return to_ruby(is_equal);
}

template<typename Enum_T, typename Enum_Traits>
Rice::Object Rice::Enum<Enum_T, Enum_Traits>::
to_i(Object self)
{
  Data_Type<Enum_T> klass;
  Rice::Data_Object<Enum_T> m(self, klass);
  return LONG2NUM(Enum_Traits::as_long(*m));
}

template<typename Enum_T, typename Enum_Traits>
Rice::Object Rice::Enum<Enum_T, Enum_Traits>::
hash(Object self)
{
  return to_i(self);
}

template<typename Enum_T, typename Enum_Traits>
Rice::Object Rice::Enum<Enum_T, Enum_Traits>::
from_int(Class klass, Object i)
{
  using ::from_ruby; // Workaround for g++ 3.3.3
  Rice::Data_Object<Enum_T> m(
      new Enum_T(static_cast<Enum_T>(from_ruby<long>(i))),
      klass);
  return m.value();
}

template<typename T>
Rice::Enum<T> Rice::
define_enum(
    char const * name,
    Module module)
{
  return Enum<T>(name, module);
}
#endif // Rice__Enum__ipp_



<|start_filename|>rice/Symbol.cpp<|end_filename|>
#include "Symbol.hpp"

namespace
{
  VALUE check_type(Rice::Object value, int type)
  {
    rb_check_type(value, type);
    return Qnil;
  }
}

Rice::Symbol::
Symbol(VALUE v)
  : Object(v)
{
  protect(check_type, v, T_SYMBOL);
}

Rice::Symbol::
Symbol(Object v)
  : Object(v)
{
  protect(check_type, v, T_SYMBOL);
}



<|start_filename|>rice/Module_defn.hpp<|end_filename|>
#ifndef Rice__Module_defn__hpp_
#define Rice__Module_defn__hpp_

#include "Object_defn.hpp"
#include "Module_impl.hpp"
#include "to_from_ruby_defn.hpp"
#include <memory>

namespace Rice
{

class Array;
class Class;
class String;

//! A helper for defining a Module and its methods.
/*! This class provides a C++-style interface to ruby's Module class and
 *  for defining methods on that module.
 *
 *  Many of the methods are defined in Module_impl.hpp so that they can
 *  return a reference to the most derived type.
 */
class Module
  // TODO: we can't inherit from Builtin_Object, because Class needs
  // type T_CLASS and Module needs type T_MODULE
  : public Module_impl<Module_base, Module>
{
public:
  //! Default construct a Module and initialize it to rb_cObject.
  Module();

  //! Construct a Module from an existing Module object.
  Module(VALUE v);

  //! Return the name of the module.
  String name() const;

  //! Swap with another Module.
  void swap(Module & other);

  //! Return an array containing the Module's ancestors.
  /*! You will need to include Array.hpp to use this function.
   */
  Array ancestors() const;

  //! Return the module's singleton class.
  /*! You will need to include Class.hpp to use this function.
   */
  Class singleton_class() const;
};

//! Define a new module in the namespace given by module.
/*! \param module the module in which to define the new module.
 *  \param name the name of the new module.
 */
Module define_module_under(
    Object module,
    char const * name);

//! Define a new module in the default namespace.
/*! \param name the name of the new module.
 */
Module define_module(
    char const * name);

//! Create a new anonymous module.
/*! \return the new module.
 */
Module anonymous_module();

} // namespace Rice

template<>
inline
Rice::Module from_ruby<Rice::Module>(Rice::Object x)
{
  return Rice::Module(x);
}

template<>
inline
Rice::Object to_ruby<Rice::Module>(Rice::Module const & x)
{
  return x;
}

#endif // Rice__Module_defn__hpp_



<|start_filename|>test/test_Data_Type.cpp<|end_filename|>
#include "unittest.hpp"
#include "rice/Data_Type.hpp"
#include "rice/Exception.hpp"
#include "rice/Constructor.hpp"
#include "rice/global_function.hpp"

using namespace Rice;

TESTSUITE(Data_Type);

/**
 * The tests here are for the feature of taking an instance
 * of a Ruby-subclass of a Rice wrapped class and passing
 * that instance back into the Rice wrapper. While that
 * might be confusing, the test code is pretty straight foward
 * to see what we're talking about.
 */

namespace {

  /**
   * The class we will subclass in Ruby
   */
  class Listener {
    public:
      Listener() {  }

      virtual ~Listener() {  }

      virtual int getValue() { return 4; }
  };

  /**
   * This class will recieve a new Listener instance
   * from Ruby
   */
  class ListenerHandler {

    public:

      ListenerHandler() {  }

      void addListener(Listener* newList) {
        mListeners.push_back(newList);
      }

      int process() {
        std::vector<Listener*>::iterator i = mListeners.begin();
        int accum = 0; 
        for(; i != mListeners.end(); i++) {
          accum += (*i)->getValue();
        }

        return accum;
      }

      int listenerCount() { return mListeners.size(); }

    private:
      std::vector<Listener*> mListeners;
  };
}

SETUP(Data_Type)
{
  ruby_init();

  define_class<Listener>("Listener")
    .define_constructor(Constructor<Listener>())
    .define_method("get_value", &Listener::getValue);

  define_class<ListenerHandler>("ListenerHandler")
    .define_constructor(Constructor<ListenerHandler>())
    .define_method("add_listener", &ListenerHandler::addListener)
    .define_method("process", &ListenerHandler::process)
    .define_method("listener_count", &ListenerHandler::listenerCount);

}

TESTCASE(can_send_ruby_instance_back_into_rice)
{
  Module m = define_module("TestingModule");
  Object handler = m.instance_eval("@handler = ListenerHandler.new");

  ASSERT_EQUAL(INT2NUM(0), handler.call("listener_count").value());

  m.instance_eval("class MyListener < Listener; end;");
  m.instance_eval("@handler.add_listener(MyListener.new)");

  ASSERT_EQUAL(INT2NUM(1), handler.call("listener_count").value());
  ASSERT_EQUAL(INT2NUM(4), handler.call("process").value());

  m.instance_eval("@handler.add_listener(Listener.new)");

  ASSERT_EQUAL(INT2NUM(2), handler.call("listener_count").value());
  ASSERT_EQUAL(INT2NUM(8), handler.call("process").value());
}

/**
 * The following test SEGFAULTs right now
 */
/*
TESTCASE(no_super_in_constructor_still_works) 
{
  Module m = define_module("TestingModule");
  Object handler = m.instance_eval("@handler = ListenerHandler.new");

  ASSERT_EQUAL(INT2NUM(0), handler.call("listener_count").value());

  // Because of this, there's a constructor but no super call
  m.instance_eval("class MyListener < Listener; def initialize; @val = 10; end; end;");
  m.instance_eval("@handler.add_listener(MyListener.new)");

  ASSERT_EQUAL(INT2NUM(1), handler.call("listener_count").value());
  ASSERT_EQUAL(INT2NUM(4), handler.call("process").value());

  m.instance_eval("@handler.add_listener(MyListener.new)");

  ASSERT_EQUAL(INT2NUM(2), handler.call("listener_count").value());
  ASSERT_EQUAL(INT2NUM(8), handler.call("process").value());
}
*/

/**
 * Implicit Casting across unrelated types
 *
 * Two ways of defining if types are implicitly castable
 *
 * 1) operator
 * 2) constructor 
 */

/**
 * Examples here taken from Ogre's Math library.
 * This uses the constructor method of casting types.
 */
namespace 
{
  const int degree2Radians = (3.14 / 180.0);
  const int radian2Degrees = (180.0 / 3.14);

  class Radian;

  class Degree
  {
    public:
      explicit Degree(float d) : val_(d) {}
      Degree(const Radian& r);

      float valueDegrees() const { return val_; }
      float valueRadians() const { return val_ * degree2Radians; }

    private:
      float val_;
  };

  class Radian
  {
    public:
      explicit Radian(float r) : val_(r) {} 
      Radian(const Degree& d) : val_(d.valueRadians()) {}

      float valueRadians() const { return val_; }
      float valueDegrees() const { return val_ * radian2Degrees; }

    private:
      float val_;
  };

  // Due to circular dependencies, need to define some
  // methods down here
  Degree::Degree(const Radian& r)
  {
    val_ = r.valueDegrees();
  }

  /**
   * And now some methods that work w/ the above two classes
   */
  bool isAcute(Degree degree) {
    return degree.valueDegrees() < 90;
  }

  bool isObtuse(Radian radian) {
    return radian.valueDegrees() > 90 && radian.valueDegrees() <= 180;
  }

  bool isRight(Degree* degree) {
    return degree->valueDegrees() == 90;
  }
}

TESTCASE(can_define_implicit_type_conversions_across_wrapped_types)
{
  define_class<Degree>("Degree")
    .define_constructor(Constructor<Degree, float>());

  define_class<Radian>("Radian")
    .define_constructor(Constructor<Radian, float>());

  define_implicit_cast<Degree, Radian>();
  define_implicit_cast<Radian, Degree>();

  define_global_function("is_acute", &isAcute);
  define_global_function("is_obtuse", &isObtuse);
  define_global_function("is_right", &isRight);

  Module m = define_module("TestingModule");
  Object result;

  // ACUTE
  result = m.instance_eval("is_acute(Degree.new(75))");
  ASSERT(from_ruby<bool>(result.value()));

  result = m.instance_eval("is_acute(Radian.new(2.0))");
  ASSERT(!from_ruby<bool>(result.value()));

  // OBTUSE
  result = m.instance_eval("is_obtuse(Degree.new(75))");
  ASSERT(!from_ruby<bool>(result.value()));

  result = m.instance_eval("is_obtuse(Radian.new(2.0))");
  ASSERT(from_ruby<bool>(result.value()));

  // RIGHT
  result = m.instance_eval("is_right(Degree.new(90))");
  ASSERT(from_ruby<bool>(result.value()));

  result = m.instance_eval("is_right(Radian.new(2.0))");
  ASSERT(!from_ruby<bool>(result.value()));
}

namespace {
  class Explicit
  {
    public:
      Explicit(float v) {
        value = v;
      }

      Explicit(const Degree &d) {
        value = d.valueDegrees();
      }

      float getValue() { return value; }

    private:
      float value;
  };

  float getExplicitValue(Explicit* v) {
    return v->getValue();
  }
}

TESTCASE(supports_multiple_implicit_conversions_for_a_type)
{
  define_class<Degree>("Degree")
    .define_constructor(Constructor<Degree, float>());

  define_class<Radian>("Radian")
    .define_constructor(Constructor<Radian, float>());

  define_class<Explicit>("Explicit")
    .define_constructor(Constructor<Explicit, float>());

  define_global_function("is_obtuse", &isObtuse);
  define_global_function("explicit_value", &getExplicitValue);

  define_implicit_cast<Radian, Degree>();
  define_implicit_cast<Degree, Radian>();
  define_implicit_cast<Degree, Explicit>();

  Module m = define_module("TestingModule");
  Object result;

  result = m.instance_eval("is_obtuse(Degree.new(75))");
  ASSERT(!from_ruby<bool>(result.value()));

  result = m.instance_eval("explicit_value(Degree.new(75))");
  ASSERT_EQUAL(75.0, from_ruby<float>(result.value()));
}

/**
 * Sample taken and modified from boost::python::implicit:
 * http://www.boost.org/doc/libs/1_41_0/libs/python/doc/v2/implicit.html
 *
 * This is the operator version of casting and shows that this works for
 * base types as well as defined types
 */
/*
namespace {
  struct Real
  {
    Real(int x)
      : v(x)
    {}

    operator int() const
    {
      return v;
    }

    int v;
  };

  int realValue(Real const& x)
  {
    return x.v;
  }

  Real makeReal(int n)
  {
    return Real(n);
  }
}

TESTCASE(can_define_implicit_type_conversions_to_base_types)
{
  define_class<Real>("Real")
    .define_constructor(Constructor<Real, int>());

  // Define the conversion rules
  define_implicit_cast<Real, int>();
  define_implicit_cast<int, Real>();

  define_global_function("real_value", &realValue);
  define_global_function("make_real", &makeReal);

  Module m = define_module("TestingModule");

  // As Real object
  Object result = m.instance_eval("real_value( Real.new(4) )");
  ASSERT_EQUAL(4, from_ruby<int>(result.value()));

  // As fixnum (int)
  result = m.instance_eval("real_value(4)");
  ASSERT_EQUAL(4, from_ruby<int>(result.value()));

  // As Real object
  result = m.instance_eval("r = make_real( Real.new(6) ); real_value(r)");
  ASSERT_EQUAL(6, from_ruby<int>(result.value()));

  // As fixnum (int)
  result = m.instance_eval("r = make_real(6); real_value(r)");
  ASSERT_EQUAL(6, from_ruby<int>(result.value()));
}
*/


<|start_filename|>rice/Address_Registration_Guard_defn.hpp<|end_filename|>
#ifndef Rice__Address_Registration_Guard_defn__hpp_
#define Rice__Address_Registration_Guard_defn__hpp_

#include "Object_defn.hpp"
#include "detail/ruby.hpp"
#include "detail/Not_Copyable.hpp"

namespace Rice
{

//! A guard to register a given address with the GC.
/*! Calls rb_gc_register_address upon construction and
 *  rb_gc_unregister_address upon destruction.
 *  For example:
 *  \code
 *    Class Foo
 *    {
 *    public:
 *      Foo()
 *        : string_(rb_str_new2())
 *        , guard_(&string_);
 * 
 *    private:
 *      VALUE string_;
 *      Address_Registration_Guard guard_;
 *    };
 *  \endcode
 */
class Address_Registration_Guard
  : private detail::Not_Copyable
{
public:
  //! Register an address with the GC.
  /*  \param address The address to register with the GC.  The address
   *  must point to a valid ruby object (RObject).
   */
  Address_Registration_Guard(VALUE * address);

  //! Register an Object with the GC.
  /*! \param object The Object to register with the GC.  The object must
   *  not be destroyed before the Address_Registration_Guard is
   *  destroyed.
   */
  Address_Registration_Guard(Object * object);

  //! Unregister an address/Object with the GC.
  /*! Destruct an Address_Registration_Guard.  The address registered
   *  with the Address_Registration_Guard when it was constructed will
   *  be unregistered from the GC.
   */
  ~Address_Registration_Guard();

  //! Get the address that is registered with the GC.
  VALUE * address() const;

  //! Swap with another Address_Registration_Guard.
  void swap(Address_Registration_Guard & other);

  /** Called during Ruby's exit process since we should not call
   * rb_gc unregister_address there
   */
  static void disable();

private:
  static bool enabled;
  static bool exit_handler_registered;

  static void registerExitHandler();

  VALUE * address_;
};

} // namespace Rice

#endif // Rice__Address_Registration_Guard_defn__hpp_


<|start_filename|>rice/Data_Object.ipp<|end_filename|>
#ifndef Rice__Data_Object__ipp_
#define Rice__Data_Object__ipp_

#include "detail/check_ruby_type.hpp"
#include "protect.hpp"

#include <algorithm>

template<typename T>
const typename Rice::Default_Mark_Function<T>::Ruby_Data_Func
Rice::Default_Mark_Function<T>::mark = ruby_mark<T>;

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<typename T>
inline VALUE wrap(
    VALUE klass,
    typename Data_Object<T>::Ruby_Data_Func mark,
    typename Data_Object<T>::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<RUBY_DATA_FUNC>(mark),
      reinterpret_cast<RUBY_DATA_FUNC>(free),
      (void *)obj);
}

template<typename T>
inline VALUE data_get_struct(VALUE value, T * * obj)
{
  Data_Get_Struct(value, T, *obj);
  return Qnil;
}

template<typename T>
inline T * unwrap(VALUE value)
{
  T * obj;
  Rice::protect(data_get_struct<T>, value, &obj);
  return obj;
}

} // namespace detail

} // namespace Rice

template<typename T>
inline Rice::Data_Object<T>::
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<typename T>
inline Rice::Data_Object<T>::
Data_Object(
    Object value)
  : Object(value)
  , obj_(detail::unwrap<T>(value))
{  
  Data_Type<T> klass;
  check_cpp_type(klass);
  detail::check_ruby_type(value, klass, true);
}

template<typename T>
template<typename U>
inline Rice::Data_Object<T>::
Data_Object(
    Object value,
    Data_Type<U> const & klass)
  : Object(value)
  , obj_(detail::unwrap<T>(value))
{  
  check_cpp_type(klass);
  detail::check_ruby_type(value, klass, true);
}

template<typename T>
inline Rice::Data_Object<T>::
Data_Object(Data_Object const & other)
  : Object(other.value())
  , obj_(other.obj_)
{
}

template<typename T>
template<typename U>
inline void Rice::Data_Object<T>::
swap(Data_Object<U> & ref)
{
  std::swap(obj_, ref.obj_);
  Object::swap(ref);
}

template<typename T>
inline void Rice::Data_Object<T>::
check_cpp_type(Data_Type<T> const & /* klass */)
{
}

template<typename T>
Rice::Object Rice::detail::to_ruby_<Rice::Data_Object<T> >::
convert(Rice::Data_Object<T> const & x)
{
  return x;
}

#endif // Rice__Data_Object__ipp_



<|start_filename|>rice/Identifier.cpp<|end_filename|>
#include "Symbol.hpp"

Rice::Identifier::
Identifier(Symbol const & symbol)
  : id_(SYM2ID(symbol.value()))
{
}



<|start_filename|>rice/Array.hpp<|end_filename|>
#ifndef Rice__Array__hpp_
#define Rice__Array__hpp_

#include "Builtin_Object.hpp"
#include "to_from_ruby_defn.hpp"
#include "detail/ruby.hpp"
#include <iterator>

namespace Rice
{

//! A wrapper for the ruby Array class.
/*! This class provides a C++-style interface to ruby's Array class and
 *  its associated rb_ary_* functions.
 *  Example:
 *  \code
 *    Array a;
 *    a.push(String("some string"));
 *    a.push(42);
 *  \endcode
 */
class Array
  : public Builtin_Object<RArray, T_ARRAY>
{
public:
  //! Construct a new array
  Array();

  //! Wrap an existing array
  /*! \param v a ruby object, which must be of type T_ARRAY.
   */
  Array(Object v);

  //! Wrap an existing array
  /*! \param v a ruby object, which must be of type T_ARRAY.
   */
  Array(VALUE v);

  //! Construct an array from a sequence.
  /*! \param begin an iterator to the beginning of the sequence.
   *  \param end an iterator to the end of the sequence.
   */
  template<typename Iter_T>
  Array(Iter_T begin, Iter_T end);

  //! Construct an Array from a C array.
  /*! \param a a C array of type T and size n.
   */
  template<typename T, size_t n>
  Array(T const (& a)[n]);

public:
  //! Return the size of the array.
  size_t size() const;

  //! Return the element at the given index.
  /*! \param index The index of the desired element.  The index may be
   *  negative, to indicate an offset from the end of the array.  If the
   *  index is out of bounds, this function has undefined behavior.
   *  \return the element at the given index.
   */
  Object operator[](ptrdiff_t index) const;

private:
  //! A helper class so array[index]=value can work.
  class Proxy;

public:
  //! Return a reference to the element at the given index.
  /*! \param index The index of the desired element.  The index may be
   *  negative, to indicate an offset from the end of the array.  If the
   *  index is out of bounds, this function has undefined behavior.
   *  \return the element at the given index.
   */
  Proxy operator[](ptrdiff_t index);

  //! Push an element onto the end of the array
  /*! \param v an object to push onto the array.
   *  \return the object which was pushed onto the array.
   */
  template<typename T>
  Object push(T const & obj);

  //! Pop an element from the end of the array
  /*! \return the object which was popped from the array, or Qnil if
   *  the array was empty.
   */
  Object pop();

  //! Unshift an element onto the beginning of the array
  /*! \param v an object to unshift onto the array.
   *  \return the object which was unshifted onto the array.
   */
  template<typename T>
  Object unshift(T const & obj);

  //! Shift an element from the beginning of the array
  /*! \return the object which was shifted from the array.
   */
  Object shift();

  //! Return a pointer to the beginning of the underlying C array.
  //! Use with caution!
  /*! \return a pointer to the beginning of the array.
   */
  VALUE * to_c_array();

private:
  template<typename Array_Ref_T, typename Value_T>
  class Iterator;

  size_t position_of(ptrdiff_t index) const;

public:
  //! An iterator.
  typedef Iterator<Array &, Proxy> iterator;

  //! A const iterator.
  typedef Iterator<Array const &, Object> const_iterator;

  //! Return an iterator to the beginning of the array.
  iterator begin();

  //! Return a const iterator to the beginning of the array.
  const_iterator begin() const;

  //! Return an iterator to the end of the array.
  iterator end();

  //! Return a const iterator to the end of the array.
  const_iterator end() const;
};

//! A helper class so array[index]=value can work.
class Array::Proxy
{
public:
  //! Construct a new Proxy
  Proxy(Array array, size_t index);

  //! Implicit conversion to Object.
  operator Object() const;

  //! Explicit conversion to VALUE.
  VALUE value() const;

  //! Assignment operator.
  template<typename T>
  Object operator=(T const & value);

private:
  Array array_;
  size_t index_;
};

//! A helper class for implementing iterators for a Array.
// TODO: This really should be a random-access iterator.
template<typename Array_Ref_T, typename Value_T>
class Array::Iterator
  : public std::iterator<
      std::forward_iterator_tag,
      Value_T,            // Type
      ptrdiff_t,          // Distance type
      Object *,           // Pointer type
      Value_T &>          // Reference type
{
public:
  Iterator(Array_Ref_T array, size_t index);

  template<typename Array_Ref_T_, typename Value_T_>
  Iterator(Iterator<Array_Ref_T_, Value_T_> const & rhs);

  template<typename Array_Ref_T_, typename Value_T_>
  Iterator & operator=(Iterator<Array_Ref_T_, Value_T_> const & rhs);

  Iterator & operator++();
  Iterator operator++(int);
  Value_T operator*();
  Object * operator->();

  template<typename Array_Ref_T_, typename Value_T_>
  bool operator==(Iterator<Array_Ref_T_, Value_T_> const & rhs) const;

  template<typename Array_Ref_T_, typename Value_T_>
  bool operator!=(Iterator<Array_Ref_T_, Value_T_> const & rhs) const;

  // Causes ICE on g++ 3.3.3
  // template<typename Array_Ref_T_, typename Value_T_>
  // friend class Iterator;

  Array_Ref_T array() const;
  size_t index() const;

private:
  Array_Ref_T array_;
  size_t index_;

  Object tmp_;
};

} // namespace Rice

template<>
inline
Rice::Array from_ruby<Rice::Array>(Rice::Object x)
{
  return Rice::Array(x);
}

template<>
inline
Rice::Object to_ruby<Rice::Array>(Rice::Array const & x)
{
  return x;
}

#include "Array.ipp"

#endif // Rice__Array__hpp_



<|start_filename|>rice/detail/mininode.hpp<|end_filename|>
#ifndef Rice__detail__mininode__hpp
#define Rice__detail__mininode__hpp

#include "ruby.hpp"

// TODO: This is silly, autoconf...
#undef PACKAGE_NAME
#undef PACKAGE_STRING
#undef PACKAGE_TARNAME
#undef PACKAGE_VERSION

#include "../config.hpp"

// TODO: This is silly, autoconf...
#undef PACKAGE_NAME
#undef PACKAGE_STRING
#undef PACKAGE_TARNAME
#undef PACKAGE_VERSION

#if !defined(HAVE_NODE_H) && !defined(REALLY_HAVE_RUBY_NODE_H)

namespace Rice
{

namespace detail
{

namespace Mininode
{

typedef struct RNode {
  unsigned long flags;
  void * reserved;
  union {
    struct RNode * node;
    VALUE (*cfunc)(ANYARGS);
  } u1;
  union {
    struct RNode * node;
    VALUE value;
  } u2;
  union {
    struct RNode * node;
  } u3;
} NODE;

#define nd_cfnc u1.cfunc
#define nd_rval u2.value

/* TODO: No way to know the correct size of node_type */
enum node_type {
  NODE_FOO,
};

extern "C"
void rb_add_method(VALUE, ID, NODE *, int);

extern "C"
NODE *rb_node_newnode(enum node_type, VALUE, VALUE, VALUE);

template<typename T, typename A0, typename A1, typename A2>
inline NODE * NEW_NODE(T t, A0 a0, A1 a1, A2 a2)
{
  return rb_node_newnode((node_type)t, (VALUE)a0, (VALUE)a1, (VALUE)a2);
}

#define NODE_METHOD Rice::detail::Mininode::get_NODE_METHOD()
#define NODE_FBODY Rice::detail::Mininode::get_NODE_FBODY()
#define NODE_CFUNC Rice::detail::Mininode::get_NODE_CFUNC()
#define NODE_SCOPE Rice::detail::Mininode::get_NODE_SCOPE()
#define NODE_BLOCK Rice::detail::Mininode::get_NODE_BLOCK()
#define NODE_IF Rice::detail::Mininode::get_NODE_IF()
#define NODE_CASE Rice::detail::Mininode::get_NODE_CASE()
#define NODE_WHEN Rice::detail::Mininode::get_NODE_WHEN()
#define NODE_OPT_N Rice::detail::Mininode::get_NODE_OPT_N()
#define NODE_WHILE Rice::detail::Mininode::get_NODE_WHILE()
#define NODE_UNTIL Rice::detail::Mininode::get_NODE_UNTIL()
#define NODE_ITER Rice::detail::Mininode::get_NODE_ITER()
#define NODE_FOR Rice::detail::Mininode::get_NODE_FOR()
#define NODE_BREAK Rice::detail::Mininode::get_NODE_BREAK()
#define NODE_NEXT Rice::detail::Mininode::get_NODE_NEXT()
#define NODE_REDO Rice::detail::Mininode::get_NODE_REDO()
#define NODE_RETRY Rice::detail::Mininode::get_NODE_RETRY()
#define NODE_BEGIN Rice::detail::Mininode::get_NODE_BEGIN()
#define NODE_RESCUE Rice::detail::Mininode::get_NODE_RESCUE()
#define NODE_RESBODY Rice::detail::Mininode::get_NODE_RESBODY()
#define NODE_ENSURE Rice::detail::Mininode::get_NODE_ENSURE()
#define NODE_AND Rice::detail::Mininode::get_NODE_AND()
#define NODE_OR Rice::detail::Mininode::get_NODE_OR()
#define NODE_MASGN Rice::detail::Mininode::get_NODE_MASGN()
#define NODE_LASGN Rice::detail::Mininode::get_NODE_LASGN()
#define NODE_DASGN Rice::detail::Mininode::get_NODE_DASGN()
#define NODE_DASGN_CURR Rice::detail::Mininode::get_NODE_DASGN_CURR()
#define NODE_GASGN Rice::detail::Mininode::get_NODE_GASGN()
#define NODE_IASGN Rice::detail::Mininode::get_NODE_IASGN()
#define NODE_IASGN2 Rice::detail::Mininode::get_NODE_IASGN2()
#define NODE_CDECL Rice::detail::Mininode::get_NODE_CDECL()
#define NODE_CVDECL Rice::detail::Mininode::get_NODE_CVDECL()
#define NODE_OP_ASGN1 Rice::detail::Mininode::get_NODE_OP_ASGN1()
#define NODE_OP_ASGN2 Rice::detail::Mininode::get_NODE_OP_ASGN2()
#define NODE_OP_ASGN_AND Rice::detail::Mininode::get_NODE_OP_ASGN_AND()
#define NODE_OP_ASGN_OR Rice::detail::Mininode::get_NODE_OP_ASGN_OR()
#define NODE_CALL Rice::detail::Mininode::get_NODE_CALL()
#define NODE_FCALL Rice::detail::Mininode::get_NODE_FCALL()
#define NODE_VCALL Rice::detail::Mininode::get_NODE_VCALL()
#define NODE_SUPER Rice::detail::Mininode::get_NODE_SUPER()
#define NODE_ZSUPER Rice::detail::Mininode::get_NODE_ZSUPER()
#define NODE_ARRAY Rice::detail::Mininode::get_NODE_ARRAY()
#define NODE_ZARRAY Rice::detail::Mininode::get_NODE_ZARRAY()
#define NODE_VALUES Rice::detail::Mininode::get_NODE_VALUES()
#define NODE_HASH Rice::detail::Mininode::get_NODE_HASH()
#define NODE_RETURN Rice::detail::Mininode::get_NODE_RETURN()
#define NODE_YIELD Rice::detail::Mininode::get_NODE_YIELD()
#define NODE_LVAR Rice::detail::Mininode::get_NODE_LVAR()
#define NODE_DVAR Rice::detail::Mininode::get_NODE_DVAR()
#define NODE_GVAR Rice::detail::Mininode::get_NODE_GVAR()
#define NODE_IVAR Rice::detail::Mininode::get_NODE_IVAR()
#define NODE_CONST Rice::detail::Mininode::get_NODE_CONST()
#define NODE_CVAR Rice::detail::Mininode::get_NODE_CVAR()
#define NODE_NTH_REF Rice::detail::Mininode::get_NODE_NTH_REF()
#define NODE_BACK_REF Rice::detail::Mininode::get_NODE_BACK_REF()
#define NODE_MATCH Rice::detail::Mininode::get_NODE_MATCH()
#define NODE_MATCH2 Rice::detail::Mininode::get_NODE_MATCH2()
#define NODE_MATCH3 Rice::detail::Mininode::get_NODE_MATCH3()
#define NODE_LIT Rice::detail::Mininode::get_NODE_LIT()
#define NODE_STR Rice::detail::Mininode::get_NODE_STR()
#define NODE_DSTR Rice::detail::Mininode::get_NODE_DSTR()
#define NODE_XSTR Rice::detail::Mininode::get_NODE_XSTR()
#define NODE_DXSTR Rice::detail::Mininode::get_NODE_DXSTR()
#define NODE_EVSTR Rice::detail::Mininode::get_NODE_EVSTR()
#define NODE_DREGX Rice::detail::Mininode::get_NODE_DREGX()
#define NODE_DREGX_ONCE Rice::detail::Mininode::get_NODE_DREGX_ONCE()
#define NODE_ARGS Rice::detail::Mininode::get_NODE_ARGS()
#define NODE_ARGS_AUX Rice::detail::Mininode::get_NODE_ARGS_AUX()
#define NODE_OPT_ARG Rice::detail::Mininode::get_NODE_OPT_ARG()
#define NODE_POSTARG Rice::detail::Mininode::get_NODE_POSTARG()
#define NODE_ARGSCAT Rice::detail::Mininode::get_NODE_ARGSCAT()
#define NODE_ARGSPUSH Rice::detail::Mininode::get_NODE_ARGSPUSH()
#define NODE_SPLAT Rice::detail::Mininode::get_NODE_SPLAT()
#define NODE_TO_ARY Rice::detail::Mininode::get_NODE_TO_ARY()
#define NODE_BLOCK_ARG Rice::detail::Mininode::get_NODE_BLOCK_ARG()
#define NODE_BLOCK_PASS Rice::detail::Mininode::get_NODE_BLOCK_PASS()
#define NODE_DEFN Rice::detail::Mininode::get_NODE_DEFN()
#define NODE_ALIAS Rice::detail::Mininode::get_NODE_ALIAS()
#define NODE_VALIAS Rice::detail::Mininode::get_NODE_VALIAS()
#define NODE_UNDEF Rice::detail::Mininode::get_NODE_UNDEF()
#define NODE_CLASS Rice::detail::Mininode::get_NODE_CLASS()
#define NODE_MODULE Rice::detail::Mininode::get_NODE_MODULE()
#define NODE_SCLASS Rice::detail::Mininode::get_NODE_SCLASS()
#define NODE_COLON2 Rice::detail::Mininode::get_NODE_COLON2()
#define NODE_COLON3 Rice::detail::Mininode::get_NODE_COLON3()
#define NODE_DOT2 Rice::detail::Mininode::get_NODE_DOT2()
#define NODE_DOT3 Rice::detail::Mininode::get_NODE_DOT3()
#define NODE_FLIP2 Rice::detail::Mininode::get_NODE_FLIP2()
#define NODE_FLIP3 Rice::detail::Mininode::get_NODE_FLIP3()
#define NODE_ATTRSET Rice::detail::Mininode::get_NODE_ATTRSET()
#define NODE_SELF Rice::detail::Mininode::get_NODE_SELF()
#define NODE_NIL Rice::detail::Mininode::get_NODE_NIL()
#define NODE_TRUE Rice::detail::Mininode::get_NODE_TRUE()
#define NODE_FALSE Rice::detail::Mininode::get_NODE_FALSE()
#define NODE_ERRINFO Rice::detail::Mininode::get_NODE_ERRINFO()
#define NODE_DEFINED Rice::detail::Mininode::get_NODE_DEFINED()
#define NODE_POSTEXE Rice::detail::Mininode::get_NODE_POSTEXE()
#define NODE_ALLOCA Rice::detail::Mininode::get_NODE_ALLOCA()
#define NODE_BMETHOD Rice::detail::Mininode::get_NODE_BMETHOD()
#define NODE_MEMO Rice::detail::Mininode::get_NODE_MEMO()
#define NODE_IFUNC Rice::detail::Mininode::get_NODE_IFUNC()
#define NODE_DSYM Rice::detail::Mininode::get_NODE_DSYM()
#define NODE_ATTRASGN Rice::detail::Mininode::get_NODE_ATTRASGN()
#define NODE_PRELUDE Rice::detail::Mininode::get_NODE_PRELUDE()
#define NODE_LAMBDA Rice::detail::Mininode::get_NODE_LAMBDA()
#define NODE_OPTBLOCK Rice::detail::Mininode::get_NODE_OPTBLOCK()
#define NODE_LAST Rice::detail::Mininode::get_NODE_LAST()

int get_NODE_METHOD();
int get_NODE_FBODY();
int get_NODE_CFUNC();
int get_NODE_SCOPE();
int get_NODE_BLOCK();
int get_NODE_IF();
int get_NODE_CASE();
int get_NODE_WHEN();
int get_NODE_OPT_N();
int get_NODE_WHILE();
int get_NODE_UNTIL();
int get_NODE_ITER();
int get_NODE_FOR();
int get_NODE_BREAK();
int get_NODE_NEXT();
int get_NODE_REDO();
int get_NODE_RETRY();
int get_NODE_BEGIN();
int get_NODE_RESCUE();
int get_NODE_RESBODY();
int get_NODE_ENSURE();
int get_NODE_AND();
int get_NODE_OR();
int get_NODE_MASGN();
int get_NODE_LASGN();
int get_NODE_DASGN();
int get_NODE_DASGN_CURR();
int get_NODE_GASGN();
int get_NODE_IASGN();
int get_NODE_IASGN2();
int get_NODE_CDECL();
int get_NODE_CVDECL();
int get_NODE_OP_ASGN1();
int get_NODE_OP_ASGN2();
int get_NODE_OP_ASGN_AND();
int get_NODE_OP_ASGN_OR();
int get_NODE_CALL();
int get_NODE_FCALL();
int get_NODE_VCALL();
int get_NODE_SUPER();
int get_NODE_ZSUPER();
int get_NODE_ARRAY();
int get_NODE_ZARRAY();
int get_NODE_VALUES();
int get_NODE_HASH();
int get_NODE_RETURN();
int get_NODE_YIELD();
int get_NODE_LVAR();
int get_NODE_DVAR();
int get_NODE_GVAR();
int get_NODE_IVAR();
int get_NODE_CONST();
int get_NODE_CVAR();
int get_NODE_NTH_REF();
int get_NODE_BACK_REF();
int get_NODE_MATCH();
int get_NODE_MATCH2();
int get_NODE_MATCH3();
int get_NODE_LIT();
int get_NODE_STR();
int get_NODE_DSTR();
int get_NODE_XSTR();
int get_NODE_DXSTR();
int get_NODE_EVSTR();
int get_NODE_DREGX();
int get_NODE_DREGX_ONCE();
int get_NODE_ARGS();
int get_NODE_ARGS_AUX();
int get_NODE_OPT_ARG();
int get_NODE_POSTARG();
int get_NODE_ARGSCAT();
int get_NODE_ARGSPUSH();
int get_NODE_SPLAT();
int get_NODE_TO_ARY();
int get_NODE_BLOCK_ARG();
int get_NODE_BLOCK_PASS();
int get_NODE_DEFN();
int get_NODE_ALIAS();
int get_NODE_VALIAS();
int get_NODE_UNDEF();
int get_NODE_CLASS();
int get_NODE_MODULE();
int get_NODE_SCLASS();
int get_NODE_COLON2();
int get_NODE_COLON3();
int get_NODE_DOT2();
int get_NODE_DOT3();
int get_NODE_FLIP2();
int get_NODE_FLIP3();
int get_NODE_ATTRSET();
int get_NODE_SELF();
int get_NODE_NIL();
int get_NODE_TRUE();
int get_NODE_FALSE();
int get_NODE_ERRINFO();
int get_NODE_DEFINED();
int get_NODE_POSTEXE();
int get_NODE_ALLOCA();
int get_NODE_BMETHOD();
int get_NODE_MEMO();
int get_NODE_IFUNC();
int get_NODE_DSYM();
int get_NODE_ATTRASGN();
int get_NODE_PRELUDE();
int get_NODE_LAMBDA();
int get_NODE_OPTBLOCK();
int get_NODE_LAST();

static const int NOEX_PUBLIC = 0x0;

inline NODE * NEW_METHOD(NODE * body, VALUE origin, int noex)
{
  return NEW_NODE(NODE_METHOD, origin, body, noex);
}

#ifdef RUBY_VM

inline NODE * NEW_FBODY(NODE * body, ID id)
{
  return NEW_NODE(NODE_FBODY, id, body, 0);
}

#else

inline NODE * NEW_FBODY(NODE * body, ID id, VALUE origin)
{
  return NEW_NODE(NODE_FBODY, body, id, origin);
}

#endif // RUBY_VM

inline NODE * NEW_CFUNC(RUBY_METHOD_FUNC cfunc, int arity)
{
  return NEW_NODE(NODE_CFUNC, cfunc, arity, 0);
}

} // namespace Mininode

} // namespace detail

} // namespace Rice

#endif

#endif // Rice__detail__mininode__hpp



<|start_filename|>test/ext/t1/Foo.hpp<|end_filename|>
#ifndef T1__FOO__HPP_
#define T1__FOO__HPP_

class Foo
{
public:
  int foo() { return 42; }
};

#endif // T1__FOO__HPP_


<|start_filename|>rice/detail/protect.cpp<|end_filename|>
#include "protect.hpp"
#include "../Exception.hpp"
#include "../Jump_Tag.hpp"

#ifndef TAG_RAISE
#define TAG_RAISE 0x6
#endif

VALUE Rice::detail::
protect(
    RUBY_VALUE_FUNC f,
    VALUE arg)
{
  int state = 0;
  VALUE retval = rb_protect(f, arg, &state);
  if(state != 0)
  {
    VALUE err = rb_errinfo();
    if(state == TAG_RAISE && RTEST(err))
    {
      // TODO: convert NoMemoryError into bad_alloc?
      rb_set_errinfo(Rice::Nil);
      throw Rice::Exception(err);
    }
    throw Jump_Tag(state);
  }
  return retval;
}



<|start_filename|>rice/Module.ipp<|end_filename|>
#ifndef Rice__Module__ipp_
#define Rice__Module__ipp_

#include "Module_impl.ipp"

#endif // Rice__Module__ipp_


<|start_filename|>rice/Arg.hpp<|end_filename|>
#ifndef Rice__Arg__hpp_
#define Rice__Arg__hpp_

#include "Arg_impl.hpp"
#include "detail/Arguments.hpp"
#include "Arg_operators.hpp"

#endif // Rice__Arg__hpp_


<|start_filename|>rice/global_function.hpp<|end_filename|>
#ifndef Rice__global_function__hpp_
#define Rice__global_function__hpp_

#include "Arg.hpp"

namespace Rice
{

  /**
   * Helper forwarder method to easily wrap
   * globally available functions. This simply
   * forwards off a call to define_module_function
   * on rb_mKernel
   */
  template<typename Func_T>
  void define_global_function(
      char const * name,
      Func_T func,
      Arguments* arguments = 0);

  // FIXME: See Module::define_method with Arg
  template<typename Func_T>
  void define_global_function(
      char const * name,
      Func_T func,
      Arg const& arg);
  

} // Rice

#include "global_function.ipp"

#endif // Rice__global_function__hpp_


<|start_filename|>rice/Exception_Base.ipp<|end_filename|>
#include "Object.hpp"

inline Rice::Exception_Base::
Exception_Base(VALUE v)
  : Object(v)
{
}

inline Rice::Exception_Base::
~Exception_Base() throw()
{
}



<|start_filename|>rice/Arg_operators.cpp<|end_filename|>
#include "Arg_impl.hpp"
#include "detail/Arguments.hpp"
#include "Arg_operators.hpp"

namespace Rice {

  Arguments* operator,(Arg arg1, Arg arg2)
  {
    Arguments* a = new Arguments();
    a->add(arg1);
    a->add(arg2);
    return a;
  }

  Arguments* operator,(Arguments* arguments, Arg arg)
  {
    arguments->add(arg);
    return arguments;
  }

}
