Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
GObject
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Class implementation== Each GObject class is implemented by at least two structures: the ''class structure'' and the ''instance structure''. ; The class structure : The class structure corresponds to the [[vtable]] of a C++ class. It must begin with the class structure of the superclass. Following that, it will hold a set of function pointers — one for each [[virtual method]] of the class. Class-specific variables can be used to emulate class members. ; The instance structure : The instance structure, which will exist in one copy per object instance, must begin with the instance structure of the [[superclass (computer science)|superclass]] (this ensures that all instances begin with a pointer to the class structure, since all fundamental instantiable types share this property). After the data belonging to the superclass, the structure can hold any instance-specific variables, corresponding to C++ member variables. Defining a class in the GObject framework is complex, requiring large amounts of [[boilerplate (text)#Boilerplate code|boilerplate]] code, such as manual definitions of type casting macros and obscure type registration incantations. Also, since a C structure cannot have access modifiers like “public”, “protected”, or “private”, workarounds must be used to provide [[Encapsulation (computer programming)|encapsulation]]. One approach is to include a pointer to the private data — conventionally called <code>_priv</code> — in the instance structure. The ''private structure'' can be declared in the public header file, but defined only in the implementation file, with the effect that the private data is opaque to users, but transparent to the implementor. If the private structure is registered with GType, it will be automatically allocated by the object system. Indeed, it is not even necessary to include the <code>_priv</code> pointer, if one is willing to use the incantation <code>G_TYPE_INSTANCE_GET_PRIVATE</code> every time the private data is needed. To address some of these complexities, several higher-level languages exist that [[source-to-source compiler|source-to-source compiles]] to GObject in C. The [[Vala (programming language)|Vala programming language]] uses a [[C Sharp (programming language)|C#]]-style syntax and is pre-processed into [[Vanilla (computing)|vanilla]] C code. The GObject Builder, or [https://www.jirka.org/gob.html GOB2], offers a template syntax reminiscent of [[Java (programming language)|Java]].
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)