rbind 0.0.33 → 0.0.34

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eea754672174a0aa6ab449d1df8bea30400e7720f5a0cd701b74bd01d377f60b
4
- data.tar.gz: d771496b0cea68ecc142775ff45a4f41397f4f40b114c6748aea8dc67c9118c3
3
+ metadata.gz: 4af779a4a5ab2c2ddebe6be732475e1ecf30c405760a70dbfe5f547af557bd40
4
+ data.tar.gz: aa14b3cd31d66748c8aed14b9a6ae4c232273d0db3e2fcdf997fb0d877ec7973
5
5
  SHA512:
6
- metadata.gz: 4813c2cb91f792c17587adb578d367fe1998f66d8cafea9290e19f3b6d146786b3d1acaebd10f47cb6fd30aaa26764bfa9c33fd8eeed1b95cd80d0da5cc23660
7
- data.tar.gz: 1182a9bcf4d35623d50eb866be4fdc48a2ada495d1e1f7e54bc5a61e45341ca89f1ea70b9e0b80110e36d8dfba93cf3b11565b4df829a2033569c75160fb4fa5
6
+ metadata.gz: 599b08d1f9706bfc53bc782666731fb00a8b3b027ba6c471e6973c9d1d14d97bde626534581a68cfe3e75b458417ce49b45aaff1e548b755470f8e7db3ecbf36
7
+ data.tar.gz: 1890afa6e1ac7843df9447082a384f4946950e4deb5d23f06cb907507ce88352a36e4b12a00bafb5389aa043fb395ad4415ad538f8060f5f2cfbc106bd671d16
@@ -208,5 +208,27 @@ module Rbind
208
208
  @specialize_ruby.call
209
209
  end
210
210
  end
211
+
212
+ # overwrite c
213
+ # depends on type
214
+ # at the moment only operations can be overwritten
215
+ def overwrite_c(&block)
216
+ if block
217
+ @overwrite_c = block
218
+ elsif @overwrite_c
219
+ @overwrite_c.call
220
+ end
221
+ end
222
+
223
+ # overwrite ruby
224
+ # depends on type
225
+ # at the moment only rbind_from_native can be overwritten
226
+ def overwrite_ruby(&block)
227
+ if block
228
+ @overwrite_ruby = block
229
+ elsif @overwrite_ruby
230
+ @overwrite_ruby.call
231
+ end
232
+ end
211
233
  end
212
234
  end
@@ -192,6 +192,8 @@ module Rbind
192
192
  end
193
193
 
194
194
  def wrap_call
195
+ str = overwrite_c()
196
+ return str if str
195
197
  paras = parameters.map do |arg|
196
198
  "#{"*" if (!arg.type.ptr? && !arg.type.basic_type?)}#{arg.name}#{"_" if !arg.type.basic_type?}"
197
199
  end.join(", ")
@@ -657,6 +657,13 @@ module Rbind
657
657
  GeneratorRuby.normalize_method_name(@root.cdelete_method)
658
658
  end
659
659
 
660
+ def rbind_from_native
661
+ overwrite = @root.overwrite_ruby
662
+ return overwrite if overwrite
663
+ "#{name}.new(ptr)"
664
+ end
665
+
666
+
660
667
  def add_specializing(root = @root)
661
668
  str = root.specialize_ruby.to_s
662
669
  root.each_type(false) do |t|
@@ -5,10 +5,13 @@
5
5
  {
6
6
  <%= wrap_parameters %><%= wrap_call %>
7
7
  }
8
- catch(std::exception &error){strncpy(&last_error_message[0],error.what(),255);}
9
- catch(...){strncpy(&last_error_message[0],"Unknown Exception",255);}
8
+ catch(std::exception &error){strncpy(&last_error_message[0],error.what(),254);}
9
+ catch(...){strncpy(&last_error_message[0],"Unknown Exception",254);}
10
10
  <%- if !return_type || return_type.ptr? || !return_type.basic_type? -%>
11
11
  return NULL;
12
+ <%- elsif return_type.ref? -%>
13
+ static <%= return_type.cname %> invalid;
14
+ return invalid;
12
15
  <%- elsif return_type.name != "void" -%>
13
16
  return (<%= return_type.cname %>) <%= return_type.invalid_value %>;
14
17
  <%- end -%>
@@ -8,7 +8,7 @@ void <%= cdelete_method %>(<%= cname %> *ptr)
8
8
  delete fromC(ptr);
9
9
  ptr->obj_ptr = NULL;
10
10
  }
11
- catch(std::exception &error){strncpy(&last_error_message[0],error.what(),255);}
12
- catch(...){strncpy(&last_error_message[0],"Unknown Exception",255);}
11
+ catch(std::exception &error){strncpy(&last_error_message[0],error.what(),254);}
12
+ catch(...){strncpy(&last_error_message[0],"Unknown Exception",254);}
13
13
  delete ptr;
14
14
  }
@@ -55,7 +55,7 @@ class <%= name %>
55
55
 
56
56
  # @private
57
57
  def self.rbind_from_native(ptr,context)
58
- <%= name %>.new(ptr)
58
+ <%= rbind_from_native %>
59
59
  end
60
60
 
61
61
  # @private
@@ -18,11 +18,42 @@ module Rbind
18
18
  klass.add_operation ROperation.new("size",type("size_t"))
19
19
  klass.add_operation ROperation.new("clear",type("void"))
20
20
  klass.add_operation ROperation.new("empty",type("bool"))
21
- klass.add_operation ROperation.new("operator[]",map_value_type, RParameter.new("key_type", map_key_type))
21
+ klass.add_operation ROperation.new("operator[]",map_value_type.to_ref, RParameter.new("key_type", map_key_type))
22
+ klass.add_operation ROperation.new("add",type("void"), RParameter.new("key", map_key_type),RParameter.new("value", map_value_type.to_ref.to_const))
23
+ klass.operation("add").overwrite_c do
24
+ "(*rbind_obj_)[#{map_key_type.basic_type? ? "key" : "*key_"}] = #{map_value_type.basic_type? ? "value" : "*value_"};"
25
+ end
26
+
22
27
  klass.add_operation ROperation.new("at",map_value_type, RParameter.new("key_type",map_key_type))
23
28
  klass.add_operation ROperation.new("erase",type("void"), RParameter.new("key_type",map_key_type))
29
+ klass.add_operation ROperation.new("getKeys",type("std::vector<#{map_key_type}>"))
30
+ klass.operation("getKeys").overwrite_c do
31
+ str = %{
32
+ auto keys = new std::vector<#{map_key_type}>();
33
+ std::transform(std::begin(*rbind_obj_), std::end(*rbind_obj_), std::back_inserter(*keys),
34
+ [](std::pair<#{map_key_type},#{map_value_type}> const& pair) {
35
+ return pair.first;
36
+ });
37
+ return toC(keys);
38
+ }
39
+ end
40
+ klass
41
+ end
24
42
 
25
- klass
43
+ # called from RTemplate when ruby_specialize is called for the instance
44
+ def specialize_ruby_specialization(klass)
45
+ %Q$
46
+ def to_hash
47
+ hash = Hash.new
48
+ keys = get_keys
49
+ keys.each do |k|
50
+ hash[k] = self[k]
51
+ end
52
+ hash
53
+ end
54
+ def []=(key,val)
55
+ add(key,val)
56
+ end$
26
57
  end
27
58
  end
28
59
  end
@@ -11,7 +11,12 @@ module Rbind
11
11
 
12
12
  para = Array.new
13
13
  para << RParameter.new("size",type("size_t"))
14
- para << RParameter.new("val",vector_type).default_value(vector_type.full_name+"()").to_const
14
+ if vector_type.is_a? REnum
15
+ para << RParameter.new("val",vector_type)
16
+ else
17
+ para << RParameter.new("val",vector_type).default_value(vector_type.full_name+"()").to_const
18
+ end
19
+
15
20
  klass.add_operation ROperation.new("resize",type("void"),para)
16
21
  klass.add_operation ROperation.new("size",type("size_t"))
17
22
  klass.add_operation ROperation.new("clear",type("void"))
data/rbind.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'rbind'
3
- s.version = '0.0.33'
4
- s.date = '2020-02-29'
3
+ s.version = '0.0.34'
4
+ s.date = '2022-04-20'
5
5
  s.platform = Gem::Platform::RUBY
6
6
  s.authors = ['Alexander Duda']
7
7
  s.email = ['Alexander.Duda@me.com']
metadata CHANGED
@@ -1,35 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbind
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.33
4
+ version: 0.0.34
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Duda
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-29 00:00:00.000000000 Z
11
+ date: 2022-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: 1.9.0
20
17
  - - "~>"
21
18
  - !ruby/object:Gem::Version
22
19
  version: '1.9'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.9.0
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- version: 1.9.0
30
27
  - - "~>"
31
28
  - !ruby/object:Gem::Version
32
29
  version: '1.9'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.9.0
33
33
  description: Rbind is developed to automatically generate ruby bindings for OpenCV
34
34
  but is not tight to this library.This gem is still under heavy development and the
35
35
  API might change in the future.
@@ -113,7 +113,7 @@ files:
113
113
  homepage: http://github.com/D-Alex/rbind
114
114
  licenses: []
115
115
  metadata: {}
116
- post_install_message:
116
+ post_install_message:
117
117
  rdoc_options: []
118
118
  require_paths:
119
119
  - lib
@@ -128,8 +128,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
128
  - !ruby/object:Gem::Version
129
129
  version: 1.3.6
130
130
  requirements: []
131
- rubygems_version: 3.0.3
132
- signing_key:
131
+ rubyforge_project:
132
+ rubygems_version: 2.7.6
133
+ signing_key:
133
134
  specification_version: 4
134
135
  summary: Library for genereating automated ffi-bindings for c/c++ libraries
135
136
  test_files: []