summaryrefslogtreecommitdiffstats
path: root/lib/efl/eina_list.rb
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2011-04-29 14:45:08 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2011-04-29 14:45:08 +0200
commit0ed32396a0fd63625ea94c4da86c2df3829acc72 (patch)
tree853b116cacf2ced99799a69868745f60ead8e254 /lib/efl/eina_list.rb
parent7d9d18850322a11f0f40913a5442b7a981b47c0a (diff)
downloadffi-efl-0ed32396a0fd63625ea94c4da86c2df3829acc72.zip
ffi-efl-0ed32396a0fd63625ea94c4da86c2df3829acc72.tar.gz
update efl/eina* and specs
Diffstat (limited to 'lib/efl/eina_list.rb')
-rw-r--r--lib/efl/eina_list.rb76
1 files changed, 76 insertions, 0 deletions
diff --git a/lib/efl/eina_list.rb b/lib/efl/eina_list.rb
new file mode 100644
index 0000000..ecd0e20
--- /dev/null
+++ b/lib/efl/eina_list.rb
@@ -0,0 +1,76 @@
+#! /usr/bin/env ruby
+# -*- coding: UTF-8 -*-
+#
+require 'efl/ffi/eina_list'
+#
+class Array
+ def self.from_eina_list o
+ if o.is_a? Efl::EinaList::REinaList
+ o.to_ary
+ elsif o.is_a? FFI::Pointer
+ Efl::EinaList::REinaList.new(o).to_ary
+ else
+ raise ArgumentError.new " wrong argument #{o.class.name}"
+ end
+ end
+end
+module Efl
+ module EinaList
+ #
+ class EinaListStruct < FFI::Struct
+ layout :data, :pointer,
+ :next, :pointer,
+ :prev, :pointer,
+ :accounting, :pointer,
+ :magic, :uint,
+ end
+ #
+ class REinaList
+ include Enumerable
+ include Efl::ClassHelper
+ @search_paths = [ [Efl::EinaList,'eina_list_'] ].freeze
+ def initialize o=nil
+ @ptr = (
+ case o
+ when FFI::Pointer
+ o
+ when NilClass
+ FFI::Pointer::NULL
+ when self.class
+ o.ptr
+ when Array
+ o.inject(FFI::Pointer::NULL) { |p,e| Efl::EinaList.eina_list_append p, e }
+ else
+ raise ArgumentError.new "#{ptr.class} valid argument"
+ end
+ )
+ end
+ def free
+ return if @ptr==FFI::Pointer::NULL
+ @ptr = Efl::EinaList.eina_list_free @ptr
+ end
+ def each
+ p = @ptr
+ while p!=::FFI::Pointer::NULL
+ l = Efl::EinaList::EinaListStruct.new p
+ yield l[:data]
+ p = l[:next]
+ end
+ end
+ def to_ary
+ inject([]) { |s,e| s<<e }
+ end
+ # for fun and tests
+ def append p
+ @ptr = Efl::EinaList.eina_list_append @ptr, p
+ end
+ alias :<< :append
+ def prepend p
+ @ptr = Efl::EinaList.eina_list_prepend @ptr, p
+ end
+ alias :unshift :prepend
+ end
+ end
+end
+#
+# EOF