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

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

Yields:

  • (o)


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

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

.release(p) ⇒ Object



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

def self.release p
    Native.eet_close f
end

Instance Method Details

#closeObject



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

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

#read(key) ⇒ Object



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

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

#write(key, data, compress = false) ⇒ Object



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

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