class CF::Base
The base class for all of the wrapper classes in CF
module.
Attributes
Public Class Methods
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
@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
@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
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
# File lib/corefoundation/base.rb, line 90 def self.type_map @@type_map end
Public Instance Methods
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
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
Uses CFHash to return a hash code
@return [Integer]
# File lib/corefoundation/base.rb, line 54 def hash CF.CFHash(self) end
Whether the instance is the CFNull singleton
@return [Boolean]
# File lib/corefoundation/base.rb, line 47 def null? equals?(CF::NULL) end
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
# File lib/corefoundation/base.rb, line 78 def to_ruby raise CF::Exceptions::MethodNotImplemented, "#{self.class} should implement the to_ruby method." end