rbplusplus 1.0.1 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,10 +1,6 @@
1
- require 'rake/gempackagetask'
2
- require 'rake/rdoctask'
1
+ require 'rdoc/task'
3
2
  require 'rake/contrib/sshpublisher'
4
3
 
5
- PROJECT_NAME = "rb++"
6
- RBPLUSPLUS_VERSION = "1.0.1"
7
-
8
4
  task :default => :test
9
5
 
10
6
  # We test this way because of what this library does.
@@ -22,7 +18,7 @@ task :test do
22
18
  # the exact ruby binary that's linked to the ruby running the Rakefile. Just saying
23
19
  # "ruby" will find the system's installed ruby and be worthless
24
20
  ruby = File.join(Config::CONFIG["bindir"], Config::CONFIG["RUBY_INSTALL_NAME"])
25
- sh "#{ruby} -Itest #{file}"
21
+ sh "#{ruby} -S rspec -Itest #{file}"
26
22
  end
27
23
  end
28
24
 
@@ -58,36 +54,3 @@ namespace :web do
58
54
  rm_rf "publish"
59
55
  end
60
56
  end
61
-
62
- spec = Gem::Specification.new do |s|
63
- s.name = "rbplusplus"
64
- s.version = RBPLUSPLUS_VERSION
65
- s.summary = 'Ruby library to generate Rice wrapper code'
66
- s.homepage = 'http://rbplusplus.rubyforge.org'
67
- s.rubyforge_project = "rbplusplus"
68
- s.author = 'Jason Roelofs'
69
- s.email = 'jameskilton@gmail.com'
70
-
71
- s.description = <<-END
72
- Rb++ combines the powerful query interface of rbgccxml and the Rice library to
73
- make Ruby wrapping extensions of C++ libraries easier to write than ever.
74
- END
75
-
76
- s.add_dependency "rbgccxml", "~> 1.0"
77
- s.add_dependency "rice", "~> 1.4.0"
78
-
79
- patterns = [
80
- 'TODO',
81
- 'Rakefile',
82
- 'lib/**/*.rb',
83
- ]
84
-
85
- s.files = patterns.map {|p| Dir.glob(p) }.flatten
86
-
87
- s.test_files = [Dir.glob('test/**/*.rb'), Dir.glob('test/headers/**/*')].flatten
88
-
89
- s.require_paths = ['lib']
90
- end
91
-
92
- Rake::GemPackageTask.new(spec) do |pkg|
93
- end
data/lib/rbplusplus.rb CHANGED
@@ -1,6 +1,3 @@
1
- $:.unshift File.expand_path(File.dirname(__FILE__))
2
- $:.unshift File.expand_path(File.dirname(__FILE__) + "/rbplusplus")
3
-
4
1
  require 'rubygems'
5
2
  require 'rbgccxml'
6
3
 
@@ -116,8 +116,10 @@ module RbPlusPlus
116
116
  next if do_not_wrap?(method)
117
117
  next if method_names.include?(method.name)
118
118
 
119
+ arguments = [method.arguments].flatten
120
+
119
121
  # Ignore methods that have non-public arguments anywhere
120
- if !method.arguments.empty? && !method.arguments.select {|a| !a.cpp_type.base_type.public?}.empty?
122
+ if !arguments.empty? && !arguments.select {|a| !a.cpp_type.base_type.public?}.empty?
121
123
  Logger.info "Ignoring method #{method.qualified_name} due to non-public argument type(s)"
122
124
  next
123
125
  end
@@ -161,8 +161,9 @@ module RbPlusPlus
161
161
  # default value. See default_arguments_test and headers/default_arguments.h
162
162
  # for an example.
163
163
  def fix_enumeration_value(enum, default_value)
164
+ enum_values = [enum.values].flatten
164
165
  found =
165
- enum.values.select do |enum_value|
166
+ enum_values.select do |enum_value|
166
167
  enum_value.name == default_value
167
168
  end.first
168
169
 
@@ -113,7 +113,6 @@ module RbPlusPlus
113
113
  next if File.directory?(f)
114
114
 
115
115
  options[:include_source_files] << f
116
- options[:includes] << f if File.extname(f) =~ /hpp/i || File.extname(f) =~ /h/i
117
116
  end
118
117
  end
119
118
 
@@ -141,6 +140,11 @@ module RbPlusPlus
141
140
 
142
141
  if (files = options.delete(:include_source_files))
143
142
  @options[:include_source_files] << files
143
+ options[:includes] ||= []
144
+
145
+ [files].flatten.each do |f|
146
+ options[:includes] << f if File.extname(f) =~ /hpp/i || File.extname(f) =~ /h/i
147
+ end
144
148
  end
145
149
 
146
150
  if (flags = options.delete(:includes))
@@ -76,7 +76,7 @@ module RbPlusPlus
76
76
  # Write out from the bottom up, makes sure that children file writers
77
77
  # update their parents as needed
78
78
  @file_writers.each do |fw|
79
- fw.write(@build_dir)
79
+ fw.write(@build_dir, self.builder.additional_includes)
80
80
  end
81
81
  end
82
82
 
@@ -151,8 +151,9 @@ module RbPlusPlus
151
151
  @nodes << node
152
152
  end
153
153
 
154
- def write(build_dir)
154
+ def write(build_dir, custom_includes = [])
155
155
  @build_dir = build_dir
156
+ @custom_includes = custom_includes.flatten
156
157
 
157
158
  build_source
158
159
  write_header if @header
@@ -227,7 +228,12 @@ module RbPlusPlus
227
228
  def write_source
228
229
  File.open(File.join(@build_dir, @source), "w+") do |cpp|
229
230
  if (incls = @includes.flatten.compact).any?
230
- cpp.puts "", incls.uniq.sort.reverse.join("\n"), ""
231
+ incl_output = incls.uniq.sort.reverse.join("\n")
232
+ cpp.puts "", incl_output, ""
233
+ end
234
+
235
+ @custom_includes.each do |incl|
236
+ cpp.puts "#include \"#{incl}\"" unless incl_output =~ %r{#{incl}}
231
237
  end
232
238
 
233
239
  if @register_method
data/test/classes_test.rb CHANGED
@@ -35,7 +35,7 @@ describe "Extension with wrapped classes" do
35
35
  # Wrapped method names default to underscore'd
36
36
  adder = Adder.new
37
37
  adder.add_integers(1,2).should == 3
38
- adder.add_floats(1.0, 2.0).should be_close(3.0, 0.001)
38
+ adder.add_floats(1.0, 2.0).should be_within(0.001).of(3.0)
39
39
  adder.add_strings("Hello", "World").should == "HelloWorld"
40
40
  adder.get_class_name.should == "Adder"
41
41
  end
@@ -73,7 +73,7 @@ describe "Extension with wrapped classes" do
73
73
  a.should_be_transformed = "TRANSFORM"
74
74
 
75
75
  a.value1.should == 10
76
- a.value2.should be_close(15.5, 0.01)
76
+ a.value2.should be_within(0.01).of(15.5)
77
77
  a.value3.should == "This is a value!"
78
78
 
79
79
  a.should_be_transformed.should == "TRANSFORM"
@@ -160,17 +160,4 @@ describe "Compiler settings" do
160
160
  # is a symbol lookup failure and death to the Ruby VM
161
161
  needs_to_ruby(3).value.should == 3
162
162
  end
163
-
164
- specify "can specify a directory containing code to be included into compilation process" do
165
- Extension.new "code_dir" do |e|
166
- e.sources full_dir("headers/needs_code.h"),
167
- :include_source_dir => full_dir("headers/code")
168
-
169
- e.namespace "needs_code"
170
- end
171
-
172
- require 'code_dir'
173
-
174
- get_number(2).should == 2
175
- end
176
163
  end
@@ -76,6 +76,11 @@ describe "Default arguments properly exposed" do
76
76
  modify2(1, Ops::REMOVE).should == 1
77
77
  end
78
78
 
79
+ specify "function calls" do
80
+ default_with_function.should == 3
81
+ default_with_function(CustomType.new(5)).should == 5
82
+ end
83
+
79
84
  specify "should properly handle argument type qualifiers like refs and consts" # do
80
85
  # build_strings("I'd ").should == "I'd kick-it"
81
86
  # build_strings("You won't", " do it").should == "You won't do it"
@@ -30,7 +30,7 @@ describe "Wrapping enumerations" do
30
30
  end
31
31
 
32
32
  specify "should wrap up enumerations at proper nesting" do
33
- lambda { Tester::TestEnum }.should_not raise_error(NameError)
33
+ lambda { Tester::MyEnum }.should_not raise_error(NameError)
34
34
 
35
35
  Tester::MyEnum::I_LIKE_MONEY.to_i.should == 3
36
36
  Tester::MyEnum::YOU_LIKE_MONEY_TOO.to_i.should == 4
@@ -85,4 +85,8 @@ describe "Wrapping enumerations" do
85
85
  FOURTY_TWO.should == 42
86
86
  SEPERATE_OUTER_VALUE.should == 14
87
87
  end
88
+
89
+ specify "works with single element enumerations" do
90
+ Tester::SINGLE_VALUE.to_i.should == 12
91
+ end
88
92
  end
@@ -12,7 +12,7 @@ describe "Extension with globally available functions" do
12
12
 
13
13
  lambda { test1 }.should_not raise_error(NameError)
14
14
 
15
- test2(2.0).should be_close(1.0, 0.001)
15
+ test2(2.0).should be_within(0.001).of(1.0)
16
16
 
17
17
  test3(2, 4.2).should == 2
18
18
  end
@@ -1,11 +1,13 @@
1
1
  #include "custom_to_from_ruby.hpp"
2
2
 
3
3
  template<>
4
- Rice::Object to_ruby<short int>(short int const & a) {
5
- return INT2NUM(a);
4
+ Rice::Object to_ruby<MyType>(const MyType & a) {
5
+ return INT2NUM(a.value());
6
6
  }
7
7
 
8
8
  template<>
9
- short int from_ruby<short int>(Rice::Object x) {
10
- return FIX2INT(x.value());
9
+ MyType from_ruby<MyType>(Rice::Object x) {
10
+ MyType my;
11
+ my.setValue(FIX2INT(x.value()));
12
+ return my;
11
13
  }
@@ -4,10 +4,12 @@
4
4
  #include <rice/Object.hpp>
5
5
  #include <rice/to_from_ruby.hpp>
6
6
 
7
+ #include "my_type.hpp"
8
+
7
9
  template<>
8
- Rice::Object to_ruby<short int>(short int const & a);
10
+ Rice::Object to_ruby<MyType>(MyType const & a);
9
11
 
10
12
  template<>
11
- short int from_ruby<short int>(Rice::Object x);
13
+ MyType from_ruby<MyType>(Rice::Object x);
12
14
 
13
15
  #endif
@@ -0,0 +1,16 @@
1
+ #ifndef __MY_TYPE_H__
2
+ #define __MY_TYPE_H__
3
+
4
+ class MyType {
5
+ int myValue;
6
+
7
+ public:
8
+ MyType() { myValue = 0; }
9
+
10
+ // Exposing attributes not implemented yet
11
+ int value() const { return myValue; }
12
+
13
+ void setValue(int value) { myValue = value; }
14
+ };
15
+
16
+ #endif
@@ -76,6 +76,18 @@ namespace default_args {
76
76
  return value;
77
77
  }
78
78
 
79
+ class CustomType {
80
+ public:
81
+ CustomType(int value) { theValue = value; };
82
+ int theValue;
83
+
84
+ // Function calls
85
+ static CustomType someValue() { return CustomType(3); }
86
+ };
87
+
88
+ int defaultWithFunction(CustomType x = CustomType::someValue()) {
89
+ return x.theValue;
90
+ }
79
91
 
80
92
  }
81
93
 
data/test/headers/enums.h CHANGED
@@ -15,6 +15,10 @@ namespace enums {
15
15
  VALUE3
16
16
  };
17
17
 
18
+ enum {
19
+ SINGLE_VALUE = 12
20
+ };
21
+
18
22
  enum {
19
23
  OUTER_ANON_1,
20
24
  OUTER_ANON_2,
@@ -1,10 +1,30 @@
1
1
  #ifndef __NEEDS_CODE_H__
2
2
  #define __NEEDS_CODE_H__
3
3
 
4
+ #include "code/my_type.hpp"
5
+
4
6
  namespace needs_code {
5
- const short getNumber(short in) {
6
- return in;
7
- }
7
+
8
+ class NeedCode1 {
9
+ public:
10
+ const int getNumber(MyType in) {
11
+ return in.value();
12
+ }
13
+ };
14
+
15
+ class NeedCode2 {
16
+ public:
17
+ const int getNumber(MyType in) {
18
+ return in.value();
19
+ }
20
+ };
21
+
22
+ class NeedCode3 {
23
+ public:
24
+ const int getNumber(MyType in) {
25
+ return in.value();
26
+ }
27
+ };
8
28
  }
9
29
 
10
30
  #endif
@@ -0,0 +1,18 @@
1
+ require 'test_helper'
2
+
3
+ describe "Using include_source_dir" do
4
+
5
+ specify "can specify a directory containing code to be included into compilation process" do
6
+ Extension.new "code_dir" do |e|
7
+ e.sources full_dir("headers/needs_code.h"),
8
+ :include_source_dir => full_dir("headers/code")
9
+
10
+ e.namespace "needs_code"
11
+ end
12
+
13
+ require 'code_dir'
14
+
15
+ NeedCode1.new.get_number(2).should == 2
16
+ end
17
+
18
+ end
@@ -0,0 +1,28 @@
1
+ require 'test_helper'
2
+
3
+ describe "Using multiple include source files" do
4
+
5
+ before(:each) do
6
+ test_setup
7
+ end
8
+
9
+ specify "can specify individual files to be pulled into the compilation" do
10
+ Extension.new "code_dir" do |e|
11
+ e.sources full_dir("headers/needs_code.h"),
12
+ :include_source_files => [
13
+ full_dir("headers/code/my_type.hpp"),
14
+ full_dir("headers/code/custom_to_from_ruby.hpp"),
15
+ full_dir("headers/code/custom_to_from_ruby.cpp")
16
+ ]
17
+
18
+ e.namespace "needs_code"
19
+ end
20
+
21
+ require 'code_dir'
22
+
23
+ NeedCode1.new.get_number(2).should == 2
24
+ NeedCode2.new.get_number(2).should == 2
25
+ NeedCode3.new.get_number(2).should == 2
26
+ end
27
+
28
+ end
data/test/modules_test.rb CHANGED
@@ -57,7 +57,7 @@ describe "Extension with modules" do
57
57
 
58
58
  specify "should wrap up C++ functions in the module" do
59
59
  lambda { Functions }.should_not raise_error(NameError)
60
- Functions::test2(2).should be_close(1.0, 0.001)
60
+ Functions::test2(2).should be_within(0.001).of(1.0)
61
61
  Functions::test3(4, 6).should == 4
62
62
  end
63
63
 
metadata CHANGED
@@ -1,66 +1,59 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rbplusplus
3
- version: !ruby/object:Gem::Version
4
- hash: 21
5
- prerelease: false
6
- segments:
7
- - 1
8
- - 0
9
- - 1
10
- version: 1.0.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.3
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Jason Roelofs
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2010-10-26 00:00:00 -04:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2012-03-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: rbgccxml
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
18
+ requirements:
27
19
  - - ~>
28
- - !ruby/object:Gem::Version
29
- hash: 15
30
- segments:
31
- - 1
32
- - 0
33
- version: "1.0"
20
+ - !ruby/object:Gem::Version
21
+ version: 1.0.0
34
22
  type: :runtime
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: rice
38
23
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
40
25
  none: false
41
- requirements:
26
+ requirements:
42
27
  - - ~>
43
- - !ruby/object:Gem::Version
44
- hash: 7
45
- segments:
46
- - 1
47
- - 4
48
- - 0
28
+ - !ruby/object:Gem::Version
29
+ version: 1.0.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: rice
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
49
37
  version: 1.4.0
50
38
  type: :runtime
51
- version_requirements: *id002
52
- description: |
53
- Rb++ combines the powerful query interface of rbgccxml and the Rice library to
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.4.0
46
+ description: ! 'Rb++ combines the powerful query interface of rbgccxml and the Rice
47
+ library to
48
+
54
49
  make Ruby wrapping extensions of C++ libraries easier to write than ever.
55
50
 
51
+ '
56
52
  email: jameskilton@gmail.com
57
53
  executables: []
58
-
59
54
  extensions: []
60
-
61
55
  extra_rdoc_files: []
62
-
63
- files:
56
+ files:
64
57
  - TODO
65
58
  - Rakefile
66
59
  - lib/inflections.rb
@@ -122,6 +115,8 @@ files:
122
115
  - test/functions_test.rb
123
116
  - test/generated/extconf.rb
124
117
  - test/implicit_cast_test.rb
118
+ - test/include_source_dir_test.rb
119
+ - test/include_source_files_test.rb
125
120
  - test/modules_test.rb
126
121
  - test/nested_test.rb
127
122
  - test/overloading_test.rb
@@ -136,6 +131,7 @@ files:
136
131
  - test/headers/class_methods.h
137
132
  - test/headers/code/custom_to_from_ruby.cpp
138
133
  - test/headers/code/custom_to_from_ruby.hpp
134
+ - test/headers/code/my_type.hpp
139
135
  - test/headers/complex_static_methods.h
140
136
  - test/headers/constructors.h
141
137
  - test/headers/default_arguments.h
@@ -161,41 +157,31 @@ files:
161
157
  - test/headers/ugly_interface.h
162
158
  - test/headers/ugly_interface_ns.h
163
159
  - test/headers/with_includes.h
164
- has_rdoc: true
165
160
  homepage: http://rbplusplus.rubyforge.org
166
161
  licenses: []
167
-
168
162
  post_install_message:
169
163
  rdoc_options: []
170
-
171
- require_paths:
164
+ require_paths:
172
165
  - lib
173
- required_ruby_version: !ruby/object:Gem::Requirement
166
+ required_ruby_version: !ruby/object:Gem::Requirement
174
167
  none: false
175
- requirements:
176
- - - ">="
177
- - !ruby/object:Gem::Version
178
- hash: 3
179
- segments:
180
- - 0
181
- version: "0"
182
- required_rubygems_version: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - ! '>='
170
+ - !ruby/object:Gem::Version
171
+ version: '0'
172
+ required_rubygems_version: !ruby/object:Gem::Requirement
183
173
  none: false
184
- requirements:
185
- - - ">="
186
- - !ruby/object:Gem::Version
187
- hash: 3
188
- segments:
189
- - 0
190
- version: "0"
174
+ requirements:
175
+ - - ! '>='
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
191
178
  requirements: []
192
-
193
179
  rubyforge_project: rbplusplus
194
- rubygems_version: 1.3.7
180
+ rubygems_version: 1.8.18
195
181
  signing_key:
196
182
  specification_version: 3
197
183
  summary: Ruby library to generate Rice wrapper code
198
- test_files:
184
+ test_files:
199
185
  - test/allocation_strategies_test.rb
200
186
  - test/class_methods_encapsulate_test.rb
201
187
  - test/class_methods_test.rb
@@ -213,6 +199,8 @@ test_files:
213
199
  - test/functions_test.rb
214
200
  - test/generated/extconf.rb
215
201
  - test/implicit_cast_test.rb
202
+ - test/include_source_dir_test.rb
203
+ - test/include_source_files_test.rb
216
204
  - test/modules_test.rb
217
205
  - test/nested_test.rb
218
206
  - test/overloading_test.rb
@@ -227,6 +215,7 @@ test_files:
227
215
  - test/headers/class_methods.h
228
216
  - test/headers/code/custom_to_from_ruby.cpp
229
217
  - test/headers/code/custom_to_from_ruby.hpp
218
+ - test/headers/code/my_type.hpp
230
219
  - test/headers/complex_static_methods.h
231
220
  - test/headers/constructors.h
232
221
  - test/headers/default_arguments.h