libGimbal 0.2.0
C17-Based Extended Standard Library and Cross-Language Runtime Framework
Loading...
Searching...
No Matches
gimbal_object.h
Go to the documentation of this file.
1/*! \file
2 * \brief GblObject structure and related functions
3 * \ingroup meta
4 *
5 * This file contains the type definitions and API for
6 * GblObject and GblObjectClass. This is the instantiable
7 * type which provides the OO meat of the instantiable types--
8 * such as properties, hierarchical relationships, event management,
9 * generic construction, named instances, etc.
10 *
11 * \author 2023, 2024, 2025, 2026 Falco Girgis
12 * \author 2025, 2026 Agustín Bellagamba
13 * \copyright MIT License
14 *
15 * \todo
16 * - Uninstall all signals upon class destructor (with property uninstallation)
17 * - Get rid of GblObject_findContext()
18 *
19 * \test
20 * - GblObjectClass::pFnConstructed() with CONSTRUCTOR properties.
21 * - GblObjectClass::pFnInitialized() with WRITE properties.
22 * - GblObject_isConstructing().
23 * - GblObject_isInstantiating().
24 * - GblObject implementing ABSTRACT properties from GblInterface.
25 */
26#ifndef GIMBAL_OBJECT_H
27#define GIMBAL_OBJECT_H
28
29#include "gimbal_box.h"
30#include "../ifaces/gimbal_ievent_receiver.h"
31#include "../properties/gimbal_property.h"
32#include "../../containers/gimbal_ring_list.h"
33
34/*! \name Type System
35 * \brief Type UUID and Cast operators
36 * @{
37 */
38#define GBL_OBJECT_TYPE GBL_TYPEID(GblObject) //!< GblType UUID for GblObject
39#define GBL_OBJECT(self) GBL_CAST(GblObject, self) //!< Casts a GblInstance to a GblObject
40#define GBL_OBJECT_CLASS(klass) GBL_CLASS_CAST(GblObject, klass) //!< Casts a GblClass to a GblObjectClass
41#define GBL_OBJECT_CLASSOF(self) GBL_CLASSOF(GblObject, self) //!< Gets a GblObjectClass from a GblInstance
42//! @}
43
44/*! \name Construction Macros
45 * \brief Helper macros for creating new GblObject instances.
46 * @{
47 */
48
49 /*! \brief DSL macro used to heap-construct a GblObject-derived type.
50 * It takes the struct name followed by an optional list of property KV pairs.
51 */
52#define GBL_NEW(/*type, ("key", value),*/ ...) GBL_OBJECT_NEW(__VA_ARGS__)
53
54/*! \brief DSL macro used to placement-construct a GblObject-derived type
55 * It takes the struct name followed by an optional list of property KV pairs.
56 */
57#define GBL_NEW_AT(/*type, self, ("key", value),*/ ...) GBL_OBJECT_NEW_AT(__VA_ARGS__)
58
59//! @}
60
61/*! \brief For-loop style iteration over the children of a GblObject
62 *
63 * Iterates over every child within the given object, setting the \p item variable to the current child.
64 * Optionally takes in a \p type parameter to specify the type of the children to iterate over.
65*/
66#define GblObject_foreachChild(/*GBL_SELF, name, type=GblObject* */ ...) GblObject_foreachChildDefault_(__VA_ARGS__)
67
68/*! \brief For-loop style iteration over the children of a GblObject, in reverse order
69 *
70 * Iterates over every child within the given object, setting the \p item variable to the current child.
71 * Optionally takes in a \p type parameter to specify the type of the children to iterate over.
72*/
73#define GblObject_foreachChildReverse(/*GBL_SELF, name, type=GblObject* */ ...) GblObject_foreachChildReverseDefault_(__VA_ARGS__)
74
75#define GBL_SELF_TYPE GblObject
76
77//! Comparator callback function which gets called with a GblObject and an arbitrary closure, returning true if the object matches the desired criteria.
78typedef GblBool (*GblObjectCmpFn)(const GblObject* pObj, void* pClosure);
79
81
83
84/*! \struct GblObjectClass
85 * \extends GblBoxClass
86 * \implements GblITableVariantClass
87 * \implements GblIEventReceiverClass
88 * \brief GblClass structure for GblObject
89 *
90 * GblObjectClass provides the virtual table for all types
91 * deriving from GblObject. It provides a constructor, event
92 * handlers, as well as accessors for reading and writing properties.
93 */
94GBL_CLASS_DERIVE(GblObject, GblBox,
95 GblITableVariant, GblIEventReceiver)
96 //! Virtual method called during construction after CONSTRUCT properties but before extra WRITE properties are set
97 GBL_RESULT (*pFnConstructed) (GBL_SELF);
98 //! Virtual method called when the object has been fully instantiated with all properties it was created with (including extra WRITE properties being set).
99 GBL_RESULT (*pFnInstantiated)(GBL_SELF);
100 //! Virtual method for reading properties
101 GBL_RESULT (*pFnProperty) (GBL_CSELF, const GblProperty* pProp, GblVariant* pValue);
102 //! Virtual method for writing properties
103 GBL_RESULT (*pFnSetProperty) (GBL_SELF, const GblProperty* pProp, GblVariant* pValue);
105
106/*! \name User-Operator Callbacks
107 * \brief Typedefs for applying various user-supplied functions over a GblObject.
108 * @{
109*/
110//! Iterator callback function which gets called over every child of a GblObject, being passed back a GblObject and an arbitrary closure, returning true should iteration cease early.
111typedef GblBool (*GblObjectIterFn)(GblObject* pChild, void* pClosure);
112//! @}
113
114/*! \class GblObject
115 * \extends GblBox
116 * \implements GblITableVariant
117 * \implements GblIEventReceiver
118 * \ingroup meta
119 * \brief Main Object-Oriented Instance with Properties, EventReceivers, and Parenting
120 *
121 * A GblObject is the default, full-blown object-oriented instantiable type.
122 * It is analogous to Qt's "QObject" or GNOME's "GObject" root type. It extends
123 * GblBox to add the following additional functionality:
124 * - properties
125 * - GblVariant table operations
126 * - constructor / post-constructor
127 * - event handling and filtering
128 * - object parenting and hierarchy
129 * - object name
130 *
131 * \note
132 * A GblObject by default has the same size of a GblBox. Additional data for
133 * fields such as name, parent, children, event filters, etc are created lazily
134 * and are stored within GblBox::pFields.
135 *
136 * \sa GblBox, GblObjectClass, GblProperty
137 */
139
140//! \cond
141GBL_PROPERTIES(GblObject,
142 (name, GBL_GENERIC, (READ, WRITE, LOAD, SAVE), GBL_STRING_TYPE),
143 (parent, GBL_GENERIC, (READ, WRITE), GBL_OBJECT_TYPE),
144 (children, GBL_GENERIC, (READ, WRITE, ACQUIRE, RELEASE), GBL_RING_LIST_TYPE),
145 (userdata, GBL_GENERIC, (READ, WRITE), GBL_POINTER_TYPE),
146 (refCount, GBL_GENERIC, (READ), GBL_UINT16_TYPE)
147// (class, GBL_GENERIC, (READ, WRITE, CONSTRUCT), GBL_POINTER_TYPE)
148)
149
150GBL_SIGNALS(GblObject,
151 (propertyChange, (GBL_INSTANCE_TYPE, pReceiver), (GBL_BOX_TYPE, pProperty))
152)
153//! \endcond
154
155//! Returns the GblType UUID associated with GblObject
157
158/*! \name Constructors
159 * \brief Methods for constructing GblObject-derived types.
160 *
161 * Each constructor takes a list of property names and values. Values for
162 * CONSTRUCT properties are set before GblObjectClass::pFnConstructed is called,
163 * and the remaining values are then set as regular writes, as though by
164 * GblObject_setProperties().
165 *
166 * Construction fails, and the object is torn down, when:
167 * - A value for a CONSTRUCT property which is not also WRITE is rejected
168 * - A CONSTRUCT property which is not also WRITE is not given a value
169 * - GblObjectClass::pFnConstructed fails
170 * - An unknown property name is given in a NULL-terminated K,V pair list,
171 * as none of the remaining arguments can then be read
172 *
173 * Upon failure, the create functions return NULL, and the construct functions
174 * return the error with the given memory left destructed. The error remains
175 * available from the thread's last call record.
176 *
177 * Any other value which is rejected, either because its property is WRITE or
178 * because setting it fails, is skipped. The object is still constructed, the
179 * result is #GBL_RESULT_INCOMPLETE, and the object must be released as usual.
180 * Since #GBL_RESULT_INCOMPLETE is not a success code, callers of the construct
181 * functions should check for failure with #GBL_RESULT_ERROR(), not
182 * #GBL_RESULT_SUCCESS(). Unknown property names given as variants are skipped
183 * with a warning.
184 *
185 * Values passed to ACQUIRE properties are moved, and are consumed even when
186 * rejected or when construction fails.
187 * @{
188 */
189//! Creates an object-derived type on the heap, initializing it with a NULL-terminated K,V pair listing of properties
191//! Variant of GblObject_create(), where the object is created with an extended size
192GBL_EXPORT GblObject* GblObject_createExt (GblType type, size_t size, ...) GBL_NOEXCEPT;
193//! Constructs an object-derived type in-place, initializing it with a NULL-terminated K,V pair listing of properties
195//! Creates an object-derived type on the heap, with the given class, initializing it with a NULL-terminated K,V pair property list
196GBL_EXPORT GblObject* GblObject_createWithClass (GblObjectClass* pClass, ...) GBL_NOEXCEPT;
197//! Variant of GblObject_createWithClass(), where the object is created with an extended size
198GBL_EXPORT GblObject* GblObject_createExtWithClass (GblObjectClass* pClass, size_t size, ...) GBL_NOEXCEPT;
199//! Constructs an object-derived type in-place, with the given class, initializing it with a NULL-terminated K,V pair property list
200GBL_EXPORT GBL_RESULT GblObject_constructWithClass (GBL_SELF, GblObjectClass* pClass, ...) GBL_NOEXCEPT;
201//! Variant of GblObject_create(), where the property list is provided as a va_list pointer
202GBL_EXPORT GblObject* GblObject_createVa (GblType type, va_list* pList) GBL_NOEXCEPT;
203//! Variant of GblObject_createVaList(), where the object is created with an extended size
204GBL_EXPORT GblObject* GblObject_createExtVa (GblType type, size_t size, va_list* pList) GBL_NOEXCEPT;
205//! Variant of GblObject_construct(), where the property list is provided as a va_list pointer
207//! Variant of GblObject_createWithClass(), where the property list is provided as a va_list pointer
208GBL_EXPORT GblObject* GblObject_createVaWithClass (GblObjectClass* pClass, va_list* pList) GBL_NOEXCEPT;
209//! Variant of GblObject_createVaListWithClass(), where the object is allocated with an extended size
210GBL_EXPORT GblObject* GblObject_createExtVaWithClass (GblObjectClass* pClass,
211 size_t size,
212 va_list* pList) GBL_NOEXCEPT;
213//! Variant of GblObject_constructWithClass(), where the property list is provided as a va_list pointer
215 GblObjectClass* pClass,
216 va_list* pList) GBL_NOEXCEPT;
217//! Creates an object-derived type on the heap, initializing it with an array of property values and a corresponding array of names
219 size_t propertyCount,
220 const char* pNames[],
221 GblVariant* pValues) GBL_NOEXCEPT;
222//! Variant of GblObject_createVariants(), where the object is allocated with an extended size
224 size_t size,
225 size_t propertyCount,
226 const char* pNames[],
227 GblVariant* pValues) GBL_NOEXCEPT;
228//! Creates an object-derived type in-place, initializing it with an array of property values and a corresponding array of names
230 GblType type,
231 size_t propertyCount,
232 const char* pNames[],
233 GblVariant* pValues) GBL_NOEXCEPT;
234//! Variant of GblObject_createVariants(), where the object is constructed with a weak reference to the given class
236 (GblObjectClass* pClass,
237 size_t propertyCount,
238 const char* pNames[],
239 GblVariant* pValues) GBL_NOEXCEPT;
240//! Variant of GblObject_createVariantsWithClass(), where the object is allocated with an extended size
242 (GblObjectClass* pClass,
243 size_t size,
244 size_t propertyCount,
245 const char* pNames[],
246 GblVariant* pValues) GBL_NOEXCEPT;
247//! Variant of GblObject_constructVariants(), where the object is constructed with a weak reference to the given class
249 (GBL_SELF,
250 GblObjectClass* pClass,
251 size_t propertyCount,
252 const char* pNames[],
253 GblVariant* pValues) GBL_NOEXCEPT;
254//! @}
255
256/*! \name Reading Properties
257 * \brief Methods for retrieving property values.
258 * \relatesalso GblObject
259 * @{
260 */
261//! Looks up the property on the object by name, storing its value in the pointer passed as a variadic argument
262GBL_EXPORT GBL_RESULT GblObject_property (GBL_CSELF, const char* pName, ...) GBL_NOEXCEPT;
263//! Looks up the property on the object by quark (faster), storing its value in the pointer passed as a variadic argument
265//! Variant of GblObject_property() with the pointer for storing the value specified by a pointer to a va_list
266GBL_EXPORT GBL_RESULT GblObject_propertyVaList (GBL_CSELF, const char* pName, va_list* pList) GBL_NOEXCEPT;
267//! Variant of GblObject_propertyVaList() with the name being specified by a quark (faster lookups)
269//! Fetches the value of the specified property, storing it within a variant
270GBL_EXPORT GBL_RESULT GblObject_propertyVariant (GBL_CSELF, const char* pName, GblVariant* pValue) GBL_NOEXCEPT;
271//! Variant of GblObject_propertyVariant(), with the property name specified as a quark (faster lookups)
273//! Takes a NULL-terminated K,V pair list of string property names and pointers to store their values within
275//! Variant of GblObject_properties() with the NULL-terminated K,V pair list being specified as a pointer to a va_list
277//! Looks up multiple properties by the names provided by the \p pNames list and stores them within the array of GblVariants
279 size_t count,
280 const char* pNames[],
281 GblVariant* pValue) GBL_NOEXCEPT;
282
283/*! \name Writing Properties
284 * \brief Methods for setting property values.
285 * \relatesalso GblObject
286 * @{
287 */
288//! Sets the property with the given string name to the value given by the pointer passed through the variadic argument list
289GBL_EXPORT GBL_RESULT GblObject_setProperty (GBL_SELF, const char* pName, ...) GBL_NOEXCEPT;
290//! Variant of GblObject_setProperty() with the name being specified as a quark (for faster lookups)
292//! Variant of GblObject_setProperty() with the pointer for storing the value being specified as a pointer to a va_list
293GBL_EXPORT GBL_RESULT GblObject_setPropertyVa (GBL_SELF, const char* pName, va_list* pList) GBL_NOEXCEPT;
294//! Variant of GblObject_setPropertyVaList() with the name being specified as a quark (for faster lookups)
296//! Variant of GblObject_setProperty() where the property value is provided as a GblVariant
297GBL_EXPORT GBL_RESULT GblObject_setPropertyVariant (GBL_SELF, const char* pName, GblVariant* pValue) GBL_NOEXCEPT;
298//! Variant of GblObject_setPropertyVariant() where the property name is provided as a quark (for faster lookups)
300/*! Sets multiple properties by taking a NULL-terminated K,V pairs list of string names and values
301
302 Each value which is rejected is skipped, while the remaining properties are still set, and the
303 last error is returned. An unknown property name stops processing of the list, as none of the
304 remaining arguments can then be read.
305*/
307//! Variant of GblObject_setProperties() where the NULL-terminated K,V pairs list is specified as a pointer to a va_list
309//! Sets the properties specified by the list of names to the corresponding values specified as the list of GblVariants
311 size_t count,
312 const char* pNames[],
313 GblVariant* pValue) GBL_NOEXCEPT;
314//! @}
315
316/*! \name Property Notification
317 * \brief Methods involving property changed notifiers.
318 * \relatesalso GblObject
319 * @{
320 */
321//! Notifies any listeners that the value of a property has changed internally, by emitting the "propertyChanged" signal.
323//! Equivalent to GblObject_emitPropertyChange(), except that the property lookup is done more efficiently by using a quark for its name.
325//! Disables or enables emission of the "propertyChange" signal, returning its previous enablement. Typically you want to only do this temporarily and restore its previous state when done.
327//! Returns true if emission of the "propertyChange" signal has been blocked on the current object or false if it is enabled.
329//! @}
330
331/*! \name State Management
332 * \brief Methods for querying GblObject state.
333 * \relatesalso GblObject
334 * @{
335 */
336//! Returns true from the time the object has been allocated to the time its final (possibly optional) initial properties have been set.
338//! Returns true immediately after type initializers are called, but before GblObject::pFnConstructed() is called with the initial constructor properties.
340//! @}
341
342/*! \name Name Accessors
343 * \brief Methods for reading and writing object name
344 * \relatesalso GblObject
345 * @{
346 */
347//! Retrieves the name of the given object or returns an empty string if it doesn't have one
349//! Sets the name of the given object to \p pName, making a copy of its contents to store internally
351//! Sets the name of the given object to \p pRef, taking ownership of the given reference
353//! @}
354
355/*! \name Hierarchy Management
356 * \brief Methods for parenting, traversing, or querying object trees
357 * \relatesalso GblObject
358 * @{
359 */
360//! Returns a pointer to the parent of the given object, or NULL if it doesn't have one
362//! Sets the parent of the given object to \p pParent, handing ownership to it.
364//! Adds \p pChild as a child of the given object, setting itself as the parent and taking ownership of it.
366//! Removes \p pChild from being a child of the given object, setting its parent to NULL
368//! Adds all the objects in \p pList as children of the given object, taking ownership of them.
369GBL_EXPORT void GblObject_addChildren (GBL_SELF, const GblRingList* pList) GBL_NOEXCEPT;
370//! Removes all the objects in \p pList as children of the given object, giving up ownership of them.
372//! Clears the children list of the given object, giving up ownership of them.
374//! Sets the children of the given object to \p pList, replacing the current children list and taking ownership of the new one.
375GBL_EXPORT void GblObject_setChildren (GBL_SELF, const GblRingList* pList) GBL_NOEXCEPT;
376/*! Iterates over every child of the given object, passing them to the given iterator function, which may optionally take a user data pointer.
377 Iteration ends early when the iterator returns GBL_TRUE.
378*/
379GBL_EXPORT GblBool GblObject_iterateChildren (GBL_CSELF, GblObjectIterFn pFnIt, void* pUd/*=NULL*/) GBL_NOEXCEPT;
380//! Returns the number of levels deep the given object is in the object tree formed by its ancestors
382//! Returns a pointer to the first child of the given object, or NULL if it has none
384//! Returns a pointer to the last child of the given object, or NULL if it has none
386//! Returns the number of children with the given object as their parent
388//! Returns the index of the given object in its parent's list of children
390//! Returns the next sibling after the given object, forming a linked list of their parents' children
392//! Returns the next sibling after the given object that satisfies the provided comparator callback, or NULL if there isn't one
393GBL_EXPORT GblObject* GblObject_siblingNextByCmpFn (GBL_CSELF, GblObjectCmpFn pCmpFn, void* pClosure) GBL_NOEXCEPT;
394//! Returns the next sibling after the given object that is of \p type, or NULL if there isn't one
396//! Returns the next sibling after the given object with the given name, or NULL if there isn't one
398//! Returns the previous sibling before the given object, forming a linked list of their parents' children
400//! Returns the previous sibling before the given object that satisfies the provided comparator callback, or NULL if there isn't one
401GBL_EXPORT GblObject* GblObject_siblingPreviousByCmpFn (GBL_CSELF, GblObjectCmpFn pCmpFn, void* pClosure) GBL_NOEXCEPT;
402//! Returns the previous sibling before the given object that is of \p type, or NULL if there isn't one
404//! Returns the previous sibling before the given object with the given name, or NULL if there isn't one
406
407//! Returns a pointer to the closest ancestor found that satisfies the provided comparator callback, or NULL if there isn't one
408GBL_EXPORT GblObject* GblObject_findAncestorByCmpFn (GBL_CSELF, GblObjectCmpFn pCmpFn, void* pClosure) GBL_NOEXCEPT;
409//! Returns a pointer to the closest ancestor object of the given object that is of \p ancestorType, or NULL if there isn't one
411//! Returns a pointer to the first ancestor found with the given name or NULL if none were found
413//! Returns a pointer to the ancestor object of the given object at the specified \p height, with 1 being the direct parent
415//! Starting at the root object, returns a pointer to the ancestor of the given object at the specified depth, or NULL if there isn't one
417//! Searches through the list of children on the given object, returning a pointer to the first one that satisfies the provided comparator callback, or NULL if there isn't one
418GBL_EXPORT GblObject* GblObject_findChildByCmpFn (GBL_CSELF, GblObjectCmpFn pCmpFn, void* pClosure) GBL_NOEXCEPT;
419//! Searches through the list of children on the given object, returning a pointer to the first one with the given type, or NULL if there isn't one
421//! Searches through the list of children on the given object, returning a pointer to the first one with the given name, or NULL if there isn't one
423//! Iterates sequentially over the list of children on the given object, returning a pointer to the one at the given type, or NULL if there isn't one
425//! Iterates sequentially over the list of siblings to the given object, returning a pointer to the first one that satisfies the provided comparator callback, or NULL if there isn't one
426GBL_EXPORT GblObject* GblObject_findSiblingByCmpFn (GBL_CSELF, GblObjectCmpFn pCmpFn, void* pClosure) GBL_NOEXCEPT;
427//! Iterates sequentially over the list of siblings to the given object, returning a pointer to the first one of the given type, or NULL if there isn't one
429//! Iterates sequentially over the list of siblings to the given object, returning a pointer to the first one with the given name, or NULL if there isn't one
431//! Iterates sequentially over the list of siblings to the given object, returning a pointer to the one at the given index, or NULL if there isn't one
433//! Returns a pointer to the closest descendant found that satisfies the provided comparator callback, or NULL if there isn't one
434GBL_EXPORT GblObject* GblObject_findDescendantByCmpFn (GBL_CSELF, GblObjectCmpFn pCmpFn, void* pClosure) GBL_NOEXCEPT;
435//! Returns a pointer to the closest descendant found that is of \p descendantType, or NULL if there isn't one
437//! Returns a pointer to the closest descendant found with the given name or NULL if none were found
439//! @}
440
441/*! \name Event Management
442 * \brief Methods for sending, notifying, and filtering events
443 * \relatesalso GblObject
444 * @{
445 */
446//! Emits an event upwards through the object hierarchy, notifying the parent of the given object of the event
448//! Notifies the given object of an event, which first propagates through its event filters before going through its event handler and propagating up if still unhandled
450//! Installs the event filter on the given object, allowing it to intercept event notifications
451GBL_EXPORT GBL_RESULT GblObject_installEventFilter (GBL_SELF, GblIEventReceiver* pFilter) GBL_NOEXCEPT;
452//! Removes the event filter from the given object, so that it no longer intercepts event notifications
453GBL_EXPORT GBL_RESULT GblObject_uninstallEventFilter (GBL_SELF, GblIEventReceiver* pFilter) GBL_NOEXCEPT;
454//! Returns the number of event filters currently installed on the given object
456//! Returns a pointer to the event filter installed on the given object at the \p index position
457GBL_EXPORT GblIEventReceiver* GblObject_eventFilter (GBL_CSELF, size_t index) GBL_NOEXCEPT;
458//! @}
459
460//! \deprecated
462
464
465///\cond
466#define GBL_OBJECT_NEW(...) GBL_VA_OVERLOAD_CALL(GBL_OBJECT_NEW, GBL_VA_OVERLOAD_SUFFIXER_1_N, __VA_ARGS__)
467
468#define GBL_OBJECT_NEW_1(typeName) ((typeName*)GblObject_create(GBL_TYPEID(typeName), GBL_NULL))
469#define GBL_OBJECT_NEW_N(...) ((GBL_TUPLE_FIRST(__VA_ARGS__)*)GblObject_create(GBL_TYPEID(GBL_TUPLE_FIRST(__VA_ARGS__)),
470 GBL_TUPLE_REST(__VA_ARGS__), NULL))
471
472#define GBL_OBJECT_NEW_AT(cType, instance, ...) (GblObject_construct(instance,GBL_TYPEID(cType), __VA_ARGS__, NULL))
473
474#define GblObject_foreachChildDefault_(...)
475 GblObject_foreachChildDefault__(__VA_ARGS__, GblObject*)
476#define GblObject_foreachChildDefault__(self, name, type, ...)
477 GblObject_foreachChildImpl_(self, name, type)
478#define GblObject_foreachChildImpl_(self, name, type)
479 for(type name = (type)GblObject_childFirst(self),
480 *name##_next_ = name ?
481 (type)GblObject_siblingNext(GBL_OBJECT(name)) :
482 NULL;
483
484 name;
485
486 name = name##_next_, name##_next_ = name ?
487 (type)GblObject_siblingNext(GBL_OBJECT(name))
488 : NULL)
489
490#define GblObject_foreachChildReverseDefault_(...)
491 GblObject_foreachChildReverseDefault__(__VA_ARGS__, GblObject*)
492#define GblObject_foreachChildReverseDefault__(self, name, type, ...)
493 GblObject_foreachChildReverseImpl_(self, name, type)
494#define GblObject_foreachChildReverseImpl_(self, name, type)
495 for(type name = (type)GblObject_childLast(self),
496 *name##_prev_ = name ?
497 (type)GblObject_siblingPrevious(GBL_OBJECT(name)) :
498 NULL;
499
500 name;
501
502 name = name##_prev_, name##_prev_ = name ?
503 (type)GblObject_siblingPrevious(GBL_OBJECT(name))
504 : NULL)
505
506///\endcond
507
508#undef GBL_SELF_TYPE
509
510#endif // GIMBAL_OBJECT_H
#define GBL_NULL
#define GBL_NOEXCEPT
#define GBL_DECLS_BEGIN
#define GBL_FORWARD_DECLARE_STRUCT(S)
#define GBL_TYPEID(instanceStruct)
#define GBL_CLASS_DERIVE(...)
#define GBL_EXPORT
#define GBL_CLASS_END
#define GBL_INSTANCE_DERIVE_EMPTY(derived, base)
#define GBL_VA_OVERLOAD_CALL(BASE, SUFFIXER,...)
#define GBL_TUPLE_REST(X,...)
#define GBL_TUPLE_FIRST(...)
#define GBL_VA_OVERLOAD_SUFFIXER_1_N(...)
GblObject * GblObject_createVariants(GblType type, size_t propertyCount, const char *pNames[], GblVariant *pValues)
Creates an object-derived type on the heap, initializing it with an array of property values and a co...
GBL_RESULT GblObject_constructWithClass(GblObject *pSelf, GblObjectClass *pClass,...)
Constructs an object-derived type in-place, with the given class, initializing it with a NULL-termina...
GblObject * GblObject_createVariantsWithClass(GblObjectClass *pClass, size_t propertyCount, const char *pNames[], GblVariant *pValues)
Variant of GblObject_createVariants(), where the object is constructed with a weak reference to the g...
GblObject * GblObject_createVa(GblType type, va_list *pList)
Variant of GblObject_create(), where the property list is provided as a va_list pointer.
GblObject * GblObject_createExtVaWithClass(GblObjectClass *pClass, size_t size, va_list *pList)
Variant of GblObject_createVaListWithClass(), where the object is allocated with an extended size.
GblObject * GblObject_createWithClass(GblObjectClass *pClass,...)
Creates an object-derived type on the heap, with the given class, initializing it with a NULL-termina...
GBL_RESULT GblObject_construct(GblObject *pSelf, GblType type,...)
Constructs an object-derived type in-place, initializing it with a NULL-terminated K,...
GblObject * GblObject_createExtVa(GblType type, size_t size, va_list *pList)
Variant of GblObject_createVaList(), where the object is created with an extended size.
GBL_RESULT GblObject_constructVariantsWithClass(GblObject *pSelf, GblObjectClass *pClass, size_t propertyCount, const char *pNames[], GblVariant *pValues)
Variant of GblObject_constructVariants(), where the object is constructed with a weak reference to th...
#define GBL_OBJECT(self)
Casts a GblInstance to a GblObject.
GblType GblObject_type(void)
Returns the GblType UUID associated with GblObject.
GblObject * GblObject_createExt(GblType type, size_t size,...)
Variant of GblObject_create(), where the object is created with an extended size.
GBL_RESULT GblObject_constructVa(GblObject *pSelf, GblType type, va_list *pList)
Variant of GblObject_construct(), where the property list is provided as a va_list pointer.
GblObject * GblObject_createVaWithClass(GblObjectClass *pClass, va_list *pList)
Variant of GblObject_createWithClass(), where the property list is provided as a va_list pointer.
GblObject * GblObject_create(GblType type,...)
Creates an object-derived type on the heap, initializing it with a NULL-terminated K,...
GblObject * GblObject_createExtWithClass(GblObjectClass *pClass, size_t size,...)
Variant of GblObject_createWithClass(), where the object is created with an extended size.
GblContext * GblObject_findContext(GblObject *pSelf)
GblObject * GblObject_createVariantsExt(GblType type, size_t size, size_t propertyCount, const char *pNames[], GblVariant *pValues)
Variant of GblObject_createVariants(), where the object is allocated with an extended size.
GBL_RESULT GblObject_constructVaWithClass(GblObject *pSelf, GblObjectClass *pClass, va_list *pList)
Variant of GblObject_constructWithClass(), where the property list is provided as a va_list pointer.
GBL_RESULT GblObject_constructVariants(GblObject *pSelf, GblType type, size_t propertyCount, const char *pNames[], GblVariant *pValues)
Creates an object-derived type in-place, initializing it with an array of property values and a corre...
#define GBL_OBJECT_TYPE
GblType UUID for GblObject.
GblObject * GblObject_createVariantsExtWithClass(GblObjectClass *pClass, size_t size, size_t propertyCount, const char *pNames[], GblVariant *pValues)
Variant of GblObject_createVariantsWithClass(), where the object is allocated with an extended size.
#define GBL_UINT16_TYPE
Builtin ID for uint16_t GblVariant type.
#define GBL_STRING_TYPE
Builtin ID for string GblVariant type.
#define GBL_PROPERTIES(object,...)
Declares a list of properties for the given object/instance structure.
#define GBL_RING_LIST_TYPE
Type UUID for GblRingList.
#define GBL_SIGNALS(instanceStruct,...)
Declares a list of signals to be associated with the given instanceStruct.
uint8_t GblBool
Basic boolean type, standardized to sizeof(char)
#define GBL_POINTER_TYPE
uintptr_t GblType
Meta Type UUID.
Definition gimbal_type.h:52
uintptr_t GblQuark
Uniquely identifiable interned string type.
const char GblStringRef
Reference-counted, const char*-compatible string type.
Main Object-Oriented Instance with Properties, EventReceivers, and Parenting.
void GblObject_addChild(GblObject *pSelf, GblObject *pChild)
Adds pChild as a child of the given object, setting itself as the parent and taking ownership of it.
GBL_RESULT GblObject_properties(const GblObject *pSelf,...)
Takes a NULL-terminated K,V pair list of string property names and pointers to store their values wit...
GblObject * GblObject_findBaseByDepth(const GblObject *pSelf, size_t depth)
Starting at the root object, returns a pointer to the ancestor of the given object at the specified d...
GblObject * GblObject_parent(const GblObject *pSelf)
Returns a pointer to the parent of the given object, or NULL if it doesn't have one.
size_t GblObject_depth(const GblObject *pSelf)
Returns the number of levels deep the given object is in the object tree formed by its ancestors.
GBL_RESULT GblObject_emitPropertyChange(const GblObject *pSelf, const char *pName)
Notifies any listeners that the value of a property has changed internally, by emitting the "property...
GBL_RESULT GblObject_setPropertiesVa(GblObject *pSelf, va_list *pList)
Variant of GblObject_setProperties() where the NULL-terminated K,V pairs list is specified as a point...
GblObject * GblObject_findChildByIndex(const GblObject *pSelf, size_t index)
Iterates sequentially over the list of children on the given object, returning a pointer to the one a...
GblObject * GblObject_findDescendantByType(const GblObject *pSelf, GblType descendantType)
Returns a pointer to the closest descendant found that is of descendantType, or NULL if there isn't o...
GblObject * GblObject_siblingPreviousByName(const GblObject *pSelf, const char *pName)
Returns the previous sibling before the given object with the given name, or NULL if there isn't one.
GblBool GblObject_isInstantiating(const GblObject *pSelf)
Returns true from the time the object has been allocated to the time its final (possibly optional) in...
GblObject * GblObject_findSiblingByType(const GblObject *pSelf, GblType siblingType)
Iterates sequentially over the list of siblings to the given object, returning a pointer to the first...
void GblObject_setParent(GblObject *pSelf, GblObject *pParent)
Sets the parent of the given object to pParent, handing ownership to it.
GblBool GblObject_propertyChangeBlocked(const GblObject *pSelf)
Returns true if emission of the "propertyChange" signal has been blocked on the current object or fal...
GblObject * GblObject_findSiblingByName(const GblObject *pSelf, const char *pName)
Iterates sequentially over the list of siblings to the given object, returning a pointer to the first...
GblObject * GblObject_findAncestorByType(const GblObject *pSelf, GblType ancestorType)
Returns a pointer to the closest ancestor object of the given object that is of ancestorType,...
GblObject * GblObject_siblingNext(const GblObject *pSelf)
Returns the next sibling after the given object, forming a linked list of their parents' children.
GBL_RESULT GblObject_property(const GblObject *pSelf, const char *pName,...)
Looks up the property on the object by name, storing its value in the pointer passed as a variadic ar...
void GblObject_addChildren(GblObject *pSelf, const GblRingList *pList)
Adds all the objects in pList as children of the given object, taking ownership of them.
GblObject * GblObject_findDescendantByCmpFn(const GblObject *pSelf, GblObjectCmpFn pCmpFn, void *pClosure)
Returns a pointer to the closest descendant found that satisfies the provided comparator callback,...
GBL_RESULT GblObject_propertyVariant(const GblObject *pSelf, const char *pName, GblVariant *pValue)
Fetches the value of the specified property, storing it within a variant.
GBL_RESULT GblObject_setProperty(GblObject *pSelf, const char *pName,...)
Sets the property with the given string name to the value given by the pointer passed through the var...
GBL_RESULT GblObject_propertiesVa(const GblObject *pSelf, va_list *pList)
Variant of GblObject_properties() with the NULL-terminated K,V pair list being specified as a pointer...
GblObject * GblObject_siblingPreviousByCmpFn(const GblObject *pSelf, GblObjectCmpFn pCmpFn, void *pClosure)
Returns the previous sibling before the given object that satisfies the provided comparator callback,...
GBL_RESULT GblObject_propertyVaByQuark(const GblObject *pSelf, GblQuark name, va_list *pList)
Variant of GblObject_propertyVaList() with the name being specified by a quark (faster lookups)
GblObject * GblObject_siblingPreviousByType(const GblObject *pSelf, GblType type)
Returns the previous sibling before the given object that is of type, or NULL if there isn't one.
GblBool GblObject_removeChild(GblObject *pSelf, GblObject *pChild)
Removes pChild from being a child of the given object, setting its parent to NULL.
GBL_RESULT GblObject_setPropertyVariant(GblObject *pSelf, const char *pName, GblVariant *pValue)
Variant of GblObject_setProperty() where the property value is provided as a GblVariant.
size_t GblObject_childCount(const GblObject *pSelf)
Returns the number of children with the given object as their parent.
GblBool GblObject_blockPropertyChange(GblObject *pSelf, GblBool blocked)
Disables or enables emission of the "propertyChange" signal, returning its previous enablement....
GblObject * GblObject_findChildByType(const GblObject *pSelf, GblType childType)
Searches through the list of children on the given object, returning a pointer to the first one with ...
GBL_RESULT GblObject_propertyByQuark(const GblObject *pSelf, GblQuark name,...)
Looks up the property on the object by quark (faster), storing its value in the pointer passed as a v...
GblObject * GblObject_childFirst(const GblObject *pSelf)
Returns a pointer to the first child of the given object, or NULL if it has none.
GBL_RESULT GblObject_emitPropertyChangeByQuark(const GblObject *pSelf, GblQuark name)
Equivalent to GblObject_emitPropertyChange(), except that the property lookup is done more efficientl...
void GblObject_setName(GblObject *pSelf, const char *pName)
Sets the name of the given object to pName, making a copy of its contents to store internally.
GblIEventReceiver * GblObject_eventFilter(const GblObject *pSelf, size_t index)
Returns a pointer to the event filter installed on the given object at the index position.
GBL_RESULT GblObject_propertyVaList(const GblObject *pSelf, const char *pName, va_list *pList)
Variant of GblObject_property() with the pointer for storing the value specified by a pointer to a va...
GblBool GblObject_iterateChildren(const GblObject *pSelf, GblObjectIterFn pFnIt, void *pUd)
Iterates over every child of the given object, passing them to the given iterator function,...
GBL_RESULT GblObject_propertiesVariants(const GblObject *pSelf, size_t count, const char *pNames[], GblVariant *pValue)
Looks up multiple properties by the names provided by the pNames list and stores them within the arra...
GblObject * GblObject_findSiblingByCmpFn(const GblObject *pSelf, GblObjectCmpFn pCmpFn, void *pClosure)
Iterates sequentially over the list of siblings to the given object, returning a pointer to the first...
GBL_RESULT GblObject_sendEvent(GblObject *pSelf, GblEvent *pEvent)
Emits an event upwards through the object hierarchy, notifying the parent of the given object of the ...
GBL_RESULT GblObject_setPropertyVa(GblObject *pSelf, const char *pName, va_list *pList)
Variant of GblObject_setProperty() with the pointer for storing the value being specified as a pointe...
GblObject * GblObject_findSiblingByIndex(const GblObject *pSelf, size_t index)
Iterates sequentially over the list of siblings to the given object, returning a pointer to the one a...
GBL_RESULT GblObject_setPropertyVaListByQuark(GblObject *pSelf, GblQuark name, va_list *pList)
Variant of GblObject_setPropertyVaList() with the name being specified as a quark (for faster lookups...
GblStringRef * GblObject_name(const GblObject *pSelf)
Retrieves the name of the given object or returns an empty string if it doesn't have one.
GBL_RESULT GblObject_installEventFilter(GblObject *pSelf, GblIEventReceiver *pFilter)
Installs the event filter on the given object, allowing it to intercept event notifications.
void GblObject_removeChildren(GblObject *pSelf, const GblRingList *pList)
Removes all the objects in pList as children of the given object, giving up ownership of them.
GblObject * GblObject_findAncestorByName(const GblObject *pSelf, const char *pName)
Returns a pointer to the first ancestor found with the given name or NULL if none were found.
GBL_RESULT GblObject_uninstallEventFilter(GblObject *pSelf, GblIEventReceiver *pFilter)
Removes the event filter from the given object, so that it no longer intercepts event notifications.
GblObject * GblObject_findDescendantByName(const GblObject *pSelf, const char *pName)
Returns a pointer to the closest descendant found with the given name or NULL if none were found.
size_t GblObject_eventFilterCount(const GblObject *pSelf)
Returns the number of event filters currently installed on the given object.
void GblObject_clearChildren(GblObject *pSelf)
Clears the children list of the given object, giving up ownership of them.
GBL_RESULT GblObject_propertyVariantByQuark(const GblObject *pSelf, GblQuark name, GblVariant *pValue)
Variant of GblObject_propertyVariant(), with the property name specified as a quark (faster lookups)
void GblObject_setNameRef(GblObject *pSelf, GblStringRef *pRef)
Sets the name of the given object to pRef, taking ownership of the given reference.
GblObject * GblObject_findChildByCmpFn(const GblObject *pSelf, GblObjectCmpFn pCmpFn, void *pClosure)
Searches through the list of children on the given object, returning a pointer to the first one that ...
size_t GblObject_childIndex(const GblObject *pSelf)
Returns the index of the given object in its parent's list of children.
GblObject * GblObject_siblingPrevious(const GblObject *pSelf)
Returns the previous sibling before the given object, forming a linked list of their parents' childre...
GBL_RESULT GblObject_setProperties(GblObject *pSelf,...)
Sets multiple properties by taking a NULL-terminated K,V pairs list of string names and values.
GBL_RESULT GblObject_setPropertyByQuark(GblObject *pSelf, GblQuark quark,...)
Variant of GblObject_setProperty() with the name being specified as a quark (for faster lookups)
GBL_RESULT GblObject_notifyEvent(GblObject *pSelf, GblEvent *pEvent)
Notifies the given object of an event, which first propagates through its event filters before going ...
GblObject * GblObject_siblingNextByName(const GblObject *pSelf, const char *pName)
Returns the next sibling after the given object with the given name, or NULL if there isn't one.
GblObject * GblObject_siblingNextByType(const GblObject *pSelf, GblType type)
Returns the next sibling after the given object that is of type, or NULL if there isn't one.
GBL_RESULT GblObject_setPropertyVariantByQuark(GblObject *pSelf, GblQuark name, GblVariant *pValue)
Variant of GblObject_setPropertyVariant() where the property name is provided as a quark (for faster ...
GblObject * GblObject_findAncestorByCmpFn(const GblObject *pSelf, GblObjectCmpFn pCmpFn, void *pClosure)
Returns a pointer to the closest ancestor found that satisfies the provided comparator callback,...
GBL_RESULT GblObject_setPropertiesVariants(GblObject *pSelf, size_t count, const char *pNames[], GblVariant *pValue)
Sets the properties specified by the list of names to the corresponding values specified as the list ...
GblBool GblObject_isConstructing(const GblObject *pSelf)
Returns true immediately after type initializers are called, but before GblObject::pFnConstructed() i...
GblObject * GblObject_findAncestorByHeight(const GblObject *pSelf, size_t height)
Returns a pointer to the ancestor object of the given object at the specified height,...
void GblObject_setChildren(GblObject *pSelf, const GblRingList *pList)
Sets the children of the given object to pList, replacing the current children list and taking owners...
GblObject * GblObject_findChildByName(const GblObject *pSelf, const char *pName)
Searches through the list of children on the given object, returning a pointer to the first one with ...
GblObject * GblObject_childLast(const GblObject *pSelf)
Returns a pointer to the last child of the given object, or NULL if it has none.
GblObject * GblObject_siblingNextByCmpFn(const GblObject *pSelf, GblObjectCmpFn pCmpFn, void *pClosure)
Returns the next sibling after the given object that satisfies the provided comparator callback,...