summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2011-04-27 16:05:02 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2011-04-27 16:05:02 +0200
commitcbee8a70f433192a69ed90d9632d696dcb4ff2ab (patch)
tree7144a785860f365b89464d55753f4f299b66c00f
parent2806b37dc8f9721ac5e84755654b6b6d4ebad5a9 (diff)
downloadffi-efl-cbee8a70f433192a69ed90d9632d696dcb4ff2ab.zip
ffi-efl-cbee8a70f433192a69ed90d9632d696dcb4ff2ab.tar.gz
add eina_list and specs
-rw-r--r--lib/efl/eina_list.rb78
-rw-r--r--lib/efl/ffi/eina_list.rb105
-rw-r--r--spec/eina_list_spec.rb100
-rwxr-xr-xtools/extract-api.sh1
-rwxr-xr-xtools/genruby.rb3
5 files changed, 285 insertions, 2 deletions
diff --git a/lib/efl/eina_list.rb b/lib/efl/eina_list.rb
new file mode 100644
index 0000000..823fe72
--- /dev/null
+++ b/lib/efl/eina_list.rb
@@ -0,0 +1,78 @@
+#! /usr/bin/env ruby
+# -*- coding: UTF-8 -*-
+#
+require 'efl/eina'
+require 'efl/ffi/eina_list'
+#
+class Array
+ def self.from_eina_list o
+ if o.is_a? Efl::Eina::EinaList
+ o.to_ary
+ elsif o.is_a? ::FFI::Pointer
+ Efl::Eina::EinaList.new(o).to_ary
+ else
+ raise ArgumentError.new " wrong argument #{o.class.name}"
+ end
+ end
+end
+module Efl
+ module FFI
+ class EinaList < ::FFI::Struct
+ layout :data, :pointer,
+ :next, :pointer,
+ :prev, :pointer,
+ :accounting, :pointer,
+ :magic, :uint,
+ end
+ end
+ module Eina
+ #
+ class EinaList
+ include Efl::Helper
+ include Enumerable
+ @func_prefixes = [ '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::FFI::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::FFI.eina_list_free @ptr
+ end
+ def each
+ p = @ptr
+ while p!=::FFI::Pointer::NULL
+ l = Efl::FFI::EinaList.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::FFI.eina_list_append @ptr, p
+ end
+ alias :<< :append
+ def prepend p
+ @ptr = Efl::FFI.eina_list_prepend @ptr, p
+ end
+ alias :unshift :prepend
+ end
+ end
+end
+#
+# EOF
diff --git a/lib/efl/ffi/eina_list.rb b/lib/efl/ffi/eina_list.rb
new file mode 100644
index 0000000..12001c6
--- /dev/null
+++ b/lib/efl/ffi/eina_list.rb
@@ -0,0 +1,105 @@
+#! /usr/bin/env ruby
+# -*- coding: UTF-8 -*-
+#
+require 'efl/ffi'
+#
+module Efl
+ #
+ module EinaList
+ def self.method_missing m, *args, &block
+ return Efl::FFI.send 'eina_list_'+m.to_s, *args, &block
+ end
+ end
+ #
+ module FFI
+ #
+ #
+ ffi_lib 'eina'
+ #
+ # ENUMS
+ #
+ # TYPEDEFS
+ # typedef struct _Eina_List Eina_List;
+ typedef :pointer, :eina_list
+ typedef :pointer, :eina_list_p
+ typedef :pointer, :eina_list_pp
+ # typedef struct _Eina_List_Accounting Eina_List_Accounting;
+ typedef :pointer, :eina_list_accounting
+ #
+ # CALLBACKS
+ #
+ # FUNCTIONS
+ fcts = [
+ # EAPI Eina_List *eina_list_append(Eina_List *list, const void *data);
+ [ :eina_list_append, [ :eina_list_p, :void_p ], :eina_list_p ],
+ # EAPI Eina_List *eina_list_prepend(Eina_List *list, const void *data);
+ [ :eina_list_prepend, [ :eina_list_p, :void_p ], :eina_list_p ],
+ # EAPI Eina_List *eina_list_append_relative(Eina_List *list, const void *data, const void *relative);
+ [ :eina_list_append_relative, [ :eina_list_p, :void_p, :void_p ], :eina_list_p ],
+ # EAPI Eina_List *eina_list_append_relative_list(Eina_List *list, const void *data, Eina_List *relative);
+ [ :eina_list_append_relative_list, [ :eina_list_p, :void_p, :eina_list_p ], :eina_list_p ],
+ # EAPI Eina_List *eina_list_prepend_relative(Eina_List *list, const void *data, const void *relative);
+ [ :eina_list_prepend_relative, [ :eina_list_p, :void_p, :void_p ], :eina_list_p ],
+ # EAPI Eina_List *eina_list_prepend_relative_list(Eina_List *list, const void *data, Eina_List *relative);
+ [ :eina_list_prepend_relative_list, [ :eina_list_p, :void_p, :eina_list_p ], :eina_list_p ],
+ # EAPI Eina_List *eina_list_sorted_insert(Eina_List *list, Eina_Compare_Cb func, const void *data);
+ [ :eina_list_sorted_insert, [ :eina_list_p, :eina_compare_cb, :void_p ], :eina_list_p ],
+ # EAPI Eina_List *eina_list_remove(Eina_List *list, const void *data);
+ [ :eina_list_remove, [ :eina_list_p, :void_p ], :eina_list_p ],
+ # EAPI Eina_List *eina_list_remove_list(Eina_List *list, Eina_List *remove_list);
+ [ :eina_list_remove_list, [ :eina_list_p, :eina_list_p ], :eina_list_p ],
+ # EAPI Eina_List *eina_list_promote_list(Eina_List *list, Eina_List *move_list);
+ [ :eina_list_promote_list, [ :eina_list_p, :eina_list_p ], :eina_list_p ],
+ # EAPI Eina_List *eina_list_demote_list(Eina_List *list, Eina_List *move_list);
+ [ :eina_list_demote_list, [ :eina_list_p, :eina_list_p ], :eina_list_p ],
+ # EAPI void *eina_list_data_find(const Eina_List *list, const void *data) EINA_PURE;
+ [ :eina_list_data_find, [ :eina_list_p, :void_p ], :void_p ],
+ # EAPI Eina_List *eina_list_data_find_list(const Eina_List *list, const void *data) EINA_PURE;
+ [ :eina_list_data_find_list, [ :eina_list_p, :void_p ], :eina_list_p ],
+ # EAPI Eina_Bool eina_list_move(Eina_List **to, Eina_List **from, void *data);
+ [ :eina_list_move, [ :eina_list_pp, :eina_list_pp, :void_p ], :eina_bool ],
+ # EAPI Eina_Bool eina_list_move_list(Eina_List **to, Eina_List **from, Eina_List *data);
+ [ :eina_list_move_list, [ :eina_list_pp, :eina_list_pp, :eina_list_p ], :eina_bool ],
+ # EAPI Eina_List *eina_list_free(Eina_List *list);
+ [ :eina_list_free, [ :eina_list_p ], :eina_list_p ],
+ # EAPI void *eina_list_nth(const Eina_List *list, unsigned int n) EINA_PURE EINA_WARN_UNUSED_RESULT;
+ [ :eina_list_nth, [ :eina_list_p, :uint ], :void_p ],
+ # EAPI Eina_List *eina_list_nth_list(const Eina_List *list, unsigned int n) EINA_PURE EINA_WARN_UNUSED_RESULT;
+ [ :eina_list_nth_list, [ :eina_list_p, :uint ], :eina_list_p ],
+ # EAPI Eina_List *eina_list_reverse(Eina_List *list) EINA_WARN_UNUSED_RESULT;
+ [ :eina_list_reverse, [ :eina_list_p ], :eina_list_p ],
+ # EAPI Eina_List *eina_list_reverse_clone(const Eina_List *list) EINA_WARN_UNUSED_RESULT;
+ [ :eina_list_reverse_clone, [ :eina_list_p ], :eina_list_p ],
+ # EAPI Eina_List *eina_list_clone(const Eina_List *list) EINA_WARN_UNUSED_RESULT;
+ [ :eina_list_clone, [ :eina_list_p ], :eina_list_p ],
+ # EAPI Eina_List *eina_list_sort(Eina_List *list, unsigned int size, Eina_Compare_Cb func);
+ [ :eina_list_sort, [ :eina_list_p, :uint, :eina_compare_cb ], :eina_list_p ],
+ # EAPI Eina_List *eina_list_merge(Eina_List *left, Eina_List *right) EINA_WARN_UNUSED_RESULT;
+ [ :eina_list_merge, [ :eina_list_p, :eina_list_p ], :eina_list_p ],
+ # EAPI Eina_List *eina_list_sorted_merge(Eina_List *left, Eina_List *right, Eina_Compare_Cb func);
+ [ :eina_list_sorted_merge, [ :eina_list_p, :eina_list_p, :eina_compare_cb ], :eina_list_p ],
+ # EAPI Eina_List *eina_list_split_list(Eina_List *list, Eina_List *relative, Eina_List **right) EINA_WARN_UNUSED_RESULT;
+ [ :eina_list_split_list, [ :eina_list_p, :eina_list_p, :eina_list_pp ], :eina_list_p ],
+ # EAPI Eina_List *eina_list_search_sorted_near_list(const Eina_List *list, Eina_Compare_Cb func, const void *data, int *result_cmp);
+ [ :eina_list_search_sorted_near_list, [ :eina_list_p, :eina_compare_cb, :void_p, :int_p ], :eina_list_p ],
+ # EAPI Eina_List *eina_list_search_sorted_list(const Eina_List *list, Eina_Compare_Cb func, const void *data);
+ [ :eina_list_search_sorted_list, [ :eina_list_p, :eina_compare_cb, :void_p ], :eina_list_p ],
+ # EAPI void *eina_list_search_sorted(const Eina_List *list, Eina_Compare_Cb func, const void *data);
+ [ :eina_list_search_sorted, [ :eina_list_p, :eina_compare_cb, :void_p ], :void_p ],
+ # EAPI Eina_List *eina_list_search_unsorted_list(const Eina_List *list, Eina_Compare_Cb func, const void *data);
+ [ :eina_list_search_unsorted_list, [ :eina_list_p, :eina_compare_cb, :void_p ], :eina_list_p ],
+ # EAPI void *eina_list_search_unsorted(const Eina_List *list, Eina_Compare_Cb func, const void *data);
+ [ :eina_list_search_unsorted, [ :eina_list_p, :eina_compare_cb, :void_p ], :void_p ],
+ # EAPI Eina_Iterator *eina_list_iterator_new(const Eina_List *list) EINA_MALLOC EINA_WARN_UNUSED_RESULT;
+ [ :eina_list_iterator_new, [ :eina_list_p ], :eina_iterator_p ],
+ # EAPI Eina_Iterator *eina_list_iterator_reversed_new(const Eina_List *list) EINA_MALLOC EINA_WARN_UNUSED_RESULT;
+ [ :eina_list_iterator_reversed_new, [ :eina_list_p ], :eina_iterator_p ],
+ # EAPI Eina_Accessor *eina_list_accessor_new(const Eina_List *list) EINA_MALLOC EINA_WARN_UNUSED_RESULT;
+ [ :eina_list_accessor_new, [ :eina_list_p ], :eina_accessor_p ],
+ ]
+ #
+ attach_fcts fcts
+ end
+end
+#
+# EOF
diff --git a/spec/eina_list_spec.rb b/spec/eina_list_spec.rb
new file mode 100644
index 0000000..5dba1de
--- /dev/null
+++ b/spec/eina_list_spec.rb
@@ -0,0 +1,100 @@
+#! /usr/bin/env ruby
+# -*- coding: UTF-8 -*-
+#
+require 'efl/eina_list'
+#
+describe Efl::Eina::EinaList do
+ #
+ before(:all) {
+ EinaList = Efl::Eina::EinaList
+ Efl::Eina.init.should eql 1
+ }
+ after(:all) {
+ Efl::Eina.shutdown.should eql 0
+ }
+ #
+ it "should append prepend and fetch" do
+ l = EinaList.new
+ d1 = ::FFI::MemoryPointer.from_string "D0"
+ d2 = ::FFI::MemoryPointer.from_string "D1"
+ d3 = ::FFI::MemoryPointer.from_string "D2"
+ d4 = ::FFI::MemoryPointer.from_string "D3"
+ l.append d3
+ l.prepend d2
+ l << d4
+ l.unshift d1
+ 0.upto 3 do |i|
+ l.nth(i).read_string.should eql "D#{i}"
+ end
+ l.each { |p| p.read_string.empty?.should be_false }
+ l.free
+ end
+ #
+ it "should be able to convert into ruby Array from NULL pointer" do
+ ary = Array.from_eina_list ::FFI::Pointer::NULL
+ ary.empty?.should be_true
+ ary.is_a?(Array).should be_true
+ end
+ #
+ it "should be able to convert into ruby Array from empty EinaList" do
+ ary = Array.from_eina_list EinaList.new
+ ary.empty?.should be_true
+ ary.is_a?(Array).should be_true
+ end
+ #
+ it "should be able to convert into ruby Array from empty EinaList pointer" do
+ ary = Array.from_eina_list EinaList.new.ptr
+ ary.empty?.should be_true
+ ary.is_a?(Array).should be_true
+ end
+ #
+ it "should be able to convert into ruby Array from non empty EinaList" do
+ l = EinaList.new
+ d1 = ::FFI::MemoryPointer.from_string "D0"
+ d2 = ::FFI::MemoryPointer.from_string "D1"
+ d3 = ::FFI::MemoryPointer.from_string "D2"
+ d4 = ::FFI::MemoryPointer.from_string "D3"
+ l.append d3
+ l.prepend d2
+ l << d4
+ l.unshift d1
+ ary = Array.from_eina_list l
+ ary.length.should eql 4
+ 0.upto 3 do |i|
+ ary[i].read_string.should eql "D#{i}"
+ end
+ l.free
+ end
+ #
+ it "should be able to convert into ruby Array from non empty EinaList pointer" do
+ l = EinaList.new
+ d1 = ::FFI::MemoryPointer.from_string "D0"
+ d2 = ::FFI::MemoryPointer.from_string "D1"
+ d3 = ::FFI::MemoryPointer.from_string "D2"
+ d4 = ::FFI::MemoryPointer.from_string "D3"
+ l.append d3
+ l.prepend d2
+ l << d4
+ l.unshift d1
+ ary = Array.from_eina_list l.ptr
+ ary.length.should eql 4
+ 0.upto 3 do |i|
+ ary[i].read_string.should eql "D#{i}"
+ end
+ l.free
+ end
+ #
+ it "should be able to build from ruby Array" do
+ a = []
+ a << ::FFI::MemoryPointer.from_string("D0")
+ a << ::FFI::MemoryPointer.from_string("D1")
+ a << ::FFI::MemoryPointer.from_string("D2")
+ a << ::FFI::MemoryPointer.from_string("D3")
+ l = EinaList.new a
+ 0.upto 3 do |i|
+ l.nth(i).read_string.should eql "D#{i}"
+ end
+ l.free
+ end
+ #
+end
diff --git a/tools/extract-api.sh b/tools/extract-api.sh
index b5a4bc1..67eafb6 100755
--- a/tools/extract-api.sh
+++ b/tools/extract-api.sh
@@ -21,6 +21,7 @@ fi
for header in \
"${INCLUDE}/eina-1/eina/eina_types.h" \
"${INCLUDE}/eina-1/eina/eina_main.h" \
+ "${INCLUDE}/eina-1/eina/eina_list.h" \
"${INCLUDE}/eet-1/Eet.h" \
"${INCLUDE}/edje-1/Edje.h" \
"${INCLUDE}/evas-1/Evas.h" \
diff --git a/tools/genruby.rb b/tools/genruby.rb
index c64ee59..c41076a 100755
--- a/tools/genruby.rb
+++ b/tools/genruby.rb
@@ -8,6 +8,7 @@ lib_path = File.join path, '..', 'lib', 'efl', 'ffi'
libraries = [
[ 'eina_types.h', 'Eina', 'eina', 'eina'],
[ 'eina_main.h', 'Eina', 'eina', 'eina'],
+ [ 'eina_list.h', 'EinaList', 'eina_list', 'eina'],
[ 'Eet.h', 'Eet', 'eet', 'eet'],
[ 'Evas.h', 'Evas', 'evas', 'evas'],
# [ 'Evas_GL.h', 'EvasGl', 'evas_gl', 'evas'],
@@ -84,8 +85,6 @@ TYPES = {
# Efl BASE TYPES
'Eina_Bool' => ':eina_bool',
'Eina_Bool *' => ':eina_bool_p',
- 'Eina_List' => ':eina_list',
- 'Eina_List *' => ':eina_list_p',
'Eina_Hash' => ':eina_hash',
'Eina_Hash *' => ':eina_hash_p',
'Eina_Iterator' => ':eina_iterator',