gecoder-with-gecode 0.9.0-x86-mswin32-60

Sign up to get free protection for your applications and to get access to all the features.
Files changed (203) hide show
  1. data/CHANGES +137 -0
  2. data/COPYING +17 -0
  3. data/LGPL-LICENSE +458 -0
  4. data/README +58 -0
  5. data/Rakefile +14 -0
  6. data/example/equation_system.rb +15 -0
  7. data/example/example_helper.rb +1 -0
  8. data/example/magic_sequence.rb +43 -0
  9. data/example/money.rb +36 -0
  10. data/example/queens.rb +42 -0
  11. data/example/send_more_money.rb +43 -0
  12. data/example/send_most_money.rb +58 -0
  13. data/example/square_tiling.rb +84 -0
  14. data/example/sudoku-set.rb +106 -0
  15. data/example/sudoku.rb +56 -0
  16. data/lib/gecode.dll +0 -0
  17. data/lib/gecoder.rb +5 -0
  18. data/lib/gecoder/bindings.rb +96 -0
  19. data/lib/gecoder/bindings/bindings.rb +2029 -0
  20. data/lib/gecoder/interface.rb +9 -0
  21. data/lib/gecoder/interface/binding_changes.rb +9 -0
  22. data/lib/gecoder/interface/branch.rb +163 -0
  23. data/lib/gecoder/interface/constraints.rb +471 -0
  24. data/lib/gecoder/interface/constraints/bool/boolean.rb +251 -0
  25. data/lib/gecoder/interface/constraints/bool/channel.rb +7 -0
  26. data/lib/gecoder/interface/constraints/bool/linear.rb +200 -0
  27. data/lib/gecoder/interface/constraints/bool_enum/channel.rb +68 -0
  28. data/lib/gecoder/interface/constraints/bool_enum/extensional.rb +106 -0
  29. data/lib/gecoder/interface/constraints/bool_enum/relation.rb +55 -0
  30. data/lib/gecoder/interface/constraints/bool_enum_constraints.rb +84 -0
  31. data/lib/gecoder/interface/constraints/bool_var_constraints.rb +155 -0
  32. data/lib/gecoder/interface/constraints/extensional_regexp.rb +101 -0
  33. data/lib/gecoder/interface/constraints/fixnum_enum/element.rb +63 -0
  34. data/lib/gecoder/interface/constraints/fixnum_enum/operation.rb +65 -0
  35. data/lib/gecoder/interface/constraints/fixnum_enum_constraints.rb +42 -0
  36. data/lib/gecoder/interface/constraints/int/arithmetic.rb +150 -0
  37. data/lib/gecoder/interface/constraints/int/channel.rb +51 -0
  38. data/lib/gecoder/interface/constraints/int/domain.rb +80 -0
  39. data/lib/gecoder/interface/constraints/int/linear.rb +143 -0
  40. data/lib/gecoder/interface/constraints/int/relation.rb +141 -0
  41. data/lib/gecoder/interface/constraints/int_enum/arithmetic.rb +63 -0
  42. data/lib/gecoder/interface/constraints/int_enum/channel.rb +86 -0
  43. data/lib/gecoder/interface/constraints/int_enum/count.rb +66 -0
  44. data/lib/gecoder/interface/constraints/int_enum/distinct.rb +64 -0
  45. data/lib/gecoder/interface/constraints/int_enum/element.rb +64 -0
  46. data/lib/gecoder/interface/constraints/int_enum/equality.rb +37 -0
  47. data/lib/gecoder/interface/constraints/int_enum/extensional.rb +187 -0
  48. data/lib/gecoder/interface/constraints/int_enum/sort.rb +135 -0
  49. data/lib/gecoder/interface/constraints/int_enum_constraints.rb +95 -0
  50. data/lib/gecoder/interface/constraints/int_var_constraints.rb +230 -0
  51. data/lib/gecoder/interface/constraints/reifiable_constraints.rb +78 -0
  52. data/lib/gecoder/interface/constraints/selected_set/select.rb +120 -0
  53. data/lib/gecoder/interface/constraints/selected_set_constraints.rb +75 -0
  54. data/lib/gecoder/interface/constraints/set/cardinality.rb +65 -0
  55. data/lib/gecoder/interface/constraints/set/channel.rb +51 -0
  56. data/lib/gecoder/interface/constraints/set/connection.rb +130 -0
  57. data/lib/gecoder/interface/constraints/set/domain.rb +156 -0
  58. data/lib/gecoder/interface/constraints/set/include.rb +36 -0
  59. data/lib/gecoder/interface/constraints/set/operation.rb +118 -0
  60. data/lib/gecoder/interface/constraints/set/relation.rb +155 -0
  61. data/lib/gecoder/interface/constraints/set_elements/relation.rb +116 -0
  62. data/lib/gecoder/interface/constraints/set_elements_constraints.rb +97 -0
  63. data/lib/gecoder/interface/constraints/set_enum/channel.rb +45 -0
  64. data/lib/gecoder/interface/constraints/set_enum/distinct.rb +43 -0
  65. data/lib/gecoder/interface/constraints/set_enum/operation.rb +69 -0
  66. data/lib/gecoder/interface/constraints/set_enum/select.rb +79 -0
  67. data/lib/gecoder/interface/constraints/set_enum_constraints.rb +84 -0
  68. data/lib/gecoder/interface/constraints/set_var_constraints.rb +243 -0
  69. data/lib/gecoder/interface/enum_matrix.rb +64 -0
  70. data/lib/gecoder/interface/enum_wrapper.rb +205 -0
  71. data/lib/gecoder/interface/model.rb +453 -0
  72. data/lib/gecoder/interface/model_sugar.rb +84 -0
  73. data/lib/gecoder/interface/search.rb +197 -0
  74. data/lib/gecoder/interface/variables.rb +306 -0
  75. data/lib/gecoder/version.rb +4 -0
  76. data/specs/bool_var.rb +81 -0
  77. data/specs/branch.rb +185 -0
  78. data/specs/constraints/bool/boolean.rb +317 -0
  79. data/specs/constraints/bool/boolean_properties.rb +51 -0
  80. data/specs/constraints/bool/linear.rb +213 -0
  81. data/specs/constraints/bool_enum/bool_enum_relation.rb +117 -0
  82. data/specs/constraints/bool_enum/channel.rb +102 -0
  83. data/specs/constraints/bool_enum/extensional.rb +225 -0
  84. data/specs/constraints/constraint_helper.rb +234 -0
  85. data/specs/constraints/constraint_receivers.rb +103 -0
  86. data/specs/constraints/constraints.rb +26 -0
  87. data/specs/constraints/fixnum_enum/element.rb +58 -0
  88. data/specs/constraints/fixnum_enum/operation.rb +67 -0
  89. data/specs/constraints/int/arithmetic.rb +149 -0
  90. data/specs/constraints/int/channel.rb +101 -0
  91. data/specs/constraints/int/domain.rb +106 -0
  92. data/specs/constraints/int/linear.rb +183 -0
  93. data/specs/constraints/int/linear_properties.rb +97 -0
  94. data/specs/constraints/int/relation.rb +84 -0
  95. data/specs/constraints/int_enum/arithmetic.rb +72 -0
  96. data/specs/constraints/int_enum/channel.rb +57 -0
  97. data/specs/constraints/int_enum/count.rb +72 -0
  98. data/specs/constraints/int_enum/distinct.rb +80 -0
  99. data/specs/constraints/int_enum/element.rb +61 -0
  100. data/specs/constraints/int_enum/equality.rb +29 -0
  101. data/specs/constraints/int_enum/extensional.rb +224 -0
  102. data/specs/constraints/int_enum/sort.rb +167 -0
  103. data/specs/constraints/operands.rb +264 -0
  104. data/specs/constraints/property_helper.rb +443 -0
  105. data/specs/constraints/reification_sugar.rb +69 -0
  106. data/specs/constraints/selected_set/select.rb +56 -0
  107. data/specs/constraints/selected_set/select_properties.rb +157 -0
  108. data/specs/constraints/set/cardinality.rb +58 -0
  109. data/specs/constraints/set/cardinality_properties.rb +46 -0
  110. data/specs/constraints/set/channel.rb +77 -0
  111. data/specs/constraints/set/connection.rb +176 -0
  112. data/specs/constraints/set/domain.rb +197 -0
  113. data/specs/constraints/set/include.rb +36 -0
  114. data/specs/constraints/set/operation.rb +132 -0
  115. data/specs/constraints/set/relation.rb +117 -0
  116. data/specs/constraints/set_elements/relation.rb +84 -0
  117. data/specs/constraints/set_enum/channel.rb +80 -0
  118. data/specs/constraints/set_enum/distinct.rb +59 -0
  119. data/specs/constraints/set_enum/operation.rb +111 -0
  120. data/specs/constraints/set_enum/select.rb +73 -0
  121. data/specs/distribution.rb +14 -0
  122. data/specs/enum_matrix.rb +43 -0
  123. data/specs/enum_wrapper.rb +179 -0
  124. data/specs/examples.rb +17 -0
  125. data/specs/int_var.rb +163 -0
  126. data/specs/logging.rb +24 -0
  127. data/specs/model.rb +325 -0
  128. data/specs/model_sugar.rb +30 -0
  129. data/specs/search.rb +383 -0
  130. data/specs/selected_set.rb +39 -0
  131. data/specs/set_elements.rb +34 -0
  132. data/specs/set_var.rb +82 -0
  133. data/specs/spec_helper.rb +265 -0
  134. data/tasks/all_tasks.rb +1 -0
  135. data/tasks/dependencies.txt +22 -0
  136. data/tasks/distribution.rake +194 -0
  137. data/tasks/rcov.rake +18 -0
  138. data/tasks/specs.rake +21 -0
  139. data/tasks/svn.rake +16 -0
  140. data/tasks/website.rake +51 -0
  141. data/vendor/gecode/win32/lib/libgecodeint.dll +0 -0
  142. data/vendor/gecode/win32/lib/libgecodekernel.dll +0 -0
  143. data/vendor/gecode/win32/lib/libgecodeminimodel.dll +0 -0
  144. data/vendor/gecode/win32/lib/libgecodesearch.dll +0 -0
  145. data/vendor/gecode/win32/lib/libgecodeset.dll +0 -0
  146. data/vendor/gecode/win32/lib/libgecodesupport.dll +0 -0
  147. data/vendor/rust/README +28 -0
  148. data/vendor/rust/bin/cxxgenerator.rb +93 -0
  149. data/vendor/rust/include/rust_checks.hh +116 -0
  150. data/vendor/rust/include/rust_conversions.hh +102 -0
  151. data/vendor/rust/rust.rb +67 -0
  152. data/vendor/rust/rust/attribute.rb +51 -0
  153. data/vendor/rust/rust/bindings.rb +172 -0
  154. data/vendor/rust/rust/class.rb +337 -0
  155. data/vendor/rust/rust/constants.rb +48 -0
  156. data/vendor/rust/rust/container.rb +110 -0
  157. data/vendor/rust/rust/cppifaceparser.rb +129 -0
  158. data/vendor/rust/rust/cwrapper.rb +72 -0
  159. data/vendor/rust/rust/cxxclass.rb +96 -0
  160. data/vendor/rust/rust/element.rb +81 -0
  161. data/vendor/rust/rust/enum.rb +63 -0
  162. data/vendor/rust/rust/function.rb +407 -0
  163. data/vendor/rust/rust/namespace.rb +61 -0
  164. data/vendor/rust/rust/templates/AttributeDefinition.rusttpl +17 -0
  165. data/vendor/rust/rust/templates/AttributeInitBinding.rusttpl +9 -0
  166. data/vendor/rust/rust/templates/BindingsHeader.rusttpl +24 -0
  167. data/vendor/rust/rust/templates/BindingsUnit.rusttpl +46 -0
  168. data/vendor/rust/rust/templates/CWrapperClassDefinitions.rusttpl +64 -0
  169. data/vendor/rust/rust/templates/ClassDeclarations.rusttpl +7 -0
  170. data/vendor/rust/rust/templates/ClassInitialize.rusttpl +6 -0
  171. data/vendor/rust/rust/templates/ConstructorStub.rusttpl +21 -0
  172. data/vendor/rust/rust/templates/CxxClassDefinitions.rusttpl +100 -0
  173. data/vendor/rust/rust/templates/CxxMethodStub.rusttpl +12 -0
  174. data/vendor/rust/rust/templates/CxxStandaloneClassDefinitions.rusttpl +26 -0
  175. data/vendor/rust/rust/templates/EnumDeclarations.rusttpl +3 -0
  176. data/vendor/rust/rust/templates/EnumDefinitions.rusttpl +29 -0
  177. data/vendor/rust/rust/templates/FunctionDefinition.rusttpl +9 -0
  178. data/vendor/rust/rust/templates/FunctionInitAlias.rusttpl +5 -0
  179. data/vendor/rust/rust/templates/FunctionInitBinding.rusttpl +9 -0
  180. data/vendor/rust/rust/templates/MethodInitBinding.rusttpl +9 -0
  181. data/vendor/rust/rust/templates/ModuleDeclarations.rusttpl +3 -0
  182. data/vendor/rust/rust/templates/ModuleDefinitions.rusttpl +3 -0
  183. data/vendor/rust/rust/templates/StandaloneClassDeclarations.rusttpl +7 -0
  184. data/vendor/rust/rust/templates/VariableFunctionCall.rusttpl +14 -0
  185. data/vendor/rust/rust/type.rb +98 -0
  186. data/vendor/rust/test/Makefile +4 -0
  187. data/vendor/rust/test/constants.rb +36 -0
  188. data/vendor/rust/test/cppclass.cc +45 -0
  189. data/vendor/rust/test/cppclass.hh +67 -0
  190. data/vendor/rust/test/cppclass.rb +59 -0
  191. data/vendor/rust/test/cwrapper.c +74 -0
  192. data/vendor/rust/test/cwrapper.h +41 -0
  193. data/vendor/rust/test/cwrapper.rb +56 -0
  194. data/vendor/rust/test/dummyclass.hh +31 -0
  195. data/vendor/rust/test/lib/extension-test.rb +98 -0
  196. data/vendor/rust/test/operators.cc +41 -0
  197. data/vendor/rust/test/operators.hh +39 -0
  198. data/vendor/rust/test/operators.rb +39 -0
  199. data/vendor/rust/test/test-constants.rb +43 -0
  200. data/vendor/rust/test/test-cppclass.rb +82 -0
  201. data/vendor/rust/test/test-cwrapper.rb +80 -0
  202. data/vendor/rust/test/test-operators.rb +42 -0
  203. metadata +393 -0
@@ -0,0 +1,61 @@
1
+ # Copyright (c) 2005-2007 Diego Pettenò <flameeyes@gmail.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge,
7
+ # publish, distribute, sublicense, and/or sell copies of the Software,
8
+ # and to permit persons to whom the Software is furnished to do so,
9
+ # subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
18
+ # BE LIABLE
19
+ # FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
20
+ # CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+
23
+ require "rust/container"
24
+ require "rust/cxxclass"
25
+ require "rust/cwrapper"
26
+ require "rust/constants"
27
+
28
+ module Rust
29
+
30
+ class Namespace < Container
31
+ attr_reader :name, :cname, :varname
32
+
33
+ def initialize(name, cname, parent = nil)
34
+ super()
35
+
36
+ @name = name
37
+
38
+ if parent.kind_of?(Namespace)
39
+ cname = "#{parent.cname}::#{cname}"
40
+ end
41
+
42
+ @parent = parent
43
+ @cname = cname == "" ? nil : cname
44
+ @varname = "#{@name.gsub("::", "_")}"
45
+
46
+ @declaration_template = Templates["ModuleDeclarations"]
47
+ @definition_template = Templates["ModuleDefinitions"]
48
+ unless parent.kind_of?(Namespace)
49
+ @initialization_template = "r!namespace_varname! = rb_define_module(\"!module_name!\");\n"
50
+ else
51
+ # TODO this should use the expansion
52
+ @initialization_template = "r!namespace_varname! = rb_define_module_under(r#{parent.varname}, \"#{@name}\");\n"
53
+ end
54
+
55
+ add_expansion 'module_name', 'name'
56
+ add_expansion 'namespace_varname', 'varname'
57
+ end
58
+
59
+ end
60
+
61
+ end
@@ -0,0 +1,17 @@
1
+ //-*-c++-*-
2
+ // Template of a generic C function call
3
+
4
+ VALUE set!parent_varname!!attribute_bindname!(VALUE self, VALUE val) {
5
+ !c_class_name!* tmp = ruby2!class_varcname!Ptr(self);
6
+ if ( ! tmp ) return Qnil;
7
+
8
+ tmp->!attribute_name! = ruby2!attribute_convert_name!(val);
9
+ return Qnil;
10
+ }
11
+
12
+ VALUE get!parent_varname!!attribute_bindname!(VALUE self) {
13
+ !c_class_name!* tmp = ruby2!class_varcname!Ptr(self);
14
+ if ( ! tmp ) return Qnil;
15
+
16
+ return cxx2ruby(static_cast<!attribute_type!>(tmp->!attribute_name!));
17
+ }
@@ -0,0 +1,9 @@
1
+ //-*-c++-*-
2
+ // Template for the init function snippet registering a method.
3
+ // Note that in the case of a method, !parent_varname! would be a
4
+ // synonim for !class_varname!.
5
+
6
+ // Set
7
+ rb_define_method(r!parent_varname!, "!attribute_bindname!=", RUBY_METHOD_FUNC(set!parent_varname!!attribute_bindname!), 1);
8
+ // Get
9
+ rb_define_method(r!parent_varname!, "!attribute_bindname!", RUBY_METHOD_FUNC(get!parent_varname!!attribute_bindname!), 0);
@@ -0,0 +1,24 @@
1
+ //-*-c++-*-
2
+ // General template for the header file (.hh) of the bindings.
3
+ // This is the base that's recursively expanded to create the actual
4
+ // header file.
5
+ //
6
+ // Please note that the ruby header and the C header files coming
7
+ // from the bound library are included with C linkage rules, while
8
+ // the rest of the header follows C++ linkage rules.
9
+
10
+ extern "C" {
11
+ #include <ruby.h>
12
+ !c_includes!
13
+ }
14
+
15
+ !cxx_includes!
16
+
17
+ /* This is for the ptrMap */
18
+ #include <map>
19
+
20
+ namespace Rust_!bindings_name! {
21
+
22
+ !modules_declaration!
23
+
24
+ }
@@ -0,0 +1,46 @@
1
+ //-*-c++-*-
2
+ // General template for the unit file (.cc) of the bindings.
3
+ // This is the base that's recursively expanded to create the actual
4
+ // header file.
5
+ //
6
+ // Please note that the visibility is set to the Init function only
7
+ // if the build processo found it, so that all the other functions
8
+ // and types are actually considered hidden, and thus not exported by
9
+ // the extension. Unfortunately GCC's libstdc++ does not correctly
10
+ // hide all of its symbols yet.
11
+
12
+ // This is needed here because I need to put the rust_conversions.hh
13
+ // include inside these bindings' namespace.
14
+ #include <string>
15
+
16
+ #include "!bindings_name!.hh"
17
+
18
+ #ifdef DEBUG
19
+ #include <stdio.h> /* Used for fprintf */
20
+ #endif
21
+
22
+ namespace Rust_!bindings_name! {
23
+
24
+ #include <rust_conversions.hh>
25
+ #include <rust_checks.hh>
26
+
27
+ !custom_definition!
28
+
29
+ !modules_definition!
30
+
31
+ }
32
+
33
+ using namespace Rust_!bindings_name!;
34
+
35
+ extern "C" {
36
+
37
+ #ifdef HAVE_VISIBILITY
38
+ void Init_!bindings_name!() __attribute__((visibility("default")));
39
+ #endif
40
+
41
+ void Init_!bindings_name!() {
42
+ !modules_initialization!
43
+ !custom_initialization!
44
+ } /* Init_!bindings_name! */
45
+
46
+ }
@@ -0,0 +1,64 @@
1
+ //-*-c++-*-
2
+
3
+ VALUE r!class_varname!;
4
+ T!class_ptrmap! !class_ptrmap!;
5
+
6
+ !c_class_name!* ruby2!class_varcname!Ptr(VALUE rval) {
7
+ !c_class_name!* ptr;
8
+ Data_Get_Struct(rval, !c_class_name!, ptr);
9
+
10
+ if ( ptr ) return reinterpret_cast< !c_class_name!* >(ptr);
11
+
12
+ T!class_ptrmap!::iterator it = !class_ptrmap!.find(rval);
13
+
14
+ if ( it == !class_ptrmap!.end() ) {
15
+ rb_raise(rb_eRuntimeError, "Unable to find !c_class_name! instance for value %x (type %d)\\n", rval, TYPE(rval));
16
+ return NULL;
17
+ }
18
+
19
+ return reinterpret_cast< !c_class_name!* >((*it).second);
20
+ }
21
+
22
+
23
+ !c_class_name!& ruby2!class_varcname!Ptr(VALUE rval) {
24
+ return *ruby2!class_varcname!Ptr(rval);
25
+ }
26
+
27
+
28
+ VALUE cxx2ruby(!c_class_name!* instance) {
29
+ if ( instance == NULL ) return Qnil;
30
+
31
+ T!class_ptrmap!::iterator it, eend = !class_ptrmap!.end();
32
+
33
+ for(it = !class_ptrmap!.begin(); it != eend; it++)
34
+ if ( (*it).second == (!c_class_name!*)instance ) break;
35
+
36
+ if ( it != !class_ptrmap!.end() )
37
+ return (*it).first;
38
+ else {
39
+ VALUE klass = r!class_varname!;
40
+
41
+ VALUE rval = Data_Wrap_Struct(klass, 0, 0, (void*)instance);
42
+ !class_ptrmap![rval] = instance;
43
+
44
+ #ifdef DEBUG
45
+ fprintf(stderr, "rust: wrapping instance %p in value %x (type %d)\\n", instance, rval, TYPE(rval));
46
+ #endif
47
+
48
+ return rval;
49
+ }
50
+ }
51
+
52
+ static VALUE !class_varname!_alloc(VALUE self) {
53
+ return Data_Wrap_Struct(self, 0, !class_free_function!, 0);
54
+ }
55
+
56
+ static void !class_varname!_free(void *p) {
57
+ T!class_ptrmap!::iterator it, eend = !class_ptrmap!.end();
58
+ for(it = !class_ptrmap!.begin(); it != eend; it++)
59
+ if ( (*it).second == (!c_class_name!*)p ) {
60
+ !class_ptrmap!.erase(it); break;
61
+ }
62
+
63
+ !cleanup_functions!;
64
+ }
@@ -0,0 +1,7 @@
1
+ //-*-c++-*-
2
+
3
+ extern VALUE r!class_varname!;
4
+ VALUE cxx2ruby(!c_class_name!* instance, bool free = false, bool create_new_if_needed = true);
5
+ bool is_!class_varname!(VALUE val);
6
+ !c_class_name!* ruby2!class_varcname!Ptr(VALUE rval, int argn = -1);
7
+ !c_class_name!& ruby2!class_varcname!(VALUE rval, int argn = -1);
@@ -0,0 +1,6 @@
1
+ //-*-c++-*-
2
+ // Template for the initialization calls for a C/C++ class
3
+
4
+ r!class_varname! = rb_define_class_under(r!namespace_varname!,
5
+ "!bind_name!", !parent_varname!);
6
+ rb_define_alloc_func(r!class_varname!, !class_varname!_alloc);
@@ -0,0 +1,21 @@
1
+ //-*-c++-*-
2
+ // Template of a C++ Constructor stub, the function used to convert the
3
+ // parameters from Ruby objects to C++, and then call the real C++ constructor.
4
+
5
+ !function_prototype! {
6
+ !c_class_name!* tmp;
7
+ Data_Get_Struct(self, !c_class_name!, tmp);
8
+
9
+ /* The exception is thrown already by ruby2* if not found */
10
+
11
+ !function_call!;
12
+
13
+ DATA_PTR(self) = tmp;
14
+ !class_ptrmap![self] = tmp;
15
+
16
+ #ifdef DEBUG
17
+ fprintf(stderr, "rust: creating new instance of !c_class_name! (%p) with value %x\n", tmp, self);
18
+ #endif
19
+
20
+ return self;
21
+ }
@@ -0,0 +1,100 @@
1
+ //-*-c++-*-
2
+
3
+ VALUE r!class_varname!;
4
+
5
+ bool is_!class_varname!(VALUE val)
6
+ {
7
+ if ( isType(val, T_DATA) )
8
+ {
9
+ !c_class_name! *obj = 0;
10
+
11
+ Data_Get_Struct(val, !c_class_name!, obj);
12
+
13
+ if( obj == 0 ) return false;
14
+
15
+ return rb_obj_is_kind_of(val, r!class_varname!) == Qtrue;
16
+ }
17
+
18
+ return false;
19
+ }
20
+
21
+ !c_class_name!* ruby2!class_varcname!Ptr(VALUE rval, int argn) {
22
+ if(rval == Qnil || rval == 0) return 0;
23
+
24
+ if( ! is_!class_varname!(rval) )
25
+ {
26
+ VALUE klass = rb_funcall(rval, rb_intern("class"), 0);
27
+
28
+ if( argn > 0)
29
+ rb_raise(rb_eArgError, "Expecting !c_class_name! given %s for argument %d", RSTRING(rb_funcall(klass, rb_intern("to_s"), 0))->ptr, argn);
30
+ else
31
+ rb_raise(rb_eArgError, "Expecting !c_class_name! given %s", RSTRING(rb_funcall(klass, rb_intern("to_s"), 0))->ptr, argn);
32
+ return 0;
33
+ }
34
+
35
+ !c_class_name!* ptr;
36
+ Data_Get_Struct(rval, !c_class_name!, ptr);
37
+
38
+ if ( ptr ) return dynamic_cast< !c_class_name!* >(ptr);
39
+
40
+ T!class_ptrmap!::iterator it = !class_ptrmap!.find(rval);
41
+
42
+ if ( it == !class_ptrmap!.end() ) {
43
+ rb_raise(rb_eRuntimeError, "Unable to find !c_class_name! instance for value %x (type %d)\\n", rval, TYPE(rval));
44
+ return NULL;
45
+ }
46
+
47
+ return dynamic_cast< !c_class_name!* >((*it).second);
48
+ }
49
+
50
+ !c_class_name!& ruby2!class_varcname!(VALUE rval, int argn) {
51
+ return *ruby2!class_varcname!Ptr(rval, argn);
52
+ }
53
+
54
+ VALUE cxx2ruby(!c_class_name!* instance, bool free, bool create_new_if_needed) {
55
+ if ( instance == NULL ) return Qnil;
56
+
57
+ T!class_ptrmap!::iterator it, eend = !class_ptrmap!.end();
58
+
59
+ #ifdef DEBUG
60
+ fprintf(stderr, "rust: searching for !c_class_name! %p\n", instance);
61
+ #endif
62
+
63
+ for(it = !class_ptrmap!.begin(); it != eend; it++)
64
+ if ( (*it).second == (!c_class_name!*)instance ) break;
65
+
66
+ if ( it != !class_ptrmap!.end() )
67
+ return (*it).first;
68
+ else {
69
+ #ifdef DEBUG
70
+ fprintf(stderr, "rust: failed to find match for %p\n", instance);
71
+ #endif
72
+ if(!create_new_if_needed) return Qnil;
73
+
74
+ VALUE klass = r!class_varname!;
75
+
76
+ !test_children!
77
+
78
+ VALUE rval;
79
+ if( !free )
80
+ {
81
+ rval = Data_Wrap_Struct(klass, 0, !class_map_free_function!, (void*)instance);
82
+ }
83
+ else
84
+ {
85
+ rval = Data_Wrap_Struct(klass, !class_mark_function!, !class_free_function!, (void*)instance);
86
+ }
87
+
88
+ !class_ptrmap![rval] = instance;
89
+
90
+ #ifdef DEBUG
91
+ fprintf(stderr, "rust: wrapping instance %p in value %x (type %d)\\n", instance, rval, TYPE(rval));
92
+ #endif
93
+
94
+ return rval;
95
+ }
96
+ }
97
+
98
+ static VALUE !class_varname!_alloc(VALUE self) {
99
+ return Data_Wrap_Struct(self, !class_mark_function!, !class_free_function!, 0);
100
+ }
@@ -0,0 +1,12 @@
1
+ //-*-c++-*-
2
+ // Template of a C++ Method stub, the function used to convert the
3
+ // parameters from Ruby objects to C++, and then call the real C++ function.
4
+
5
+ !function_prototype! {
6
+ !c_class_name!* tmp = ruby2!class_varcname!Ptr(self);
7
+ if ( ! tmp ) return Qnil;
8
+
9
+ // The exception is thrown already by ruby2*
10
+
11
+ !function_call!
12
+ }
@@ -0,0 +1,26 @@
1
+ //-*-c++-*-
2
+
3
+ T!class_ptrmap! !class_ptrmap!;
4
+
5
+ static void !class_varname!_free(void *p) {
6
+ !class_map_free_function!(p);
7
+ delete (!c_class_name!*)p;
8
+ }
9
+
10
+ static void !class_varname!_free_map_entry(void *p) {
11
+ #ifdef DEBUG
12
+ fprintf(stderr, "rust: Freeing %p (!class_varname!) \\n", p);
13
+ #endif
14
+
15
+ T!class_ptrmap!::iterator it, eend = !class_ptrmap!.end();
16
+ for(it = !class_ptrmap!.begin(); it != eend; it++)
17
+ if ( (*it).second == (!c_class_name!*)p ) {
18
+ !class_ptrmap!.erase(it); break;
19
+ }
20
+ }
21
+
22
+ static void !class_varname!_mark(void *p) {
23
+ #ifdef DEBUG
24
+ fprintf(stderr, "rust: Marking %p (!class_varname!) \\n", p);
25
+ #endif
26
+ }
@@ -0,0 +1,3 @@
1
+ //-*-c++-*-
2
+
3
+ !enum_cname! ruby2!enum_varname!(VALUE rval, int argn = -1);
@@ -0,0 +1,29 @@
1
+ //-*-c++-*-
2
+
3
+ !enum_cname! ruby2!enum_varname!(VALUE rval, int argn) {
4
+ int cval = ruby2int(rval, argn);
5
+
6
+ switch(cval) {
7
+ !enum_cases!
8
+ return static_cast<!enum_cname!>(cval);
9
+ default:
10
+ if( argn > 0)
11
+ rb_raise(rb_eArgError, "value %d for enum !enum_name! is out of bound for argument %d", cval, argn);
12
+ else
13
+ rb_raise(rb_eArgError, "value %d for enum !enum_name! is out of bound", cval);
14
+ return static_cast<!enum_cname!>(-1);
15
+ }
16
+ }
17
+
18
+ bool is_!enum_varname!(VALUE rval) {
19
+ if( is_int(rval) )
20
+ {
21
+ switch(ruby2int(rval))
22
+ {
23
+ !enum_cases!
24
+ return true;
25
+ }
26
+ }
27
+
28
+ return false;
29
+ }