class CF::Base

The base class for all of the wrapper classes in CF module.

Attributes

ptr[R]

Public Class Methods

check_cftype(cftyperef) click to toggle source

Raises an exception if the argument does not inherit from CF::Base

@param cftyperef object to check

# File lib/corefoundation/base.rb, line 18
def self.check_cftype(cftyperef)
  raise TypeError, "#{cftyperef.inspect} is not a cftype" unless cftyperef.is_a?(CF::Base)
end
finalize(pointer) click to toggle source

@param [FFI::Pointer] pointer to the address of the object

# File lib/corefoundation/base.rb, line 40
def self.finalize(pointer)
  proc { CF.release(pointer) unless pointer.address.zero? }
end
new(pointer) click to toggle source

@param [FFI::Pointer] pointer The pointer to wrap

# File lib/corefoundation/base.rb, line 33
def initialize(pointer)
  @ptr = FFI::Pointer.new(pointer)
  ObjectSpace.define_finalizer(self, self.class.finalize(ptr))
  CF.retain(ptr)
end
typecast(cftyperef) click to toggle source

Wraps an FFI::Pointer with the appropriate subclass of CF::Base If the pointer is not a CFTypeRef behaviour is undefined

@param [FFI::Pointer] cftyperef Object to wrap @return A wrapper object inheriting from CF::Base

# File lib/corefoundation/base.rb, line 27
def self.typecast(cftyperef)
  klass = klass_from_cf_type cftyperef
  klass.new(cftyperef)
end

Private Class Methods

type_map() click to toggle source
# File lib/corefoundation/base.rb, line 90
def self.type_map
  @@type_map
end

Public Instance Methods

==(other)
Alias for: eql?
eql?(other) click to toggle source

eql? (and ==) are implemented using CFEqual

# File lib/corefoundation/base.rb, line 59
def eql?(other)
  if other.is_a?(CF::Base)
    CF.CFEqual(self, other) != 0
  else
    false
  end
end
Also aliased as: ==
equals?(other) click to toggle source

equals? is defined as returning true if the wrapped pointer is the same

# File lib/corefoundation/base.rb, line 70
def equals?(other)
  if other.is_a?(CF::Base)
    @ptr.address == other.to_ptr.address
  else
    false
  end
end
hash() click to toggle source

Uses CFHash to return a hash code

@return [Integer]

# File lib/corefoundation/base.rb, line 54
def hash
  CF.CFHash(self)
end
null?() click to toggle source

Whether the instance is the CFNull singleton

@return [Boolean]

# File lib/corefoundation/base.rb, line 47
def null?
  equals?(CF::NULL)
end
to_cf() click to toggle source

This is a no-op on CF::Base and its subclasses. Always returns self.

@return Returns self

# File lib/corefoundation/base.rb, line 85
def to_cf
  self
end
to_ruby() click to toggle source
# File lib/corefoundation/base.rb, line 78
def to_ruby
  raise CF::Exceptions::MethodNotImplemented, "#{self.class} should implement the to_ruby method."
end