Class: Efl::EinaList::REinaList

Inherits:
Object
  • Object
show all
Includes:
ClassHelper, Enumerable
Defined in:
lib/efl/eina_list.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ClassHelper

#===, #address, included, #method_missing, #null?, #to_ptr, #to_s

Constructor Details

#initialize(o = nil) ⇒ REinaList



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/efl/eina_list.rb', line 26

def initialize o=nil
    @ptr = (
        case o
        when FFI::Pointer
            o
        when NilClass
            FFI::Pointer::NULL
        when Array
            o.inject(FFI::Pointer::NULL) { |p,e| Native.eina_list_append p, e }
        else
            raise ArgumentError.new "wrong argument #{o.class.name}"
        end
    )
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Efl::ClassHelper

Class Method Details

.from_a(ary, ptrt) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/efl/eina_list.rb', line 44

def self.from_a ary, ptrt
    REinaList.new ary.inject(FFI::Pointer::NULL) { |p,e|
        ptr = FFI::MemoryPointer.new ptrt
        ptr.send 'write_'+ptrt.to_s, e
        Native.eina_list_append p, ptr
    }
end

Instance Method Details

#append(p) ⇒ Object Also known as: <<

for fun and tests



66
67
68
# File 'lib/efl/eina_list.rb', line 66

def append p
    @ptr = Native.eina_list_append @ptr, p
end

#eachObject



51
52
53
54
55
56
57
58
59
# File 'lib/efl/eina_list.rb', line 51

def each
    return if not block_given?
    p = @ptr
    while p!=::FFI::Pointer::NULL
        l = Native::EinaListStruct.new p
        yield l[:data]
        p = l[:next]
    end
end

#freeObject



40
41
42
43
# File 'lib/efl/eina_list.rb', line 40

def free
    Native.eina_list_free @ptr
    @ptr = nil
end

#prepend(p) ⇒ Object Also known as: unshift



70
71
72
# File 'lib/efl/eina_list.rb', line 70

def prepend p
    @ptr = Native.eina_list_prepend @ptr, p
end

#to_a(ptrt = nil) ⇒ Object Also known as: to_ary



60
61
62
63
# File 'lib/efl/eina_list.rb', line 60

def to_a ptrt=nil
    return inject([]) { |s,e| s<<e } if ptrt.nil?
    inject([]) { |s,e| s<< e.send('read_'+ptrt.to_s) }
end