12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- #ifndef HEADER_RUBY_FUNCTOR_HXX
- #define HEADER_RUBY_FUNCTOR_HXX
- #include <iostream>
- #include "ruby.h"
- #include "ruby_object.hpp"
- #include "flexlay_wrap.hpp"
- class RubyFunctor
- {
- private:
- RubyObject val;
- public:
- RubyFunctor(const RubyObject& val_);
- ~RubyFunctor();
- void operator()();
- void operator()(int i);
- void operator()(int x, int y);
-
- static void print_error();
-
- template<class C> void operator()(const C& c)
- {
- if (1) {
- rb_funcall(val.ptr(), rb_intern("call"), 1,
- convert_to_ruby_value(c));
- } else {
-
-
- int state = 0;
- VALUE args[2];
- args[0] = reinterpret_cast<VALUE>(this);
- args[1] = convert_to_ruby_value(c);
- rb_protect(&RubyFunctor::funcall_protect1, reinterpret_cast<VALUE>(args), &state);
- if (state)
- print_error();
- }
- }
- template<class C, class D> void operator()(const C& c, const D& d)
- {
- if (1) {
- rb_funcall(val.ptr(), rb_intern("call"), 2,
- convert_to_ruby_value(c),
- convert_to_ruby_value(d));
- } else {
- std::cout << "Calling operator() with two args" << std::endl;
- int state = 0;
- VALUE args[2];
- args[0] = reinterpret_cast<VALUE>(this);
- args[1] = convert_to_ruby_value(c);
- args[2] = convert_to_ruby_value(d);
- rb_protect(&RubyFunctor::funcall_protect2, reinterpret_cast<VALUE>(args), &state);
- if (state)
- print_error();
- }
- }
-
- static VALUE funcall_protect(VALUE self);
- static VALUE funcall_protect1(VALUE self);
- static VALUE funcall_protect2(VALUE self);
- };
- #endif
|