1 /*
2 * Copyright © 2018 Google, Inc.
3 *
4 * This is part of HarfBuzz, a text shaping library.
5 *
6 * Permission is hereby granted, without written agreement and without
7 * license or royalty fees, to use, copy, modify, and distribute this
8 * software and its documentation for any purpose, provided that the
9 * above copyright notice and the following two paragraphs appear in
10 * all copies of this software.
11 *
12 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
16 * DAMAGE.
17 *
18 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
21 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
23 *
24 * Google Author(s): Behdad Esfahbod
25 */
26
27 #include "hb-map.hh"
28
29
30 /**
31 * SECTION:hb-map
32 * @title: hb-map
33 * @short_description: Object representing integer to integer mapping
34 * @include: hb.h
35 *
36 * Map objects are integer-to-integer hash-maps. Currently they are
37 * not used in the HarfBuzz public API, but are provided for client's
38 * use if desired.
39 **/
40
41
42 /**
43 * hb_map_create: (Xconstructor)
44 *
45 * Return value: (transfer full):
46 *
47 * Since: 1.7.7
48 **/
49 hb_map_t *
hb_map_create()50 hb_map_create ()
51 {
52 hb_map_t *map;
53
54 if (!(map = hb_object_create<hb_map_t> ()))
55 return hb_map_get_empty ();
56
57 map->init_shallow ();
58
59 return map;
60 }
61
62 /**
63 * hb_map_get_empty:
64 *
65 * Return value: (transfer full):
66 *
67 * Since: 1.7.7
68 **/
69 hb_map_t *
hb_map_get_empty()70 hb_map_get_empty ()
71 {
72 return const_cast<hb_map_t *> (&Null(hb_map_t));
73 }
74
75 /**
76 * hb_map_reference: (skip)
77 * @map: a map.
78 *
79 * Return value: (transfer full):
80 *
81 * Since: 1.7.7
82 **/
83 hb_map_t *
hb_map_reference(hb_map_t * map)84 hb_map_reference (hb_map_t *map)
85 {
86 return hb_object_reference (map);
87 }
88
89 /**
90 * hb_map_destroy: (skip)
91 * @map: a map.
92 *
93 * Since: 1.7.7
94 **/
95 void
hb_map_destroy(hb_map_t * map)96 hb_map_destroy (hb_map_t *map)
97 {
98 if (!hb_object_destroy (map)) return;
99
100 map->fini_shallow ();
101
102 free (map);
103 }
104
105 /**
106 * hb_map_set_user_data: (skip)
107 * @map: a map.
108 * @key:
109 * @data:
110 * @destroy:
111 * @replace:
112 *
113 * Return value:
114 *
115 * Since: 1.7.7
116 **/
117 hb_bool_t
hb_map_set_user_data(hb_map_t * map,hb_user_data_key_t * key,void * data,hb_destroy_func_t destroy,hb_bool_t replace)118 hb_map_set_user_data (hb_map_t *map,
119 hb_user_data_key_t *key,
120 void * data,
121 hb_destroy_func_t destroy,
122 hb_bool_t replace)
123 {
124 return hb_object_set_user_data (map, key, data, destroy, replace);
125 }
126
127 /**
128 * hb_map_get_user_data: (skip)
129 * @map: a map.
130 * @key:
131 *
132 * Return value: (transfer none):
133 *
134 * Since: 1.7.7
135 **/
136 void *
hb_map_get_user_data(hb_map_t * map,hb_user_data_key_t * key)137 hb_map_get_user_data (hb_map_t *map,
138 hb_user_data_key_t *key)
139 {
140 return hb_object_get_user_data (map, key);
141 }
142
143
144 /**
145 * hb_map_allocation_successful:
146 * @map: a map.
147 *
148 *
149 *
150 * Return value:
151 *
152 * Since: 1.7.7
153 **/
154 hb_bool_t
hb_map_allocation_successful(const hb_map_t * map)155 hb_map_allocation_successful (const hb_map_t *map)
156 {
157 return map->successful;
158 }
159
160
161 /**
162 * hb_map_set:
163 * @map: a map.
164 * @key:
165 * @value:
166 *
167 *
168 *
169 * Since: 1.7.7
170 **/
171 void
hb_map_set(hb_map_t * map,hb_codepoint_t key,hb_codepoint_t value)172 hb_map_set (hb_map_t *map,
173 hb_codepoint_t key,
174 hb_codepoint_t value)
175 {
176 map->set (key, value);
177 }
178
179 /**
180 * hb_map_get:
181 * @map: a map.
182 * @key:
183 *
184 *
185 *
186 * Since: 1.7.7
187 **/
188 hb_codepoint_t
hb_map_get(const hb_map_t * map,hb_codepoint_t key)189 hb_map_get (const hb_map_t *map,
190 hb_codepoint_t key)
191 {
192 return map->get (key);
193 }
194
195 /**
196 * hb_map_del:
197 * @map: a map.
198 * @key:
199 *
200 *
201 *
202 * Since: 1.7.7
203 **/
204 void
hb_map_del(hb_map_t * map,hb_codepoint_t key)205 hb_map_del (hb_map_t *map,
206 hb_codepoint_t key)
207 {
208 map->del (key);
209 }
210
211 /**
212 * hb_map_has:
213 * @map: a map.
214 * @key:
215 *
216 *
217 *
218 * Since: 1.7.7
219 **/
220 hb_bool_t
hb_map_has(const hb_map_t * map,hb_codepoint_t key)221 hb_map_has (const hb_map_t *map,
222 hb_codepoint_t key)
223 {
224 return map->has (key);
225 }
226
227
228 /**
229 * hb_map_clear:
230 * @map: a map.
231 *
232 *
233 *
234 * Since: 1.7.7
235 **/
236 void
hb_map_clear(hb_map_t * map)237 hb_map_clear (hb_map_t *map)
238 {
239 return map->clear ();
240 }
241
242 /**
243 * hb_map_is_empty:
244 * @map: a map.
245 *
246 *
247 *
248 * Since: 1.7.7
249 **/
250 hb_bool_t
hb_map_is_empty(const hb_map_t * map)251 hb_map_is_empty (const hb_map_t *map)
252 {
253 return map->is_empty ();
254 }
255
256 /**
257 * hb_map_get_population:
258 * @map: a map.
259 *
260 *
261 *
262 * Since: 1.7.7
263 **/
264 unsigned int
hb_map_get_population(const hb_map_t * map)265 hb_map_get_population (const hb_map_t *map)
266 {
267 return map->get_population ();
268 }
269