nice-ffi 0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,88 @@
1
+ #--
2
+ #
3
+ # This file is one part of:
4
+ #
5
+ # Nice-FFI - Convenience layer atop Ruby-FFI
6
+ #
7
+ # Copyright (c) 2009 John Croisant
8
+ #
9
+ # Permission is hereby granted, free of charge, to any person obtaining
10
+ # a copy of this software and associated documentation files (the
11
+ # "Software"), to deal in the Software without restriction, including
12
+ # without limitation the rights to use, copy, modify, merge, publish,
13
+ # distribute, sublicense, and/or sell copies of the Software, and to
14
+ # permit persons to whom the Software is furnished to do so, subject to
15
+ # the following conditions:
16
+ #
17
+ # The above copyright notice and this permission notice shall be
18
+ # included in all copies or substantial portions of the Software.
19
+ #
20
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
+ #
28
+ #++
29
+
30
+
31
+ require 'ffi'
32
+
33
+
34
+ # TypedPointer represents a :pointer (FFI type) that is a specific
35
+ # struct type. You can use TypedPointer( SomeStructClass ) instead
36
+ # of :pointer in these situations:
37
+ #
38
+ # * As the type for NiceFFI::Struct#layout to create type-smart accessors.
39
+ # * As the return type for NiceFFI::Library#attach_function to
40
+ # wrap the returned pointer.
41
+ #
42
+ class NiceFFI::TypedPointer
43
+
44
+ # Create a new TypedPointer whose type is the given struct class.
45
+ #
46
+ # type must be a class (not an instance) which is a descendent of
47
+ # FFI::Struct (or is FFI::Struct itself).
48
+ #
49
+ def initialize( type )
50
+ # unless type.is_a? Class and type.ancestors.include? FFI::Struct
51
+ # raise TypeError, "#{self.class} only wraps FFI::Struct and subclasses."
52
+ # end
53
+ @type = type
54
+ end
55
+
56
+ attr_reader :type
57
+
58
+
59
+ # Wrap a FFI::Pointer or FFI::MemoryPointer in a new struct of this type.
60
+ def wrap( pointer )
61
+ unless pointer.is_a? FFI::Pointer or pointer.is_a? FFI::MemoryPointer
62
+ raise TypeError, "#{self.class}[ #{@type} ] cannot wrap #{pointer.type}"
63
+ end
64
+ @type.new( pointer )
65
+ end
66
+
67
+
68
+ # Unwrap (i.e. extract the pointer) from a struct of this type.
69
+ def unwrap( struct )
70
+ unless struct.is_a? @type
71
+ raise TypeError, "#{self.class}[ #{@type} ] cannot unwrap #{struct.type}"
72
+ end
73
+ struct.to_ptr
74
+ end
75
+
76
+
77
+ def to_s
78
+ "#<#{self.class}[ #{@type} ]>"
79
+ end
80
+ alias :inspect :to_s
81
+
82
+ end
83
+
84
+
85
+ # Equivalent to TypedPointer.new( type )
86
+ def NiceFFI::TypedPointer( type )
87
+ NiceFFI::TypedPointer.new( type )
88
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nice-ffi
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.1"
5
+ platform: ruby
6
+ authors:
7
+ - John Croisant
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-07-05 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: ffi
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.3.0
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: need
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.1.0
34
+ version:
35
+ description: |
36
+ Nice-FFI is a layer on top of Ruby-FFI (and compatible FFI
37
+ systems) to augment that library with features to aide
38
+ development of FFI-based libraries.
39
+
40
+ email: jacius@gmail.com
41
+ executables: []
42
+
43
+ extensions: []
44
+
45
+ extra_rdoc_files: []
46
+
47
+ files:
48
+ - docs/usage.rdoc
49
+ - TODO.rdoc
50
+ - README.rdoc
51
+ - lib/nice-ffi/pathset.rb
52
+ - lib/nice-ffi/nicelibrary.rb
53
+ - lib/nice-ffi/typedpointer.rb
54
+ - lib/nice-ffi/nicestruct.rb
55
+ - lib/nice-ffi.rb
56
+ - ChangeLog.txt
57
+ has_rdoc: true
58
+ homepage: http://github.com/jacius/nice-ffi/
59
+ licenses: []
60
+
61
+ post_install_message:
62
+ rdoc_options: []
63
+
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: "1.8"
71
+ version:
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: "0"
77
+ version:
78
+ requirements: []
79
+
80
+ rubyforge_project:
81
+ rubygems_version: 1.3.3
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: Convenience layer atop Ruby-FFI
85
+ test_files: []
86
+