gecoder 0.4.0 → 0.5.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.
- data/CHANGES +11 -0
- data/README +12 -1
- 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/sudoku.rb +65 -0
- data/ext/missing.cpp +15 -21
- data/ext/missing.h +14 -20
- data/ext/vararray.cpp +14 -20
- data/ext/vararray.h +18 -22
- data/lib/gecoder/bindings/bindings.rb +1979 -1969
- data/lib/gecoder/interface/binding_changes.rb +123 -2
- data/lib/gecoder/interface/constraints/bool/boolean.rb +80 -65
- data/lib/gecoder/interface/constraints/bool_enum/boolean.rb +59 -0
- data/lib/gecoder/interface/constraints/bool_enum_constraints.rb +8 -0
- data/lib/gecoder/interface/constraints/bool_var_constraints.rb +42 -0
- data/lib/gecoder/interface/constraints/int/arithmetic.rb +21 -44
- data/lib/gecoder/interface/constraints/int/domain.rb +6 -4
- data/lib/gecoder/interface/constraints/int_enum/arithmetic.rb +18 -44
- data/lib/gecoder/interface/constraints/int_enum/count.rb +3 -18
- data/lib/gecoder/interface/constraints/int_enum/distinct.rb +4 -16
- data/lib/gecoder/interface/constraints/int_enum/element.rb +9 -20
- data/lib/gecoder/interface/constraints/int_var_constraints.rb +28 -0
- data/lib/gecoder/interface/constraints/set/cardinality.rb +56 -0
- data/lib/gecoder/interface/constraints/set/domain.rb +66 -0
- data/lib/gecoder/interface/constraints/set/relation.rb +125 -0
- data/lib/gecoder/interface/constraints/set_var_constraints.rb +37 -0
- data/lib/gecoder/interface/constraints.rb +229 -65
- data/lib/gecoder/interface/enum_wrapper.rb +42 -11
- data/lib/gecoder/interface/model.rb +75 -0
- data/lib/gecoder/interface/search.rb +4 -9
- data/lib/gecoder/interface/variables.rb +36 -2
- data/lib/gecoder/version.rb +1 -1
- data/specs/bool_var.rb +58 -0
- data/specs/constraints/arithmetic.rb +91 -90
- data/specs/constraints/bool_enum.rb +130 -0
- data/specs/constraints/boolean.rb +95 -2
- data/specs/constraints/cardinality.rb +127 -0
- data/specs/constraints/constraint_helper.rb +91 -0
- data/specs/constraints/constraints.rb +31 -0
- data/specs/constraints/element.rb +43 -72
- data/specs/constraints/{domain.rb → int_domain.rb} +4 -0
- data/specs/constraints/{relation.rb → int_relation.rb} +0 -0
- data/specs/constraints/set_domain.rb +165 -0
- data/specs/constraints/set_relation.rb +181 -0
- data/specs/enum_wrapper.rb +13 -2
- data/specs/int_var.rb +33 -1
- data/specs/model.rb +80 -0
- data/specs/set_var.rb +39 -0
- data/specs/spec_helper.rb +35 -0
- data/specs/tmp +11 -124
- data/tasks/distribution.rake +1 -1
- data/vendor/rust/rust/class.rb +10 -10
- data/vendor/rust/rust/constants.rb +1 -1
- data/vendor/rust/rust/function.rb +5 -5
- data/vendor/rust/rust/type.rb +1 -1
- data/vendor/rust/test/constants.rb +1 -0
- data/vendor/rust/test/cppclass.cc +5 -0
- data/vendor/rust/test/cppclass.hh +4 -0
- data/vendor/rust/test/lib/extension-test.rb +1 -1
- 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-cwrapper.rb +3 -0
- data/vendor/rust/test/test-operators.rb +42 -0
- metadata +31 -4
data/specs/int_var.rb
CHANGED
@@ -89,7 +89,7 @@ describe Gecode::FreeIntVar, ' (with non-range domain of size > 1)' do
|
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
|
-
describe Gecode::FreeIntVar, '(with a domain of size 1)' do
|
92
|
+
describe Gecode::FreeIntVar, ' (with a domain of size 1)' do
|
93
93
|
before do
|
94
94
|
@domain = [1]
|
95
95
|
model = Gecode::Model.new
|
@@ -105,4 +105,36 @@ describe Gecode::FreeIntVar, '(with a domain of size 1)' do
|
|
105
105
|
it 'should be a range domain' do
|
106
106
|
@var.should be_range
|
107
107
|
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe Gecode::FreeIntVar, ' (assigned)' do
|
111
|
+
before do
|
112
|
+
@domain = [1]
|
113
|
+
model = Gecode::Model.new
|
114
|
+
@var = model.int_var(*@domain)
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'should be assigned' do
|
118
|
+
@var.should be_assigned
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'should give the assigned number when inspecting' do
|
122
|
+
@var.inspect.should include(" #{@domain[0]}>")
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
describe Gecode::FreeIntVar, ' (not assigned)' do
|
127
|
+
before do
|
128
|
+
@domain = 1..2
|
129
|
+
model = Gecode::Model.new
|
130
|
+
@var = model.int_var(*@domain)
|
131
|
+
end
|
132
|
+
|
133
|
+
it 'should not be assigned' do
|
134
|
+
@var.should_not be_assigned
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'should give the domain range when inspecting' do
|
138
|
+
@var.inspect.should include(" #{@domain.first}..#{@domain.last}>")
|
139
|
+
end
|
108
140
|
end
|
data/specs/model.rb
CHANGED
@@ -81,4 +81,84 @@ describe Gecode::Model, ' (bool creation)' do
|
|
81
81
|
matrix.row_size.should equal(3)
|
82
82
|
matrix.column_size.should equal(4)
|
83
83
|
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe Gecode::Model, ' (set creation)' do
|
87
|
+
before do
|
88
|
+
@model = Gecode::Model.new
|
89
|
+
@glb_range = 0..3
|
90
|
+
@lub_range = 0..5
|
91
|
+
@glb_enum = [0, 3]
|
92
|
+
@lub_enum = [0, 1, 2, 3, 5]
|
93
|
+
@lower_card = 1
|
94
|
+
@upper_card = 3
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'should allow the creation of set variables with glb range and lub range' do
|
98
|
+
@model.set_var(@glb_range, @lub_range).should have_bounds(@glb_range,
|
99
|
+
@lub_range)
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'should allow the creation of set variables with glb enum and lub range' do
|
103
|
+
@model.set_var(@glb_enum, @lub_range).should have_bounds(@glb_enum,
|
104
|
+
@lub_range)
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'should allow the creation of set variables with glb range and lub enum' do
|
108
|
+
@model.set_var(@glb_range, @lub_enum).should have_bounds(@glb_range,
|
109
|
+
@lub_enum)
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'should allow the creation of set variables with glb enum and lub enum' do
|
113
|
+
@model.set_var(@glb_enum, @lub_enum).should have_bounds(@glb_enum,
|
114
|
+
@lub_enum)
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'should allow the creation of set variables with specified lower cardinality bound' do
|
118
|
+
@model.set_var(@glb_range, @lub_range,
|
119
|
+
@lower_card).card_min.should >= @lower_card
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'should allow the creation of set variables with specified cardinality range' do
|
123
|
+
var = @model.set_var(@glb_range, @lub_range, @lower_card..@upper_card)
|
124
|
+
var.card_max.should <= @upper_card
|
125
|
+
var.card_min.should >= @lower_card
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'should allow the creation of arrays of set variables' do
|
129
|
+
arr = @model.set_var_array(3, @glb_enum, @lub_enum, @lower_card..@upper_card)
|
130
|
+
arr.size.should == 3
|
131
|
+
arr.each do |var|
|
132
|
+
var.should have_bounds(@glb_enum, @lub_enum)
|
133
|
+
var.card_max.should <= @upper_card
|
134
|
+
var.card_min.should >= @lower_card
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'should allow the creation of matrices of set variables' do
|
139
|
+
matrix = @model.set_var_matrix(4, 5, @glb_enum, @lub_enum,
|
140
|
+
@lower_card..@upper_card)
|
141
|
+
matrix.row_size.should == 4
|
142
|
+
matrix.column_size.should == 5
|
143
|
+
matrix.each do |var|
|
144
|
+
var.should have_bounds(@glb_enum, @lub_enum)
|
145
|
+
var.card_max.should <= @upper_card
|
146
|
+
var.card_min.should >= @lower_card
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'should raise error if glb and lub are not valid when they are given as range' do
|
151
|
+
lambda{ @model.set_var(@lub_range, @glb_range).should }.should raise_error(
|
152
|
+
ArgumentError)
|
153
|
+
end
|
154
|
+
|
155
|
+
it 'should raise error if glb and lub are not valid when one is given as enum' do
|
156
|
+
lambda{ @model.set_var(@lub_range, @glb_enum).should }.should raise_error(
|
157
|
+
ArgumentError)
|
158
|
+
end
|
159
|
+
|
160
|
+
it 'should raise error if glb and lub are not valid when both are given as enums' do
|
161
|
+
lambda{ @model.set_var(@lub_enum, @glb_enum).should }.should raise_error(
|
162
|
+
ArgumentError)
|
163
|
+
end
|
84
164
|
end
|
data/specs/set_var.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe Gecode::FreeSetVar, '(not assigned)' do
|
4
|
+
before do
|
5
|
+
model = Gecode::Model.new
|
6
|
+
@var = model.set_var(0..3, 0..4)
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should not be assigned' do
|
10
|
+
@var.should_not be_assigned
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should give glb and lub ranges when inspecting' do
|
14
|
+
@var.inspect.should include('lub-range')
|
15
|
+
@var.inspect.should include('glb-range')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe Gecode::FreeSetVar, '(assigned)' do
|
20
|
+
before do
|
21
|
+
model = Gecode::Model.new
|
22
|
+
@var = model.set_var([1], [1])
|
23
|
+
model.solve!
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should be assigned' do
|
27
|
+
@var.should be_assigned
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should include the assigned elements' do
|
31
|
+
@var.should include(1)
|
32
|
+
@var.should_not include(0)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should give it's value when inspecting" do
|
36
|
+
@var.inspect.should include('1..1')
|
37
|
+
@var.inspect.should_not include('lub-range')
|
38
|
+
end
|
39
|
+
end
|
data/specs/spec_helper.rb
CHANGED
@@ -29,6 +29,41 @@ module CustomVarMatchers
|
|
29
29
|
HaveDomain.new(expected)
|
30
30
|
end
|
31
31
|
|
32
|
+
class HaveBounds
|
33
|
+
def initialize(expected_glb, expected_lub)
|
34
|
+
@expected_glb = expected_glb.to_a
|
35
|
+
@expected_lub = expected_lub.to_a
|
36
|
+
end
|
37
|
+
|
38
|
+
def matches?(target)
|
39
|
+
@target = target
|
40
|
+
return false unless @target.glb_size == @expected_glb.size and
|
41
|
+
@target.lub_size == @expected_lub.size
|
42
|
+
@expected_glb.each do |element|
|
43
|
+
return false unless @target.include_glb?(element)
|
44
|
+
end
|
45
|
+
@expected_lub.each do |element|
|
46
|
+
return false unless @target.include_lub?(element)
|
47
|
+
end
|
48
|
+
return true
|
49
|
+
end
|
50
|
+
|
51
|
+
def failure_message
|
52
|
+
"expected #{@target.inspect} to have greatest lower bound " +
|
53
|
+
"#{@expected_glb.inspect} and least upper bound #{@expected_lub.inspect}"
|
54
|
+
end
|
55
|
+
|
56
|
+
def negative_failure_message
|
57
|
+
"expected #{@target.inspect} to not have greatest lower bound " +
|
58
|
+
"#{@expected_glb.inspect} and least upper bound #{@expected_lub.inspect}"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# Tests whether a set variable has the expected bounds.
|
63
|
+
def have_bounds(expected_glb, expected_lub)
|
64
|
+
HaveBounds.new(expected_glb, expected_lub)
|
65
|
+
end
|
66
|
+
|
32
67
|
class IsAlias
|
33
68
|
def initialize(expected)
|
34
69
|
@expected = expected.to_a
|
data/specs/tmp
CHANGED
@@ -2,134 +2,21 @@ Idea: Write constraints in separate modules and then include the modules in
|
|
2
2
|
the respective place.
|
3
3
|
|
4
4
|
|
5
|
-
=begin
|
6
|
-
it 'should handle relation with integer variables' do
|
7
|
-
fail
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'should handle propagation strength domain' do
|
11
|
-
fail
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'should handle propagation strength val' do
|
15
|
-
fail
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'should handle propagation strength range' do
|
19
|
-
fail
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'should raise error for unknown propagation strengths' do
|
23
|
-
fail
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'should handle reification' do
|
27
|
-
fail
|
28
|
-
end
|
29
|
-
=end
|
30
5
|
|
31
|
-
=begin
|
32
|
-
it 'should handle variables as right hand side' do
|
33
|
-
(@x + @y).must == @z
|
34
|
-
sol = @model.solution
|
35
|
-
x = sol.x.val
|
36
|
-
y = sol.y.val
|
37
|
-
z = sol.z.val
|
38
|
-
(x + y).should equal(z)
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'should handle multiplication with a constant' do
|
42
|
-
Gecode::Raw.should_receive(:linear).once.with(@model.active_space,
|
43
|
-
an_instance_of(Gecode::Raw::IntVarArray), Gecode::Raw::IRT_EQ, 1,
|
44
|
-
Gecode::Raw::ICL_DEF).and_return{ |s, arr, irt, res, strength| arr }
|
45
|
-
((10*@x + @y).must == 1).should contain_vars_with_domains(@x_dom, @y_dom)
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'should handle addition with a constant' do
|
49
|
-
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'should handle relation...' do
|
53
|
-
|
54
|
-
end
|
55
|
-
=end
|
56
6
|
|
57
7
|
|
58
8
|
|
59
|
-
module CustomVarMatchers
|
60
|
-
class ContainVarsWithDomains
|
61
|
-
def initialize(*expected_domains)
|
62
|
-
@expected_domains = expected_domains
|
63
|
-
end
|
64
|
-
|
65
|
-
def matches?(target)
|
66
|
-
@target = target
|
67
|
-
return false unless @target.kind_of? Gecode::Raw::IntVarArray
|
68
|
-
return false unless @target.size == @expected_domains.size
|
69
|
-
@target.size do |i|
|
70
|
-
var = @target.at(i)
|
71
|
-
detected = @expected_domains.detect do |domain|
|
72
|
-
variable_has_domain?(var, domain)
|
73
|
-
end
|
74
|
-
unless detected.nil?
|
75
|
-
@expected_domains.delete(@expected_domains.index(detected))
|
76
|
-
else
|
77
|
-
return false
|
78
|
-
end
|
79
|
-
end
|
80
|
-
return true
|
81
|
-
end
|
82
|
-
|
83
|
-
def failure_message
|
84
|
-
"expected #{@target.inspect} to contain variables with domains " +
|
85
|
-
@expected_vars.inspect
|
86
|
-
end
|
87
|
-
|
88
|
-
def negative_failure_message
|
89
|
-
"expected #{@target.inspect} to not contain variables with domains " +
|
90
|
-
@expected_vars.inspect
|
91
|
-
end
|
92
9
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
return false unless target.in(element)
|
99
|
-
end
|
100
|
-
return true
|
101
|
-
end
|
10
|
+
=begin
|
11
|
+
it 'should handle disjunction being constraint to be true' do
|
12
|
+
@bools.disjunction.must_be.true
|
13
|
+
@model.solve!
|
14
|
+
@bools.any?{ |b| b.true? }.should be_true
|
102
15
|
end
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
16
|
+
|
17
|
+
it 'should handle disjunction being constraint to be false' do
|
18
|
+
@bools.disjunction.must_be.false
|
19
|
+
@model.solve!
|
20
|
+
@bools.all?{ |b| b.false? }.should be_true
|
108
21
|
end
|
109
|
-
end
|
110
|
-
|
111
|
-
Spec::Runner.configure do |config|
|
112
|
-
config.include(CustomVarMatchers)
|
113
|
-
end
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
Left:
|
119
|
-
* Sorted
|
120
|
-
* Arithmetic
|
121
|
-
|
122
|
-
|
123
|
-
xs.occurrences_of(y).must == z
|
124
|
-
xs.occurrences_of(3).must >= 5
|
125
|
-
xs.count(y).must == z
|
126
|
-
xs.number_of(y).must == z
|
127
|
-
|
128
|
-
|
129
|
-
ys.sorted.must == xs
|
130
|
-
ys.sorted_with(zs).must == xs
|
131
|
-
|
132
|
-
ys.sort.must == xs
|
133
|
-
ys.must_be.xs.sorted
|
134
|
-
ys.must_be.sort(xs)
|
135
|
-
ys.sort.must_be.xs
|
22
|
+
=end
|
data/tasks/distribution.rake
CHANGED
data/vendor/rust/rust/class.rb
CHANGED
@@ -117,13 +117,13 @@ module Rust
|
|
117
117
|
end
|
118
118
|
|
119
119
|
def add_attribute(name, type, bindname = name)
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
120
|
+
attribute = Attribute.new(name, type, { :parent => self })
|
121
|
+
|
122
|
+
yield attribute if block_given?
|
123
|
+
|
124
|
+
@children << attribute
|
125
|
+
|
126
|
+
attribute
|
127
127
|
end
|
128
128
|
|
129
129
|
def add_operator(name, return_value, bindname = name)
|
@@ -294,11 +294,11 @@ module Rust
|
|
294
294
|
@position = 3
|
295
295
|
"notequalop"
|
296
296
|
when "<<"
|
297
|
-
|
298
|
-
|
297
|
+
@position = 3
|
298
|
+
"outstream"
|
299
299
|
when ">>"
|
300
300
|
@position = 3
|
301
|
-
|
301
|
+
"intstream"
|
302
302
|
when "!"
|
303
303
|
@position = 1
|
304
304
|
"notop"
|
@@ -388,13 +388,13 @@ module Rust
|
|
388
388
|
call += " if( is_#{valid_name}(argv[#{argindex}]) ) {\n"
|
389
389
|
end
|
390
390
|
}
|
391
|
-
|
391
|
+
|
392
392
|
call += " #{func.bind_call(argc)}"
|
393
393
|
call += " ok = true;\n"
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
394
|
+
call += "}"*argc # closes if's
|
395
|
+
call += "\n"
|
396
|
+
|
397
|
+
current_function_index += 1
|
398
398
|
}
|
399
399
|
call += " } break;\n"
|
400
400
|
|
data/vendor/rust/rust/type.rb
CHANGED
@@ -53,7 +53,7 @@ module Rust
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def native?
|
56
|
-
[ /int\s*\*{0,1}/, /float\s*\*{0,1}/, /double\s*\*{0,1}/, /char\s*\*{0,1}/, /bool/ ].each { |type|
|
56
|
+
[ /(u){0,1}int(\d\d_t){0,1}\s*\*{0,1}/, /float\s*\*{0,1}/, /double\s*\*{0,1}/, /char\s*\*{0,1}/, /bool/, /(std::){0,1}string/ ].each { |type|
|
57
57
|
if @name =~ type
|
58
58
|
return true
|
59
59
|
end
|
@@ -27,6 +27,9 @@ TestClass::TestClass() {
|
|
27
27
|
str = "undefined";
|
28
28
|
}
|
29
29
|
|
30
|
+
TestClass::~TestClass() {
|
31
|
+
}
|
32
|
+
|
30
33
|
void TestClass::action1(uint32_t unused_parameter) {
|
31
34
|
val = unused_parameter;
|
32
35
|
}
|
@@ -38,3 +41,5 @@ void TestClass::action2(char *string) {
|
|
38
41
|
void TestClass::action3(const TestClass &tc) {
|
39
42
|
str = "action3 called";
|
40
43
|
}
|
44
|
+
|
45
|
+
|
@@ -0,0 +1,41 @@
|
|
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
|
+
|
24
|
+
#include "operators.hh"
|
25
|
+
|
26
|
+
Operators::Operators() {
|
27
|
+
m_array = new uint32_t(4*sizeof(uint32_t));
|
28
|
+
|
29
|
+
for(int i = 0; i < 4; i++)
|
30
|
+
m_array[i] = i;
|
31
|
+
}
|
32
|
+
|
33
|
+
Operators::~Operators() {
|
34
|
+
delete m_array;
|
35
|
+
}
|
36
|
+
|
37
|
+
uint32_t &Operators::operator [](uint32_t index) {
|
38
|
+
return m_array[index];
|
39
|
+
}
|
40
|
+
|
41
|
+
|
@@ -0,0 +1,39 @@
|
|
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
|
+
|
24
|
+
#include <string>
|
25
|
+
#include <stdint.h>
|
26
|
+
|
27
|
+
class Operators {
|
28
|
+
public:
|
29
|
+
Operators();
|
30
|
+
~Operators();
|
31
|
+
|
32
|
+
uint32_t &operator [](uint32_t index);
|
33
|
+
|
34
|
+
protected:
|
35
|
+
uint32_t *m_array;
|
36
|
+
};
|
37
|
+
|
38
|
+
|
39
|
+
|
@@ -0,0 +1,39 @@
|
|
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'
|
24
|
+
|
25
|
+
Rust::Bindings::create_bindings Rust::Bindings::LangCxx, "operators_rb" do |b|
|
26
|
+
b.include_header 'operators.hh', Rust::Bindings::HeaderLocal
|
27
|
+
|
28
|
+
b.add_namespace "RustTestOperators", "" do |ns|
|
29
|
+
ns.add_cxx_class "Operators" do |klass|
|
30
|
+
klass.add_constructor do |method|
|
31
|
+
end
|
32
|
+
|
33
|
+
klass.add_operator "[]", "uint32_t", "at" do |method|
|
34
|
+
method.add_parameter "uint32_t", "index"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
@@ -0,0 +1,42 @@
|
|
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 'lib/extension-test'
|
24
|
+
|
25
|
+
module Rust::Test
|
26
|
+
|
27
|
+
class CppClassTest < Test::Unit::TestCase
|
28
|
+
include ExtensionTest
|
29
|
+
|
30
|
+
def setup
|
31
|
+
extension_setup("operators", "cc")
|
32
|
+
|
33
|
+
@instance = RustTestOperators::Operators.new
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_at
|
37
|
+
v = @instance.at(3)
|
38
|
+
assert(v == 3, "must be 3")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|