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,48 @@
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/element'
24
+
25
+ module Rust
26
+ # This class represents a C/C++ constants or enumeration, it is
27
+ # simply going to map a Ruby constant with the given name under its
28
+ # parent with the given value
29
+ class Constant < Element
30
+ def initialize(name, value, parent)
31
+ super()
32
+
33
+ @name = name
34
+ @value = value
35
+ @parent = parent
36
+
37
+ @declaration_template = ""
38
+ @definition_template = ""
39
+ @initialization_template =
40
+ "rb_define_const(r!parent_varname!, \"!name!\", cxx2ruby(!value!));\n"
41
+
42
+ add_expansion 'parent_varname', '@parent.varname'
43
+ add_expansion 'name', '@name'
44
+ add_expansion 'value', '@value'
45
+ end
46
+ end
47
+
48
+ end
@@ -0,0 +1,110 @@
1
+ # Copyright (c) 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/element'
24
+ require 'rust/enum'
25
+
26
+ module Rust
27
+ # This class defines a 'container', an element that can contain
28
+ # functions, constants and classes. Both modules and classes are
29
+ # modules, as you can have singleton methods and constants in both
30
+ # of them
31
+ class Container < Element
32
+ def initialize
33
+ super
34
+
35
+ @functions = {}
36
+ end
37
+
38
+ def add_cxx_class(name, parent = nil)
39
+ klass = CxxClass.new(name, self, parent)
40
+
41
+ yield klass
42
+
43
+ @children << klass
44
+ return klass
45
+ end
46
+
47
+ def add_class_wrapper(name, type)
48
+ klass = ClassWrapper.new(name, type, self)
49
+
50
+ yield klass
51
+
52
+ @children << klass
53
+ return klass
54
+ end
55
+
56
+ def add_function(name, return_value = "void", bindname = name)
57
+ function = Function.new({ :name => name,
58
+ :bindname => bindname,
59
+ :return => return_value,
60
+ :parent => self
61
+ })
62
+
63
+ begin
64
+ yield function
65
+ rescue LocalJumpError
66
+ # Ignore this, we can easily have methods without parameters
67
+ # or other extra informations.
68
+ end if block_given?
69
+
70
+ register_function(function)
71
+
72
+ return function
73
+ end
74
+
75
+ def add_constant(name, value = name)
76
+ @children << Constant.new(name, value, self)
77
+ end
78
+
79
+ def add_enum(name, ctype = nil)
80
+ enum = Enum.new(name, self, ctype)
81
+
82
+ yield enum
83
+
84
+ @children << enum
85
+
86
+ return enum
87
+ end
88
+
89
+ def add_namespace(name, cname = name)
90
+ ns = Namespace.new(name, cname, self)
91
+
92
+ yield ns
93
+
94
+ @children << ns
95
+ end
96
+
97
+
98
+ protected
99
+ def register_function(func)
100
+ key = func.name
101
+ if not @functions.has_key? key
102
+ @functions[key] = func
103
+ @children << func
104
+ else
105
+ @functions[key].add_overload(func)
106
+ end
107
+ end
108
+
109
+ end
110
+ end
@@ -0,0 +1,129 @@
1
+
2
+
3
+ module Rust
4
+
5
+ module Cpp
6
+
7
+ class IfaceParser
8
+ def initialize
9
+ end
10
+
11
+ def parseFile(path)
12
+ lines = ""
13
+ File.open(path) { |f|
14
+ lines = f.readlines.join
15
+ }
16
+
17
+ parse(lines)
18
+ end
19
+
20
+ def parse(cpph)
21
+ classes = []
22
+
23
+ ignore = true
24
+
25
+ # FIXME: remove \n and split by ";" and "*/"
26
+
27
+ cpph.to_s.split(/$/).each { |line|
28
+ line = line.split("//").first
29
+ if line =~ /\/\*/ # open comment
30
+ ignore = true
31
+ end
32
+
33
+ if line =~ /\*\// # close comment
34
+ ignore = false
35
+ end
36
+
37
+ if line =~ /public:/
38
+ ignore = false
39
+ elsif line =~ /private:|protected:/
40
+ ignore = true
41
+ elsif line =~ /class\s+(\w+\s+){0,1}(\w+)/ # function
42
+ if not classes.last.nil?
43
+ if classes.last[:name] == $2
44
+ next
45
+ end
46
+ end
47
+
48
+ classes << {:name => $2, :methods => [], :constructors => [] }
49
+ elsif line =~ /namespace\s+(\w+)\s+\{{0,1}/
50
+ $stderr << "Warning: Namespace will be ignore.\n"
51
+ end
52
+
53
+ if not ignore and classes.last
54
+ parseEntity(line, classes.last)
55
+ end
56
+ }
57
+
58
+ classes.delete_if { |klass|
59
+ klass[:methods].empty?
60
+ }
61
+
62
+ classes
63
+ end
64
+
65
+ private
66
+ def parseEntity(line, klass)
67
+ if line =~ /((\w+::)*\w+)\s+(const\s+){0,1}(\*{0,3}|&){0,1}\s*(\w+)\s*\((.*)\)/
68
+ type = "#{$1}#{$4}"
69
+ fname = $5
70
+ params = []
71
+
72
+ if not $6.nil?
73
+ $6.strip!
74
+ if not $6.empty?
75
+ params = parseParams($6)
76
+ end
77
+ end
78
+
79
+ klass[:methods] << { :name => fname, :type => type, :params => params }
80
+ elsif line =~ /^\s*#{klass[:name]}\s*\((.*)\)/ #constructor
81
+ params = parseParams($1)
82
+ klass[:constructors] << { :params => params }
83
+ end
84
+ end
85
+
86
+ def parseParams(params)
87
+ result = []
88
+ params.split(",").each { |param|
89
+ param = param.split("=").first
90
+ param.strip!
91
+
92
+ if param =~ /((\w+::)*\w+)\s*(const){0,1}(\*{0,3}|&){0,1}(const\s+){0,1}\s*(\w*)\s*$/
93
+ type = "#{$1}#{$2}#{$4}"
94
+
95
+ name = $6
96
+ if name.empty?
97
+ name = "par#{result.size}"
98
+ end
99
+ result << {:type => type, :name => name}
100
+ end
101
+ }
102
+
103
+ result
104
+ end
105
+ end
106
+
107
+ end # Cpp
108
+
109
+ end # Rust
110
+
111
+ if __FILE__ == $0
112
+ parser = Rust::Cpp::IfaceParser.new
113
+
114
+ classes = parser.parseFile(ARGV[0].to_s)
115
+
116
+ classes.each { |klass|
117
+ puts "Class: #{klass[:name]}"
118
+ klass[:methods].each { |method|
119
+ params = "("
120
+
121
+ method[:params].each { |par|
122
+ params += "#{par[:type]} #{par[:name]}, "
123
+ }
124
+ params += ")"
125
+ puts "Method: #{method[:type]} #{method[:name]} #{params};"
126
+ }
127
+ }
128
+ end
129
+
@@ -0,0 +1,72 @@
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
+ module Rust
24
+
25
+ # C class wrapper class, this is used to provide support for those
26
+ # wrappers around C libraries that are bound by Rust.
27
+ class ClassWrapper < Class
28
+ attr_reader :cleanup_functions
29
+
30
+ def initialize(name, type, namespace) # :notnew:
31
+ super(name, namespace)
32
+
33
+ @cname = type
34
+ @varcname = @cname.sub("*", "Ptr").gsub("::", "_").gsub(' ', '')
35
+ @cleanup_functions = ""
36
+
37
+ @definition_template = Templates["CWrapperClassDefinitions"]
38
+ @declaration_template << Templates["StandaloneClassDeclarations"]
39
+
40
+ add_expansion 'cleanup_functions', '@cleanup_functions'
41
+ end
42
+
43
+ def add_constructor(name)
44
+ constructor = super()
45
+
46
+ constructor.name = name
47
+
48
+ return constructor
49
+ end
50
+
51
+ def add_cleanup_function(call)
52
+ @cleanup_functions << call << "\n"
53
+ end
54
+
55
+ # This class is used to represente the constructor of a C++ class
56
+ # bound in a Ruby extension.
57
+ class Constructor < Class::Constructor
58
+ attr_writer :name
59
+
60
+ def raw_call(nparam = nil)
61
+ "tmp = #{super(nparam)}"
62
+ end
63
+ end
64
+
65
+ class Method < Class::Method
66
+ def add_instance_parameter
67
+ add_static_parameter 'tmp'
68
+ end
69
+ end
70
+ end
71
+
72
+ end
@@ -0,0 +1,96 @@
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/class'
24
+
25
+ module Rust
26
+ class CxxClass < Class
27
+ # This function initializes the CxxClass instance by setting the
28
+ # values to the attributes defining its parent, namespace, name
29
+ # and a few other needed information.
30
+ #
31
+ # When a C++ Class is bound that is a child of another class, it
32
+ # shares its highest anchestor's pointer map (as that is the
33
+ # more general pointer type it can be referred to with), and
34
+ # function to call when free()'ing.
35
+ #
36
+ # Don't call this function directly, use Namespace.add_cxx_class
37
+ #
38
+ # *FIXME*: multiple inheritance can make Rust bail out, badly.
39
+ def initialize(name, namespace, parent = nil) # :notnew:
40
+ super(name, namespace)
41
+ @parent = parent
42
+
43
+ @children_classes = []
44
+
45
+ @definition_template = Templates["CxxClassDefinitions"]
46
+
47
+ if @parent
48
+ @ptrmap = @parent.ptrmap
49
+ @function_free = @parent.function_free
50
+ @parent_varname = "r#{@parent.varname}"
51
+ else
52
+ @declaration_template << Templates["StandaloneClassDeclarations"]
53
+ @definition_template << Templates["CxxStandaloneClassDefinitions"]
54
+ end
55
+
56
+ add_expansion 'test_children'
57
+ end
58
+
59
+ def custom_extends(parent)
60
+ @parent_varname = parent
61
+ end
62
+
63
+ # This function is used during ruby to C/C++ conversion of the
64
+ # types, and test for the deepest class the pointer is valid for.
65
+ def test_children
66
+ return unless @children_classes
67
+
68
+ ret = ""
69
+
70
+ @children_classes.each do |klass|
71
+ ret << %@
72
+ if ( dynamic_cast< #{klass.namespace.cname}::#{klass.name}* >(instance) != NULL )
73
+ {
74
+ klass = c#{klass.varname};
75
+ #{klass.test_children}
76
+ }
77
+ @
78
+ end
79
+
80
+ return ret
81
+ end
82
+
83
+ class Method < Class::Method
84
+ def raw_call(nparam = nil)
85
+ "tmp->#{super(nparam)}"
86
+ end
87
+ end
88
+
89
+ class Constructor < Class::Constructor
90
+ def raw_call(nparam = nil)
91
+ "tmp = new #{@parent.namespace.cname}::#{super(nparam)}"
92
+ end
93
+ end
94
+
95
+ end
96
+ end