1 /*
2  * Copyright © 2012  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-set-private.hh"
28 
29 
30 /* Public API */
31 
32 
33 /**
34  * hb_set_create: (Xconstructor)
35  *
36  * Return value: (transfer full):
37  *
38  * Since: 0.9.2
39  **/
40 hb_set_t *
hb_set_create(void)41 hb_set_create (void)
42 {
43   hb_set_t *set;
44 
45   if (!(set = hb_object_create<hb_set_t> ()))
46     return hb_set_get_empty ();
47 
48   set->init ();
49 
50   return set;
51 }
52 
53 /**
54  * hb_set_get_empty:
55  *
56  * Return value: (transfer full):
57  *
58  * Since: 0.9.2
59  **/
60 hb_set_t *
hb_set_get_empty(void)61 hb_set_get_empty (void)
62 {
63   static const hb_set_t _hb_set_nil = {
64     HB_OBJECT_HEADER_STATIC,
65     true, /* in_error */
66 
67     {0} /* elts */
68   };
69 
70   return const_cast<hb_set_t *> (&_hb_set_nil);
71 }
72 
73 /**
74  * hb_set_reference: (skip)
75  * @set: a set.
76  *
77  * Return value: (transfer full):
78  *
79  * Since: 0.9.2
80  **/
81 hb_set_t *
hb_set_reference(hb_set_t * set)82 hb_set_reference (hb_set_t *set)
83 {
84   return hb_object_reference (set);
85 }
86 
87 /**
88  * hb_set_destroy: (skip)
89  * @set: a set.
90  *
91  * Since: 0.9.2
92  **/
93 void
hb_set_destroy(hb_set_t * set)94 hb_set_destroy (hb_set_t *set)
95 {
96   if (!hb_object_destroy (set)) return;
97 
98   set->finish ();
99 
100   free (set);
101 }
102 
103 /**
104  * hb_set_set_user_data: (skip)
105  * @set: a set.
106  * @key:
107  * @data:
108  * @destroy:
109  * @replace:
110  *
111  * Return value:
112  *
113  * Since: 0.9.2
114  **/
115 hb_bool_t
hb_set_set_user_data(hb_set_t * set,hb_user_data_key_t * key,void * data,hb_destroy_func_t destroy,hb_bool_t replace)116 hb_set_set_user_data (hb_set_t           *set,
117 		      hb_user_data_key_t *key,
118 		      void *              data,
119 		      hb_destroy_func_t   destroy,
120 		      hb_bool_t           replace)
121 {
122   return hb_object_set_user_data (set, key, data, destroy, replace);
123 }
124 
125 /**
126  * hb_set_get_user_data: (skip)
127  * @set: a set.
128  * @key:
129  *
130  * Return value: (transfer none):
131  *
132  * Since: 0.9.2
133  **/
134 void *
hb_set_get_user_data(hb_set_t * set,hb_user_data_key_t * key)135 hb_set_get_user_data (hb_set_t           *set,
136 		      hb_user_data_key_t *key)
137 {
138   return hb_object_get_user_data (set, key);
139 }
140 
141 
142 /**
143  * hb_set_allocation_successful:
144  * @set: a set.
145  *
146  *
147  *
148  * Return value:
149  *
150  * Since: 0.9.2
151  **/
152 hb_bool_t
hb_set_allocation_successful(const hb_set_t * set HB_UNUSED)153 hb_set_allocation_successful (const hb_set_t  *set HB_UNUSED)
154 {
155   return !set->in_error;
156 }
157 
158 /**
159  * hb_set_clear:
160  * @set: a set.
161  *
162  *
163  *
164  * Since: 0.9.2
165  **/
166 void
hb_set_clear(hb_set_t * set)167 hb_set_clear (hb_set_t *set)
168 {
169   set->clear ();
170 }
171 
172 /**
173  * hb_set_is_empty:
174  * @set: a set.
175  *
176  *
177  *
178  * Return value:
179  *
180  * Since: 0.9.7
181  **/
182 hb_bool_t
hb_set_is_empty(const hb_set_t * set)183 hb_set_is_empty (const hb_set_t *set)
184 {
185   return set->is_empty ();
186 }
187 
188 /**
189  * hb_set_has:
190  * @set: a set.
191  * @codepoint:
192  *
193  *
194  *
195  * Return value:
196  *
197  * Since: 0.9.2
198  **/
199 hb_bool_t
hb_set_has(const hb_set_t * set,hb_codepoint_t codepoint)200 hb_set_has (const hb_set_t *set,
201 	    hb_codepoint_t  codepoint)
202 {
203   return set->has (codepoint);
204 }
205 
206 /**
207  * hb_set_add:
208  * @set: a set.
209  * @codepoint:
210  *
211  *
212  *
213  * Since: 0.9.2
214  **/
215 void
hb_set_add(hb_set_t * set,hb_codepoint_t codepoint)216 hb_set_add (hb_set_t       *set,
217 	    hb_codepoint_t  codepoint)
218 {
219   set->add (codepoint);
220 }
221 
222 /**
223  * hb_set_add_range:
224  * @set: a set.
225  * @first:
226  * @last:
227  *
228  *
229  *
230  * Since: 0.9.7
231  **/
232 void
hb_set_add_range(hb_set_t * set,hb_codepoint_t first,hb_codepoint_t last)233 hb_set_add_range (hb_set_t       *set,
234 		  hb_codepoint_t  first,
235 		  hb_codepoint_t  last)
236 {
237   set->add_range (first, last);
238 }
239 
240 /**
241  * hb_set_del:
242  * @set: a set.
243  * @codepoint:
244  *
245  *
246  *
247  * Since: 0.9.2
248  **/
249 void
hb_set_del(hb_set_t * set,hb_codepoint_t codepoint)250 hb_set_del (hb_set_t       *set,
251 	    hb_codepoint_t  codepoint)
252 {
253   set->del (codepoint);
254 }
255 
256 /**
257  * hb_set_del_range:
258  * @set: a set.
259  * @first:
260  * @last:
261  *
262  *
263  *
264  * Since: 0.9.7
265  **/
266 void
hb_set_del_range(hb_set_t * set,hb_codepoint_t first,hb_codepoint_t last)267 hb_set_del_range (hb_set_t       *set,
268 		  hb_codepoint_t  first,
269 		  hb_codepoint_t  last)
270 {
271   set->del_range (first, last);
272 }
273 
274 /**
275  * hb_set_is_equal:
276  * @set: a set.
277  * @other:
278  *
279  *
280  *
281  * Return value:
282  *
283  * Since: 0.9.7
284  **/
285 hb_bool_t
hb_set_is_equal(const hb_set_t * set,const hb_set_t * other)286 hb_set_is_equal (const hb_set_t *set,
287 		 const hb_set_t *other)
288 {
289   return set->is_equal (other);
290 }
291 
292 /**
293  * hb_set_set:
294  * @set: a set.
295  * @other:
296  *
297  *
298  *
299  * Since: 0.9.2
300  **/
301 void
hb_set_set(hb_set_t * set,const hb_set_t * other)302 hb_set_set (hb_set_t       *set,
303 	    const hb_set_t *other)
304 {
305   set->set (other);
306 }
307 
308 /**
309  * hb_set_union:
310  * @set: a set.
311  * @other:
312  *
313  *
314  *
315  * Since: 0.9.2
316  **/
317 void
hb_set_union(hb_set_t * set,const hb_set_t * other)318 hb_set_union (hb_set_t       *set,
319 	      const hb_set_t *other)
320 {
321   set->union_ (other);
322 }
323 
324 /**
325  * hb_set_intersect:
326  * @set: a set.
327  * @other:
328  *
329  *
330  *
331  * Since: 0.9.2
332  **/
333 void
hb_set_intersect(hb_set_t * set,const hb_set_t * other)334 hb_set_intersect (hb_set_t       *set,
335 		  const hb_set_t *other)
336 {
337   set->intersect (other);
338 }
339 
340 /**
341  * hb_set_subtract:
342  * @set: a set.
343  * @other:
344  *
345  *
346  *
347  * Since: 0.9.2
348  **/
349 void
hb_set_subtract(hb_set_t * set,const hb_set_t * other)350 hb_set_subtract (hb_set_t       *set,
351 		 const hb_set_t *other)
352 {
353   set->subtract (other);
354 }
355 
356 /**
357  * hb_set_symmetric_difference:
358  * @set: a set.
359  * @other:
360  *
361  *
362  *
363  * Since: 0.9.2
364  **/
365 void
hb_set_symmetric_difference(hb_set_t * set,const hb_set_t * other)366 hb_set_symmetric_difference (hb_set_t       *set,
367 			     const hb_set_t *other)
368 {
369   set->symmetric_difference (other);
370 }
371 
372 /**
373  * hb_set_invert:
374  * @set: a set.
375  *
376  *
377  *
378  * Since: 0.9.10
379  *
380  * Deprecated: 1.6.1
381  **/
382 void
hb_set_invert(hb_set_t * set)383 hb_set_invert (hb_set_t *set)
384 {
385 }
386 
387 /**
388  * hb_set_get_population:
389  * @set: a set.
390  *
391  * Returns the number of numbers in the set.
392  *
393  * Return value: set population.
394  *
395  * Since: 0.9.7
396  **/
397 unsigned int
hb_set_get_population(const hb_set_t * set)398 hb_set_get_population (const hb_set_t *set)
399 {
400   return set->get_population ();
401 }
402 
403 /**
404  * hb_set_get_min:
405  * @set: a set.
406  *
407  * Finds the minimum number in the set.
408  *
409  * Return value: minimum of the set, or %HB_SET_VALUE_INVALID if set is empty.
410  *
411  * Since: 0.9.7
412  **/
413 hb_codepoint_t
hb_set_get_min(const hb_set_t * set)414 hb_set_get_min (const hb_set_t *set)
415 {
416   return set->get_min ();
417 }
418 
419 /**
420  * hb_set_get_max:
421  * @set: a set.
422  *
423  * Finds the maximum number in the set.
424  *
425  * Return value: minimum of the set, or %HB_SET_VALUE_INVALID if set is empty.
426  *
427  * Since: 0.9.7
428  **/
429 hb_codepoint_t
hb_set_get_max(const hb_set_t * set)430 hb_set_get_max (const hb_set_t *set)
431 {
432   return set->get_max ();
433 }
434 
435 /**
436  * hb_set_next:
437  * @set: a set.
438  * @codepoint: (inout):
439  *
440  *
441  *
442  * Return value: whether there was a next value.
443  *
444  * Since: 0.9.2
445  **/
446 hb_bool_t
hb_set_next(const hb_set_t * set,hb_codepoint_t * codepoint)447 hb_set_next (const hb_set_t *set,
448 	     hb_codepoint_t *codepoint)
449 {
450   return set->next (codepoint);
451 }
452 
453 /**
454  * hb_set_next_range:
455  * @set: a set.
456  * @first: (out): output first codepoint in the range.
457  * @last: (inout): input current last and output last codepoint in the range.
458  *
459  * Gets the next consecutive range of numbers in @set that
460  * are greater than current value of @last.
461  *
462  * Return value: whether there was a next range.
463  *
464  * Since: 0.9.7
465  **/
466 hb_bool_t
hb_set_next_range(const hb_set_t * set,hb_codepoint_t * first,hb_codepoint_t * last)467 hb_set_next_range (const hb_set_t *set,
468 		   hb_codepoint_t *first,
469 		   hb_codepoint_t *last)
470 {
471   return set->next_range (first, last);
472 }
473