rbplusplus 1.0 → 1.0.1
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/Rakefile +1 -1
- data/lib/rbplusplus/builders/helpers/class.rb +13 -10
- data/lib/rbplusplus/transformers/constructor.rb +4 -4
- data/test/director_test.rb +1 -1
- data/test/headers/implicit_cast.h +0 -47
- data/test/implicit_cast_test.rb +2 -29
- data/test/modules_test.rb +1 -1
- data/test/nested_test.rb +1 -1
- data/test/subclass_test.rb +1 -1
- data/test/to_from_ruby_test.rb +1 -1
- metadata +4 -3
data/Rakefile
CHANGED
@@ -38,16 +38,18 @@ module RbPlusPlus
|
|
38
38
|
[to_use || real_constructors].flatten.each do |constructor|
|
39
39
|
next if do_not_wrap?(constructor)
|
40
40
|
|
41
|
-
|
42
|
-
next if ignore_artificial || constructor.arguments.length == 1
|
43
|
-
end
|
41
|
+
Logger.debug "Wrapping constructor: #{constructor.attributes["demangled"]}"
|
44
42
|
|
45
|
-
if
|
46
|
-
if constructor.
|
47
|
-
|
43
|
+
if constructor.attributes["artificial"]
|
44
|
+
if ignore_artificial && constructor.arguments.length == 1
|
45
|
+
Logger.debug "Not wrapping artificial constructor #{constructor.attributes["demangled"]}"
|
46
|
+
next
|
48
47
|
end
|
48
|
+
end
|
49
49
|
|
50
|
-
|
50
|
+
if implicit_casting?(constructor)
|
51
|
+
Logger.debug "Wrapping implicit constructor #{constructor.to_cpp}"
|
52
|
+
parent.add_child ImplicitCasterNode.new(constructor, self)
|
51
53
|
next
|
52
54
|
end
|
53
55
|
|
@@ -60,9 +62,10 @@ module RbPlusPlus
|
|
60
62
|
end
|
61
63
|
|
62
64
|
# Is this constructor a converter constructor?
|
63
|
-
def
|
64
|
-
|
65
|
-
|
65
|
+
def implicit_casting?(constructor)
|
66
|
+
constructor.implicit_casting? &&
|
67
|
+
# Only works on single argument constructors
|
68
|
+
constructor.arguments.length == 1 &&
|
66
69
|
# We are wrapping the type converting from
|
67
70
|
!do_not_wrap?(constructor.arguments[0].cpp_type.base_type)
|
68
71
|
end
|
@@ -9,9 +9,9 @@ module RbGCCXML
|
|
9
9
|
# They manage the conversion of one type to another. Rice handles this functionality
|
10
10
|
# through a special method, define_implicit_cast<From, To>().
|
11
11
|
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
12
|
+
# Use this method to specify which constructors are meant to be used in implicit casting.
|
13
|
+
# This will mark the constructor as such and won't wrap it directly, but will build an
|
14
|
+
# appropriate define_implicit_cast<> call for the two types (class and argument)
|
15
15
|
#
|
16
16
|
# This method can be called per Constructor or per Class.
|
17
17
|
def implicit_casting(state)
|
@@ -20,7 +20,7 @@ module RbGCCXML
|
|
20
20
|
|
21
21
|
def implicit_casting? #:nodoc:
|
22
22
|
if @implicit_casting.nil?
|
23
|
-
@implicit_casting =
|
23
|
+
@implicit_casting = false
|
24
24
|
end
|
25
25
|
|
26
26
|
@implicit_casting
|
data/test/director_test.rb
CHANGED
@@ -55,53 +55,6 @@ namespace implicit_cast {
|
|
55
55
|
bool isRight(Degree* degree) {
|
56
56
|
return degree->valueDegrees() == 90;
|
57
57
|
}
|
58
|
-
|
59
|
-
/**
|
60
|
-
* Classes to show how to turn off the implicit casting
|
61
|
-
*/
|
62
|
-
class Explicit
|
63
|
-
{
|
64
|
-
public:
|
65
|
-
Explicit(float v) {
|
66
|
-
value = v;
|
67
|
-
}
|
68
|
-
|
69
|
-
Explicit(const Degree &d) {
|
70
|
-
value = d.valueDegrees();
|
71
|
-
}
|
72
|
-
|
73
|
-
Explicit(const Radian &r) {
|
74
|
-
value = r.valueDegrees();
|
75
|
-
}
|
76
|
-
|
77
|
-
float value;
|
78
|
-
};
|
79
|
-
|
80
|
-
float explicitValue(Explicit e) {
|
81
|
-
return e.value;
|
82
|
-
}
|
83
|
-
|
84
|
-
class NotImplicit
|
85
|
-
{
|
86
|
-
public:
|
87
|
-
NotImplicit(float v, int a) {
|
88
|
-
value = v * a;
|
89
|
-
}
|
90
|
-
|
91
|
-
NotImplicit(const Degree &d) {
|
92
|
-
value = d.valueDegrees();
|
93
|
-
}
|
94
|
-
|
95
|
-
NotImplicit(const Radian &r) {
|
96
|
-
value = r.valueDegrees();
|
97
|
-
}
|
98
|
-
|
99
|
-
float value;
|
100
|
-
};
|
101
|
-
|
102
|
-
float notImplicitValue(NotImplicit i) {
|
103
|
-
return i.value;
|
104
|
-
}
|
105
58
|
}
|
106
59
|
|
107
60
|
#endif
|
data/test/implicit_cast_test.rb
CHANGED
@@ -10,11 +10,10 @@ describe "Specify types to allow implicit casting" do
|
|
10
10
|
node = e.namespace "implicit_cast"
|
11
11
|
|
12
12
|
# Can flag individual constructors
|
13
|
-
node.classes("
|
14
|
-
find(:arguments => ["const Radian&"]).implicit_casting(false)
|
13
|
+
node.classes("Degree").constructors.find(:arguments => ["const Radian&"]).implicit_casting(true)
|
15
14
|
|
16
15
|
# Or flag the class as a whole
|
17
|
-
node.classes("
|
16
|
+
node.classes("Radian").implicit_casting(true)
|
18
17
|
end
|
19
18
|
|
20
19
|
require 'implicit_cast'
|
@@ -37,31 +36,5 @@ describe "Specify types to allow implicit casting" do
|
|
37
36
|
is_right(Degree.new(90)).should be_true
|
38
37
|
is_right(Radian.new(2.0)).should be_false
|
39
38
|
end
|
40
|
-
|
41
|
-
specify "can turn off implicit cast wrapping for a given constructor" do
|
42
|
-
lambda do
|
43
|
-
explicit_value(Radian.new(60.0))
|
44
|
-
end.should raise_error
|
45
|
-
|
46
|
-
lambda do
|
47
|
-
e = Explicit.new(14.0)
|
48
|
-
explicit_value(e).should be_close(14.0, 0.001)
|
49
|
-
end.should_not raise_error
|
50
|
-
end
|
51
|
-
|
52
|
-
specify "can turn off implicit casting for an entire class" do
|
53
|
-
n = NotImplicit.new(10.0, 3)
|
54
|
-
|
55
|
-
not_implicit_value(n).should be_close(30.0, 0.001)
|
56
|
-
|
57
|
-
lambda do
|
58
|
-
not_implicit_value(Degree.new(15.0))
|
59
|
-
end.should raise_error
|
60
|
-
|
61
|
-
lambda do
|
62
|
-
not_implicit_value(Radian.new(1.0))
|
63
|
-
end.should raise_error
|
64
|
-
end
|
65
|
-
|
66
39
|
end
|
67
40
|
|
data/test/modules_test.rb
CHANGED
data/test/nested_test.rb
CHANGED
data/test/subclass_test.rb
CHANGED
data/test/to_from_ruby_test.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
|
3
|
+
describe "Properly build known required to_ruby and from_ruby methods" do
|
4
4
|
|
5
5
|
specify "should build for const & types as needed" do
|
6
6
|
Extension.new "to_from_ruby" do |e|
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbplusplus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
|
9
|
+
- 1
|
10
|
+
version: 1.0.1
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Jason Roelofs
|
@@ -14,7 +15,7 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-
|
18
|
+
date: 2010-10-26 00:00:00 -04:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|