Class: Svn::Utils::Factory

Inherits:
Object
  • Object
show all
Includes:
FFI::DataConverter
Defined in:
lib/svn/utils.rb

Overview

a generic factory class for use with FFI data types that adds default arguments to constructor calls

# when NativeHash is created, the args are [ptr, :string, :string]
bind :get_hash, :returning => NativeHash.factory( :string, :string )

Instance Method Summary collapse

Constructor Details

#initialize(klass, *args) ⇒ Factory

Returns a new instance of Factory.



33
34
35
36
# File 'lib/svn/utils.rb', line 33

def initialize( klass, *args )
  @klass = klass
  @added_args = args
end

Instance Method Details

#from_native(ptr, ctx) ⇒ Object



42
43
44
# File 'lib/svn/utils.rb', line 42

def from_native( ptr, ctx )
  @klass.new( ptr, *@added_args )
end

#native_typeObject



46
47
48
# File 'lib/svn/utils.rb', line 46

def native_type
  @klass.native_type
end

#new(*args) ⇒ Object



38
39
40
# File 'lib/svn/utils.rb', line 38

def new( *args )
  @klass.new( *(args + @added_args) )
end

#real_classObject



50
51
52
# File 'lib/svn/utils.rb', line 50

def real_class
  @klass
end

#sizeObject



54
55
56
# File 'lib/svn/utils.rb', line 54

def size
  @klass.size
end