wurlinc-rice 1.4.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (186) hide show
  1. data/COPYING +23 -0
  2. data/Doxyfile +1253 -0
  3. data/Makefile.am +26 -0
  4. data/README +1119 -0
  5. data/README.mingw +8 -0
  6. data/Rakefile +33 -0
  7. data/bootstrap +9 -0
  8. data/configure.ac +52 -0
  9. data/doxygen.ac +314 -0
  10. data/doxygen.am +186 -0
  11. data/extconf.rb +41 -0
  12. data/post-autoconf.rb +22 -0
  13. data/post-automake.rb +28 -0
  14. data/rice/Address_Registration_Guard.hpp +7 -0
  15. data/rice/Address_Registration_Guard.ipp +34 -0
  16. data/rice/Address_Registration_Guard_defn.hpp +65 -0
  17. data/rice/Allocation_Strategies.hpp +37 -0
  18. data/rice/Arg.hpp +8 -0
  19. data/rice/Arg_impl.hpp +127 -0
  20. data/rice/Arg_operators.cpp +21 -0
  21. data/rice/Arg_operators.hpp +19 -0
  22. data/rice/Array.hpp +220 -0
  23. data/rice/Array.ipp +263 -0
  24. data/rice/Builtin_Object.hpp +8 -0
  25. data/rice/Builtin_Object.ipp +50 -0
  26. data/rice/Builtin_Object_defn.hpp +51 -0
  27. data/rice/Class.cpp +57 -0
  28. data/rice/Class.hpp +8 -0
  29. data/rice/Class.ipp +6 -0
  30. data/rice/Class_defn.hpp +83 -0
  31. data/rice/Constructor.hpp +367 -0
  32. data/rice/Critical_Guard.hpp +40 -0
  33. data/rice/Critical_Guard.ipp +26 -0
  34. data/rice/Data_Object.hpp +8 -0
  35. data/rice/Data_Object.ipp +133 -0
  36. data/rice/Data_Object_defn.hpp +132 -0
  37. data/rice/Data_Type.cpp +54 -0
  38. data/rice/Data_Type.hpp +8 -0
  39. data/rice/Data_Type.ipp +365 -0
  40. data/rice/Data_Type_defn.hpp +261 -0
  41. data/rice/Data_Type_fwd.hpp +12 -0
  42. data/rice/Director.cpp +13 -0
  43. data/rice/Director.hpp +39 -0
  44. data/rice/Enum.hpp +117 -0
  45. data/rice/Enum.ipp +246 -0
  46. data/rice/Exception.cpp +59 -0
  47. data/rice/Exception.hpp +9 -0
  48. data/rice/Exception_Base.hpp +8 -0
  49. data/rice/Exception_Base.ipp +13 -0
  50. data/rice/Exception_Base_defn.hpp +27 -0
  51. data/rice/Exception_defn.hpp +69 -0
  52. data/rice/Hash.hpp +210 -0
  53. data/rice/Hash.ipp +338 -0
  54. data/rice/Identifier.cpp +8 -0
  55. data/rice/Identifier.hpp +50 -0
  56. data/rice/Identifier.ipp +33 -0
  57. data/rice/Jump_Tag.hpp +24 -0
  58. data/rice/Makefile.am +129 -0
  59. data/rice/Module.cpp +84 -0
  60. data/rice/Module.hpp +8 -0
  61. data/rice/Module.ipp +6 -0
  62. data/rice/Module_defn.hpp +88 -0
  63. data/rice/Module_impl.hpp +281 -0
  64. data/rice/Module_impl.ipp +348 -0
  65. data/rice/Object.cpp +160 -0
  66. data/rice/Object.hpp +8 -0
  67. data/rice/Object.ipp +19 -0
  68. data/rice/Object_defn.hpp +191 -0
  69. data/rice/Require_Guard.hpp +21 -0
  70. data/rice/String.cpp +94 -0
  71. data/rice/String.hpp +89 -0
  72. data/rice/Struct.cpp +117 -0
  73. data/rice/Struct.hpp +162 -0
  74. data/rice/Struct.ipp +26 -0
  75. data/rice/Symbol.cpp +25 -0
  76. data/rice/Symbol.hpp +66 -0
  77. data/rice/Symbol.ipp +44 -0
  78. data/rice/VM.cpp +92 -0
  79. data/rice/VM.hpp +32 -0
  80. data/rice/config.hpp.in +40 -0
  81. data/rice/detail/Arguments.hpp +118 -0
  82. data/rice/detail/Auto_Function_Wrapper.hpp +829 -0
  83. data/rice/detail/Auto_Function_Wrapper.ipp +3391 -0
  84. data/rice/detail/Auto_Member_Function_Wrapper.hpp +828 -0
  85. data/rice/detail/Auto_Member_Function_Wrapper.ipp +2503 -0
  86. data/rice/detail/Caster.hpp +103 -0
  87. data/rice/detail/Exception_Handler.hpp +8 -0
  88. data/rice/detail/Exception_Handler.ipp +68 -0
  89. data/rice/detail/Exception_Handler_defn.hpp +96 -0
  90. data/rice/detail/Iterator.hpp +93 -0
  91. data/rice/detail/Not_Copyable.hpp +25 -0
  92. data/rice/detail/Wrapped_Function.hpp +33 -0
  93. data/rice/detail/cfp.hpp +24 -0
  94. data/rice/detail/cfp.ipp +51 -0
  95. data/rice/detail/check_ruby_type.cpp +27 -0
  96. data/rice/detail/check_ruby_type.hpp +23 -0
  97. data/rice/detail/creation_funcs.hpp +37 -0
  98. data/rice/detail/creation_funcs.ipp +36 -0
  99. data/rice/detail/default_allocation_func.hpp +23 -0
  100. data/rice/detail/default_allocation_func.ipp +11 -0
  101. data/rice/detail/define_method_and_auto_wrap.hpp +31 -0
  102. data/rice/detail/define_method_and_auto_wrap.ipp +30 -0
  103. data/rice/detail/demangle.cpp +56 -0
  104. data/rice/detail/demangle.hpp +19 -0
  105. data/rice/detail/env.hpp +19 -0
  106. data/rice/detail/from_ruby.hpp +43 -0
  107. data/rice/detail/from_ruby.ipp +60 -0
  108. data/rice/detail/method_data.cpp +159 -0
  109. data/rice/detail/method_data.hpp +21 -0
  110. data/rice/detail/mininode.cpp +1220 -0
  111. data/rice/detail/mininode.hpp +320 -0
  112. data/rice/detail/node.hpp +13 -0
  113. data/rice/detail/object_call.hpp +68 -0
  114. data/rice/detail/object_call.ipp +131 -0
  115. data/rice/detail/protect.cpp +29 -0
  116. data/rice/detail/protect.hpp +34 -0
  117. data/rice/detail/ruby.hpp +93 -0
  118. data/rice/detail/ruby_version_code.hpp.in +6 -0
  119. data/rice/detail/rubysig.hpp +19 -0
  120. data/rice/detail/st.hpp +60 -0
  121. data/rice/detail/to_ruby.hpp +22 -0
  122. data/rice/detail/to_ruby.ipp +36 -0
  123. data/rice/detail/traits.hpp +43 -0
  124. data/rice/detail/win32.hpp +16 -0
  125. data/rice/detail/wrap_function.hpp +341 -0
  126. data/rice/detail/wrap_function.ipp +514 -0
  127. data/rice/global_function.hpp +33 -0
  128. data/rice/global_function.ipp +22 -0
  129. data/rice/protect.hpp +91 -0
  130. data/rice/protect.ipp +1133 -0
  131. data/rice/ruby_mark.hpp +13 -0
  132. data/rice/ruby_try_catch.hpp +86 -0
  133. data/rice/rubypp.rb +97 -0
  134. data/rice/to_from_ruby.hpp +8 -0
  135. data/rice/to_from_ruby.ipp +297 -0
  136. data/rice/to_from_ruby_defn.hpp +71 -0
  137. data/ruby/Makefile.am +1 -0
  138. data/ruby/lib/Makefile.am +3 -0
  139. data/ruby/lib/mkmf-rice.rb.in +216 -0
  140. data/ruby/lib/version.rb +3 -0
  141. data/ruby.ac +136 -0
  142. data/sample/Makefile.am +47 -0
  143. data/sample/enum/extconf.rb +3 -0
  144. data/sample/enum/sample_enum.cpp +54 -0
  145. data/sample/enum/test.rb +8 -0
  146. data/sample/inheritance/animals.cpp +98 -0
  147. data/sample/inheritance/extconf.rb +3 -0
  148. data/sample/inheritance/test.rb +7 -0
  149. data/sample/map/extconf.rb +3 -0
  150. data/sample/map/map.cpp +81 -0
  151. data/sample/map/test.rb +7 -0
  152. data/test/Makefile.am +78 -0
  153. data/test/ext/Makefile.am +43 -0
  154. data/test/ext/t1/Foo.hpp +10 -0
  155. data/test/ext/t1/extconf.rb +2 -0
  156. data/test/ext/t1/t1.cpp +15 -0
  157. data/test/ext/t2/extconf.rb +2 -0
  158. data/test/ext/t2/t2.cpp +11 -0
  159. data/test/test_Address_Registration_Guard.cpp +43 -0
  160. data/test/test_Allocation_Strategies.cpp +77 -0
  161. data/test/test_Array.cpp +241 -0
  162. data/test/test_Builtin_Object.cpp +72 -0
  163. data/test/test_Class.cpp +498 -0
  164. data/test/test_Constructor.cpp +128 -0
  165. data/test/test_Critical_Guard.cpp +51 -0
  166. data/test/test_Data_Object.cpp +275 -0
  167. data/test/test_Data_Type.cpp +348 -0
  168. data/test/test_Director.cpp +301 -0
  169. data/test/test_Enum.cpp +195 -0
  170. data/test/test_Exception.cpp +46 -0
  171. data/test/test_Hash.cpp +195 -0
  172. data/test/test_Identifier.cpp +70 -0
  173. data/test/test_Jump_Tag.cpp +17 -0
  174. data/test/test_Memory_Management.cpp +50 -0
  175. data/test/test_Module.cpp +481 -0
  176. data/test/test_Object.cpp +148 -0
  177. data/test/test_String.cpp +94 -0
  178. data/test/test_Struct.cpp +192 -0
  179. data/test/test_Symbol.cpp +63 -0
  180. data/test/test_To_From_Ruby.cpp +263 -0
  181. data/test/test_VM.cpp +26 -0
  182. data/test/test_global_functions.cpp +114 -0
  183. data/test/test_rice.rb +43 -0
  184. data/test/unittest.cpp +136 -0
  185. data/test/unittest.hpp +292 -0
  186. metadata +276 -0
data/rice/Struct.hpp ADDED
@@ -0,0 +1,162 @@
1
+ #ifndef Rice__ruby_struct__hpp_
2
+ #define Ruplu__ruby_struct__hpp_
3
+
4
+ #include "Array.hpp"
5
+ #include "Hash.hpp"
6
+ #include "Module.hpp"
7
+ #include "Class.hpp"
8
+ #include "Builtin_Object.hpp"
9
+ #include "Address_Registration_Guard.hpp"
10
+
11
+ namespace Rice
12
+ {
13
+ class Struct;
14
+
15
+ //! Define a new Struct
16
+ Struct define_struct();
17
+
18
+ //! A wrapper for creating Struct classes.
19
+ /*! The Struct class is used for creating new Classes. Note that the
20
+ * notation used here differs slightly from the notation inside the
21
+ * interpreter.
22
+ *
23
+ * Inside the interpreter, calling Struct.new creates a new Class:
24
+ * \code
25
+ * irb(main):001:0> MyStruct = Struct.new(:a, :b, :c)
26
+ * => S
27
+ * irb(main):002:0> MyStruct.class
28
+ * => Class
29
+ * \endcode
30
+ *
31
+ * Instantiating that Class creates an instance of that Class:
32
+ * \code
33
+ * irb(main):003:0> mystruct_instance = MyStruct.new
34
+ * => #<struct MyStruct a=nil, b=nil, c=nil>
35
+ * irb(main):004:0> mystruct_instance.class
36
+ * => MyStruct
37
+ * irb(main):005:0> mystruct_instance.class.ancestors
38
+ * => [MyStruct, Struct, Enumerable, Object, Kernel]
39
+ * \endcode
40
+ *
41
+ * Thus, inside the interpreter, MyStruct is a Class which inherits
42
+ * from Struct, and mystruct_instance is an instance of MyStruct.
43
+ *
44
+ * At the C++ level, we might do this instead:
45
+ * \code
46
+ * Struct rb_cMyStruct = define_struct()
47
+ * .define_member("a")
48
+ * .define_member("b")
49
+ * .define_member("c")
50
+ * .initialize("MyStruct");
51
+ * Struct::Instance mystruct_instance(rb_cMyStruct.new_instance());
52
+ * \endcode
53
+ *
54
+ * Here rb_cMyStruct is an instance of Struct and that mystruct_instance
55
+ * is an instance of Struct::Instance.
56
+ */
57
+ class Struct
58
+ : public Module_impl<Class, Struct>
59
+ {
60
+ public:
61
+ //! Create a new Struct.
62
+ Struct();
63
+
64
+ //! Copy constructor.
65
+ Struct(Struct const & s);
66
+
67
+ //! Destructor.
68
+ virtual ~Struct();
69
+
70
+ //! Define a new Struct member.
71
+ /*! Defines a new member of the Struct. Must be called before the
72
+ * Struct is initialized.
73
+ * \return *this
74
+ */
75
+ Struct & define_member(
76
+ Identifier name);
77
+
78
+ //! Initialize the Struct class.
79
+ /*! Must be called after all Struct members have been defined.
80
+ * \param module the module under which to define the Struct.
81
+ * \param name the name of the Class at the ruby level.
82
+ */
83
+ Struct & initialize(
84
+ Module module,
85
+ Identifier name);
86
+
87
+ //! Get the offset of a member in the Struct.
88
+ /*! Internally, Struct members are stored as a single array of VALUE.
89
+ * This function determines the offset of a given member in that
90
+ * array.
91
+ * \param member the name of the desired member.
92
+ * \return the index of the given member.
93
+ */
94
+ size_t offset_of(Identifier name) const;
95
+
96
+ class Instance;
97
+ friend class Instance;
98
+ friend Struct Rice::define_struct();
99
+
100
+ //! Create a new instance of the Struct
101
+ /*! \param args the arguments to the constructor.
102
+ * \return a new Struct::Instance
103
+ */
104
+ Instance new_instance(Array args = Array()) const;
105
+
106
+ //! Swap with another Struct.
107
+ void swap(Struct & other);
108
+
109
+ Array members() const { return members_; }
110
+
111
+ private:
112
+ Array members_;
113
+ Address_Registration_Guard members_guard_;
114
+
115
+ Hash member_offset_;
116
+ Address_Registration_Guard member_offset_guard_;
117
+ };
118
+
119
+
120
+ //! An instance of a Struct
121
+ //! \sa Struct
122
+ class Struct::Instance
123
+ : public Builtin_Object<RStruct, T_STRUCT>
124
+ {
125
+ public:
126
+ //! Create a new Instance of a Struct.
127
+ /*! \param type the Struct type to create.
128
+ * \param args the initial values for the objects of the instance.
129
+ */
130
+ Instance(
131
+ Struct const & type,
132
+ Array args = Array());
133
+
134
+ //! Encapsulate an existing Struct instance.
135
+ /*! \param type the Struct type to encapsulate.
136
+ * \param s the instance to encapsulate.
137
+ */
138
+ Instance(
139
+ Struct const & type,
140
+ Object s);
141
+
142
+ //! Get a member, given its offset.
143
+ /*! \param index the (integral) index into the Struct's internal
144
+ * array or its name (an Identifier or char const *)
145
+ * \return the member.
146
+ */
147
+ template<typename T>
148
+ Object operator[](T index);
149
+
150
+ //! Swap with another Struct::Instance.
151
+ void swap(Instance & other);
152
+
153
+ private:
154
+ Struct type_;
155
+ };
156
+
157
+ } // namespace Rice
158
+
159
+ #include "Struct.ipp"
160
+
161
+ #endif // Rice__ruby_struct__hpp_
162
+
data/rice/Struct.ipp ADDED
@@ -0,0 +1,26 @@
1
+ namespace Rice
2
+ {
3
+
4
+ template<typename T>
5
+ inline Object Struct::Instance::
6
+ operator[](T index)
7
+ {
8
+ return rb_struct_aref(value(), ULONG2NUM(index));
9
+ }
10
+
11
+ template<>
12
+ inline Object Struct::Instance::
13
+ operator[]<Identifier>(Identifier member)
14
+ {
15
+ size_t index = type_.offset_of(member);
16
+ return (*this)[index];
17
+ }
18
+
19
+ template<>
20
+ inline Object Struct::Instance::
21
+ operator[]<char const *>(char const * name)
22
+ {
23
+ return (*this)[Identifier(name)];
24
+ }
25
+
26
+ } // Rice
data/rice/Symbol.cpp ADDED
@@ -0,0 +1,25 @@
1
+ #include "Symbol.hpp"
2
+
3
+ namespace
4
+ {
5
+ VALUE check_type(Rice::Object value, int type)
6
+ {
7
+ rb_check_type(value, type);
8
+ return Qnil;
9
+ }
10
+ }
11
+
12
+ Rice::Symbol::
13
+ Symbol(VALUE v)
14
+ : Object(v)
15
+ {
16
+ protect(check_type, v, T_SYMBOL);
17
+ }
18
+
19
+ Rice::Symbol::
20
+ Symbol(Object v)
21
+ : Object(v)
22
+ {
23
+ protect(check_type, v, T_SYMBOL);
24
+ }
25
+
data/rice/Symbol.hpp ADDED
@@ -0,0 +1,66 @@
1
+ #ifndef Rice__Symbol__hpp_
2
+ #define Rice__Symbol__hpp_
3
+
4
+ #include "Identifier.hpp"
5
+ #include "Object.hpp"
6
+ #include "detail/ruby.hpp"
7
+ #include <string>
8
+
9
+ namespace Rice
10
+ {
11
+
12
+ //! A wrapper for ruby's Symbol class.
13
+ /*! Symbols are internal identifiers in ruby. They are singletons and
14
+ * can be thought of as frozen strings. They differ from an Identifier
15
+ * in that they are in fact real Objects, but they can be converted
16
+ * back and forth between Identifier and Symbol.
17
+ */
18
+ class Symbol
19
+ : public Object
20
+ {
21
+ public:
22
+ //! Wrap an existing symbol.
23
+ Symbol(VALUE v);
24
+
25
+ //! Wrap an existing symbol.
26
+ Symbol(Object v);
27
+
28
+ //! Construct a Symbol from an Identifier.
29
+ Symbol(Identifier id);
30
+
31
+ //! Construct a Symbol from a null-terminated C string.
32
+ Symbol(char const * s = "");
33
+
34
+ //! Construct a Symbol from an std::string.
35
+ Symbol(std::string const & s);
36
+
37
+ //! Return a string representation of the Symbol.
38
+ char const * c_str() const;
39
+
40
+ //! Return a string representation of the Symbol.
41
+ std::string str() const;
42
+
43
+ //! Return the Symbol as an Identifier.
44
+ Identifier to_id() const;
45
+ };
46
+
47
+ } // namespace Rice
48
+
49
+ template<>
50
+ inline
51
+ Rice::Symbol from_ruby<Rice::Symbol>(Rice::Object x)
52
+ {
53
+ return Rice::Symbol(x);
54
+ }
55
+
56
+ template<>
57
+ inline
58
+ Rice::Object to_ruby<Rice::Symbol>(Rice::Symbol const & x)
59
+ {
60
+ return x;
61
+ }
62
+
63
+ #include "Symbol.ipp"
64
+
65
+ #endif // Rice__Symbol__hpp_
66
+
data/rice/Symbol.ipp ADDED
@@ -0,0 +1,44 @@
1
+ #ifndef Rice__Symbol__ipp_
2
+ #define Rice__Symbol__ipp_
3
+
4
+ #include "protect.hpp"
5
+ #include "detail/ruby.hpp"
6
+
7
+ inline Rice::Symbol::
8
+ Symbol(char const * s)
9
+ : Object(ID2SYM(rb_intern(s)))
10
+ {
11
+ }
12
+
13
+ inline Rice::Symbol::
14
+ Symbol(std::string const & s)
15
+ : Object(ID2SYM(rb_intern(s.c_str())))
16
+ {
17
+ }
18
+
19
+ inline Rice::Symbol::
20
+ Symbol(Identifier id)
21
+ : Object(ID2SYM(id))
22
+ {
23
+ }
24
+
25
+ inline char const * Rice::Symbol::
26
+ c_str() const
27
+ {
28
+ return to_id().c_str();
29
+ }
30
+
31
+ inline std::string Rice::Symbol::
32
+ str() const
33
+ {
34
+ return to_id().str();
35
+ }
36
+
37
+ inline Rice::Identifier Rice::Symbol::
38
+ to_id() const
39
+ {
40
+ return rb_to_id(value());
41
+ }
42
+
43
+ #endif // Rice__Symbol__ipp_
44
+
data/rice/VM.cpp ADDED
@@ -0,0 +1,92 @@
1
+ #include "VM.hpp"
2
+ #include "detail/ruby.hpp"
3
+ #include "detail/env.hpp"
4
+ #include "detail/ruby_version_code.hpp"
5
+
6
+ #include <stdexcept>
7
+
8
+ Rice::VM::
9
+ VM(char * app_name)
10
+ {
11
+ init_stack();
12
+ init(1, &app_name);
13
+ }
14
+
15
+ Rice::VM::
16
+ VM(int argc, char * argv[])
17
+ {
18
+ init_stack();
19
+ init(argc, argv);
20
+ }
21
+
22
+ Rice::VM::
23
+ VM(std::vector<const char *> const & args)
24
+ {
25
+ check_not_initialized();
26
+ init_stack();
27
+ init(args.size(), const_cast<char * *>(&args[0]));
28
+ }
29
+
30
+ Rice::VM::
31
+ ~VM()
32
+ {
33
+ init_stack();
34
+ }
35
+
36
+ #if RICE__RUBY_VERSION_CODE < 186
37
+ extern "C"
38
+ void Init_stack(VALUE *);
39
+ #endif
40
+
41
+ void Rice::VM::
42
+ init_stack()
43
+ {
44
+ #if RICE__RUBY_VERSION_CODE >= 186
45
+ RUBY_INIT_STACK;
46
+ #else
47
+ VALUE v;
48
+ Init_stack(&v);
49
+ #endif
50
+ }
51
+
52
+ void Rice::VM::
53
+ run()
54
+ {
55
+ #if RICE__RUBY_VERSION_CODE >= 190
56
+ ruby_run_node(node_);
57
+ #else
58
+ ruby_run();
59
+ #endif
60
+ }
61
+
62
+ extern "C"
63
+ {
64
+
65
+ #if RICE__RUBY_VERSION_CODE < 190
66
+ RUBY_EXTERN VALUE * rb_gc_stack_start;
67
+ #endif
68
+
69
+ }
70
+
71
+ void Rice::VM::
72
+ check_not_initialized() const
73
+ {
74
+ #if RICE__RUBY_VERSION_CODE < 190
75
+ if(rb_gc_stack_start)
76
+ {
77
+ throw std::runtime_error("Only one VM allowed per application");
78
+ }
79
+ #endif
80
+ // TODO: how to do this check on 1.9?
81
+ }
82
+
83
+ void Rice::VM::
84
+ init(int argc, char * argv[])
85
+ {
86
+ ruby_init();
87
+ #if RICE__RUBY_VERSION_CODE >= 190
88
+ node_ =
89
+ #endif
90
+ ruby_options(argc, argv);
91
+ }
92
+
data/rice/VM.hpp ADDED
@@ -0,0 +1,32 @@
1
+ #ifndef VM__hpp
2
+ #define VM__hpp
3
+
4
+ #include <vector>
5
+ #include "detail/ruby_version_code.hpp"
6
+
7
+ namespace Rice
8
+ {
9
+
10
+ class VM
11
+ {
12
+ public:
13
+ VM(char * app_name);
14
+ VM(int argc, char * argv[]);
15
+ VM(std::vector<const char *> const & args);
16
+ ~VM();
17
+
18
+ void init_stack();
19
+ void run();
20
+
21
+ private:
22
+ void check_not_initialized() const;
23
+ void init(int argc, char * argv[]);
24
+
25
+ #if RICE__RUBY_VERSION_CODE >= 190
26
+ void * node_;
27
+ #endif
28
+ };
29
+
30
+ }
31
+
32
+ #endif // VM__hpp
@@ -0,0 +1,40 @@
1
+ /* rice/config.hpp.in. Generated from configure.ac by autoheader. */
2
+
3
+ /* Define to 1 if you have the <env.h> header file. */
4
+ #undef HAVE_ENV_H
5
+
6
+ /* Define to 1 if you have the <node.h> header file. */
7
+ #undef HAVE_NODE_H
8
+
9
+ /* Define to 1 if you have the <ruby.h> header file. */
10
+ #undef HAVE_RUBY_H
11
+
12
+ /* Define to 1 if you have the <ruby/node.h> header file. */
13
+ #undef HAVE_RUBY_NODE_H
14
+
15
+ /* Define to 1 if you have the <version.h> header file. */
16
+ #undef HAVE_VERSION_H
17
+
18
+ /* Name of package */
19
+ #undef PACKAGE
20
+
21
+ /* Define to the address where bug reports for this package should be sent. */
22
+ #undef PACKAGE_BUGREPORT
23
+
24
+ /* Define to the full name of this package. */
25
+ #undef PACKAGE_NAME
26
+
27
+ /* Define to the full name and version of this package. */
28
+ #undef PACKAGE_STRING
29
+
30
+ /* Define to the one symbol short name of this package. */
31
+ #undef PACKAGE_TARNAME
32
+
33
+ /* Define to the version of this package. */
34
+ #undef PACKAGE_VERSION
35
+
36
+ /* Define this macro to use ruby/node.h */
37
+ #undef REALLY_HAVE_RUBY_NODE_H
38
+
39
+ /* Version number of package */
40
+ #undef VERSION
@@ -0,0 +1,118 @@
1
+ #ifndef Rice__Arguments__hpp_
2
+ #define Rice__Arguments__hpp_
3
+
4
+ #include "../Arg_impl.hpp"
5
+ #include <sstream>
6
+ #include <vector>
7
+ #include "../to_from_ruby_defn.hpp"
8
+
9
+ namespace Rice {
10
+
11
+ class Arguments
12
+ {
13
+ public:
14
+ Arguments() {
15
+ required_ = 0;
16
+ optional_ = 0;
17
+ }
18
+
19
+ ~Arguments() {
20
+ }
21
+
22
+ /**
23
+ * Get the full argument count of this
24
+ * list of arguments.
25
+ * Returns -1 no defined arguments
26
+ */
27
+ int count() {
28
+ if(required_ == 0 && optional_ == 0) {
29
+ return -1;
30
+ } else {
31
+ return required_ + optional_;
32
+ }
33
+ }
34
+
35
+ /**
36
+ * Get the rb_scan_args format string for this
37
+ * list of arguments.
38
+ * In the case of no Args (default case), this
39
+ * method uses the passed in full argument count
40
+ */
41
+ std::string formatString(int fullArgCount)
42
+ {
43
+ std::stringstream s;
44
+ if(required_ == 0 && optional_ == 0)
45
+ {
46
+ s << fullArgCount << 0;
47
+ }
48
+ else
49
+ {
50
+ s << required_ << optional_;
51
+ }
52
+
53
+ return s.str();
54
+ }
55
+
56
+ /**
57
+ * Add a defined Arg to this list of Arguments
58
+ */
59
+ void add(const Arg& arg)
60
+ {
61
+ args_.push_back(arg);
62
+
63
+ if(arg.hasDefaultValue())
64
+ {
65
+ optional_++;
66
+ }
67
+ else
68
+ {
69
+ required_++;
70
+ }
71
+ }
72
+
73
+ /**
74
+ * Is the argument at the request location an optional
75
+ * argument?
76
+ */
77
+ bool isOptional(unsigned int pos)
78
+ {
79
+ if(required_ == 0 && optional_ == 0)
80
+ {
81
+ return false;
82
+ }
83
+ if(pos >= args_.size())
84
+ {
85
+ return false;
86
+ }
87
+ return args_[pos].hasDefaultValue();
88
+ }
89
+
90
+ /**
91
+ * Given a position, a type, and a ruby VALUE, figure out
92
+ * what argument value we need to return according to
93
+ * defaults and if that VALUE is nil or not
94
+ */
95
+ template<typename Arg_T>
96
+ Arg_T getArgumentOrDefault(int pos, VALUE in)
97
+ {
98
+ if(isOptional(pos) && NIL_P(in))
99
+ {
100
+ return args_[pos].getDefaultValue<Arg_T>();
101
+ }
102
+ else
103
+ {
104
+ return from_ruby<Arg_T>(in);
105
+ }
106
+ }
107
+
108
+ private:
109
+ std::vector<Arg> args_;
110
+
111
+ /** Keep counts of required and optional parameters */
112
+ int required_;
113
+ int optional_;
114
+ };
115
+
116
+ }
117
+
118
+ #endif // Rice__Arguments__hpp_