rice 1.1.0 → 1.2.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.
Files changed (54) hide show
  1. data/Doxyfile +1 -1
  2. data/Makefile.in +3 -2
  3. data/README +247 -16
  4. data/aclocal.m4 +62 -51
  5. data/configure +1585 -1456
  6. data/extconf.rb +9 -1
  7. data/rice/Arg.hpp +8 -0
  8. data/rice/Arg_impl.hpp +124 -0
  9. data/rice/Arg_operators.cpp +21 -0
  10. data/rice/Arg_operators.hpp +19 -0
  11. data/rice/Constructor.hpp +150 -0
  12. data/rice/Data_Type.ipp +51 -6
  13. data/rice/Director.cpp +19 -0
  14. data/rice/Director.hpp +47 -0
  15. data/rice/Enum.hpp +2 -3
  16. data/rice/Enum.ipp +1 -1
  17. data/rice/Hash.hpp +1 -1
  18. data/rice/Makefile.am +7 -0
  19. data/rice/Makefile.in +18 -7
  20. data/rice/Module_impl.hpp +36 -3
  21. data/rice/Module_impl.ipp +56 -7
  22. data/rice/VM.cpp +2 -2
  23. data/rice/config.hpp +1 -1
  24. data/rice/detail/Arguments.hpp +118 -0
  25. data/rice/detail/Auto_Function_Wrapper.hpp +206 -96
  26. data/rice/detail/Auto_Function_Wrapper.ipp +1687 -144
  27. data/rice/detail/Auto_Member_Function_Wrapper.hpp +234 -123
  28. data/rice/detail/Auto_Member_Function_Wrapper.ipp +1133 -306
  29. data/rice/detail/Caster.hpp +3 -1
  30. data/rice/detail/creation_funcs.hpp +0 -8
  31. data/rice/detail/creation_funcs.ipp +1 -27
  32. data/rice/detail/define_method_and_auto_wrap.hpp +3 -1
  33. data/rice/detail/define_method_and_auto_wrap.ipp +4 -3
  34. data/rice/detail/object_call.ipp +1 -1
  35. data/rice/detail/ruby.hpp +1 -33
  36. data/rice/detail/wrap_function.hpp +103 -48
  37. data/rice/detail/wrap_function.ipp +154 -96
  38. data/rice/generate_code.rb +520 -55
  39. data/rice/global_function.hpp +12 -1
  40. data/rice/global_function.ipp +14 -2
  41. data/ruby/Makefile.in +5 -4
  42. data/ruby/lib/Makefile.in +4 -3
  43. data/ruby/lib/version.rb +1 -1
  44. data/sample/Makefile.in +4 -3
  45. data/test/Makefile.am +2 -0
  46. data/test/Makefile.in +32 -13
  47. data/test/test_Class.cpp +36 -14
  48. data/test/test_Constructor.cpp +176 -1
  49. data/test/test_Data_Type.cpp +121 -0
  50. data/test/test_Director.cpp +225 -0
  51. data/test/test_Enum.cpp +33 -0
  52. data/test/test_Module.cpp +175 -0
  53. data/test/test_global_functions.cpp +70 -1
  54. metadata +27 -7
@@ -36,11 +36,10 @@ struct Default_Enum_Traits
36
36
  * Example:
37
37
  * \code
38
38
  * enum Color { Red, Green, Blue };
39
- * Enum<Color> rb_cColor = define_enum<Color>()
39
+ * Enum<Color> rb_cColor = define_enum<Color>("Color")
40
40
  * .define_value("Red", Red)
41
41
  * .define_value("Green", Green)
42
- * .define_value("Blue", Blue)
43
- * .initialize("Color");
42
+ * .define_value("Blue", Blue);
44
43
  * \endcode
45
44
  */
46
45
  template<typename Enum_T, typename Enum_Traits = Default_Enum_Traits<Enum_T> >
@@ -75,7 +75,7 @@ initialize(
75
75
  .define_method("to_i", to_i)
76
76
  .define_method("inspect", inspect)
77
77
  .define_method("<=>", compare)
78
- .define_method("hash", hash)
78
+ //.define_method("hash", hash)
79
79
  .define_method("eql?", eql)
80
80
  .define_method("==", eql)
81
81
  .define_method("===", eql)
@@ -192,7 +192,7 @@ public:
192
192
  private:
193
193
  Hash hash_;
194
194
  st_table * tbl_;
195
- #if RUBY_VERSION_CODE >= 190
195
+ #if RICE__RUBY_VERSION_CODE >= 190
196
196
  st_index_t bin_;
197
197
  #else
198
198
  int bin_;
@@ -3,6 +3,7 @@ lib_LIBRARIES = librice.a
3
3
  librice_a_SOURCES = \
4
4
  Class.cpp \
5
5
  Data_Type.cpp \
6
+ Director.cpp \
6
7
  Exception.cpp \
7
8
  Identifier.cpp \
8
9
  Module.cpp \
@@ -11,6 +12,7 @@ String.cpp \
11
12
  Struct.cpp \
12
13
  Symbol.cpp \
13
14
  VM.cpp \
15
+ Arg_operators.cpp \
14
16
  detail/check_ruby_type.cpp \
15
17
  detail/demangle.cpp \
16
18
  detail/method_data.cpp \
@@ -24,6 +26,9 @@ Address_Registration_Guard_defn.hpp \
24
26
  Allocation_Strategies.hpp \
25
27
  Array.hpp \
26
28
  Array.ipp \
29
+ Arg.hpp \
30
+ Arg_impl.hpp \
31
+ Arg_operators.hpp \
27
32
  Builtin_Object.hpp \
28
33
  Builtin_Object.ipp \
29
34
  Builtin_Object_defn.hpp \
@@ -40,6 +45,7 @@ Data_Type.hpp \
40
45
  Data_Type.ipp \
41
46
  Data_Type_defn.hpp \
42
47
  Data_Type_fwd.hpp \
48
+ Director.hpp \
43
49
  Enum.hpp \
44
50
  Enum.ipp \
45
51
  Exception.hpp \
@@ -82,6 +88,7 @@ detail/Auto_Function_Wrapper.hpp \
82
88
  detail/Auto_Function_Wrapper.ipp \
83
89
  detail/Auto_Member_Function_Wrapper.hpp \
84
90
  detail/Auto_Member_Function_Wrapper.ipp \
91
+ detail/Arguments.hpp \
85
92
  detail/Caster.hpp \
86
93
  detail/Exception_Handler.hpp \
87
94
  detail/Exception_Handler.ipp \
@@ -1,4 +1,4 @@
1
- # Makefile.in generated by automake 1.10.1 from Makefile.am.
1
+ # Makefile.in generated by automake 1.10.2 from Makefile.am.
2
2
  # @configure_input@
3
3
 
4
4
  # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
@@ -58,9 +58,10 @@ ARFLAGS = cru
58
58
  librice_a_AR = $(AR) $(ARFLAGS)
59
59
  librice_a_LIBADD =
60
60
  am_librice_a_OBJECTS = Class.$(OBJEXT) Data_Type.$(OBJEXT) \
61
- Exception.$(OBJEXT) Identifier.$(OBJEXT) Module.$(OBJEXT) \
62
- Object.$(OBJEXT) String.$(OBJEXT) Struct.$(OBJEXT) \
63
- Symbol.$(OBJEXT) VM.$(OBJEXT) check_ruby_type.$(OBJEXT) \
61
+ Director.$(OBJEXT) Exception.$(OBJEXT) Identifier.$(OBJEXT) \
62
+ Module.$(OBJEXT) Object.$(OBJEXT) String.$(OBJEXT) \
63
+ Struct.$(OBJEXT) Symbol.$(OBJEXT) VM.$(OBJEXT) \
64
+ Arg_operators.$(OBJEXT) check_ruby_type.$(OBJEXT) \
64
65
  demangle.$(OBJEXT) method_data.$(OBJEXT) protect.$(OBJEXT) \
65
66
  mininode.$(OBJEXT)
66
67
  librice_a_OBJECTS = $(am_librice_a_OBJECTS)
@@ -206,12 +207,14 @@ sharedstatedir = @sharedstatedir@
206
207
  srcdir = @srcdir@
207
208
  sysconfdir = @sysconfdir@
208
209
  target_alias = @target_alias@
210
+ top_build_prefix = @top_build_prefix@
209
211
  top_builddir = @top_builddir@
210
212
  top_srcdir = @top_srcdir@
211
213
  lib_LIBRARIES = librice.a
212
214
  librice_a_SOURCES = \
213
215
  Class.cpp \
214
216
  Data_Type.cpp \
217
+ Director.cpp \
215
218
  Exception.cpp \
216
219
  Identifier.cpp \
217
220
  Module.cpp \
@@ -220,6 +223,7 @@ String.cpp \
220
223
  Struct.cpp \
221
224
  Symbol.cpp \
222
225
  VM.cpp \
226
+ Arg_operators.cpp \
223
227
  detail/check_ruby_type.cpp \
224
228
  detail/demangle.cpp \
225
229
  detail/method_data.cpp \
@@ -233,6 +237,9 @@ Address_Registration_Guard_defn.hpp \
233
237
  Allocation_Strategies.hpp \
234
238
  Array.hpp \
235
239
  Array.ipp \
240
+ Arg.hpp \
241
+ Arg_impl.hpp \
242
+ Arg_operators.hpp \
236
243
  Builtin_Object.hpp \
237
244
  Builtin_Object.ipp \
238
245
  Builtin_Object_defn.hpp \
@@ -249,6 +256,7 @@ Data_Type.hpp \
249
256
  Data_Type.ipp \
250
257
  Data_Type_defn.hpp \
251
258
  Data_Type_fwd.hpp \
259
+ Director.hpp \
252
260
  Enum.hpp \
253
261
  Enum.ipp \
254
262
  Exception.hpp \
@@ -291,6 +299,7 @@ detail/Auto_Function_Wrapper.hpp \
291
299
  detail/Auto_Function_Wrapper.ipp \
292
300
  detail/Auto_Member_Function_Wrapper.hpp \
293
301
  detail/Auto_Member_Function_Wrapper.ipp \
302
+ detail/Arguments.hpp \
294
303
  detail/Caster.hpp \
295
304
  detail/Exception_Handler.hpp \
296
305
  detail/Exception_Handler.ipp \
@@ -336,8 +345,8 @@ $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
336
345
  @for dep in $?; do \
337
346
  case '$(am__configure_deps)' in \
338
347
  *$$dep*) \
339
- cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
340
- && exit 0; \
348
+ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
349
+ && { if test -f $@; then exit 0; else break; fi; }; \
341
350
  exit 1;; \
342
351
  esac; \
343
352
  done; \
@@ -418,8 +427,10 @@ mostlyclean-compile:
418
427
  distclean-compile:
419
428
  -rm -f *.tab.c
420
429
 
430
+ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Arg_operators.Po@am__quote@
421
431
  @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Class.Po@am__quote@
422
432
  @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Data_Type.Po@am__quote@
433
+ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Director.Po@am__quote@
423
434
  @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Exception.Po@am__quote@
424
435
  @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Identifier.Po@am__quote@
425
436
  @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Module.Po@am__quote@
@@ -542,7 +553,7 @@ ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
542
553
  unique=`for i in $$list; do \
543
554
  if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
544
555
  done | \
545
- $(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \
556
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
546
557
  END { if (nonempty) { for (i in files) print i; }; }'`; \
547
558
  mkid -fID $$unique
548
559
  tags: TAGS
@@ -5,6 +5,7 @@
5
5
  #include "detail/ruby.hpp"
6
6
  #include "Object_defn.hpp"
7
7
  #include "Address_Registration_Guard_defn.hpp"
8
+ #include "Arg.hpp"
8
9
 
9
10
  namespace Rice
10
11
  {
@@ -97,12 +98,24 @@ public:
97
98
  * \param name the name of the method
98
99
  * \param func the implementation of the function, either a function
99
100
  * pointer or a member function pointer.
101
+ * \param arguments the list of arguments of this function, used for
102
+ * defining default parameters (optional)
100
103
  * \return *this
101
104
  */
102
105
  template<typename Func_T>
103
106
  Derived_T & define_method(
104
107
  Identifier name,
105
- Func_T func);
108
+ Func_T func,
109
+ Arguments* arguments = 0);
110
+
111
+ // FIXME There's GOT to be a better way to
112
+ // do this. Handles the case where there is a single
113
+ // argument defined for this method
114
+ template<typename Func_T>
115
+ Derived_T & define_method(
116
+ Identifier name,
117
+ Func_T func,
118
+ Arg const& arg);
106
119
 
107
120
  //! Define a singleton method.
108
121
  /*! The method's implementation can be any function or member
@@ -113,12 +126,22 @@ public:
113
126
  * \param name the name of the method
114
127
  * \param func the implementation of the function, either a function
115
128
  * pointer or a member function pointer.
129
+ * \param arguments the list of arguments of this function, used for
130
+ * defining default parameters (optional)
116
131
  * \return *this
117
132
  */
118
133
  template<typename Func_T>
119
134
  Derived_T & define_singleton_method(
120
135
  Identifier name,
121
- Func_T func);
136
+ Func_T func,
137
+ Arguments* arguments = 0);
138
+
139
+ // FIXME: See define_method with Arg above
140
+ template<typename Func_T>
141
+ Derived_T & define_singleton_method(
142
+ Identifier name,
143
+ Func_T func,
144
+ Arg const& arg);
122
145
 
123
146
  //! Define a module function.
124
147
  /*! A module function is a function that can be accessed either as a
@@ -131,12 +154,22 @@ public:
131
154
  * \param name the name of the method
132
155
  * \param func the implementation of the function, either a function
133
156
  * pointer or a member function pointer.
157
+ * \param arguments the list of arguments of this function, used for
158
+ * defining default parameters (optional)
134
159
  * \return *this
135
160
  */
136
161
  template<typename Func_T>
137
162
  Derived_T & define_module_function(
138
163
  Identifier name,
139
- Func_T func);
164
+ Func_T func,
165
+ Arguments* arguments = 0);
166
+
167
+ // FIXME: See define_method with Arg above
168
+ template<typename Func_T>
169
+ Derived_T & define_module_function(
170
+ Identifier name,
171
+ Func_T func,
172
+ Arg const& arg);
140
173
 
141
174
  //! Define an iterator.
142
175
  /*! Essentially this is a conversion from a C++-style begin/end
@@ -120,13 +120,30 @@ Derived_T &
120
120
  Rice::Module_impl<Base_T, Derived_T>::
121
121
  define_method(
122
122
  Identifier name,
123
- Func_T func)
123
+ Func_T func,
124
+ Arguments* arguments)
124
125
  {
125
126
  detail::define_method_and_auto_wrap(
126
- *this, name, func, this->handler());
127
+ *this, name, func, this->handler(), arguments);
127
128
  return (Derived_T &)*this;
128
129
  }
129
130
 
131
+ template<typename Base_T, typename Derived_T>
132
+ template<typename Func_T>
133
+ inline
134
+ Derived_T &
135
+ Rice::Module_impl<Base_T, Derived_T>::
136
+ define_method(
137
+ Identifier name,
138
+ Func_T func,
139
+ Arg const& arg)
140
+ {
141
+ Arguments* args = new Arguments();
142
+ args->add(arg);
143
+ return define_method(name, func, args);
144
+ }
145
+
146
+
130
147
  template<typename Base_T, typename Derived_T>
131
148
  template<typename Func_T>
132
149
  inline
@@ -134,13 +151,29 @@ Derived_T &
134
151
  Rice::Module_impl<Base_T, Derived_T>::
135
152
  define_singleton_method(
136
153
  Identifier name,
137
- Func_T func)
154
+ Func_T func,
155
+ Arguments* arguments)
138
156
  {
139
157
  detail::define_method_and_auto_wrap(
140
- rb_class_of(*this), name, func, this->handler());
158
+ rb_class_of(*this), name, func, this->handler(), arguments);
141
159
  return (Derived_T &)*this;
142
160
  }
143
161
 
162
+ template<typename Base_T, typename Derived_T>
163
+ template<typename Func_T>
164
+ inline
165
+ Derived_T &
166
+ Rice::Module_impl<Base_T, Derived_T>::
167
+ define_singleton_method(
168
+ Identifier name,
169
+ Func_T func,
170
+ Arg const& arg)
171
+ {
172
+ Arguments* args = new Arguments();
173
+ args->add(arg);
174
+ return define_singleton_method(name, func, args);
175
+ }
176
+
144
177
  template<typename Base_T, typename Derived_T>
145
178
  template<typename Func_T>
146
179
  inline
@@ -148,7 +181,8 @@ Derived_T &
148
181
  Rice::Module_impl<Base_T, Derived_T>::
149
182
  define_module_function(
150
183
  Identifier name,
151
- Func_T func)
184
+ Func_T func,
185
+ Arguments* arguments)
152
186
  {
153
187
  if(this->rb_type() != T_MODULE)
154
188
  {
@@ -157,11 +191,26 @@ define_module_function(
157
191
  "can only define module functions for modules");
158
192
  }
159
193
 
160
- define_method(name, func);
161
- define_singleton_method(name, func);
194
+ define_method(name, func, arguments);
195
+ define_singleton_method(name, func, arguments);
162
196
  return (Derived_T &)*this;
163
197
  }
164
198
 
199
+ template<typename Base_T, typename Derived_T>
200
+ template<typename Func_T>
201
+ inline
202
+ Derived_T &
203
+ Rice::Module_impl<Base_T, Derived_T>::
204
+ define_module_function(
205
+ Identifier name,
206
+ Func_T func,
207
+ Arg const& arg)
208
+ {
209
+ Arguments* args = new Arguments();
210
+ args->add(arg);
211
+ return define_module_function(name, func, args);
212
+ }
213
+
165
214
  template<typename Base_T, typename Derived_T>
166
215
  template<typename T, typename Iterator_T>
167
216
  inline
@@ -33,7 +33,7 @@ Rice::VM::
33
33
  init_stack();
34
34
  }
35
35
 
36
- #if RUBY_VERSION_CODE < 186
36
+ #if RICE__RUBY_VERSION_CODE < 186
37
37
  extern "C"
38
38
  void Init_stack(VALUE *);
39
39
  #endif
@@ -41,7 +41,7 @@ Rice::VM::
41
41
  void Rice::VM::
42
42
  init_stack()
43
43
  {
44
- #if RUBY_VERSION_CODE >= 186
44
+ #if RICE__RUBY_VERSION_CODE >= 186
45
45
  RUBY_INIT_STACK;
46
46
  #else
47
47
  VALUE v;
@@ -8,7 +8,7 @@
8
8
  #define HAVE_NODE_H 1
9
9
 
10
10
  /* Define this macro if rb_class_boot is defined */
11
- #define HAVE_RB_CLASS_BOOT
11
+ #define HAVE_RB_CLASS_BOOT /**/
12
12
 
13
13
  /* Define to 1 if you have the <ruby.h> header file. */
14
14
  #define HAVE_RUBY_H 1
@@ -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
+ const char* 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().c_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_