Class: Efl::Eet::REetFile

Inherits:
Object
  • Object
show all
Includes:
ClassHelper
Defined in:
lib/efl/eet.rb

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from ClassHelper

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

Dynamic Method Handling

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

Class Method Details

+ (Object) open(path, mode = :eet_file_mode_read) {|o| ... }

Yields:

  • (o)


24
25
26
27
28
29
30
31
32
# File 'lib/efl/eet.rb', line 24

def self.open path, mode=:eet_file_mode_read
    p = Native.eet_open path, mode
    raise Exception.new "Unable to open file #{path}" if p.nil?
    o = REetFile.new FFI::AutoPointer.new p, REetFile.method(:release)
    return o if not block_given?
    yield o
    o.close
    nil
end

+ (Object) release(p)



33
34
35
# File 'lib/efl/eet.rb', line 33

def self.release p
    Native.eet_close f
end

Instance Method Details

- (Object) close



36
37
38
39
40
# File 'lib/efl/eet.rb', line 36

def close
    @ptr.autorelease=false
    Native.eet_close @ptr
    @ptr = nil
end

- (Object) read(key)



46
47
48
49
50
51
52
53
# File 'lib/efl/eet.rb', line 46

def read key
    ptr = FFI::MemoryPointer.new(:int)
    data = Native.eet_read @ptr, key, ptr
    s = ptr.read_int
    ptr.free
    return nil if s==0
    ( data.null? ? nil : data.read_string[0..s-1] )
end

- (Object) write(key, data, compress = false)



42
43
44
# File 'lib/efl/eet.rb', line 42

def write key, data, compress=false
    Native.eet_write @ptr, key, data, data.bytesize, ( compress ? 1 : 0 )
end