gecoder-with-gecode 0.7.1-mswin32
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/CHANGES +81 -0
- data/COPYING +17 -0
- data/LGPL-LICENSE +458 -0
- data/README +45 -0
- data/Rakefile +13 -0
- data/example/example_helper.rb +1 -0
- data/example/magic_sequence.rb +43 -0
- data/example/queens.rb +43 -0
- data/example/raw_bindings.rb +42 -0
- data/example/send_more_money.rb +43 -0
- data/example/send_most_money.rb +58 -0
- data/example/square_tiling.rb +84 -0
- data/example/sudoku-set.rb +110 -0
- data/example/sudoku.rb +61 -0
- data/lib/gecode.dll +0 -0
- data/lib/gecoder.rb +5 -0
- data/lib/gecoder/bindings.rb +54 -0
- data/lib/gecoder/bindings/bindings.rb +2210 -0
- data/lib/gecoder/interface.rb +8 -0
- data/lib/gecoder/interface/binding_changes.rb +313 -0
- data/lib/gecoder/interface/branch.rb +152 -0
- data/lib/gecoder/interface/constraints.rb +397 -0
- data/lib/gecoder/interface/constraints/bool/boolean.rb +246 -0
- data/lib/gecoder/interface/constraints/bool/linear.rb +29 -0
- data/lib/gecoder/interface/constraints/bool_enum/boolean.rb +84 -0
- data/lib/gecoder/interface/constraints/bool_enum_constraints.rb +8 -0
- data/lib/gecoder/interface/constraints/bool_var_constraints.rb +75 -0
- data/lib/gecoder/interface/constraints/int/arithmetic.rb +71 -0
- data/lib/gecoder/interface/constraints/int/domain.rb +78 -0
- data/lib/gecoder/interface/constraints/int/linear.rb +295 -0
- data/lib/gecoder/interface/constraints/int_enum/arithmetic.rb +72 -0
- data/lib/gecoder/interface/constraints/int_enum/channel.rb +100 -0
- data/lib/gecoder/interface/constraints/int_enum/count.rb +92 -0
- data/lib/gecoder/interface/constraints/int_enum/distinct.rb +69 -0
- data/lib/gecoder/interface/constraints/int_enum/element.rb +82 -0
- data/lib/gecoder/interface/constraints/int_enum/equality.rb +38 -0
- data/lib/gecoder/interface/constraints/int_enum/sort.rb +126 -0
- data/lib/gecoder/interface/constraints/int_enum_constraints.rb +37 -0
- data/lib/gecoder/interface/constraints/int_var_constraints.rb +58 -0
- data/lib/gecoder/interface/constraints/reifiable_constraints.rb +78 -0
- data/lib/gecoder/interface/constraints/set/cardinality.rb +75 -0
- data/lib/gecoder/interface/constraints/set/connection.rb +193 -0
- data/lib/gecoder/interface/constraints/set/domain.rb +109 -0
- data/lib/gecoder/interface/constraints/set/operation.rb +132 -0
- data/lib/gecoder/interface/constraints/set/relation.rb +178 -0
- data/lib/gecoder/interface/constraints/set_enum/channel.rb +18 -0
- data/lib/gecoder/interface/constraints/set_enum/distinct.rb +80 -0
- data/lib/gecoder/interface/constraints/set_enum/operation.rb +60 -0
- data/lib/gecoder/interface/constraints/set_enum/selection.rb +217 -0
- data/lib/gecoder/interface/constraints/set_enum_constraints.rb +34 -0
- data/lib/gecoder/interface/constraints/set_var_constraints.rb +72 -0
- data/lib/gecoder/interface/enum_matrix.rb +64 -0
- data/lib/gecoder/interface/enum_wrapper.rb +153 -0
- data/lib/gecoder/interface/model.rb +251 -0
- data/lib/gecoder/interface/search.rb +123 -0
- data/lib/gecoder/interface/variables.rb +254 -0
- data/lib/gecoder/version.rb +4 -0
- data/specs/binding_changes.rb +76 -0
- data/specs/bool_var.rb +74 -0
- data/specs/branch.rb +170 -0
- data/specs/constraints/arithmetic.rb +266 -0
- data/specs/constraints/bool_enum.rb +140 -0
- data/specs/constraints/boolean.rb +232 -0
- data/specs/constraints/cardinality.rb +154 -0
- data/specs/constraints/channel.rb +126 -0
- data/specs/constraints/connection.rb +373 -0
- data/specs/constraints/constraint_helper.rb +180 -0
- data/specs/constraints/constraints.rb +74 -0
- data/specs/constraints/count.rb +139 -0
- data/specs/constraints/distinct.rb +218 -0
- data/specs/constraints/element.rb +106 -0
- data/specs/constraints/equality.rb +31 -0
- data/specs/constraints/int_domain.rb +69 -0
- data/specs/constraints/int_relation.rb +78 -0
- data/specs/constraints/linear.rb +332 -0
- data/specs/constraints/reification_sugar.rb +96 -0
- data/specs/constraints/selection.rb +292 -0
- data/specs/constraints/set_domain.rb +181 -0
- data/specs/constraints/set_operation.rb +285 -0
- data/specs/constraints/set_relation.rb +201 -0
- data/specs/constraints/sort.rb +175 -0
- data/specs/distribution.rb +14 -0
- data/specs/enum_matrix.rb +43 -0
- data/specs/enum_wrapper.rb +122 -0
- data/specs/int_var.rb +144 -0
- data/specs/logging.rb +24 -0
- data/specs/model.rb +190 -0
- data/specs/search.rb +246 -0
- data/specs/set_var.rb +68 -0
- data/specs/spec_helper.rb +93 -0
- data/tasks/all_tasks.rb +1 -0
- data/tasks/building.howto +65 -0
- data/tasks/distribution.rake +156 -0
- data/tasks/rcov.rake +17 -0
- data/tasks/specs.rake +15 -0
- data/tasks/svn.rake +11 -0
- data/tasks/website.rake +51 -0
- data/vendor/gecode/win32/lib/libgecodeint.dll +0 -0
- data/vendor/gecode/win32/lib/libgecodekernel.dll +0 -0
- data/vendor/gecode/win32/lib/libgecodeminimodel.dll +0 -0
- data/vendor/gecode/win32/lib/libgecodesearch.dll +0 -0
- data/vendor/gecode/win32/lib/libgecodeset.dll +0 -0
- data/vendor/rust/README +28 -0
- data/vendor/rust/bin/cxxgenerator.rb +93 -0
- data/vendor/rust/include/rust_checks.hh +115 -0
- data/vendor/rust/include/rust_conversions.hh +102 -0
- data/vendor/rust/rust.rb +67 -0
- data/vendor/rust/rust/attribute.rb +51 -0
- data/vendor/rust/rust/bindings.rb +172 -0
- data/vendor/rust/rust/class.rb +339 -0
- data/vendor/rust/rust/constants.rb +48 -0
- data/vendor/rust/rust/container.rb +110 -0
- data/vendor/rust/rust/cppifaceparser.rb +129 -0
- data/vendor/rust/rust/cwrapper.rb +72 -0
- data/vendor/rust/rust/cxxclass.rb +98 -0
- data/vendor/rust/rust/element.rb +81 -0
- data/vendor/rust/rust/enum.rb +63 -0
- data/vendor/rust/rust/function.rb +407 -0
- data/vendor/rust/rust/namespace.rb +61 -0
- data/vendor/rust/rust/templates/AttributeDefinition.rusttpl +17 -0
- data/vendor/rust/rust/templates/AttributeInitBinding.rusttpl +9 -0
- data/vendor/rust/rust/templates/BindingsHeader.rusttpl +24 -0
- data/vendor/rust/rust/templates/BindingsUnit.rusttpl +46 -0
- data/vendor/rust/rust/templates/CWrapperClassDefinitions.rusttpl +64 -0
- data/vendor/rust/rust/templates/ClassDeclarations.rusttpl +7 -0
- data/vendor/rust/rust/templates/ClassInitialize.rusttpl +6 -0
- data/vendor/rust/rust/templates/ConstructorStub.rusttpl +21 -0
- data/vendor/rust/rust/templates/CxxClassDefinitions.rusttpl +91 -0
- data/vendor/rust/rust/templates/CxxMethodStub.rusttpl +12 -0
- data/vendor/rust/rust/templates/CxxStandaloneClassDefinitions.rusttpl +26 -0
- data/vendor/rust/rust/templates/EnumDeclarations.rusttpl +3 -0
- data/vendor/rust/rust/templates/EnumDefinitions.rusttpl +29 -0
- data/vendor/rust/rust/templates/FunctionDefinition.rusttpl +9 -0
- data/vendor/rust/rust/templates/FunctionInitAlias.rusttpl +5 -0
- data/vendor/rust/rust/templates/FunctionInitBinding.rusttpl +9 -0
- data/vendor/rust/rust/templates/MethodInitBinding.rusttpl +9 -0
- data/vendor/rust/rust/templates/ModuleDeclarations.rusttpl +3 -0
- data/vendor/rust/rust/templates/ModuleDefinitions.rusttpl +3 -0
- data/vendor/rust/rust/templates/StandaloneClassDeclarations.rusttpl +7 -0
- data/vendor/rust/rust/templates/VariableFunctionCall.rusttpl +14 -0
- data/vendor/rust/rust/type.rb +98 -0
- data/vendor/rust/test/Makefile +4 -0
- data/vendor/rust/test/constants.rb +36 -0
- data/vendor/rust/test/cppclass.cc +45 -0
- data/vendor/rust/test/cppclass.hh +67 -0
- data/vendor/rust/test/cppclass.rb +59 -0
- data/vendor/rust/test/cwrapper.c +74 -0
- data/vendor/rust/test/cwrapper.h +41 -0
- data/vendor/rust/test/cwrapper.rb +56 -0
- data/vendor/rust/test/dummyclass.hh +31 -0
- data/vendor/rust/test/lib/extension-test.rb +98 -0
- data/vendor/rust/test/operators.cc +41 -0
- data/vendor/rust/test/operators.hh +39 -0
- data/vendor/rust/test/operators.rb +39 -0
- data/vendor/rust/test/test-constants.rb +43 -0
- data/vendor/rust/test/test-cppclass.rb +82 -0
- data/vendor/rust/test/test-cwrapper.rb +80 -0
- data/vendor/rust/test/test-operators.rb +42 -0
- metadata +293 -0
@@ -0,0 +1,172 @@
|
|
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/namespace'
|
24
|
+
|
25
|
+
module Rust
|
26
|
+
# Base class to use to create bindings for ruby.
|
27
|
+
# You shouldn't instantiate this manually, but rather use the
|
28
|
+
# create_bindings function.
|
29
|
+
class Bindings
|
30
|
+
# Constant to use with Bindings.create_bindings to state that the
|
31
|
+
# bindings that are to be created are for a C library.
|
32
|
+
LangC = "c"
|
33
|
+
|
34
|
+
# Constant to use with Bindings.create_bindings to state that the
|
35
|
+
# bindings that are to be created are for a C++ library.
|
36
|
+
LangCxx = "cxx"
|
37
|
+
|
38
|
+
# Constant to use with include_header method to state that the
|
39
|
+
# included header is a system library header.
|
40
|
+
HeaderGlobal = "global"
|
41
|
+
|
42
|
+
# Constant to use with include_header method to state that the
|
43
|
+
# included header is a local header.
|
44
|
+
HeaderLocal = "local"
|
45
|
+
|
46
|
+
def initialize(name, lang) # :notnew:
|
47
|
+
@name = name
|
48
|
+
@lang = lang
|
49
|
+
|
50
|
+
@modules = Array.new
|
51
|
+
@custom_definition = Array.new
|
52
|
+
@custom_initialization = Array.new
|
53
|
+
|
54
|
+
@cxx_includes = ""
|
55
|
+
@c_includes = ""
|
56
|
+
end
|
57
|
+
|
58
|
+
# This function is called when creating Ruby bindings for a
|
59
|
+
# library.
|
60
|
+
#
|
61
|
+
# The first parameter has to be one between Rust::Bindings::LangC
|
62
|
+
# or Rust::Bindings::LangCxx, and tells Rust which programming
|
63
|
+
# language the library to bind is written into.
|
64
|
+
#
|
65
|
+
# Please note that Rust always generates C++ code even when
|
66
|
+
# binding a library written in C, as STL templates are used all
|
67
|
+
# over the generics code.
|
68
|
+
def Bindings.create_bindings(lang, name)
|
69
|
+
bindings =
|
70
|
+
case lang
|
71
|
+
when Bindings::LangCxx, Bindings::LangC
|
72
|
+
bindings = Bindings.new(name, lang)
|
73
|
+
else
|
74
|
+
raise ArgumentError, "#{lang} is not a valid value for type parameter"
|
75
|
+
end
|
76
|
+
|
77
|
+
yield bindings
|
78
|
+
|
79
|
+
header = File.new("#{name}.hh", File::CREAT|File::TRUNC|File::RDWR)
|
80
|
+
unit = File.new("#{name}.cc", File::CREAT|File::TRUNC|File::RDWR)
|
81
|
+
|
82
|
+
header.puts bindings.header
|
83
|
+
unit.puts bindings.unit
|
84
|
+
|
85
|
+
header.close
|
86
|
+
unit.close
|
87
|
+
end
|
88
|
+
|
89
|
+
# Adds an include header with the specified name.
|
90
|
+
# This function adds to the list of header files to include the
|
91
|
+
# one with the specified name.
|
92
|
+
#
|
93
|
+
# If the scope paramether is set to Bindings.HeaderLocal, the name of
|
94
|
+
# the header file will be enclosed in double quotes ("") while
|
95
|
+
# including it, while it will be included it in angle quotes if
|
96
|
+
# the parameter is set to Bindings.HeaderGlobal (the default).
|
97
|
+
def include_header(name, scope = Bindings::HeaderGlobal, lang = @lang)
|
98
|
+
name =
|
99
|
+
case scope
|
100
|
+
when HeaderLocal then "\"#{name}\""
|
101
|
+
when HeaderGlobal then "<#{name}>"
|
102
|
+
else
|
103
|
+
raise ArgumentError, "#{scope} not a valid value for scope parameter."
|
104
|
+
end
|
105
|
+
|
106
|
+
case lang
|
107
|
+
when Bindings::LangCxx
|
108
|
+
@cxx_includes << "\n#include #{name}"
|
109
|
+
when Bindings::LangC
|
110
|
+
@c_includes << "\n#include #{name}"
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
# Binds a new Namespace to a Ruby module; the name parameter is
|
115
|
+
# used as the name of the module, while the cxxname one (if not
|
116
|
+
# null) is used to indicate the actual C++ namespace to use; when
|
117
|
+
# binding a C library, you should rather use the add_module
|
118
|
+
# function, although that's just a partial wrapper around this one.
|
119
|
+
def add_namespace(name, cxxname = nil)
|
120
|
+
cxxname = name if cxxname == nil
|
121
|
+
|
122
|
+
ns = Namespace.new(name, cxxname)
|
123
|
+
|
124
|
+
yield ns
|
125
|
+
|
126
|
+
@modules << ns
|
127
|
+
end
|
128
|
+
|
129
|
+
# Create a new Ruby module with the given name; this is used when
|
130
|
+
# binding C libraries, as they don't use namespace, so you have to
|
131
|
+
# create the modules from scratch.
|
132
|
+
def add_module(name)
|
133
|
+
add_namespace(name, "")
|
134
|
+
end
|
135
|
+
|
136
|
+
# Returns the content of the header for the bindings, recursively
|
137
|
+
# calling the proper functions to get the declarations for the
|
138
|
+
# modules bound and so on.
|
139
|
+
#
|
140
|
+
# This should *never* be used directly
|
141
|
+
def header
|
142
|
+
Templates["BindingsHeader"].
|
143
|
+
gsub("!bindings_name!", @name).
|
144
|
+
gsub("!modules_declaration!", @modules.collect { |ns| ns.declaration }.join("\n")).
|
145
|
+
gsub("!cxx_includes!", @cxx_includes).
|
146
|
+
gsub("!c_includes!", @c_includes)
|
147
|
+
end
|
148
|
+
|
149
|
+
# Returns the content of the unit for the bindings, recursively
|
150
|
+
# calling the proper functions to get the definitions and the
|
151
|
+
# initialisation function for the modules bound and so on.
|
152
|
+
#
|
153
|
+
# This should *never* be used directly
|
154
|
+
def unit
|
155
|
+
Templates["BindingsUnit"].
|
156
|
+
gsub("!bindings_name!", @name).
|
157
|
+
gsub("!modules_initialization!", @modules.collect { |ns| ns.initialization }.join("\n")).
|
158
|
+
gsub("!modules_definition!", @modules.collect { |ns| ns.definition }.join("\n")).
|
159
|
+
gsub("!custom_definition!", @custom_definition.join("\n")).
|
160
|
+
gsub("!custom_initialization!", @custom_initialization.join("\n"))
|
161
|
+
end
|
162
|
+
|
163
|
+
def add_custom_definition(element)
|
164
|
+
@custom_definition << element
|
165
|
+
end
|
166
|
+
|
167
|
+
def add_custom_initialization(initialization)
|
168
|
+
@custom_initialization << initialization
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
end
|
@@ -0,0 +1,339 @@
|
|
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/function'
|
25
|
+
require 'rust/attribute'
|
26
|
+
require 'rust/type'
|
27
|
+
|
28
|
+
module Rust
|
29
|
+
class Class < Container
|
30
|
+
attr_accessor :bindname
|
31
|
+
attr_accessor :function_mark
|
32
|
+
attr_reader :name, :cname
|
33
|
+
attr_reader :varname, :varcname, :ptrmap, :function_free, :function_map_free, :parent_varname
|
34
|
+
|
35
|
+
# Rust::Namespace object for the class, used to get the proper C++
|
36
|
+
# name.
|
37
|
+
attr_reader :namespace
|
38
|
+
|
39
|
+
# This function initializes the Class instance by setting the
|
40
|
+
# values to the attributes defining its namespace, name
|
41
|
+
# and a few other needed information.
|
42
|
+
#
|
43
|
+
# Don't call this function directly, use Namespace.add_cxx_class
|
44
|
+
def initialize(name, namespace, bindname = name.split("::").last ) # :notnew:
|
45
|
+
super()
|
46
|
+
|
47
|
+
@name = name
|
48
|
+
@namespace = namespace
|
49
|
+
|
50
|
+
type = Type.new(complete_name)
|
51
|
+
@varname = type.valid_name
|
52
|
+
@parent_varname = "rb_cObject"
|
53
|
+
|
54
|
+
@ptrmap = "#{type.valid_name}Map"
|
55
|
+
@function_free = "#{varname}_free"
|
56
|
+
@function_map_free = "#{varname}_free_map_entry"
|
57
|
+
@function_mark = "#{varname}_mark"
|
58
|
+
|
59
|
+
@cname = @namespace.cname ? "#{@namespace.cname}::#{@name}" : @name
|
60
|
+
|
61
|
+
type = Type.new(@cname)
|
62
|
+
@varcname = type.valid_name
|
63
|
+
@bindname = bindname
|
64
|
+
|
65
|
+
@declaration_template = Templates["ClassDeclarations"]
|
66
|
+
@initialization_template = Templates["ClassInitialize"]
|
67
|
+
|
68
|
+
add_expansion 'class_varname', 'varname'
|
69
|
+
add_expansion 'class_varcname', 'varcname'
|
70
|
+
add_expansion 'c_class_name', 'cname'
|
71
|
+
# add_expansion 'c_class_basename', '@name.split("::").last'
|
72
|
+
add_expansion 'bind_name', '@bindname'
|
73
|
+
add_expansion 'class_ptrmap', 'ptrmap'
|
74
|
+
add_expansion 'class_free_function', '@function_free'
|
75
|
+
add_expansion 'class_map_free_function', '@function_map_free'
|
76
|
+
add_expansion 'class_mark_function', '@function_mark'
|
77
|
+
add_expansion 'parent_varname', '@parent_varname'
|
78
|
+
end
|
79
|
+
|
80
|
+
# Adds a new constructor for the class.
|
81
|
+
# This function creates a new constructor method for the C/C++
|
82
|
+
# class to bind, and yields it so that parameters can be added
|
83
|
+
# afterward.
|
84
|
+
def add_constructor
|
85
|
+
constructor = self.class::Constructor.new(self)
|
86
|
+
|
87
|
+
begin
|
88
|
+
yield constructor
|
89
|
+
rescue LocalJumpError
|
90
|
+
# Ignore this, we can easily have methods without parameters
|
91
|
+
# or other extra informations.
|
92
|
+
end if block_given?
|
93
|
+
|
94
|
+
register_function(constructor)
|
95
|
+
|
96
|
+
return constructor
|
97
|
+
end
|
98
|
+
|
99
|
+
# Adds a new method for the class.
|
100
|
+
# This function adds a new generic method for the class. In the
|
101
|
+
# case of C++ classes, this is an actual method of the bound
|
102
|
+
# class, while in case of Class Wrappers, this is just a function
|
103
|
+
# that expects to find a static parameter that is the instance
|
104
|
+
# pointer itself.
|
105
|
+
def add_method(name, return_value = "void", bindname = name)
|
106
|
+
method = self.class::Method.new({ :name => name,
|
107
|
+
:bindname => bindname,
|
108
|
+
:return => return_value,
|
109
|
+
:klass => self
|
110
|
+
})
|
111
|
+
|
112
|
+
begin
|
113
|
+
yield method
|
114
|
+
rescue LocalJumpError
|
115
|
+
# Ignore this, we can easily have methods without parameters
|
116
|
+
# or other extra informations.
|
117
|
+
end if block_given?
|
118
|
+
|
119
|
+
register_function(method)
|
120
|
+
|
121
|
+
method
|
122
|
+
end
|
123
|
+
|
124
|
+
def add_attribute(name, type, bindname = name)
|
125
|
+
attribute = Attribute.new(name, type, { :parent => self })
|
126
|
+
|
127
|
+
yield attribute if block_given?
|
128
|
+
|
129
|
+
@children << attribute
|
130
|
+
|
131
|
+
attribute
|
132
|
+
end
|
133
|
+
|
134
|
+
def add_operator(name, return_value, bindname = name)
|
135
|
+
operator = Class::Operator.new({ :name => name,
|
136
|
+
:bindname => bindname,
|
137
|
+
:return => return_value,
|
138
|
+
:klass => self
|
139
|
+
})
|
140
|
+
begin
|
141
|
+
yield operator
|
142
|
+
rescue LocalJumpError
|
143
|
+
end if block_given?
|
144
|
+
|
145
|
+
register_function(operator)
|
146
|
+
|
147
|
+
|
148
|
+
return operator
|
149
|
+
end
|
150
|
+
|
151
|
+
def complete_name
|
152
|
+
name = @name
|
153
|
+
parent = @parent
|
154
|
+
namespace = @namespace
|
155
|
+
|
156
|
+
if not parent.nil?
|
157
|
+
name = "#{parent.cname}::#{name}"
|
158
|
+
end
|
159
|
+
|
160
|
+
if not namespace.nil?
|
161
|
+
name = "#{namespace.cname}::#{name}"
|
162
|
+
end
|
163
|
+
|
164
|
+
return name if parent.nil?
|
165
|
+
|
166
|
+
while not parent.parent.nil?
|
167
|
+
name = "#{parent.parent.cname}::#{name}"
|
168
|
+
parent = parent.parent
|
169
|
+
end
|
170
|
+
|
171
|
+
return name if namespace.nil?
|
172
|
+
|
173
|
+
while not namespace.parent.nil?
|
174
|
+
name = "#{namespace.parent.cname}::#{name}"
|
175
|
+
namespace = namespace.parent
|
176
|
+
end
|
177
|
+
|
178
|
+
name
|
179
|
+
end
|
180
|
+
|
181
|
+
# Adds a new variable for the class. It's not an actual variable,
|
182
|
+
# as hopefully there aren't global or class public variables in
|
183
|
+
# any library.
|
184
|
+
# These virtual variables have setter and getter methods, usually
|
185
|
+
# called 'var' and 'setVar' in C++ (or 'getVar' and 'setVar'), and
|
186
|
+
# are mapped to 'var' and 'var=' in Ruby, so that setting the
|
187
|
+
# variable in Ruby will just call the setter method.
|
188
|
+
def add_variable(name, type, getter = nil, setter = nil)
|
189
|
+
getter = name unless getter
|
190
|
+
setter = "set" + name[0..0].capitalize + name[1..-1] unless
|
191
|
+
setter
|
192
|
+
|
193
|
+
method_get = add_method getter, type
|
194
|
+
method_get.add_alias name
|
195
|
+
|
196
|
+
method_set = add_method setter, "void"
|
197
|
+
method_set.add_alias "#{name}="
|
198
|
+
|
199
|
+
begin
|
200
|
+
yield method_get, method_set
|
201
|
+
rescue LocalJumpError
|
202
|
+
# Ignore this, we can easily have methods without parameters
|
203
|
+
# or other extra informations.
|
204
|
+
end if block_given?
|
205
|
+
|
206
|
+
method_set.add_parameter type, "value"
|
207
|
+
|
208
|
+
return [method_get, method_set]
|
209
|
+
end
|
210
|
+
|
211
|
+
# This class is used to represent a method for a C/C++ class bound
|
212
|
+
# in a Ruby extension. Through an object of this class you can add
|
213
|
+
# parameters and more to the method.
|
214
|
+
class Method < Function
|
215
|
+
|
216
|
+
# Initialisation function, calls Function.initialize and sets
|
217
|
+
# the important parameters that differs from a generic function
|
218
|
+
def initialize(params) # :notnew:
|
219
|
+
params[:parent] = params[:klass]
|
220
|
+
super
|
221
|
+
|
222
|
+
@varname =
|
223
|
+
"f#{@parent.namespace.name.gsub("::","_")}_#{@parent.name}_#{@name}"
|
224
|
+
|
225
|
+
@definition_template = Templates["CxxMethodStub"]
|
226
|
+
@initialization_template = Templates["MethodInitBinding"]
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
class Operator < Function
|
231
|
+
attr_reader :position # 1: pre 2: mid 3: post 4: mixed
|
232
|
+
|
233
|
+
def initialize(params)
|
234
|
+
params[:parent] = params[:klass]
|
235
|
+
super
|
236
|
+
|
237
|
+
type = Type.new(@parent.namespace.cname+"::"+@parent.cname)
|
238
|
+
|
239
|
+
@varname = "f#{type.valid_name}_#{valid_name}"
|
240
|
+
|
241
|
+
@definition_template = Templates["CxxMethodStub"]
|
242
|
+
@initialization_template = Templates["MethodInitBinding"]
|
243
|
+
end
|
244
|
+
|
245
|
+
def bind_call(nparam = nil)
|
246
|
+
case @return
|
247
|
+
when nil
|
248
|
+
raise "nil return value is not supported for non-constructors."
|
249
|
+
when "void"
|
250
|
+
return "#{raw_call(nparam)}; return Qnil;\n"
|
251
|
+
else
|
252
|
+
type = Type.new(@return)
|
253
|
+
if not @return.include?("*") and not type.native?
|
254
|
+
"return cxx2ruby( new #{@return.gsub("&", "")}(#{raw_call(nparam)}), true );\n" # XXX: needs a copy constructor
|
255
|
+
else
|
256
|
+
"return cxx2ruby( static_cast<#{@return}>(#{raw_call(nparam)}) );\n"
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
private
|
262
|
+
def raw_call(nparam = nil)
|
263
|
+
case @position
|
264
|
+
when 1 # pre
|
265
|
+
"#{@name} (*tmp)"
|
266
|
+
when 2 # mid
|
267
|
+
"(*tmp) #{@name[0].chr} #{params_conversion(nparam)} #{@name[@name.length-1].chr} "
|
268
|
+
when 4
|
269
|
+
"(*tmp) #{@name[0].chr} #{self.parameters[0].conversion} #{@name[1].chr} #{@name[@name.length-1].chr} #{self.parameters[1].conversion}" if self.parameters.size == 2
|
270
|
+
else
|
271
|
+
"(*tmp) #{@name} #{params_conversion(nparam)} "
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
def valid_name
|
276
|
+
case @name
|
277
|
+
when "+"
|
278
|
+
@position = 3
|
279
|
+
"plusop"
|
280
|
+
when "-"
|
281
|
+
@position = 3
|
282
|
+
"minusop"
|
283
|
+
when "*"
|
284
|
+
@position = 3
|
285
|
+
"multop"
|
286
|
+
when "/"
|
287
|
+
@position = 3
|
288
|
+
"divop"
|
289
|
+
when /\[\s*\]=/
|
290
|
+
@position = 4
|
291
|
+
"ateqop"
|
292
|
+
when /\[\s*\]/
|
293
|
+
@position = 2
|
294
|
+
"atop"
|
295
|
+
when "=="
|
296
|
+
@position = 3
|
297
|
+
"equalop"
|
298
|
+
when "!="
|
299
|
+
@position = 3
|
300
|
+
"notequalop"
|
301
|
+
when "<<"
|
302
|
+
@position = 3
|
303
|
+
"outstream"
|
304
|
+
when ">>"
|
305
|
+
@position = 3
|
306
|
+
"intstream"
|
307
|
+
when "!"
|
308
|
+
@position = 1
|
309
|
+
"notop"
|
310
|
+
else
|
311
|
+
@position = 3
|
312
|
+
"undefop_#{@name[0].chr.to_i}#{rand(1024)}"
|
313
|
+
end
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
317
|
+
# This class is used to represente the constructor of a C++ class
|
318
|
+
# bound in a Ruby extension.
|
319
|
+
class Constructor < Function
|
320
|
+
|
321
|
+
# Initialisation function, calls Function.initialise, but accepts
|
322
|
+
# only a single parameter, the class the constructor belong to.
|
323
|
+
def initialize(klass) # :notnew:
|
324
|
+
super({
|
325
|
+
:parent => klass,
|
326
|
+
:bindname => "initialize",
|
327
|
+
:name => klass.name
|
328
|
+
})
|
329
|
+
|
330
|
+
@definition_template = Templates["ConstructorStub"]
|
331
|
+
end
|
332
|
+
|
333
|
+
def bind_call(nparam = nil)
|
334
|
+
"#{raw_call(nparam)};\n"
|
335
|
+
end
|
336
|
+
end
|
337
|
+
|
338
|
+
end
|
339
|
+
end
|