From 0ed32396a0fd63625ea94c4da86c2df3829acc72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Fri, 29 Apr 2011 14:45:08 +0200 Subject: update efl/eina* and specs --- lib/efl/eina.rb | 8 ++ lib/efl/eina/eina_hash.rb | 81 ------------------- lib/efl/eina/eina_list.rb | 78 ------------------- lib/efl/eina_hash.rb | 80 +++++++++++++++++++ lib/efl/eina_list.rb | 76 ++++++++++++++++++ spec/eina/eina_hash_spec.rb | 186 -------------------------------------------- spec/eina/eina_list_spec.rb | 100 ------------------------ spec/eina_hash_spec.rb | 186 ++++++++++++++++++++++++++++++++++++++++++++ spec/eina_list_spec.rb | 101 ++++++++++++++++++++++++ 9 files changed, 451 insertions(+), 445 deletions(-) delete mode 100644 lib/efl/eina/eina_hash.rb delete mode 100644 lib/efl/eina/eina_list.rb create mode 100644 lib/efl/eina_hash.rb create mode 100644 lib/efl/eina_list.rb delete mode 100644 spec/eina/eina_hash_spec.rb delete mode 100644 spec/eina/eina_list_spec.rb create mode 100644 spec/eina_hash_spec.rb create mode 100644 spec/eina_list_spec.rb 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/eina_hash.rb deleted file mode 100644 index 76cd5d2..0000000 --- a/lib/efl/eina/eina_hash.rb +++ /dev/null @@ -1,81 +0,0 @@ -#! /usr/bin/env ruby -# -*- coding: UTF-8 -*- -# -require 'efl/eina' -require 'efl/ffi/eina/eina_hash' -# -class Hash - def self.from_eina_hash o - if o.is_a? Efl::Eina::EinaHash - o.to_h - elsif o.is_a? ::FFI::Pointer - Efl::Eina::EinaHash.new(o).to_h - else - raise ArgumentError.new " wrong argument #{o.class.name}" - end - end -end -module Efl - module Eina - # - class EinaHash - include Efl::Helper - include Enumerable - @func_prefixes = [ 'eina_hash_' ].freeze - def initialize o=nil, &block - cstr = ( block_given? ? block : Proc.new { Efl::FFI.eina_hash_string_djb2_new ::FFI::Pointer::NULL } ) - @ptr = ( - case 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 - ptr - else - raise ArgumentError.new "#{ptr.class} valid argument" - end - ) - end - def free - return if @ptr==::FFI::Pointer::NULL - @ptr = Efl::FFI.eina_hash_free @ptr - end - 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 - end - def to_h - rh = {} - each { |k,v| rh[k]=v; true } - rh - end - def to_h_conv &block - rh = {} - if block_given? - each { |k,v| rh[block.call(k)]=v; true } - else - each { |k,v| rh[k.read_string]=v; true } - end - rh - end - # for fun and tests - def add k, v - Efl::FFI.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 ) - end - alias :[] :find - end - end -end -# -# EOF diff --git a/lib/efl/eina/eina_list.rb b/lib/efl/eina/eina_list.rb deleted file mode 100644 index fdbc176..0000000 --- a/lib/efl/eina/eina_list.rb +++ /dev/null @@ -1,78 +0,0 @@ -#! /usr/bin/env ruby -# -*- coding: UTF-8 -*- -# -require 'efl/eina' -require 'efl/ffi/eina/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<