rice 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/COPYING +23 -0
- data/Doxyfile +1253 -0
- data/Makefile.am +26 -0
- data/Makefile.in +736 -0
- data/README +881 -0
- data/README.mingw +8 -0
- data/bootstrap +8 -0
- data/config.guess +1535 -0
- data/config.sub +1644 -0
- data/configure +7310 -0
- data/configure.ac +48 -0
- data/depcomp +584 -0
- data/doxygen.ac +314 -0
- data/doxygen.am +186 -0
- data/install-sh +507 -0
- data/missing +367 -0
- data/post-autoconf.rb +22 -0
- data/post-automake.rb +28 -0
- data/rice/Address_Registration_Guard.hpp +7 -0
- data/rice/Address_Registration_Guard.ipp +34 -0
- data/rice/Address_Registration_Guard_defn.hpp +65 -0
- data/rice/Allocation_Strategies.hpp +37 -0
- data/rice/Array.hpp +220 -0
- data/rice/Array.ipp +262 -0
- data/rice/Builtin_Object.hpp +8 -0
- data/rice/Builtin_Object.ipp +50 -0
- data/rice/Builtin_Object_defn.hpp +51 -0
- data/rice/Class.cpp +57 -0
- data/rice/Class.hpp +8 -0
- data/rice/Class.ipp +4 -0
- data/rice/Class_defn.hpp +83 -0
- data/rice/Constructor.hpp +189 -0
- data/rice/Critical_Guard.hpp +34 -0
- data/rice/Critical_Guard.ipp +20 -0
- data/rice/Data_Object.hpp +127 -0
- data/rice/Data_Object.ipp +129 -0
- data/rice/Data_Type.cpp +21 -0
- data/rice/Data_Type.hpp +8 -0
- data/rice/Data_Type.ipp +227 -0
- data/rice/Data_Type_defn.hpp +219 -0
- data/rice/Data_Type_fwd.hpp +12 -0
- data/rice/Enum.hpp +118 -0
- data/rice/Enum.ipp +246 -0
- data/rice/Exception.cpp +59 -0
- data/rice/Exception.hpp +69 -0
- data/rice/Exception_Base.hpp +30 -0
- data/rice/Exception_Base.ipp +11 -0
- data/rice/Hash.hpp +206 -0
- data/rice/Hash.ipp +336 -0
- data/rice/Identifier.cpp +8 -0
- data/rice/Identifier.hpp +50 -0
- data/rice/Identifier.ipp +33 -0
- data/rice/Jump_Tag.hpp +24 -0
- data/rice/Makefile.am +112 -0
- data/rice/Makefile.in +675 -0
- data/rice/Module.cpp +75 -0
- data/rice/Module.hpp +8 -0
- data/rice/Module.ipp +6 -0
- data/rice/Module_defn.hpp +87 -0
- data/rice/Module_impl.hpp +237 -0
- data/rice/Module_impl.ipp +302 -0
- data/rice/Object.cpp +153 -0
- data/rice/Object.hpp +8 -0
- data/rice/Object.ipp +19 -0
- data/rice/Object_defn.hpp +183 -0
- data/rice/Require_Guard.hpp +21 -0
- data/rice/String.cpp +93 -0
- data/rice/String.hpp +88 -0
- data/rice/Struct.cpp +117 -0
- data/rice/Struct.hpp +162 -0
- data/rice/Struct.ipp +26 -0
- data/rice/Symbol.cpp +25 -0
- data/rice/Symbol.hpp +66 -0
- data/rice/Symbol.ipp +44 -0
- data/rice/VM.cpp +79 -0
- data/rice/VM.hpp +27 -0
- data/rice/config.hpp +23 -0
- data/rice/config.hpp.in +22 -0
- data/rice/detail/Auto_Function_Wrapper.hpp +719 -0
- data/rice/detail/Auto_Function_Wrapper.ipp +1354 -0
- data/rice/detail/Auto_Member_Function_Wrapper.hpp +685 -0
- data/rice/detail/Auto_Member_Function_Wrapper.ipp +1435 -0
- data/rice/detail/Caster.hpp +61 -0
- data/rice/detail/Exception_Handler.hpp +118 -0
- data/rice/detail/Iterator_Definer.hpp +98 -0
- data/rice/detail/Not_Copyable.hpp +25 -0
- data/rice/detail/Wrapped_Function.hpp +33 -0
- data/rice/detail/check_ruby_type.cpp +21 -0
- data/rice/detail/check_ruby_type.hpp +23 -0
- data/rice/detail/creation_funcs.hpp +45 -0
- data/rice/detail/creation_funcs.ipp +62 -0
- data/rice/detail/default_allocation_func.hpp +23 -0
- data/rice/detail/default_allocation_func.ipp +11 -0
- data/rice/detail/define_method_and_auto_wrap.hpp +27 -0
- data/rice/detail/define_method_and_auto_wrap.ipp +20 -0
- data/rice/detail/env.hpp +13 -0
- data/rice/detail/from_ruby.hpp +43 -0
- data/rice/detail/from_ruby.ipp +74 -0
- data/rice/detail/method_data.cpp +105 -0
- data/rice/detail/method_data.hpp +33 -0
- data/rice/detail/node.hpp +13 -0
- data/rice/detail/object_call.hpp +85 -0
- data/rice/detail/object_call.ipp +147 -0
- data/rice/detail/protect.cpp +27 -0
- data/rice/detail/protect.hpp +34 -0
- data/rice/detail/remove_const.hpp +21 -0
- data/rice/detail/ruby.hpp +85 -0
- data/rice/detail/rubysig.hpp +13 -0
- data/rice/detail/st.hpp +56 -0
- data/rice/detail/to_ruby.hpp +16 -0
- data/rice/detail/to_ruby.ipp +10 -0
- data/rice/detail/win32.hpp +16 -0
- data/rice/detail/wrap_function.hpp +288 -0
- data/rice/detail/wrap_function.ipp +473 -0
- data/rice/generate_code.rb +1092 -0
- data/rice/global_function.hpp +16 -0
- data/rice/global_function.ipp +11 -0
- data/rice/protect.hpp +91 -0
- data/rice/protect.ipp +803 -0
- data/rice/ruby_try_catch.hpp +86 -0
- data/rice/to_from_ruby.hpp +8 -0
- data/rice/to_from_ruby.ipp +299 -0
- data/rice/to_from_ruby_defn.hpp +71 -0
- data/ruby.ac +105 -0
- data/ruby/Makefile.am +1 -0
- data/ruby/Makefile.in +493 -0
- data/ruby/lib/Makefile.am +3 -0
- data/ruby/lib/Makefile.in +369 -0
- data/ruby/lib/mkmf-rice.rb.in +199 -0
- data/sample/Makefile.am +47 -0
- data/sample/Makefile.in +375 -0
- data/sample/enum/extconf.rb +3 -0
- data/sample/enum/sample_enum.cpp +54 -0
- data/sample/enum/test.rb +8 -0
- data/sample/inheritance/animals.cpp +98 -0
- data/sample/inheritance/extconf.rb +3 -0
- data/sample/inheritance/test.rb +7 -0
- data/sample/map/extconf.rb +3 -0
- data/sample/map/map.cpp +81 -0
- data/sample/map/test.rb +7 -0
- data/test/Makefile.am +44 -0
- data/test/Makefile.in +575 -0
- data/test/test_Address_Registration_Guard.cpp +43 -0
- data/test/test_Allocation_Strategies.cpp +77 -0
- data/test/test_Array.cpp +241 -0
- data/test/test_Builtin_Object.cpp +72 -0
- data/test/test_Class.cpp +350 -0
- data/test/test_Constructor.cpp +30 -0
- data/test/test_Critical_Guard.cpp +47 -0
- data/test/test_Data_Object.cpp +235 -0
- data/test/test_Enum.cpp +162 -0
- data/test/test_Exception.cpp +46 -0
- data/test/test_Hash.cpp +195 -0
- data/test/test_Identifier.cpp +70 -0
- data/test/test_Jump_Tag.cpp +17 -0
- data/test/test_Module.cpp +253 -0
- data/test/test_Object.cpp +148 -0
- data/test/test_String.cpp +94 -0
- data/test/test_Struct.cpp +192 -0
- data/test/test_Symbol.cpp +63 -0
- data/test/test_To_From_Ruby.cpp +281 -0
- data/test/test_VM.cpp +26 -0
- data/test/test_rice.rb +30 -0
- data/test/unittest.cpp +136 -0
- data/test/unittest.hpp +292 -0
- metadata +209 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
#ifndef Rice__detail__Caster__hpp_
|
|
2
|
+
#define Rice__detail__Caster__hpp_
|
|
3
|
+
|
|
4
|
+
#include "../Module.hpp"
|
|
5
|
+
#include <stdexcept>
|
|
6
|
+
|
|
7
|
+
namespace Rice
|
|
8
|
+
{
|
|
9
|
+
|
|
10
|
+
namespace detail
|
|
11
|
+
{
|
|
12
|
+
|
|
13
|
+
class Abstract_Caster
|
|
14
|
+
{
|
|
15
|
+
public:
|
|
16
|
+
virtual void * cast_to_base(void * derived, Module type) const = 0;
|
|
17
|
+
virtual ~Abstract_Caster() { }
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
template<typename Derived_T, typename Base_T>
|
|
21
|
+
class Caster
|
|
22
|
+
: public Abstract_Caster
|
|
23
|
+
{
|
|
24
|
+
public:
|
|
25
|
+
Caster(Abstract_Caster * base_caster, Module type)
|
|
26
|
+
: base_caster_(base_caster)
|
|
27
|
+
, type_(type)
|
|
28
|
+
{
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
protected:
|
|
32
|
+
virtual void * cast_to_base(void * derived, Module type) const
|
|
33
|
+
{
|
|
34
|
+
if(type.value() == type_.value())
|
|
35
|
+
{
|
|
36
|
+
Derived_T * d(static_cast<Derived_T *>(derived));
|
|
37
|
+
return static_cast<Base_T *>(d);
|
|
38
|
+
}
|
|
39
|
+
else
|
|
40
|
+
{
|
|
41
|
+
if(base_caster_)
|
|
42
|
+
{
|
|
43
|
+
return base_caster_->cast_to_base(derived, type);
|
|
44
|
+
}
|
|
45
|
+
else
|
|
46
|
+
{
|
|
47
|
+
throw std::runtime_error("bad cast");
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
private:
|
|
53
|
+
Abstract_Caster * base_caster_;
|
|
54
|
+
Module type_;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
} // detail
|
|
58
|
+
|
|
59
|
+
} // Rice
|
|
60
|
+
|
|
61
|
+
#endif //Rice__detail__Caster__hpp_
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
#ifndef Rice__detail__Exception_Handler__hpp_
|
|
2
|
+
#define Rice__detail__Exception_Handler__hpp_
|
|
3
|
+
|
|
4
|
+
#include "ruby.h"
|
|
5
|
+
#undef TYPE
|
|
6
|
+
|
|
7
|
+
namespace Rice
|
|
8
|
+
{
|
|
9
|
+
|
|
10
|
+
namespace detail
|
|
11
|
+
{
|
|
12
|
+
|
|
13
|
+
// A class for converting C++ exceptions to ruby exceptions. It's used
|
|
14
|
+
// like this:
|
|
15
|
+
//
|
|
16
|
+
// try
|
|
17
|
+
// {
|
|
18
|
+
// }
|
|
19
|
+
// catch(...)
|
|
20
|
+
// {
|
|
21
|
+
// handler->handle_exception();
|
|
22
|
+
// }
|
|
23
|
+
//
|
|
24
|
+
// If an exception is thrown the handler will pass the exception up the
|
|
25
|
+
// chain, then the last handler in the chain will throw the exception
|
|
26
|
+
// down the chain until a lower handler can handle it, e.g.:
|
|
27
|
+
//
|
|
28
|
+
// try
|
|
29
|
+
// {
|
|
30
|
+
// return call_next_exception_handler();
|
|
31
|
+
// }
|
|
32
|
+
// catch(MyException const & ex)
|
|
33
|
+
// {
|
|
34
|
+
// throw Rice::Exception(rb_cMyException, "%s", ex.what());
|
|
35
|
+
// }
|
|
36
|
+
//
|
|
37
|
+
class Exception_Handler
|
|
38
|
+
{
|
|
39
|
+
public:
|
|
40
|
+
Exception_Handler(Exception_Handler const * next_exception_handler)
|
|
41
|
+
: next_exception_handler_(next_exception_handler)
|
|
42
|
+
{
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
virtual ~Exception_Handler()
|
|
46
|
+
{
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
virtual VALUE handle_exception() const = 0;
|
|
50
|
+
|
|
51
|
+
VALUE call_next_exception_handler() const
|
|
52
|
+
{
|
|
53
|
+
return next_exception_handler_->handle_exception();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
private:
|
|
57
|
+
Exception_Handler const * next_exception_handler_;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// The default exception handler just rethrows the exception. If there
|
|
61
|
+
// are other handlers in the chain, they will try to handle the rethrown
|
|
62
|
+
// exception.
|
|
63
|
+
class Default_Exception_Handler
|
|
64
|
+
: public Exception_Handler
|
|
65
|
+
{
|
|
66
|
+
public:
|
|
67
|
+
Default_Exception_Handler()
|
|
68
|
+
: Exception_Handler(0)
|
|
69
|
+
{
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
virtual VALUE handle_exception() const
|
|
73
|
+
{
|
|
74
|
+
throw;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
// An exception handler that takes a functor as an argument. The
|
|
79
|
+
// functor should throw a Rice::Exception to handle the exception. If
|
|
80
|
+
// the functor does not handle the exception, the exception will be
|
|
81
|
+
// re-thrown.
|
|
82
|
+
template <typename Exception_T, typename Functor_T>
|
|
83
|
+
class Functor_Exception_Handler
|
|
84
|
+
: public Exception_Handler
|
|
85
|
+
{
|
|
86
|
+
public:
|
|
87
|
+
Functor_Exception_Handler(
|
|
88
|
+
Functor_T handler,
|
|
89
|
+
Exception_Handler const * next_exception_handler)
|
|
90
|
+
: Exception_Handler(next_exception_handler)
|
|
91
|
+
, handler_(handler)
|
|
92
|
+
{
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
private:
|
|
96
|
+
virtual VALUE handle_exception() const
|
|
97
|
+
{
|
|
98
|
+
try
|
|
99
|
+
{
|
|
100
|
+
return call_next_exception_handler();
|
|
101
|
+
}
|
|
102
|
+
catch(Exception_T const & ex)
|
|
103
|
+
{
|
|
104
|
+
handler_(ex);
|
|
105
|
+
throw;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
private:
|
|
110
|
+
Functor_T handler_;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
} // namespace detail
|
|
114
|
+
|
|
115
|
+
} // namespace Rice
|
|
116
|
+
|
|
117
|
+
#endif // Rice__detail__Exception_Handler__hpp_
|
|
118
|
+
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
#ifndef Rice__detail__Iterator_Definer__hpp_
|
|
2
|
+
#define Rice__detail__Iterator_Definer__hpp_
|
|
3
|
+
|
|
4
|
+
#include "method_data.hpp"
|
|
5
|
+
#include "ruby.hpp"
|
|
6
|
+
#include "../protect.hpp"
|
|
7
|
+
#include "../Data_Object.hpp"
|
|
8
|
+
|
|
9
|
+
namespace Rice
|
|
10
|
+
{
|
|
11
|
+
|
|
12
|
+
namespace detail
|
|
13
|
+
{
|
|
14
|
+
|
|
15
|
+
template<typename Derived_T>
|
|
16
|
+
class Iterator_Definer
|
|
17
|
+
{
|
|
18
|
+
public:
|
|
19
|
+
virtual ~Iterator_Definer()
|
|
20
|
+
{
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
class Iterator
|
|
24
|
+
{
|
|
25
|
+
public:
|
|
26
|
+
virtual ~Iterator() { }
|
|
27
|
+
|
|
28
|
+
virtual VALUE call_impl(VALUE self) = 0;
|
|
29
|
+
|
|
30
|
+
static VALUE call(VALUE self)
|
|
31
|
+
{
|
|
32
|
+
void * data = method_data();
|
|
33
|
+
Iterator * iterator = static_cast<Iterator *>(data);
|
|
34
|
+
return iterator->call_impl(self);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
template<typename T, typename Iterator_T>
|
|
39
|
+
class Iterator_Impl
|
|
40
|
+
: public Iterator
|
|
41
|
+
{
|
|
42
|
+
public:
|
|
43
|
+
Iterator_Impl(
|
|
44
|
+
Iterator_T (T::*begin)(),
|
|
45
|
+
Iterator_T (T::*end)(),
|
|
46
|
+
Data_Type<T> data_type)
|
|
47
|
+
: begin_(begin)
|
|
48
|
+
, end_(end)
|
|
49
|
+
, data_type_(data_type)
|
|
50
|
+
{
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
virtual VALUE call_impl(VALUE self)
|
|
54
|
+
{
|
|
55
|
+
Data_Object<T> obj(self, data_type_);
|
|
56
|
+
Iterator_T it = obj->begin();
|
|
57
|
+
Iterator_T end = obj->end();
|
|
58
|
+
for(; it != end; ++it)
|
|
59
|
+
{
|
|
60
|
+
Rice::protect(rb_yield, to_ruby(*it));
|
|
61
|
+
}
|
|
62
|
+
return self;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private:
|
|
66
|
+
Iterator_T (T::*begin_)();
|
|
67
|
+
Iterator_T (T::*end_)();
|
|
68
|
+
Data_Type<T> data_type_;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
template<typename T, typename Iterator_T>
|
|
72
|
+
Derived_T & define_iterator(
|
|
73
|
+
char const * name,
|
|
74
|
+
Iterator_T (T::*begin)(),
|
|
75
|
+
Iterator_T (T::*end)())
|
|
76
|
+
{
|
|
77
|
+
Derived_T & self = static_cast<Derived_T &>(*this);
|
|
78
|
+
// TODO: memory leak!!!!!!!
|
|
79
|
+
Iterator * iterator = new Iterator_Impl<T, Iterator_T>(
|
|
80
|
+
begin,
|
|
81
|
+
end,
|
|
82
|
+
Data_Type<T>(self));
|
|
83
|
+
define_method_with_data(
|
|
84
|
+
static_cast<VALUE>(self),
|
|
85
|
+
name,
|
|
86
|
+
(RUBY_METHOD_FUNC)iterator->call,
|
|
87
|
+
0,
|
|
88
|
+
iterator);
|
|
89
|
+
return self;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
} // namespac edetail
|
|
94
|
+
|
|
95
|
+
} // namespace Rice
|
|
96
|
+
|
|
97
|
+
#endif // Rice__detail__Iterator_Definer__hpp_
|
|
98
|
+
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#ifndef Rice__Not_Copyable__hpp_
|
|
2
|
+
#define Rice__Not_Copyable__hpp_
|
|
3
|
+
|
|
4
|
+
namespace Rice
|
|
5
|
+
{
|
|
6
|
+
|
|
7
|
+
namespace detail
|
|
8
|
+
{
|
|
9
|
+
|
|
10
|
+
// Inherit from Not_Copyable to prevent copying instances of a class.
|
|
11
|
+
class Not_Copyable
|
|
12
|
+
{
|
|
13
|
+
public:
|
|
14
|
+
Not_Copyable() { }
|
|
15
|
+
|
|
16
|
+
private:
|
|
17
|
+
Not_Copyable(Not_Copyable const &);
|
|
18
|
+
Not_Copyable & operator=(Not_Copyable const &);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
} // namespace detail
|
|
22
|
+
|
|
23
|
+
} // namespace Rice
|
|
24
|
+
|
|
25
|
+
#endif // Rice__Not_Copyable__hpp_
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#ifndef Rice__detail__Wrapped_Function__hpp_
|
|
2
|
+
#define Rice__detail__Wrapped_Function__hpp_
|
|
3
|
+
|
|
4
|
+
#include "ruby.hpp"
|
|
5
|
+
|
|
6
|
+
namespace Rice
|
|
7
|
+
{
|
|
8
|
+
|
|
9
|
+
namespace detail
|
|
10
|
+
{
|
|
11
|
+
|
|
12
|
+
class Wrapped_Function
|
|
13
|
+
{
|
|
14
|
+
public:
|
|
15
|
+
Wrapped_Function(RUBY_METHOD_FUNC func, int arity)
|
|
16
|
+
: func_(func)
|
|
17
|
+
, arity_(arity)
|
|
18
|
+
{
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
RUBY_METHOD_FUNC func() const { return func_; }
|
|
22
|
+
int arity() const { return arity_; }
|
|
23
|
+
|
|
24
|
+
private:
|
|
25
|
+
RUBY_METHOD_FUNC func_;
|
|
26
|
+
int arity_;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
} // detail
|
|
30
|
+
|
|
31
|
+
} // Rice
|
|
32
|
+
|
|
33
|
+
#endif // Rice__detail__Wrapped_Function__hpp_
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#include "check_ruby_type.hpp"
|
|
2
|
+
#include "../Exception.hpp"
|
|
3
|
+
|
|
4
|
+
void Rice::detail::
|
|
5
|
+
check_ruby_type(
|
|
6
|
+
VALUE value,
|
|
7
|
+
VALUE klass,
|
|
8
|
+
bool include_super
|
|
9
|
+
)
|
|
10
|
+
{
|
|
11
|
+
if( !rb_obj_is_kind_of(value, klass) ||
|
|
12
|
+
(!include_super && rb_obj_class(value) != klass))
|
|
13
|
+
{
|
|
14
|
+
throw Exception(
|
|
15
|
+
rb_eTypeError,
|
|
16
|
+
"wrong argument type %s (expected %s)",
|
|
17
|
+
STR2CSTR(protect(rb_mod_name, rb_obj_class(value))),
|
|
18
|
+
STR2CSTR(protect(rb_mod_name, klass)));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#ifndef Rice__detail__check_ruby_type__hpp_
|
|
2
|
+
#define Rice__detail__check_ruby_type__hpp_
|
|
3
|
+
|
|
4
|
+
#include "ruby.hpp"
|
|
5
|
+
|
|
6
|
+
namespace Rice
|
|
7
|
+
{
|
|
8
|
+
|
|
9
|
+
namespace detail
|
|
10
|
+
{
|
|
11
|
+
|
|
12
|
+
// Throws an exception if the given object is not of type klass.
|
|
13
|
+
void check_ruby_type(
|
|
14
|
+
VALUE value,
|
|
15
|
+
VALUE klass,
|
|
16
|
+
bool include_super);
|
|
17
|
+
|
|
18
|
+
} // namespace detail
|
|
19
|
+
|
|
20
|
+
} // namespace Rice
|
|
21
|
+
|
|
22
|
+
#endif // Rice__detail__check_ruby_type__hpp_
|
|
23
|
+
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#ifndef Rice__detail__creation_funcs__hpp_
|
|
2
|
+
#define Rice__detail__creation_funcs__hpp_
|
|
3
|
+
|
|
4
|
+
namespace Rice
|
|
5
|
+
{
|
|
6
|
+
|
|
7
|
+
class Class;
|
|
8
|
+
|
|
9
|
+
namespace detail
|
|
10
|
+
{
|
|
11
|
+
|
|
12
|
+
//! Ruby 1.6.x doesn't have rb_define_alloc_func, but Ruby 1.8 will.
|
|
13
|
+
//! It's the "new" way to allocate objects. This function will just
|
|
14
|
+
//! define a singleton new method on older versions of Ruby, and will
|
|
15
|
+
//! call rb_define_alloc_func() on newer versions of Ruby.
|
|
16
|
+
void define_alloc_func(
|
|
17
|
+
Class const & klass,
|
|
18
|
+
RUBY_VALUE_FUNC allocate_func);
|
|
19
|
+
|
|
20
|
+
//! Like define_alloc_func, but allows the user to define an
|
|
21
|
+
//! "initialize" method too.
|
|
22
|
+
template<typename Initialize_Func_T>
|
|
23
|
+
void define_creation_funcs(
|
|
24
|
+
Class const & klass,
|
|
25
|
+
RUBY_VALUE_FUNC allocate_func,
|
|
26
|
+
Initialize_Func_T initialize_func);
|
|
27
|
+
|
|
28
|
+
//! This is just the opposite of define_alloc_func. It can be
|
|
29
|
+
//! used to create a class that cannot be instantiated by the user.
|
|
30
|
+
void undef_alloc_func(
|
|
31
|
+
Class const & klass);
|
|
32
|
+
|
|
33
|
+
//! This is just the opposite of define_creation_func. It can be
|
|
34
|
+
//! used to create a class that cannot be instantiated by the user.
|
|
35
|
+
void undef_creation_funcs(
|
|
36
|
+
Class const & klass);
|
|
37
|
+
|
|
38
|
+
} // namespace detail
|
|
39
|
+
|
|
40
|
+
} // namespace Rice
|
|
41
|
+
|
|
42
|
+
#include "creation_funcs.ipp"
|
|
43
|
+
|
|
44
|
+
#endif // Rice__detail__creation_funcs__hpp_
|
|
45
|
+
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
#ifndef Rice__detail__creation_funcs__ipp_
|
|
2
|
+
#define Rice__detail__creation_funcs__ipp_
|
|
3
|
+
|
|
4
|
+
namespace Rice
|
|
5
|
+
{
|
|
6
|
+
|
|
7
|
+
namespace detail
|
|
8
|
+
{
|
|
9
|
+
|
|
10
|
+
namespace
|
|
11
|
+
{
|
|
12
|
+
inline VALUE ruby_16_new(int argc, VALUE * argv, VALUE klass)
|
|
13
|
+
{
|
|
14
|
+
VALUE obj = rb_funcall(klass, rb_intern("allocate"), 0);
|
|
15
|
+
rb_obj_call_init(obj, argc, argv);
|
|
16
|
+
return obj;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
inline void define_alloc_func(
|
|
21
|
+
Class const & klass,
|
|
22
|
+
RUBY_VALUE_FUNC allocate_func)
|
|
23
|
+
{
|
|
24
|
+
#if RUBY_VERSION_CODE < 170
|
|
25
|
+
klass.define_singleton_method("allocate", allocate_func);
|
|
26
|
+
klass.define_singleton_method("new", ruby_16_new);
|
|
27
|
+
#else
|
|
28
|
+
rb_define_alloc_func(klass, allocate_func);
|
|
29
|
+
#endif
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
template<typename Initialize_Func_T>
|
|
33
|
+
inline void define_creation_funcs(
|
|
34
|
+
Class const & klass,
|
|
35
|
+
RUBY_VALUE_FUNC allocate_func,
|
|
36
|
+
Initialize_Func_T initialize_func)
|
|
37
|
+
{
|
|
38
|
+
define_alloc_func(klass, allocate_func);
|
|
39
|
+
klass.define_method("initialize", initialize_func);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
inline void undef_alloc_func(Class const & klass)
|
|
43
|
+
{
|
|
44
|
+
#if RUBY_VERSION_CODE >= 170
|
|
45
|
+
rb_undef_alloc_func(klass);
|
|
46
|
+
#else
|
|
47
|
+
rb_undef_method(CLASS_OF(klass), "new");
|
|
48
|
+
#endif
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
inline void undef_creation_funcs(Class const & klass)
|
|
52
|
+
{
|
|
53
|
+
undef_alloc_func(klass);
|
|
54
|
+
rb_undef_method(klass, "initialize");
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
} // namespace detail
|
|
58
|
+
|
|
59
|
+
} // namespace Rice
|
|
60
|
+
|
|
61
|
+
#endif // Rice__detail__creation_funcs__ipp_
|
|
62
|
+
|