rbind 0.0.22 → 0.0.23

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.
@@ -59,7 +59,8 @@ module Rbind
59
59
  end
60
60
 
61
61
  def parse(*files)
62
- files.each do |path|
62
+ files.flatten.each do |path|
63
+ raise ArgumentError, "File '#{path}' does not exist" if not File.exists?(path)
63
64
  parser.parse File.new(path).read
64
65
  end
65
66
  end
@@ -195,8 +196,9 @@ module Rbind
195
196
  @generator_c.libs
196
197
  end
197
198
 
198
- def add_std_string
199
+ def add_std_string(with_c_string = true)
199
200
  @generator_c.includes << "<string>"
201
+ @generator_c.includes << "<cstring>" if with_c_string
200
202
  @parser.add_type(StdString.new("std::string",@parser))
201
203
  @parser.type_alias["basic_string"] = @parser.std.string
202
204
  self
@@ -208,9 +210,26 @@ module Rbind
208
210
  self
209
211
  end
210
212
 
213
+ def add_std_map
214
+ @generator_c.includes << "<map>"
215
+ @parser.add_type(StdMap.new("std::map"))
216
+ end
217
+
218
+ def add_std_except
219
+ @generator_c.includes << "<stdexcept>"
220
+ exception = RClass.new(RBase.normalize("std::exception"))
221
+ @parser.add_type(exception)
222
+
223
+ runtime_error = RClass.new(RBase.normalize("std::runtime_error"))
224
+ runtime_error.add_parent(exception)
225
+ @parser.add_type(runtime_error)
226
+ end
227
+
211
228
  def add_std_types
212
229
  add_std_vector
213
230
  add_std_string
231
+ add_std_map
232
+ add_std_except
214
233
  end
215
234
 
216
235
  def method_missing(m,*args)
@@ -1,4 +1,4 @@
1
- // wrapper for <%= attribute? ? "#{owner.full_name}.#{attribute.name}" : signature %>
1
+ // operation wrapper for <%= attribute? ? "#{owner.full_name}.#{attribute.name}" : signature %>
2
2
  <%= csignature %>
3
3
  {
4
4
  try
@@ -7,9 +7,9 @@
7
7
  }
8
8
  catch(std::exception &error){strncpy(&last_error_message[0],error.what(),255);}
9
9
  catch(...){strncpy(&last_error_message[0],"Unknown Exception",255);}
10
- <%- if !return_type || !return_type.basic_type? -%>
10
+ <%- if !return_type || return_type.ptr? || !return_type.basic_type? -%>
11
11
  return NULL;
12
- <%- elsif return_type.name != "void" || return_type.ptr?-%>
13
- return <%= return_type.invalid_value %>;
12
+ <%- elsif return_type.name != "void" -%>
13
+ return (<%= return_type.cname %>) <%= return_type.invalid_value %>;
14
14
  <%- end -%>
15
15
  }
@@ -1,5 +1,6 @@
1
1
  // converts <%= full_name %>* to <%= cname %>*
2
- <%= cname %>* toC(<%= full_name %>* ptr, bool owner)
2
+
3
+ const <%= cname %>* toC(const <%= full_name %>* ptr, bool owner)
3
4
  {
4
5
  <%= cname %>* r_ptr = new <%= cname %>;
5
6
  r_ptr->version = <%= version %>;
@@ -10,6 +11,11 @@
10
11
  return r_ptr;
11
12
  }
12
13
 
14
+ <%= cname %>* toC(<%= full_name %>* ptr, bool owner)
15
+ {
16
+ return const_cast<<%= cname %>*>(toC(static_cast<const <%= full_name %>*>(ptr),owner));
17
+ }
18
+
13
19
  // converts const <%= cname %> to const <%= full_name %>
14
20
  const <%= full_name %>* fromC(const <%= cname %>* ptr)
15
21
  {
@@ -1,4 +1,5 @@
1
1
  // convert functions for <%= full_name %>* to and from <%= cname %>*
2
+ const <%= cname %>* toC(const <%= full_name %>* ptr, bool owner = true);
2
3
  <%= cname %>* toC(<%= full_name %>* ptr, bool owner = true);
3
4
  const <%= full_name %>* fromC(const <%= cname %>* ptr);
4
5
  <%= full_name %>* fromC(<%= cname %>* ptr);
@@ -18,6 +18,10 @@ module <%= name %>
18
18
  end
19
19
  ffi_lib ["<%= library_name %>", path]
20
20
 
21
+ # @!group Enums
22
+ <%= add_enums%>
23
+ # @!endgroup
24
+
21
25
  #add error checking
22
26
  #rbindCreateMatrix -> create_matrix
23
27
  def self.attach_function(ruby_name,c_name, args, returns,error_checking=true)
@@ -1,5 +1,5 @@
1
1
  <%= add_doc -%>
2
- # @note wrapper for <%= signature %>
2
+ # @note method wrapper for <%= signature %>
3
3
  def <%=name%>(<%= wrap_parameters_signature %>)
4
4
  <%= add_specialize_ruby -%>
5
5
  <%- if return_type.basic_type? || operator? -%>
@@ -1,10 +1,10 @@
1
1
  <%= add_doc -%>
2
- # @note wrapper for <%= full_name %>
2
+ # @note namespace wrapper for <%= full_name %>
3
3
  module <%= name %>
4
4
  # @!group Constants
5
5
  <%= add_consts%>
6
6
  # @!endgroup
7
- #
7
+
8
8
  <%= add_methods %>
9
9
  <%= add_types %>
10
10
  end
@@ -1,4 +1,4 @@
1
- # wrapper for <%= signature %>
1
+ # overloaded method wrapper for <%= signature %>
2
2
  @@<%=cname%>_defaults<%= index %> ||= <%= signature_default_values %>
3
3
  if(args.size >= <%= min_number_of_parameters %> && args.size <= <%= parameters.size %>)
4
4
  targs = args.clone
@@ -1,5 +1,5 @@
1
1
  <%= add_doc -%>
2
- # @note wrapper for overloaded method <%= name %>
2
+ # @note wrapper for overloaded static method <%= name %>
3
3
  def self.<%=name%>(*args)
4
4
  <%= add_methods %>
5
5
  raise ArgumentError, "No overloaded signature fits to: #{args.map(&:class)}"
@@ -1,5 +1,5 @@
1
1
  <%= add_doc -%>
2
- # @note wrapper for <%= signature %>
2
+ # @note wrapper for static method <%= signature %>
3
3
  def self.<%= name %>(<%= wrap_parameters_signature %>)
4
4
  <%= add_specialize_ruby -%>
5
5
  Rbind::<%= cname %>(<%= wrap_parameters_call %>)
@@ -1,4 +1,4 @@
1
- # wrapper for <%= signature %>
1
+ # wrapper for type constructor <%= signature %>
2
2
  if args.size == <%= parameters.size %>
3
3
  return Rbind::<%= cname %>(*args)
4
4
  end
@@ -1,6 +1,6 @@
1
1
  # template <%= full_name %>
2
2
  class <%= name %>
3
- # @!group Sepcializing
3
+ # @!group Specializing
4
4
  <%= add_specializing %>
5
5
  # @!endgroup
6
6
  end
@@ -0,0 +1,29 @@
1
+ module Rbind
2
+ class StdMap < RTemplateClass
3
+ def specialize(klass,*parameters)
4
+ if parameters.size < 2
5
+ raise ArgumentError,"StdMap does require at least two template parameters. Got: #{parameters}}"
6
+ end
7
+ map_key_type = parameters.flatten[0]
8
+ map_value_type = parameters.flatten[1]
9
+ if parameters.size > 2
10
+ map_comp_type = parameters.flatten[2]
11
+ else
12
+ map_comp_type = nil
13
+ end
14
+
15
+ klass.add_operation ROperation.new(klass.name,nil)
16
+ klass.add_operation ROperation.new(klass.name,nil,RParameter.new("other",klass).to_const)
17
+
18
+ klass.add_operation ROperation.new("size",type("size_t"))
19
+ klass.add_operation ROperation.new("clear",type("void"))
20
+ klass.add_operation ROperation.new("capacity",type("size_t"))
21
+ klass.add_operation ROperation.new("empty",type("bool"))
22
+ klass.add_operation ROperation.new("operator[]",map_value_type, RParameter.new("key_type", map_key_type))
23
+ klass.add_operation ROperation.new("at",map_value_type, RParameter.new("key_type",map_key_type))
24
+ klass.add_operation ROperation.new("erase",type("void"), RParameter.new("key_type",map_key_type))
25
+
26
+ klass
27
+ end
28
+ end
29
+ end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'rbind'
3
- s.version = '0.0.22'
3
+ s.version = '0.0.23'
4
4
  s.date = '2013-10-29'
5
5
  s.platform = Gem::Platform::RUBY
6
6
  s.authors = ['Alexander Duda']
@@ -0,0 +1,35 @@
1
+ #ifndef RBIND_CLASSES_HPP
2
+ #define RBIND_CLASSES_HPP
3
+
4
+
5
+ class TestClass
6
+ {
7
+ public:
8
+ bool public_field;
9
+
10
+ void public_function();
11
+
12
+ class PublicClass
13
+ {
14
+ };
15
+
16
+ private:
17
+ bool private_field;
18
+
19
+ void private_function();
20
+
21
+ class PrivateClass
22
+ {
23
+ };
24
+
25
+ protected:
26
+ bool protected_field;
27
+
28
+ void protected_function();
29
+
30
+ class ProtectedClass
31
+ {
32
+ };
33
+ };
34
+
35
+ #endif
@@ -12,7 +12,6 @@ describe Rbind::ClangParser do
12
12
  describe "parse" do
13
13
 
14
14
  it "must parse enums" do
15
- next
16
15
  file = File.join(File.dirname(__FILE__),'headers','enums.hpp')
17
16
  parser = Rbind::ClangParser.new
18
17
  parser.parse file
@@ -24,7 +23,6 @@ describe Rbind::ClangParser do
24
23
  end
25
24
 
26
25
  it "must parse constants" do
27
- next
28
26
  file = File.join(File.dirname(__FILE__),'headers','constants.hpp')
29
27
  parser = Rbind::ClangParser.new
30
28
  parser.parse file
@@ -41,7 +39,6 @@ describe Rbind::ClangParser do
41
39
  end
42
40
 
43
41
  it "must parse c functions" do
44
- next
45
42
  file = File.join(File.dirname(__FILE__),'headers','cfunctions.h')
46
43
  parser = Rbind::ClangParser.new
47
44
  parser.parse file
@@ -80,22 +77,21 @@ describe Rbind::ClangParser do
80
77
  end
81
78
 
82
79
  it "must parse classes" do
83
- next
84
80
  file = File.join(File.dirname(__FILE__),'headers','classes.hpp')
85
81
  parser = Rbind::ClangParser.new
86
82
  parser.parse file
87
83
 
88
- assert_equal "void TestClass::TestClass(int i1, char c)", parser.TestClass.TestClass.signature
84
+ assert_equal "TestClass::TestClass(int i1, char c)", parser.TestClass.TestClass.signature
89
85
  assert_equal "void TestClass::setB(bool val)", parser.TestClass.setB.signature
90
86
  assert_equal "void TestClass::setF(float& val)", parser.TestClass.setF.signature
91
87
  assert_equal "void TestClass::setF2(const float& val)", parser.TestClass.setF2.signature
92
88
  assert_equal "void TestClass::setD(double& val)", parser.TestClass.setD.signature
93
- assert_equal "TestClass TestClass::setS(TestClass other)", parser.TestClass.setS.signature
94
- assert_equal "TestClass TestClass::setS2(TestClass* other)", parser.TestClass.setS2.signature
95
- assert_equal "TestClass TestClass::setS3(TestClass** other)", parser.TestClass.setS3.signature
96
- assert_equal "TestClass TestClass::setS4(TestClass& other)", parser.TestClass.setS4.signature
97
- assert_equal "TestClass TestClass::setS5(const TestClass& other)", parser.TestClass.setS5.signature
98
- assert_equal "TestClass TestClass::setS6(const TestClass* other)", parser.TestClass.setS6.signature
89
+ assert_equal "void TestClass::setS(TestClass other)", parser.TestClass.setS.signature
90
+ assert_equal "void TestClass::setS2(TestClass* other)", parser.TestClass.setS2.signature
91
+ assert_equal "void TestClass::setS3(TestClass** other)", parser.TestClass.setS3.signature
92
+ assert_equal "void TestClass::setS4(TestClass& other)", parser.TestClass.setS4.signature
93
+ assert_equal "void TestClass::setS5(const TestClass& other)", parser.TestClass.setS5.signature
94
+ assert_equal "void TestClass::setS6(const TestClass* other)", parser.TestClass.setS6.signature
99
95
  assert_equal "TestClass TestClass::getS()", parser.TestClass.getS.signature
100
96
  assert_equal "TestClass* TestClass::getS2()", parser.TestClass.getS2.signature
101
97
  assert_equal "TestClass& TestClass::getS3()", parser.TestClass.getS3.signature
@@ -104,10 +100,45 @@ describe Rbind::ClangParser do
104
100
  assert parser.TestClass.attribute("ifield")
105
101
  end
106
102
 
103
+ it "must ignore non public classes and attributes" do
104
+ file = File.join(File.dirname(__FILE__),'headers','non_public_classes.hpp')
105
+ parser = Rbind::ClangParser.new
106
+ parser.parse file
107
+
108
+ # Fields
109
+ assert parser.TestClass.attribute("public_field"), "Public field should exist"
110
+ assert !parser.TestClass.attribute("protected_field"), "Protected field should not exist"
111
+ assert !parser.TestClass.attribute("private_field"), "Private field should not exist"
112
+
113
+ # Functions
114
+ assert parser.TestClass.operations.select { |o| o == "void TestClass::public_function()" } , "Public function should exist: #{parser.TestClass.operations}"
115
+ protected_function = parser.TestClass.operations.select { |o| o == "void TestClass::protected_function()" }
116
+ assert protected_function.empty? , "Protected function not should exist: #{parser.TestClass.operations}"
117
+
118
+ private_function = parser.TestClass.operations.select { |o| o == "void TestClass::private_function()" }
119
+ assert private_function.empty? , "private function not should exist: #{parser.TestClass.operations}"
120
+
121
+ # Classes
122
+ assert parser.TestClass.PublicClass
123
+ begin
124
+ parser.TestClass.ProtectedClass
125
+ assert false, "Protected class should not be available"
126
+ rescue
127
+ assert true, "Protected class should be available"
128
+ end
129
+
130
+ begin
131
+ parser.TestClass.PrivateClass
132
+ assert false, "Private class should not be available"
133
+ rescue
134
+ assert true, "Private class should be available"
135
+ end
136
+ end
137
+
107
138
  it "must parse std vector types" do
108
- next
109
139
  file = File.join(File.dirname(__FILE__),'headers','std_vector.hpp')
110
140
  parser = Rbind::ClangParser.new
141
+ parser.add_type(Rbind::StdVector.new("std::vector"), parser)
111
142
  parser.parse file
112
143
 
113
144
  assert_equal "void TestClass::setValues(std::vector<int> ints)", parser.TestClass.setValues.signature
@@ -136,11 +167,14 @@ describe Rbind::ClangParser do
136
167
  end
137
168
 
138
169
  # this is not fully supported yet
139
- #it "must parse templates" do
140
- # file = File.join(File.dirname(__FILE__),'headers','templates.hpp')
141
- # parser = Rbind::ClangParser.new
142
- # parser.parse file
143
- # #assert_equal("_test123",result)
144
- #end
170
+ it "must parse templates" do
171
+ file = File.join(File.dirname(__FILE__),'headers','templates.hpp')
172
+ parser = Rbind::ClangParser.new
173
+ parser.parse file
174
+
175
+ assert_equal "void Test::setType(TemplateType<int> type)", parser.Test.setType.signature
176
+ template_type = parser.type("TemplateType<int>")
177
+ assert_equal "void TemplateType<int>::setInt(int i)", template_type.setInt.signature
178
+ end
145
179
  end
146
180
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbind
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.22
4
+ version: 0.0.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Duda
@@ -48,6 +48,7 @@ extensions: []
48
48
  extra_rdoc_files: []
49
49
  files:
50
50
  - README.md
51
+ - do_install.sh
51
52
  - lib/rbind.rb
52
53
  - lib/rbind/clang/clang.rb
53
54
  - lib/rbind/clang/clang_types.rb
@@ -105,6 +106,7 @@ files:
105
106
  - lib/rbind/templates/ruby/rtype_template.rb
106
107
  - lib/rbind/tools/hdr_parser.py
107
108
  - lib/rbind/typelib.rb
109
+ - lib/rbind/types/std_map.rb
108
110
  - lib/rbind/types/std_string.rb
109
111
  - lib/rbind/types/std_vector.rb
110
112
  - manifest.xml
@@ -113,6 +115,7 @@ files:
113
115
  - test/headers/classes.hpp
114
116
  - test/headers/constants.hpp
115
117
  - test/headers/enums.hpp
118
+ - test/headers/non_public_classes.hpp
116
119
  - test/headers/std_string.hpp
117
120
  - test/headers/std_vector.hpp
118
121
  - test/headers/structs.hpp
@@ -145,3 +148,4 @@ signing_key:
145
148
  specification_version: 4
146
149
  summary: Library for genereating automated ffi-bindings for c/c++ libraries
147
150
  test_files: []
151
+ has_rdoc: