Skip to content

Add a G_DECLARE macro for "protected" types

Emmanuele Bassi requested to merge protected-type into main

Certain libraries want to provide types that are derivable for internal users, but final for any external consumer of the API. Other languages use the term "protected" to refer to this kind of type visibility attribute.

Since we're providing macros to declare derivable and final types, we should also provide a macro for declaring protected types.

The mechanism is the same as the other G_DECLARE macros; protected types:

  • define an opaque type for the instance, like G_DEFINE_FINAL_TYPE
  • define an opaque type for the class
  • define cast and type check functions for instance pointers, for public consumers, and cast and type check functions for class pointers, for internal consumers
  • omit an accessor for retrieving the class structure from the instance structure, as it would be pointless to do so

Merge request reports