Fix FSF address (Tobias Mueller, #470445)
[platform/upstream/evolution-data-server.git] / camel / camel-index.h
1 /*
2  *  Copyright (C) 2001 Ximian Inc.
3  *
4  *  Authors: Michael Zucchi <notzed@ximian.com>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of version 2 of the GNU Lesser General Public
8  * License as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20
21 #ifndef _CAMEL_INDEX_H
22 #define _CAMEL_INDEX_H
23
24 #include <camel/camel-exception.h>
25 #include <camel/camel-object.h>
26
27 #define CAMEL_INDEX(obj)         CAMEL_CHECK_CAST (obj, camel_index_get_type (), CamelIndex)
28 #define CAMEL_INDEX_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_index_get_type (), CamelIndexClass)
29 #define CAMEL_IS_INDEX(obj)      CAMEL_CHECK_TYPE (obj, camel_index_get_type ())
30
31 G_BEGIN_DECLS
32
33 typedef struct _CamelIndex      CamelIndex;
34 typedef struct _CamelIndexClass CamelIndexClass;
35
36 #define CAMEL_INDEX_NAME(obj)         CAMEL_CHECK_CAST (obj, camel_index_name_get_type (), CamelIndexName)
37 #define CAMEL_INDEX_NAME_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_index_name_get_type (), CamelIndexNameClass)
38 #define CAMEL_IS_INDEX_NAME(obj)      CAMEL_CHECK_TYPE (obj, camel_index_name_get_type ())
39
40 typedef struct _CamelIndexName      CamelIndexName;
41 typedef struct _CamelIndexNameClass CamelIndexNameClass;
42
43 #define CAMEL_INDEX_CURSOR(obj)         CAMEL_CHECK_CAST (obj, camel_index_cursor_get_type (), CamelIndexCursor)
44 #define CAMEL_INDEX_CURSOR_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_index_cursor_get_type (), CamelIndexCursorClass)
45 #define CAMEL_IS_INDEX_CURSOR(obj)      CAMEL_CHECK_TYPE (obj, camel_index_cursor_get_type ())
46
47 typedef struct _CamelIndexCursor      CamelIndexCursor;
48 typedef struct _CamelIndexCursorClass CamelIndexCursorClass;
49
50 typedef char * (*CamelIndexNorm)(CamelIndex *idx, const char *word, void *data);
51
52 /* ********************************************************************** */
53
54 struct _CamelIndexCursor {
55         CamelObject parent;
56
57         struct _CamelIndexCursorPrivate *priv;
58
59         CamelIndex *index;
60 };
61
62 struct _CamelIndexCursorClass {
63         CamelObjectClass parent;
64
65         const char * (*next) (CamelIndexCursor *idc);
66         void         (*reset) (CamelIndexCursor *idc);
67 };
68
69 CamelType                  camel_index_cursor_get_type(void);
70
71 CamelIndexCursor  *camel_index_cursor_new(CamelIndex *idx, const char *name);
72
73 const char        *camel_index_cursor_next(CamelIndexCursor *idc);
74 void               camel_index_cursor_reset(CamelIndexCursor *idc);
75
76 /* ********************************************************************** */
77
78 struct _CamelIndexName {
79         CamelObject parent;
80
81         struct _CamelIndexNamePrivate *priv;
82
83         CamelIndex *index;
84
85         char *name;             /* name being indexed */
86
87         GByteArray *buffer;     /* used for normalisation */
88         GHashTable *words;      /* unique list of words */
89 };
90
91 struct _CamelIndexNameClass {
92         CamelObjectClass parent;
93
94         int (*sync)(CamelIndexName *name);
95         void (*add_word)(CamelIndexName *name, const char *word);
96         size_t (*add_buffer)(CamelIndexName *name, const char *buffer, size_t len);
97 };
98
99 CamelType                  camel_index_name_get_type    (void);
100
101 CamelIndexName    *camel_index_name_new(CamelIndex *idx, const char *name);
102
103 void               camel_index_name_add_word(CamelIndexName *name, const char *word);
104 size_t             camel_index_name_add_buffer(CamelIndexName *name, const char *buffer, size_t len);
105
106 /* ********************************************************************** */
107
108 struct _CamelIndex {
109         CamelObject parent;
110
111         struct _CamelIndexPrivate *priv;
112
113         char *path;
114         guint32 version;
115         guint32 flags;          /* open flags */
116         guint32 state;
117
118         CamelIndexNorm normalise;
119         void *normalise_data;
120 };
121
122 struct _CamelIndexClass {
123         CamelObjectClass parent_class;
124
125         int                     (*sync)(CamelIndex *idx);
126         int                     (*compress)(CamelIndex *idx);
127         int                     (*delete)(CamelIndex *idx);
128
129         int                     (*rename)(CamelIndex *idx, const char *path);
130
131         int                     (*has_name)(CamelIndex *idx, const char *name);
132         CamelIndexName *        (*add_name)(CamelIndex *idx, const char *name);
133         int                     (*write_name)(CamelIndex *idx, CamelIndexName *idn);
134         CamelIndexCursor *      (*find_name)(CamelIndex *idx, const char *name);
135         void                    (*delete_name)(CamelIndex *idx, const char *name);
136         CamelIndexCursor *      (*find)(CamelIndex *idx, const char *word);
137
138         CamelIndexCursor *      (*words)(CamelIndex *idx);
139         CamelIndexCursor *      (*names)(CamelIndex *idx);
140 };
141
142 /* flags, stored in 'state', set with set_state */
143 #define CAMEL_INDEX_DELETED (1<<0)
144
145 CamelType                  camel_index_get_type (void);
146
147 CamelIndex        *camel_index_new(const char *path, int flags);
148 void               camel_index_construct(CamelIndex *, const char *path, int flags);
149 int                camel_index_rename(CamelIndex *, const char *path);
150
151 void               camel_index_set_normalise(CamelIndex *idx, CamelIndexNorm func, void *data);
152
153 int                camel_index_sync(CamelIndex *idx);
154 int                camel_index_compress(CamelIndex *idx);
155 int                camel_index_delete(CamelIndex *idx);
156
157 int                camel_index_has_name(CamelIndex *idx, const char *name);
158 CamelIndexName    *camel_index_add_name(CamelIndex *idx, const char *name);
159 int                camel_index_write_name(CamelIndex *idx, CamelIndexName *idn);
160 CamelIndexCursor  *camel_index_find_name(CamelIndex *idx, const char *name);
161 void               camel_index_delete_name(CamelIndex *idx, const char *name);
162 CamelIndexCursor  *camel_index_find(CamelIndex *idx, const char *word);
163
164 CamelIndexCursor  *camel_index_words(CamelIndex *idx);
165 CamelIndexCursor  *camel_index_names(CamelIndex *idx);
166
167 G_END_DECLS
168
169 #endif /* ! _CAMEL_INDEX_H */