Parent

NiceFFI::TypedPointer

TypedPointer represents a :pointer (FFI type) that is a specific struct type. You can use TypedPointer( SomeStructClass ) instead of :pointer in these situations:

Attributes

type[R]

Public Class Methods

new( type, options={} ) click to toggle source

Create a new TypedPointer whose type is the given struct class.

type must be a class (not an instance) which is a descendent of FFI::Struct (or is FFI::Struct itself).

options must be a Hash of zero or more options. The current meaningful options are:

  • :autorelease - If false, instances of NiceStruct and OpaqueStruct (and subclasses) created via this TypedPointer will be passed {:autorelease => false} to disable automatic memory management. Use this for return values of functions that should not be autoreleased.

# File lib/nice-ffi/typedpointer.rb, line 55
def initialize( type, options={} )
  # unless type.is_a? Class and type.ancestors.include? FFI::Struct
  #   raise TypeError, "#{self.class} only wraps FFI::Struct and subclasses."
  # end
  @type = type
  options = {:autorelease => true}.merge!( options )
  @autorelease = options[:autorelease]
end

Public Instance Methods

inspect() click to toggle source
Alias for: to_s
to_s() click to toggle source
# File lib/nice-ffi/typedpointer.rb, line 90
def to_s
  "#<#{self.class}[ #{@type} ]>"
end
Also aliased as: inspect
unwrap( struct ) click to toggle source

Unwrap (i.e. extract the pointer) from a struct of this type.

# File lib/nice-ffi/typedpointer.rb, line 82
def unwrap( struct )
  unless struct.is_a? @type
    raise TypeError, "#{self.class}[ #{@type} ] cannot unwrap #{struct.type}"
  end
  struct.to_ptr
end
wrap( pointer ) click to toggle source

Wrap a FFI::Pointer in a new struct of this type.

# File lib/nice-ffi/typedpointer.rb, line 68
def wrap( pointer )
  unless pointer.is_a? FFI::Pointer
    raise TypeError, "#{self.class}[ #{@type} ] cannot wrap #{pointer.type}"
  end

  if @type.included_modules.include?( NiceFFI::AutoRelease )
    @type.new( pointer, :autorelease => @autorelease )
  else
    @type.new( pointer )
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.