diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2017-05-21 16:48:11 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2017-05-21 16:48:11 (GMT) |
commit | acd355c4c5ae25fb9cac64b8dc17407a2bcc979b (patch) | |
tree | d5b43201049116cd9734ff554e61ed8a7e0084cc /src/arch/operand.c | |
parent | 4691a434a34a19317156a761967f719e408b73bb (diff) |
Refined the whole share system for operands.
Diffstat (limited to 'src/arch/operand.c')
-rw-r--r-- | src/arch/operand.c | 115 |
1 files changed, 94 insertions, 21 deletions
diff --git a/src/arch/operand.c b/src/arch/operand.c index 584e3c0..8bc85fb 100644 --- a/src/arch/operand.c +++ b/src/arch/operand.c @@ -49,11 +49,17 @@ static void g_arch_operand_dispose(GArchOperand *); /* Procède à la libération totale de la mémoire. */ static void g_arch_operand_finalize(GArchOperand *); +/* Fournit le gestionnaire de partages attribué à un type. */ +static GShareManager *get_arch_operand_share_manager(const GArchOperand *); + /* Initialise un nouvel objet partagé avec des informations. */ -static bool g_arch_operand_do_init(GArchOperand *, const GArchOperand *); +static bool g_arch_operand_apply_template(GArchOperand *, const GArchOperand *); /* Réalise une copie minimale d'un contenu partagé. */ -static void g_arch_operand_quickly_copy(const GArchOperand *, GArchOperand *); +static void g_arch_operand_define_template(const GArchOperand *, GArchOperand *); + +/* Libère la mémoire utilisée par un patron d'instance. */ +static void g_arch_operand_free_template(const GArchOperand *, GArchOperand *); /* Fournit la valeur du compteur de partage. */ static unsigned int g_arch_operand_get_references(const GArchOperand *); @@ -64,8 +70,8 @@ static void g_arch_operand_inc_references(GArchOperand *); /* Décrémente le compteur de partage. */ static void g_arch_operand_dec_references(GArchOperand *); -/* Compare de façon accélérée un opérande avec un autre. */ -static int g_arch_operand_quickly_compare(const GArchOperand **, const GArchOperand **); +/* Compare le contenu d'un opérande avec un autre. */ +static int g_arch_operand_compare_shared(const GArchOperand * const *, const GArchOperand * const *); @@ -131,14 +137,17 @@ static void g_arch_operand_init(GArchOperand *operand) static void g_arch_operand_interface_init(GSharedInstanceInterface *iface) { - iface->init = (init_shared_fc)g_arch_operand_do_init; - iface->qck_copy = (qck_copy_shared_fc)g_arch_operand_quickly_copy; + iface->get_manager = (get_share_manager_fc)get_arch_operand_share_manager; + + iface->apply_template = (apply_shared_template_fc)g_arch_operand_apply_template; + iface->define_template = (define_shared_template_fc)g_arch_operand_define_template; + iface->free_template = (free_shared_template_fc)g_arch_operand_free_template; iface->get_ref = (get_shared_ref_fc)g_arch_operand_get_references; iface->inc_ref = (inc_shared_ref_fc)g_arch_operand_inc_references; iface->dec_ref = (dec_shared_ref_fc)g_arch_operand_dec_references; - iface->qck_cmp = (qck_compare_shared_fc)g_arch_operand_quickly_compare; + iface->compare = (compare_shared_fc)g_arch_operand_compare_shared; } @@ -185,8 +194,34 @@ static void g_arch_operand_finalize(GArchOperand *operand) /****************************************************************************** * * -* Paramètres : operand = objet partagé à initialiser. * -* info = information à utiliser pour la mise en place. * +* Paramètres : operand = instance partagée à consulter. * +* * +* Description : Fournit le gestionnaire de partages attribué à un type. * +* * +* Retour : Gestionnaire de partages en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static GShareManager *get_arch_operand_share_manager(const GArchOperand *operand) +{ + GShareManager *result; /* Instance à retourner */ + + if (G_ARCH_OPERAND_GET_CLASS(operand)->get_manager == NULL) + printf("No manager for '%s'\n", G_OBJECT_TYPE_NAME(operand)); + + result = G_ARCH_OPERAND_GET_CLASS(operand)->get_manager(); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : operand = objet partagé à initialiser. * +* template = information à utiliser pour la mise en place. * * * * Description : Initialise un nouvel objet partagé avec des informations. * * * @@ -196,11 +231,25 @@ static void g_arch_operand_finalize(GArchOperand *operand) * * ******************************************************************************/ -static bool g_arch_operand_do_init(GArchOperand *operand, const GArchOperand *info) +static bool g_arch_operand_apply_template(GArchOperand *operand, const GArchOperand *template) { bool result; /* Bilan à retourner */ + apply_operand_template_fc func; /* Fonction à appeler */ - result = G_ARCH_OPERAND_GET_CLASS(operand)->init(operand, info); + func = G_ARCH_OPERAND_GET_CLASS(operand)->apply_template; + + if (func != NULL) + result = func(operand, template); + + else + { + if (G_ARCH_OPERAND_GET_CLASS(operand)->define_template == NULL) + printf("No def for '%s'\n", G_OBJECT_TYPE_NAME(operand)); + + + G_ARCH_OPERAND_GET_CLASS(operand)->define_template(template, operand); + result = true; + } return result; @@ -220,9 +269,34 @@ static bool g_arch_operand_do_init(GArchOperand *operand, const GArchOperand *in * * ******************************************************************************/ -static void g_arch_operand_quickly_copy(const GArchOperand *operand, GArchOperand *template) +static void g_arch_operand_define_template(const GArchOperand *operand, GArchOperand *template) { - G_ARCH_OPERAND_GET_CLASS(operand)->qck_copy(operand, template); + G_ARCH_OPERAND_GET_CLASS(operand)->define_template(operand, template); + +} + + +/****************************************************************************** +* * +* Paramètres : operand = objet partagé à consulter. * +* template = informations dont le contenu est à libérer. * +* * +* Description : Libère la mémoire utilisée par un patron d'instance. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_arch_operand_free_template(const GArchOperand *operand, GArchOperand *template) +{ + free_operand_template_fc func; /* Fonction à appeler */ + + func = G_ARCH_OPERAND_GET_CLASS(operand)->free_template; + + if (func != NULL) + func(operand, template); } @@ -289,7 +363,7 @@ static void g_arch_operand_dec_references(GArchOperand *operand) * Paramètres : a = premier opérande à consulter. * * b = second opérande à consulter. * * * -* Description : Compare de façon accélérée un opérande avec un autre. * +* Description : Compare le contenu d'un opérande avec un autre. * * * * Retour : Bilan de la comparaison. * * * @@ -297,17 +371,16 @@ static void g_arch_operand_dec_references(GArchOperand *operand) * * ******************************************************************************/ -static int g_arch_operand_quickly_compare(const GArchOperand **a, const GArchOperand **b) +static int g_arch_operand_compare_shared(const GArchOperand * const *a, const GArchOperand * const *b) { int result; /* Bilan à faire remonter */ - result = G_ARCH_OPERAND_GET_CLASS(*a)->compare(a, b); + result = G_ARCH_OPERAND_GET_CLASS(*a)->compare(*a, *b); return result; } - /****************************************************************************** * * * Paramètres : a = premier opérande à consulter. * @@ -321,21 +394,21 @@ static int g_arch_operand_quickly_compare(const GArchOperand **a, const GArchOpe * * ******************************************************************************/ -int g_arch_operand_compare(const GArchOperand * const *a, const GArchOperand * const *b) +int g_arch_operand_compare(const GArchOperand *a, const GArchOperand *b) { int result; /* Bilan à faire remonter */ GType type_a; /* Type de l'object A */ GType type_b; /* Type de l'object B */ - type_a = G_OBJECT_TYPE(G_OBJECT(*a)); - type_b = G_OBJECT_TYPE(G_OBJECT(*b)); + type_a = G_OBJECT_TYPE(G_OBJECT(a)); + type_b = G_OBJECT_TYPE(G_OBJECT(b)); assert(sizeof(GType) <= sizeof(unsigned long)); result = sort_unsigned_long(type_a, type_b); if (result == 0) - result = G_ARCH_OPERAND_GET_CLASS(*a)->compare(a, b); + result = G_ARCH_OPERAND_GET_CLASS(a)->compare(a, b); return result; |