1 /* Copyright (C) 2005 Emmanuele Bassi <ebassi@gmail.com>
2  * Copyright (C) 2012-2021 MATE Developers
3  *
4  * This file is part of MATE Utils.
5  *
6  * MATE Utils is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * MATE Utils is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with MATE Utils.  If not, see <https://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef __GDICT_PRIVATE_H__
21 #define __GDICT_PRIVATE_H__
22 
23 #ifndef GDICT_ENABLE_INTERNALS
24 #error "You are trying to access Gdict's internals outside Gdict.  The API of these internal functions is not fixed."
25 #endif
26 
27 #include <glib-object.h>
28 
29 #include "gdict-context.h"
30 
31 G_BEGIN_DECLS
32 
33 /* boilerplate code, similar to G_DEFINE_TYPE in spirit, used to define
34  * our boxed types and their ref/unref functions; you still have to
35  * implement your own ref/unref functions!
36  */
37 #define GDICT_DEFINE_BOXED_TYPE(TypeName,type_name)	\
38 \
39 static gpointer type_name##_intern_ref (gpointer self) \
40 { \
41   return type_name##_ref ((TypeName *) self); \
42 } \
43 static void type_name##_intern_unref (gpointer self) \
44 { \
45   type_name##_unref ((TypeName *) self); \
46 } \
47 \
48 GType \
49 type_name##_get_type (void) \
50 { \
51   static GType gdict_define_boxed_type = 0; \
52   if (G_UNLIKELY (gdict_define_boxed_type == 0)) \
53     gdict_define_boxed_type = g_boxed_type_register_static (#TypeName, (GBoxedCopyFunc) type_name##_intern_ref, (GBoxedFreeFunc) type_name##_intern_unref); \
54   return gdict_define_boxed_type; \
55 }
56 
57 /* Never, _ever_ access the members of these structures, unless you
58  * know what you are doing.
59  */
60 
61 struct _GdictDatabase
62 {
63   gchar *name;
64   gchar *full_name;
65 
66   guint ref_count;
67 };
68 
69 struct _GdictStrategy
70 {
71   gchar *name;
72   gchar *description;
73 
74   guint ref_count;
75 };
76 
77 struct _GdictMatch
78 {
79   gchar *database;
80   gchar *word;
81 
82   guint ref_count;
83 };
84 
85 struct _GdictDefinition
86 {
87   gint total;
88 
89   gchar *word;
90   gchar *database_name;
91   gchar *database_full;
92   gchar *definition;
93 
94   guint ref_count;
95 };
96 
97 /* constructors for these objects are private, as the world outside do
98  * not know what they hold, and accessor functions are getters only
99  */
100 GdictDatabase *   _gdict_database_new   (const gchar *name);
101 GdictStrategy *   _gdict_strategy_new   (const gchar *name);
102 GdictMatch *      _gdict_match_new      (const gchar *word);
103 GdictDefinition * _gdict_definition_new (gint         total);
104 
105 G_END_DECLS
106 
107 #endif /* __GDICT_PRIVATE_H__ */
108