Modify for C++.
[chise/libchise.git] / chise.h
1 /* Copyright (C) 2003,2004,2005 MORIOKA Tomohiko
2    This file is part of the CHISE Library.
3
4    The CHISE Library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Lesser General Public
6    License as published by the Free Software Foundation; either
7    version 2.1 of the License, or (at your option) any later version.
8
9    The CHISE Library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Lesser General Public License for more details.
13
14    You should have received a copy of the GNU Lesser General Public
15    License along with the CHISE Library; if not, write to the Free
16    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17    02111-1307 USA.  */
18
19 #ifndef _CHISE_H
20 #define _CHISE_H
21
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25
26 #include <db.h>
27 #include <errno.h>
28
29 extern const unsigned char chise_db_dir[];
30 extern const unsigned char chise_system_db_dir[];
31
32 typedef enum CHISE_DS_Type
33 {
34   CHISE_DS_NONE,
35   CHISE_DS_Berkeley_DB
36 } CHISE_DS_Type;
37
38 typedef struct CHISE_DS CHISE_DS;
39
40 CHISE_DS*
41 CHISE_DS_open (CHISE_DS_Type type, const unsigned char *location,
42                int subtype, int modemask);
43
44 int CHISE_DS_close (CHISE_DS *ds);
45
46 unsigned char* chise_ds_location (CHISE_DS *ds);
47
48 int
49 chise_ds_foreach_char_feature_name (CHISE_DS *ds,
50                                     int (*func) (CHISE_DS *ds,
51                                                  unsigned char *name));
52
53
54 typedef int CHISE_Char_ID;
55
56
57 typedef DBT CHISE_Value;
58
59 static inline int
60 chise_value_size (const CHISE_Value *s)
61 {
62   return s->size;
63 }
64
65 static inline char *
66 chise_value_data (const CHISE_Value *s)
67 {
68   return (char *)s->data;
69 }
70
71 static inline char *
72 chise_value_to_c_string (const CHISE_Value *s)
73 {
74   return (char *)s->data;
75 }
76
77
78 typedef struct CHISE_Feature_Table CHISE_Feature_Table;
79 typedef CHISE_Feature_Table* CHISE_Feature;
80
81 CHISE_Feature
82 chise_ds_get_feature (CHISE_DS *ds, const unsigned char *name);
83
84 static inline int
85 chise_ds_load_char_feature_value (CHISE_DS *ds,
86                                   CHISE_Char_ID cid,
87                                   const unsigned char *name,
88                                   CHISE_Value *valdatum);
89
90 int chise_feature_setup_db (CHISE_Feature feature, int writable);
91
92 int chise_feature_sync (CHISE_Feature feature);
93
94 int chise_char_set_feature_value (CHISE_Char_ID cid,
95                                   CHISE_Feature feature,
96                                   unsigned char *value);
97
98 int chise_char_load_feature_value (CHISE_Char_ID cid,
99                                    CHISE_Feature feature,
100                                    CHISE_Value *valdatum);
101
102 static inline int
103 chise_ds_load_char_feature_value (CHISE_DS *ds,
104                                   CHISE_Char_ID cid,
105                                   const unsigned char *name,
106                                   CHISE_Value *valdatum)
107 {
108   return
109     chise_char_load_feature_value (cid, chise_ds_get_feature (ds, name),
110                                    valdatum);
111 }
112
113 unsigned char*
114 chise_char_gets_feature_value (CHISE_Char_ID cid,
115                                CHISE_Feature feature,
116                                unsigned char *dst, size_t size);
117
118 int
119 chise_feature_foreach_char_with_value (CHISE_Feature feature,
120                                        int (*func) (CHISE_Char_ID cid,
121                                                     CHISE_Feature feature,
122                                                     CHISE_Value *valdatum));
123
124 #if 0
125 int
126 chise_feature_foreach_char_with_str (CHISE_Feature feature,
127                                      int (*func) (CHISE_Char_ID cid,
128                                                   CHISE_Feature feature,
129                                                   unsigned char *str));
130 #endif
131
132
133 typedef struct CHISE_CCS_Table CHISE_CCS_Table;
134 typedef CHISE_CCS_Table* CHISE_CCS;
135
136 CHISE_CCS
137 chise_ds_get_ccs (CHISE_DS *ds, const unsigned char *name);
138
139 static inline CHISE_Char_ID
140 chise_ds_decode_char (CHISE_DS *ds,
141                       const unsigned char *ccs, int code_point);
142
143 int chise_ccs_setup_db (CHISE_CCS ccs, int writable);
144
145 int chise_ccs_sync (CHISE_CCS ccs);
146
147 int chise_ccs_set_decoded_char (CHISE_CCS ccs,
148                                 int code_point, CHISE_Char_ID cid);
149
150 CHISE_Char_ID chise_ccs_decode (CHISE_CCS ccs, int code_point);
151
152 static inline CHISE_Char_ID
153 chise_ds_decode_char (CHISE_DS *ds,
154                       const unsigned char *name, int code_point)
155 {
156   return
157     chise_ccs_decode (chise_ds_get_ccs (ds, name), code_point);
158 }
159
160
161 typedef struct CHISE_Property_Table CHISE_Property_Table;
162 typedef CHISE_Property_Table* CHISE_Property;
163
164 CHISE_Property_Table*
165 chise_ds_get_property (CHISE_DS *ds, const unsigned char *property);
166
167 int chise_property_setup_db (CHISE_Property property, int writable);
168
169 int chise_property_sync (CHISE_Property property);
170
171 int chise_feature_set_property_value (CHISE_Feature feature,
172                                       CHISE_Property property,
173                                       unsigned char *value);
174
175 int chise_feature_load_property_value (CHISE_Feature feature,
176                                        CHISE_Property_Table *table,
177                                        CHISE_Value *valdatum);
178
179 unsigned char*
180 chise_feature_gets_property_value (CHISE_Feature feature,
181                                    CHISE_Property_Table *table,
182                                    unsigned char *buf, size_t size);
183
184 #ifdef __cplusplus
185 }
186 #endif
187
188 #endif /* !_CHISE_H */