summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/efl/eina.rb8
-rw-r--r--lib/efl/eina_hash.rb (renamed from lib/efl/eina/eina_hash.rb)39
-rw-r--r--lib/efl/eina_list.rb (renamed from lib/efl/eina/eina_list.rb)38
-rw-r--r--spec/eina_hash_spec.rb (renamed from spec/eina/eina_hash_spec.rb)96
-rw-r--r--spec/eina_list_spec.rb (renamed from spec/eina/eina_list_spec.rb)29
5 files changed, 108 insertions, 102 deletions
diff --git a/lib/efl/eina.rb b/lib/efl/eina.rb
index e5fcc67..dfa266c 100644
--- a/lib/efl/eina.rb
+++ b/lib/efl/eina.rb
@@ -3,4 +3,12 @@
#
require 'efl/ffi/eina'
#
+module Efl
+ #
+ module Eina
+ #
+ end
+ #
+end
+#
# EOF
diff --git a/lib/efl/eina/eina_hash.rb b/lib/efl/eina_hash.rb
index 76cd5d2..03619dc 100644
--- a/lib/efl/eina/eina_hash.rb
+++ b/lib/efl/eina_hash.rb
@@ -1,40 +1,39 @@
#! /usr/bin/env ruby
# -*- coding: UTF-8 -*-
#
-require 'efl/eina'
-require 'efl/ffi/eina/eina_hash'
+require 'efl/ffi/eina_hash'
#
class Hash
def self.from_eina_hash o
- if o.is_a? Efl::Eina::EinaHash
+ if o.is_a? Efl::EinaHash::REinaHash
o.to_h
- elsif o.is_a? ::FFI::Pointer
- Efl::Eina::EinaHash.new(o).to_h
+ elsif o.is_a? FFI::Pointer
+ Efl::EinaHash::REinaHash.new(o).to_h
else
raise ArgumentError.new " wrong argument #{o.class.name}"
end
end
end
module Efl
- module Eina
+ module EinaHash
#
- class EinaHash
- include Efl::Helper
+ class REinaHash
include Enumerable
- @func_prefixes = [ 'eina_hash_' ].freeze
+ include Efl::ClassHelper
+ @func_prefixes = [ [Efl::EinaHash,'eina_hash_'] ].freeze
def initialize o=nil, &block
- cstr = ( block_given? ? block : Proc.new { Efl::FFI.eina_hash_string_djb2_new ::FFI::Pointer::NULL } )
+ cstr = ( block_given? ? block : Proc.new { Efl::EinaHash.eina_hash_string_djb2_new FFI::Pointer::NULL } )
@ptr = (
case o
- when ::FFI::Pointer
- ( o==::FFI::Pointer::NULL ? cstr.call : o )
+ when FFI::Pointer
+ ( o==FFI::Pointer::NULL ? cstr.call : o )
when NilClass
cstr.call
when self.class
o.ptr
when Hash
ptr = cstr.call
- o.each do |k,v| Efl::FFI.eina_hash_add ptr, k, v end
+ o.each do |k,v| Efl::EinaHash.eina_hash_add ptr, k, v end
ptr
else
raise ArgumentError.new "#{ptr.class} valid argument"
@@ -42,12 +41,12 @@ module Efl
)
end
def free
- return if @ptr==::FFI::Pointer::NULL
- @ptr = Efl::FFI.eina_hash_free @ptr
+ return if @ptr==FFI::Pointer::NULL
+ @ptr = Efl::EinaHash.eina_hash_free @ptr
end
- def each data=::FFI::Pointer::NULL, &block
+ def each data=FFI::Pointer::NULL, &block
return if not block_given?
- Efl::FFI::eina_hash_foreach @ptr, Proc.new{|h,k,v,d| block.call(k,v) }, data
+ Efl::EinaHash::eina_hash_foreach @ptr, Proc.new{|h,k,v,d| block.call(k,v) }, data
end
def to_h
rh = {}
@@ -65,13 +64,13 @@ module Efl
end
# for fun and tests
def add k, v
- Efl::FFI.eina_hash_add @ptr, k, v
+ Efl::EinaHash.eina_hash_add @ptr, k, v
v
end
alias :[]= :add
def find k
- r = Efl::FFI.eina_hash_find @ptr, k
- return ( r==::FFI::Pointer::NULL ? nil : r )
+ r = Efl::EinaHash.eina_hash_find @ptr, k
+ return ( r==FFI::Pointer::NULL ? nil : r )
end
alias :[] :find
end
diff --git a/lib/efl/eina/eina_list.rb b/lib/efl/eina_list.rb
index fdbc176..ecd0e20 100644
--- a/lib/efl/eina/eina_list.rb
+++ b/lib/efl/eina_list.rb
@@ -1,60 +1,58 @@
#! /usr/bin/env ruby
# -*- coding: UTF-8 -*-
#
-require 'efl/eina'
-require 'efl/ffi/eina/eina_list'
+require 'efl/ffi/eina_list'
#
class Array
def self.from_eina_list o
- if o.is_a? Efl::Eina::EinaList
+ if o.is_a? Efl::EinaList::REinaList
o.to_ary
- elsif o.is_a? ::FFI::Pointer
- Efl::Eina::EinaList.new(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 FFI
- class EinaList < ::FFI::Struct
+ module EinaList
+ #
+ class EinaListStruct < FFI::Struct
layout :data, :pointer,
:next, :pointer,
:prev, :pointer,
:accounting, :pointer,
:magic, :uint,
end
- end
- module Eina
#
- class EinaList
- include Efl::Helper
+ class REinaList
include Enumerable
- @func_prefixes = [ 'eina_list_' ].freeze
+ include Efl::ClassHelper
+ @search_paths = [ [Efl::EinaList,'eina_list_'] ].freeze
def initialize o=nil
@ptr = (
case o
- when ::FFI::Pointer
+ when FFI::Pointer
o
when NilClass
- ::FFI::Pointer::NULL
+ FFI::Pointer::NULL
when self.class
o.ptr
when Array
- o.inject(::FFI::Pointer::NULL) { |p,e| Efl::FFI::eina_list_append p, e }
+ 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::FFI.eina_list_free @ptr
+ 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::FFI::EinaList.new p
+ l = Efl::EinaList::EinaListStruct.new p
yield l[:data]
p = l[:next]
end
@@ -64,11 +62,11 @@ module Efl
end
# for fun and tests
def append p
- @ptr = Efl::FFI.eina_list_append @ptr, p
+ @ptr = Efl::EinaList.eina_list_append @ptr, p
end
alias :<< :append
def prepend p
- @ptr = Efl::FFI.eina_list_prepend @ptr, p
+ @ptr = Efl::EinaList.eina_list_prepend @ptr, p
end
alias :unshift :prepend
end
diff --git a/spec/eina/eina_hash_spec.rb b/spec/eina_hash_spec.rb
index 3cd5504..5efc062 100644
--- a/spec/eina/eina_hash_spec.rb
+++ b/spec/eina_hash_spec.rb
@@ -1,24 +1,24 @@
#! /usr/bin/env ruby
# -*- coding: UTF-8 -*-
#
-require 'efl/eina/eina_hash'
+require 'efl/eina_hash'
#
-describe Efl::Eina::EinaHash do
+describe Efl::EinaHash do
#
before(:all) {
- EinaHash = Efl::Eina::EinaHash
+ REinaHash = Efl::EinaHash::REinaHash
Efl::Eina.init.should eql 1
- @d0 = ::FFI::MemoryPointer.from_string "D0"
- @d1 = ::FFI::MemoryPointer.from_string "D1"
- @d2 = ::FFI::MemoryPointer.from_string "D2"
- @d3 = ::FFI::MemoryPointer.from_string "D3"
+ @d0 = FFI::MemoryPointer.from_string "D0"
+ @d1 = FFI::MemoryPointer.from_string "D1"
+ @d2 = FFI::MemoryPointer.from_string "D2"
+ @d3 = FFI::MemoryPointer.from_string "D3"
}
after(:all) {
Efl::Eina.shutdown.should eql 0
}
#
it "should append prepend and fetch" do
- h = EinaHash.new
+ h = REinaHash.new
h.add 'k2', @d2
h.add 'k1', @d1
h['k3']=@d3
@@ -37,29 +37,29 @@ describe Efl::Eina::EinaHash do
end
#
it "should be able to convert into ruby Hash from NULL pointer" do
- h = Hash.from_eina_hash ::FFI::Pointer::NULL
+ h = Hash.from_eina_hash FFI::Pointer::NULL
h.empty?.should be_true
h.is_a?(Hash).should be_true
end
#
- it "should be able to convert into ruby Hash from empty EinaHash" do
- h = Hash.from_eina_hash EinaHash.new
+ it "should be able to convert into ruby Hash from empty REinaHash" do
+ h = Hash.from_eina_hash REinaHash.new
h.empty?.should be_true
h.is_a?(Hash).should be_true
end
#
- it "should be able to convert into ruby Hash from empty EinaHash pointer" do
- h = Hash.from_eina_hash EinaHash.new.ptr
+ it "should be able to convert into ruby Hash from empty REinaHash pointer" do
+ h = Hash.from_eina_hash REinaHash.new.to_ptr
h.empty?.should be_true
h.is_a?(Hash).should be_true
end
#
- it "should be able to convert into ruby Hash from non empty EinaHash" do
- h = EinaHash.new
- d0 = ::FFI::MemoryPointer.from_string "D0"
- d1 = ::FFI::MemoryPointer.from_string "D1"
- d2 = ::FFI::MemoryPointer.from_string "D2"
- d3 = ::FFI::MemoryPointer.from_string "D3"
+ it "should be able to convert into ruby Hash from non empty REinaHash" do
+ h = REinaHash.new
+ d0 = FFI::MemoryPointer.from_string "D0"
+ d1 = FFI::MemoryPointer.from_string "D1"
+ d2 = FFI::MemoryPointer.from_string "D2"
+ d3 = FFI::MemoryPointer.from_string "D3"
h.add 'k2', d2
h.add 'k1', d1
h['k3']=d3
@@ -89,12 +89,12 @@ describe Efl::Eina::EinaHash do
h.free
end
#
- it "should be able to convert into ruby Hash from non empty EinaHash pointer" do
- h = EinaHash.new
- d0 = ::FFI::MemoryPointer.from_string "D0"
- d1 = ::FFI::MemoryPointer.from_string "D1"
- d2 = ::FFI::MemoryPointer.from_string "D2"
- d3 = ::FFI::MemoryPointer.from_string "D3"
+ it "should be able to convert into ruby Hash from non empty REinaHash pointer" do
+ h = REinaHash.new
+ d0 = FFI::MemoryPointer.from_string "D0"
+ d1 = FFI::MemoryPointer.from_string "D1"
+ d2 = FFI::MemoryPointer.from_string "D2"
+ d3 = FFI::MemoryPointer.from_string "D3"
h.add 'k2', d2
h.add 'k1', d1
h['k3']=d3
@@ -103,17 +103,17 @@ describe Efl::Eina::EinaHash do
h['k1'].read_string.should eql "D1"
h['k2'].read_string.should eql "D2"
h['k3'].read_string.should eql "D3"
- rh = Hash.from_eina_hash h.ptr
+ rh = Hash.from_eina_hash h.to_ptr
rh.length.should eql 4
h.free
end
#
- it "should be able to convert into ruby Hash from non empty EinaHash pointer, with key from string" do
- h = EinaHash.new
- d0 = ::FFI::MemoryPointer.from_string "D0"
- d1 = ::FFI::MemoryPointer.from_string "D1"
- d2 = ::FFI::MemoryPointer.from_string "D2"
- d3 = ::FFI::MemoryPointer.from_string "D3"
+ it "should be able to convert into ruby Hash from non empty REinaHash pointer, with key from string" do
+ h = REinaHash.new
+ d0 = FFI::MemoryPointer.from_string "D0"
+ d1 = FFI::MemoryPointer.from_string "D1"
+ d2 = FFI::MemoryPointer.from_string "D2"
+ d3 = FFI::MemoryPointer.from_string "D3"
h.add 'k2', d2
h.add 'k1', d1
h['k3']=d3
@@ -131,12 +131,12 @@ describe Efl::Eina::EinaHash do
h.free
end
#
- it "should be able to convert into ruby Hash from non empty EinaHash pointer, with key from string block" do
- h = EinaHash.new
- d0 = ::FFI::MemoryPointer.from_string "D0"
- d1 = ::FFI::MemoryPointer.from_string "D1"
- d2 = ::FFI::MemoryPointer.from_string "D2"
- d3 = ::FFI::MemoryPointer.from_string "D3"
+ it "should be able to convert into ruby Hash from non empty REinaHash pointer, with key from string block" do
+ h = REinaHash.new
+ d0 = FFI::MemoryPointer.from_string "D0"
+ d1 = FFI::MemoryPointer.from_string "D1"
+ d2 = FFI::MemoryPointer.from_string "D2"
+ d3 = FFI::MemoryPointer.from_string "D3"
h.add 'k2', d2
h.add 'k1', d1
h['k3']=d3
@@ -158,19 +158,19 @@ describe Efl::Eina::EinaHash do
#
it "should be able to build from ruby Hash" do
rh = {}
- k0 = ::FFI::MemoryPointer.from_string "0"
- k1 = ::FFI::MemoryPointer.from_string "1"
- k2 = ::FFI::MemoryPointer.from_string "2"
- k3 = ::FFI::MemoryPointer.from_string "3"
- d0 = ::FFI::MemoryPointer.from_string "D0"
- d1 = ::FFI::MemoryPointer.from_string "D1"
- d2 = ::FFI::MemoryPointer.from_string "D2"
- d3 = ::FFI::MemoryPointer.from_string "D3"
+ k0 = FFI::MemoryPointer.from_string "0"
+ k1 = FFI::MemoryPointer.from_string "1"
+ k2 = FFI::MemoryPointer.from_string "2"
+ k3 = FFI::MemoryPointer.from_string "3"
+ d0 = FFI::MemoryPointer.from_string "D0"
+ d1 = FFI::MemoryPointer.from_string "D1"
+ d2 = FFI::MemoryPointer.from_string "D2"
+ d3 = FFI::MemoryPointer.from_string "D3"
rh[k0]=d0
rh[k1]=d1
rh[k2]=d2
rh[k3]=d3
- h = EinaHash.new rh
+ h = REinaHash.new rh
h[k0].read_string.should eql "D0"
h[k1].read_string.should eql "D1"
h[k2].read_string.should eql "D2"
@@ -180,7 +180,7 @@ describe Efl::Eina::EinaHash do
#
it "alternate constructor should work" do
cstr_cnt = 0
- h = EinaHash.new { cstr_cnt+=1; Efl::FFI.eina_hash_string_superfast_new ::FFI::Pointer::NULL }
+ h = REinaHash.new { cstr_cnt+=1; Efl::EinaHash.eina_hash_string_superfast_new FFI::Pointer::NULL }
cstr_cnt.should eql 1
end
end
diff --git a/spec/eina/eina_list_spec.rb b/spec/eina_list_spec.rb
index 2522256..74f89c5 100644
--- a/spec/eina/eina_list_spec.rb
+++ b/spec/eina_list_spec.rb
@@ -1,12 +1,13 @@
#! /usr/bin/env ruby
# -*- coding: UTF-8 -*-
#
-require 'efl/eina/eina_list'
+require 'efl/eina'
+require 'efl/eina_list'
#
-describe Efl::Eina::EinaList do
+describe Efl::EinaList do
#
before(:all) {
- EinaList = Efl::Eina::EinaList
+ REinaList = Efl::EinaList::REinaList
Efl::Eina.init.should eql 1
}
after(:all) {
@@ -14,7 +15,7 @@ describe Efl::Eina::EinaList do
}
#
it "should append prepend and fetch" do
- l = EinaList.new
+ l = REinaList.new
d1 = ::FFI::MemoryPointer.from_string "D0"
d2 = ::FFI::MemoryPointer.from_string "D1"
d3 = ::FFI::MemoryPointer.from_string "D2"
@@ -36,20 +37,20 @@ describe Efl::Eina::EinaList do
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
+ it "should be able to convert into ruby Array from empty REinaList" do
+ ary = Array.from_eina_list REinaList.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
+ it "should be able to convert into ruby Array from empty REinaList pointer" do
+ ary = Array.from_eina_list REinaList.new.to_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
+ it "should be able to convert into ruby Array from non empty REinaList" do
+ l = REinaList.new
d1 = ::FFI::MemoryPointer.from_string "D0"
d2 = ::FFI::MemoryPointer.from_string "D1"
d3 = ::FFI::MemoryPointer.from_string "D2"
@@ -66,8 +67,8 @@ describe Efl::Eina::EinaList do
l.free
end
#
- it "should be able to convert into ruby Array from non empty EinaList pointer" do
- l = EinaList.new
+ it "should be able to convert into ruby Array from non empty REinaList pointer" do
+ l = REinaList.new
d1 = ::FFI::MemoryPointer.from_string "D0"
d2 = ::FFI::MemoryPointer.from_string "D1"
d3 = ::FFI::MemoryPointer.from_string "D2"
@@ -76,7 +77,7 @@ describe Efl::Eina::EinaList do
l.prepend d2
l << d4
l.unshift d1
- ary = Array.from_eina_list l.ptr
+ ary = Array.from_eina_list l.to_ptr
ary.length.should eql 4
0.upto 3 do |i|
ary[i].read_string.should eql "D#{i}"
@@ -90,7 +91,7 @@ describe Efl::Eina::EinaList do
a << ::FFI::MemoryPointer.from_string("D1")
a << ::FFI::MemoryPointer.from_string("D2")
a << ::FFI::MemoryPointer.from_string("D3")
- l = EinaList.new a
+ l = REinaList.new a
0.upto 3 do |i|
l.nth(i).read_string.should eql "D#{i}"
end