TypeClassProtocol

public protocol TypeClassProtocol

The TypeClassProtocol protocol exposes the methods and properties of an underlying GTypeClass instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, see TypeClass. Alternatively, use TypeClassRef as a lighweight, unowned reference if you already have an instance you just want to use.

An opaque structure used as the base of all classes.

  • ptr

    Untyped pointer to the underlying GTypeClass instance.

    Declaration

    Swift

    var ptr: UnsafeMutableRawPointer { get }
  • _ptr Default implementation

    Typed pointer to the underlying GTypeClass instance.

    Default Implementation

    Return the stored, untyped pointer as a typed pointer to the GTypeClass instance.

    Declaration

    Swift

    var _ptr: UnsafeMutablePointer<GTypeClass> { get }

TypeClass Record: TypeClassProtocol extension (methods and fields)

  • addPrivate(privateSize:) Extension method

    Registers a private structure for an instantiatable type.

    When an object is allocated, the private structures for the type and all of its parent types are allocated sequentially in the same memory block as the public structures, and are zero-filled.

    Note that the accumulated size of the private structures of a type and all its parent types cannot exceed 64 KiB.

    This function should be called in the type’s class_init() function. The private structure can be retrieved using the G_TYPE_INSTANCE_GET_PRIVATE() macro.

    The following example shows attaching a private structure MyObjectPrivate to an object MyObject defined in the standard GObject fashion in the type’s class_init() function.

    Note the use of a structure member “priv” to avoid the overhead of repeatedly calling MY_OBJECT_GET_PRIVATE().

    (C Language Example):

    typedef struct _MyObject        MyObject;
    typedef struct _MyObjectPrivate MyObjectPrivate;
    
    struct _MyObject {
     GObject parent;
    
     MyObjectPrivate *priv;
    };
    
    struct _MyObjectPrivate {
      int some_field;
    };
    
    static void
    my_object_class_init (MyObjectClass *klass)
    {
      g_type_class_add_private (klass, sizeof (MyObjectPrivate));
    }
    
    static void
    my_object_init (MyObject *my_object)
    {
      my_object->priv = G_TYPE_INSTANCE_GET_PRIVATE (my_object,
                                                     MY_TYPE_OBJECT,
                                                     MyObjectPrivate);
      // my_object->priv->some_field will be automatically initialised to 0
    }
    
    static int
    my_object_get_some_field (MyObject *my_object)
    {
      MyObjectPrivate *priv;
    
      g_return_val_if_fail (MY_IS_OBJECT (my_object), 0);
    
      priv = my_object->priv;
    
      return priv->some_field;
    }
    

    add_private is deprecated: Use the G_ADD_PRIVATE() macro with the G_DEFINE_* family of macros to add instance private data to a type

    Declaration

    Swift

    @available(*, deprecated)
    func addPrivate(privateSize private_size: Int)
  • getInstancePrivateOffset() Extension method

    Gets the offset of the private data for instances of g_class.

    This is how many bytes you should add to the instance pointer of a class in order to get the private data for the type represented by g_class.

    You can only call this function after you have registered a private data area for g_class using g_type_class_add_private().

    Declaration

    Swift

    func getInstancePrivateOffset() -> Int
  • getPrivate(privateType:) Extension method

    Undocumented

    Declaration

    Swift

    func getPrivate(privateType private_type: GType) -> UnsafeMutableRawPointer!
  • peekParent() Extension method

    This is a convenience function often needed in class initializers. It returns the class structure of the immediate parent type of the class passed in. Since derived classes hold a reference count on their parent classes as long as they are instantiated, the returned class will always exist.

    This function is essentially equivalent to: g_type_class_peek (g_type_parent (G_TYPE_FROM_CLASS (g_class)))

    Declaration

    Swift

    func peekParent() -> UnsafeMutableRawPointer!
  • unref() Extension method

    Decrements the reference count of the class structure being passed in. Once the last reference count of a class has been released, classes may be finalized by the type system, so further dereferencing of a class pointer after g_type_class_unref() are invalid.

    Declaration

    Swift

    func unref()
  • unrefUncached() Extension method

    A variant of g_type_class_unref() for use in GTypeClassCacheFunc implementations. It unreferences a class without consulting the chain of GTypeClassCacheFuncs, avoiding the recursion which would occur otherwise.

    Declaration

    Swift

    func unrefUncached()
  • typeCheckClassCast(isAType:) Extension method

    Undocumented

    Declaration

    Swift

    func typeCheckClassCast(isAType is_a_type: GType) -> UnsafeMutablePointer<GTypeClass>!
  • typeCheckClassIsA(isAType:) Extension method

    Undocumented

    Declaration

    Swift

    func typeCheckClassIsA(isAType is_a_type: GType) -> Bool
  • Returns the GTypeInterface structure of an interface to which the passed in class conforms.

    Declaration

    Swift

    func typeInterfacePeek(ifaceType iface_type: GType) -> UnsafeMutableRawPointer!
  • typeNameFromClass() Extension method

    Undocumented

    Declaration

    Swift

    func typeNameFromClass() -> String!
  • instancePrivateOffset Extension method

    Gets the offset of the private data for instances of g_class.

    This is how many bytes you should add to the instance pointer of a class in order to get the private data for the type represented by g_class.

    You can only call this function after you have registered a private data area for g_class using g_type_class_add_private().

    Declaration

    Swift

    var instancePrivateOffset: Int { get }