|
@@ -259,31 +259,23 @@ struct Object
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
- * OBJECT_DEFINE_TYPE_EXTENDED:
|
|
|
|
|
|
+ * DO_OBJECT_DEFINE_TYPE_EXTENDED:
|
|
* @ModuleObjName: the object name with initial caps
|
|
* @ModuleObjName: the object name with initial caps
|
|
* @module_obj_name: the object name in lowercase with underscore separators
|
|
* @module_obj_name: the object name in lowercase with underscore separators
|
|
* @MODULE_OBJ_NAME: the object name in uppercase with underscore separators
|
|
* @MODULE_OBJ_NAME: the object name in uppercase with underscore separators
|
|
* @PARENT_MODULE_OBJ_NAME: the parent object name in uppercase with underscore
|
|
* @PARENT_MODULE_OBJ_NAME: the parent object name in uppercase with underscore
|
|
* separators
|
|
* separators
|
|
* @ABSTRACT: boolean flag to indicate whether the object can be instantiated
|
|
* @ABSTRACT: boolean flag to indicate whether the object can be instantiated
|
|
|
|
+ * @CLASS_SIZE: size of the type's class
|
|
* @...: list of initializers for "InterfaceInfo" to declare implemented interfaces
|
|
* @...: list of initializers for "InterfaceInfo" to declare implemented interfaces
|
|
*
|
|
*
|
|
- * This macro is typically used in a source file, and will:
|
|
|
|
- *
|
|
|
|
- * - declare prototypes for _finalize, _class_init and _init methods
|
|
|
|
- * - declare the TypeInfo struct instance
|
|
|
|
- * - provide the constructor to register the type
|
|
|
|
- *
|
|
|
|
- * After using this macro, implementations of the _finalize, _class_init,
|
|
|
|
- * and _init methods need to be written. Any of these can be zero-line
|
|
|
|
- * no-op impls if no special logic is required for a given type.
|
|
|
|
- *
|
|
|
|
- * This macro should rarely be used, instead one of the more specialized
|
|
|
|
- * macros is usually a better choice.
|
|
|
|
|
|
+ * This is the base macro used to implement all the OBJECT_DEFINE_*
|
|
|
|
+ * macros. It should never be used directly in a source file.
|
|
*/
|
|
*/
|
|
-#define OBJECT_DEFINE_TYPE_EXTENDED(ModuleObjName, module_obj_name, \
|
|
|
|
- MODULE_OBJ_NAME, PARENT_MODULE_OBJ_NAME, \
|
|
|
|
- ABSTRACT, ...) \
|
|
|
|
|
|
+#define DO_OBJECT_DEFINE_TYPE_EXTENDED(ModuleObjName, module_obj_name, \
|
|
|
|
+ MODULE_OBJ_NAME, \
|
|
|
|
+ PARENT_MODULE_OBJ_NAME, \
|
|
|
|
+ ABSTRACT, CLASS_SIZE, ...) \
|
|
static void \
|
|
static void \
|
|
module_obj_name##_finalize(Object *obj); \
|
|
module_obj_name##_finalize(Object *obj); \
|
|
static void \
|
|
static void \
|
|
@@ -298,7 +290,7 @@ struct Object
|
|
.instance_align = __alignof__(ModuleObjName), \
|
|
.instance_align = __alignof__(ModuleObjName), \
|
|
.instance_init = module_obj_name##_init, \
|
|
.instance_init = module_obj_name##_init, \
|
|
.instance_finalize = module_obj_name##_finalize, \
|
|
.instance_finalize = module_obj_name##_finalize, \
|
|
- .class_size = sizeof(ModuleObjName##Class), \
|
|
|
|
|
|
+ .class_size = CLASS_SIZE, \
|
|
.class_init = module_obj_name##_class_init, \
|
|
.class_init = module_obj_name##_class_init, \
|
|
.abstract = ABSTRACT, \
|
|
.abstract = ABSTRACT, \
|
|
.interfaces = (InterfaceInfo[]) { __VA_ARGS__ } , \
|
|
.interfaces = (InterfaceInfo[]) { __VA_ARGS__ } , \
|
|
@@ -311,6 +303,37 @@ struct Object
|
|
} \
|
|
} \
|
|
type_init(module_obj_name##_register_types);
|
|
type_init(module_obj_name##_register_types);
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+ * OBJECT_DEFINE_TYPE_EXTENDED:
|
|
|
|
+ * @ModuleObjName: the object name with initial caps
|
|
|
|
+ * @module_obj_name: the object name in lowercase with underscore separators
|
|
|
|
+ * @MODULE_OBJ_NAME: the object name in uppercase with underscore separators
|
|
|
|
+ * @PARENT_MODULE_OBJ_NAME: the parent object name in uppercase with underscore
|
|
|
|
+ * separators
|
|
|
|
+ * @ABSTRACT: boolean flag to indicate whether the object can be instantiated
|
|
|
|
+ * @...: list of initializers for "InterfaceInfo" to declare implemented interfaces
|
|
|
|
+ *
|
|
|
|
+ * This macro is typically used in a source file, and will:
|
|
|
|
+ *
|
|
|
|
+ * - declare prototypes for _finalize, _class_init and _init methods
|
|
|
|
+ * - declare the TypeInfo struct instance
|
|
|
|
+ * - provide the constructor to register the type
|
|
|
|
+ *
|
|
|
|
+ * After using this macro, implementations of the _finalize, _class_init,
|
|
|
|
+ * and _init methods need to be written. Any of these can be zero-line
|
|
|
|
+ * no-op impls if no special logic is required for a given type.
|
|
|
|
+ *
|
|
|
|
+ * This macro should rarely be used, instead one of the more specialized
|
|
|
|
+ * macros is usually a better choice.
|
|
|
|
+ */
|
|
|
|
+#define OBJECT_DEFINE_TYPE_EXTENDED(ModuleObjName, module_obj_name, \
|
|
|
|
+ MODULE_OBJ_NAME, PARENT_MODULE_OBJ_NAME, \
|
|
|
|
+ ABSTRACT, ...) \
|
|
|
|
+ DO_OBJECT_DEFINE_TYPE_EXTENDED(ModuleObjName, module_obj_name, \
|
|
|
|
+ MODULE_OBJ_NAME, PARENT_MODULE_OBJ_NAME, \
|
|
|
|
+ ABSTRACT, sizeof(ModuleObjName##Class), \
|
|
|
|
+ __VA_ARGS__)
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* OBJECT_DEFINE_TYPE:
|
|
* OBJECT_DEFINE_TYPE:
|
|
* @ModuleObjName: the object name with initial caps
|
|
* @ModuleObjName: the object name with initial caps
|
|
@@ -368,6 +391,45 @@ struct Object
|
|
MODULE_OBJ_NAME, PARENT_MODULE_OBJ_NAME, \
|
|
MODULE_OBJ_NAME, PARENT_MODULE_OBJ_NAME, \
|
|
true, { NULL })
|
|
true, { NULL })
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+ * OBJECT_DEFINE_SIMPLE_TYPE_WITH_INTERFACES:
|
|
|
|
+ * @ModuleObjName: the object name with initial caps
|
|
|
|
+ * @module_obj_name: the object name in lowercase with underscore separators
|
|
|
|
+ * @MODULE_OBJ_NAME: the object name in uppercase with underscore separators
|
|
|
|
+ * @PARENT_MODULE_OBJ_NAME: the parent object name in uppercase with underscore
|
|
|
|
+ * separators
|
|
|
|
+ *
|
|
|
|
+ * This is a variant of OBJECT_DEFINE_TYPE_EXTENDED, which is suitable for
|
|
|
|
+ * the case of a non-abstract type, with interfaces, and with no requirement
|
|
|
|
+ * for a class struct.
|
|
|
|
+ */
|
|
|
|
+#define OBJECT_DEFINE_SIMPLE_TYPE_WITH_INTERFACES(ModuleObjName, \
|
|
|
|
+ module_obj_name, \
|
|
|
|
+ MODULE_OBJ_NAME, \
|
|
|
|
+ PARENT_MODULE_OBJ_NAME, ...) \
|
|
|
|
+ DO_OBJECT_DEFINE_TYPE_EXTENDED(ModuleObjName, module_obj_name, \
|
|
|
|
+ MODULE_OBJ_NAME, PARENT_MODULE_OBJ_NAME, \
|
|
|
|
+ false, 0, __VA_ARGS__)
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * OBJECT_DEFINE_SIMPLE_TYPE:
|
|
|
|
+ * @ModuleObjName: the object name with initial caps
|
|
|
|
+ * @module_obj_name: the object name in lowercase with underscore separators
|
|
|
|
+ * @MODULE_OBJ_NAME: the object name in uppercase with underscore separators
|
|
|
|
+ * @PARENT_MODULE_OBJ_NAME: the parent object name in uppercase with underscore
|
|
|
|
+ * separators
|
|
|
|
+ *
|
|
|
|
+ * This is a variant of OBJECT_DEFINE_TYPE_EXTENDED, which is suitable for
|
|
|
|
+ * the common case of a non-abstract type, without any interfaces, and with
|
|
|
|
+ * no requirement for a class struct. If you declared your type with
|
|
|
|
+ * OBJECT_DECLARE_SIMPLE_TYPE then this is probably the right choice for
|
|
|
|
+ * defining it.
|
|
|
|
+ */
|
|
|
|
+#define OBJECT_DEFINE_SIMPLE_TYPE(ModuleObjName, module_obj_name, \
|
|
|
|
+ MODULE_OBJ_NAME, PARENT_MODULE_OBJ_NAME) \
|
|
|
|
+ OBJECT_DEFINE_SIMPLE_TYPE_WITH_INTERFACES(ModuleObjName, module_obj_name, \
|
|
|
|
+ MODULE_OBJ_NAME, PARENT_MODULE_OBJ_NAME, { NULL })
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* struct TypeInfo:
|
|
* struct TypeInfo:
|
|
* @name: The name of the type.
|
|
* @name: The name of the type.
|