diff options
Diffstat (limited to 'src/glibext/singleton.h')
-rw-r--r-- | src/glibext/singleton.h | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/src/glibext/singleton.h b/src/glibext/singleton.h new file mode 100644 index 0000000..6de9f41 --- /dev/null +++ b/src/glibext/singleton.h @@ -0,0 +1,97 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * singleton.h - prototypes pour la réduction du nombre d'instances d'un même type + * + * Copyright (C) 2021 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Foobar. If not, see <http://www.gnu.org/licenses/>. + */ + + +#ifndef _GLIBEXT_SINGLETON_H +#define _GLIBEXT_SINGLETON_H + + +#include <glib-object.h> +#include <stdbool.h> + + + +/* ------------------ INTERFACE POUR CANDIDAT A UNE CENTRALISATION ------------------ */ + + +#define G_TYPE_SINGLETON_CANDIDATE (g_singleton_candidate_get_type()) +#define G_SINGLETON_CANDIDATE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_SINGLETON_CANDIDATE, GSingletonCandidate)) +#define G_SINGLETON_CANDIDATE_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST((vtable), G_TYPE_SINGLETON_CANDIDATE, GSingletonCandidateIface)) +#define G_IS_SINGLETON_CANDIDATE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_SINGLETON_CANDIDATE)) +#define G_IS_SINGLETON_CANDIDATE_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE((vtable), G_TYPE_SINGLETON_CANDIDATE)) +#define G_SINGLETON_CANDIDATE_GET_IFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE((inst), G_TYPE_SINGLETON_CANDIDATE, GSingletonCandidateIface)) + + +/* Instance d'objet visant à être unique (coquille vide) */ +typedef struct _GSingletonCandidate GSingletonCandidate; + +/* Instance d'objet visant à être unique (interface) */ +typedef struct _GSingletonCandidateIface GSingletonCandidateIface; + + +/* Détermine le type d'une interface pour la lecture de binaire. */ +GType g_singleton_candidate_get_type(void) G_GNUC_CONST; + +/* Fournit l'empreinte d'un candidat à une centralisation. */ +guint g_singleton_candidate_hash(const GSingletonCandidate *); + +/* Détermine si deux candidats à l'unicité sont identiques. */ +gboolean g_singleton_candidate_is_equal(const GSingletonCandidate *, const GSingletonCandidate *); + +/* Marque un candidat comme traité ou en cours de traitement. */ +void g_singleton_candidate_mark_as_processed(GSingletonCandidate *, bool); + +/* Indique si un objet marqué comme unique. */ +bool g_singleton_candidate_is_processed(const GSingletonCandidate *, bool); + + + +/* ------------------------- COLLECTION D'INSTANCES UNIQUES ------------------------- */ + + +#define G_TYPE_SINGLETON_FACTORY g_singleton_factory_get_type() +#define G_SINGLETON_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_SINGLETON_FACTORY, GSingletonFactory)) +#define G_IS_SINGLETON_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_SINGLETON_FACTORY)) +#define G_SINGLETON_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_SINGLETON_FACTORY, GSingletonFactoryClass)) +#define G_IS_SINGLETON_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_SINGLETON_FACTORY)) +#define G_SINGLETON_FACTORY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_SINGLETON_FACTORY, GSingletonFactoryClass)) + + +/* Définition d'un compacteur d'instances de types (instance) */ +typedef struct _GSingletonFactory GSingletonFactory; + +/* Définition d'un compacteur d'instances de types (classe) */ +typedef struct _GSingletonFactoryClass GSingletonFactoryClass; + + +/* Indique le type défini pour une mémoire de types d'objets. */ +GType g_singleton_factory_get_type(void); + +/* Crée un compacteur d'instances de types. */ +GSingletonFactory *g_singleton_factory_new(void); + +/* Fournit l'instance unique correspondant à un objet. */ +GSingletonCandidate *g_singleton_factory_get_instance(GSingletonFactory *, GSingletonCandidate *); + + + +#endif /* _GLIBEXT_SINGLETON_H */ |