Class: GObjectIntrospection::IBaseInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/ffi-gobject_introspection/i_base_info.rb

Overview

Wraps GIBaseInfo struct, the base type for all info types. Decendant types will be implemented as needed.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ptr) ⇒ IBaseInfo

Returns a new instance of IBaseInfo.

Raises:

  • (ArgumentError)


7
8
9
10
11
12
13
# File 'lib/ffi-gobject_introspection/i_base_info.rb', line 7

def initialize(ptr)
  raise ArgumentError, "ptr must not be null" if ptr.null?

  ObjectSpace.define_finalizer self, self.class.make_finalizer(ptr)

  @pointer = ptr
end

Instance Attribute Details

#pointerObject (readonly)

Returns the value of attribute pointer.



15
16
17
# File 'lib/ffi-gobject_introspection/i_base_info.rb', line 15

def pointer
  @pointer
end

Class Method Details

.build_array_method(method, single = nil) ⇒ Object

This is a helper method to construct a method returning an array, out of the methods returning their number and the individual elements.

For example, given the methods n_foos and foo(i), this method will create an additional method foos returning all foos.

Provide the second parameter if the plural is not trivially constructed by adding s to the singular.

Examples:

build_array_method :fields
build_array_method :properties, :property
build_array_method :get_methods


48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/ffi-gobject_introspection/i_base_info.rb', line 48

def self.build_array_method(method, single = nil)
  method = method.to_s
  cache_ivar = "@#{method}_cache"
  single ||= method[0..-2]
  count = method.sub(/^(get_)?/, "\\1n_")
  class_eval <<-CODE, __FILE__, __LINE__ + 1
    def #{method}                       # def fields
      #{cache_ivar} ||=                 #   @fields_cache ||=
        (0..(#{count} - 1)).map do |i|  #     (0..(n_fields - 1)).map do |i|
          #{single} i                   #       field i
        end                             #     end
    end                                 # end
  CODE
end

.build_finder_method(method, counter = nil, fetcher = nil) ⇒ Object

This is a helper method to construct a method for finding an element, out of the methods returning their number and the individual elements.

For example, given the methods n_foos and foo(i), this method will create an additional method find_foo returning the foo with the matching name.

Optionally provide counter and fetcher methods if they cannot be trivially derived from the finder method.

Examples:

build_finder_method :find_field
build_finder_method :find_property, :n_properties
build_finder_method :find_method, :get_n_methods, :get_method


79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/ffi-gobject_introspection/i_base_info.rb', line 79

def self.build_finder_method(method, counter = nil, fetcher = nil)
  method = method.to_s
  cache_ivar = "@#{method}_cache"
  single = method.sub(/^find_/, "")
  counter ||= "n_#{single}s"
  fetcher ||= single
  class_eval <<-CODE, __FILE__, __LINE__ + 1
    def #{method}(name)           # def find_field(name)
      #{cache_ivar} ||= begin     #   @find_field_cache ||= begin
          hash = {}               #       hash = {}
          #{counter}.times do |i| #       n_fields.times do |i|
            it = #{fetcher}(i)    #         it = field(i)
            hash[it.name] = it    #         hash[it.name] = it
          end                     #       end
          hash                    #       hash
        end                       #     end
      name = name.to_s            #   name = name.to_s
      #{cache_ivar}[name]         #   @find_field_cache[name]
    end                           # end
  CODE
end

.make_finalizer(ptr) ⇒ Object



17
18
19
# File 'lib/ffi-gobject_introspection/i_base_info.rb', line 17

def self.make_finalizer(ptr)
  proc { finalize ptr }
end

.wrap(ptr) ⇒ Object



135
136
137
# File 'lib/ffi-gobject_introspection/i_base_info.rb', line 135

def self.wrap(ptr)
  new ptr unless ptr.null?
end

Instance Method Details

#==(other) ⇒ Object



139
140
141
# File 'lib/ffi-gobject_introspection/i_base_info.rb', line 139

def ==(other)
  other.is_a?(IBaseInfo) && Lib.g_base_info_equal(self, other)
end

#attribute(name) ⇒ Object



131
132
133
# File 'lib/ffi-gobject_introspection/i_base_info.rb', line 131

def attribute(name)
  Lib.g_base_info_get_attribute self, name
end

#containerObject



117
118
119
120
121
122
123
124
125
# File 'lib/ffi-gobject_introspection/i_base_info.rb', line 117

def container
  @container ||= begin
                   ptr = Lib.g_base_info_get_container self
                   unless ptr.null?
                     Lib.g_base_info_ref ptr
                     IRepository.wrap_ibaseinfo_pointer ptr
                   end
                 end
end

#deprecated?Boolean

Returns:

  • (Boolean)


127
128
129
# File 'lib/ffi-gobject_introspection/i_base_info.rb', line 127

def deprecated?
  Lib.g_base_info_is_deprecated self
end

#info_typeObject



105
106
107
# File 'lib/ffi-gobject_introspection/i_base_info.rb', line 105

def info_type
  @info_type ||= Lib.g_base_info_get_type self
end

#nameObject



101
102
103
# File 'lib/ffi-gobject_introspection/i_base_info.rb', line 101

def name
  @name ||= Lib.g_base_info_get_name self
end

#namespaceObject



109
110
111
# File 'lib/ffi-gobject_introspection/i_base_info.rb', line 109

def namespace
  @namespace ||= Lib.g_base_info_get_namespace self
end

#safe_namespaceObject



113
114
115
# File 'lib/ffi-gobject_introspection/i_base_info.rb', line 113

def safe_namespace
  namespace.sub(/^[a-z]/, &:upcase)
end

#to_ptrObject



29
30
31
# File 'lib/ffi-gobject_introspection/i_base_info.rb', line 29

def to_ptr
  @pointer
end