• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.hh"
28 
29 
30 /**
31  * SECTION:hb-set
32  * @title: hb-set
33  * @short_description: Object representing a set of integers
34  * @include: hb.h
35  *
36  * Set objects represent a mathematical set of integer values.  They are
37  * used in non-shaping API to query certain set of characters or glyphs,
38  * or other integer values.
39  **/
40 
41 
42 /**
43  * hb_set_create: (Xconstructor)
44  *
45  * Return value: (transfer full):
46  *
47  * Since: 0.9.2
48  **/
49 hb_set_t *
hb_set_create()50 hb_set_create ()
51 {
52   hb_set_t *set;
53 
54   if (!(set = hb_object_create<hb_set_t> ()))
55     return hb_set_get_empty ();
56 
57   set->init_shallow ();
58 
59   return set;
60 }
61 
62 /**
63  * hb_set_get_empty:
64  *
65  * Return value: (transfer full):
66  *
67  * Since: 0.9.2
68  **/
69 hb_set_t *
hb_set_get_empty()70 hb_set_get_empty ()
71 {
72   return const_cast<hb_set_t *> (&Null(hb_set_t));
73 }
74 
75 /**
76  * hb_set_reference: (skip)
77  * @set: a set.
78  *
79  * Return value: (transfer full):
80  *
81  * Since: 0.9.2
82  **/
83 hb_set_t *
hb_set_reference(hb_set_t * set)84 hb_set_reference (hb_set_t *set)
85 {
86   return hb_object_reference (set);
87 }
88 
89 /**
90  * hb_set_destroy: (skip)
91  * @set: a set.
92  *
93  * Since: 0.9.2
94  **/
95 void
hb_set_destroy(hb_set_t * set)96 hb_set_destroy (hb_set_t *set)
97 {
98   if (!hb_object_destroy (set)) return;
99 
100   set->fini_shallow ();
101 
102   free (set);
103 }
104 
105 /**
106  * hb_set_set_user_data: (skip)
107  * @set: a set.
108  * @key:
109  * @data:
110  * @destroy:
111  * @replace:
112  *
113  * Return value:
114  *
115  * Since: 0.9.2
116  **/
117 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)118 hb_set_set_user_data (hb_set_t           *set,
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 (set, key, data, destroy, replace);
125 }
126 
127 /**
128  * hb_set_get_user_data: (skip)
129  * @set: a set.
130  * @key:
131  *
132  * Return value: (transfer none):
133  *
134  * Since: 0.9.2
135  **/
136 void *
hb_set_get_user_data(hb_set_t * set,hb_user_data_key_t * key)137 hb_set_get_user_data (hb_set_t           *set,
138 		      hb_user_data_key_t *key)
139 {
140   return hb_object_get_user_data (set, key);
141 }
142 
143 
144 /**
145  * hb_set_allocation_successful:
146  * @set: a set.
147  *
148  *
149  *
150  * Return value:
151  *
152  * Since: 0.9.2
153  **/
154 hb_bool_t
hb_set_allocation_successful(const hb_set_t * set)155 hb_set_allocation_successful (const hb_set_t  *set)
156 {
157   return set->successful;
158 }
159 
160 /**
161  * hb_set_clear:
162  * @set: a set.
163  *
164  *
165  *
166  * Since: 0.9.2
167  **/
168 void
hb_set_clear(hb_set_t * set)169 hb_set_clear (hb_set_t *set)
170 {
171   set->clear ();
172 }
173 
174 /**
175  * hb_set_is_empty:
176  * @set: a set.
177  *
178  *
179  *
180  * Return value:
181  *
182  * Since: 0.9.7
183  **/
184 hb_bool_t
hb_set_is_empty(const hb_set_t * set)185 hb_set_is_empty (const hb_set_t *set)
186 {
187   return set->is_empty ();
188 }
189 
190 /**
191  * hb_set_has:
192  * @set: a set.
193  * @codepoint:
194  *
195  *
196  *
197  * Return value:
198  *
199  * Since: 0.9.2
200  **/
201 hb_bool_t
hb_set_has(const hb_set_t * set,hb_codepoint_t codepoint)202 hb_set_has (const hb_set_t *set,
203 	    hb_codepoint_t  codepoint)
204 {
205   return set->has (codepoint);
206 }
207 
208 /**
209  * hb_set_add:
210  * @set: a set.
211  * @codepoint:
212  *
213  *
214  *
215  * Since: 0.9.2
216  **/
217 void
hb_set_add(hb_set_t * set,hb_codepoint_t codepoint)218 hb_set_add (hb_set_t       *set,
219 	    hb_codepoint_t  codepoint)
220 {
221   set->add (codepoint);
222 }
223 
224 /**
225  * hb_set_add_range:
226  * @set: a set.
227  * @first:
228  * @last:
229  *
230  *
231  *
232  * Since: 0.9.7
233  **/
234 void
hb_set_add_range(hb_set_t * set,hb_codepoint_t first,hb_codepoint_t last)235 hb_set_add_range (hb_set_t       *set,
236 		  hb_codepoint_t  first,
237 		  hb_codepoint_t  last)
238 {
239   set->add_range (first, last);
240 }
241 
242 /**
243  * hb_set_del:
244  * @set: a set.
245  * @codepoint:
246  *
247  *
248  *
249  * Since: 0.9.2
250  **/
251 void
hb_set_del(hb_set_t * set,hb_codepoint_t codepoint)252 hb_set_del (hb_set_t       *set,
253 	    hb_codepoint_t  codepoint)
254 {
255   set->del (codepoint);
256 }
257 
258 /**
259  * hb_set_del_range:
260  * @set: a set.
261  * @first:
262  * @last:
263  *
264  *
265  *
266  * Since: 0.9.7
267  **/
268 void
hb_set_del_range(hb_set_t * set,hb_codepoint_t first,hb_codepoint_t last)269 hb_set_del_range (hb_set_t       *set,
270 		  hb_codepoint_t  first,
271 		  hb_codepoint_t  last)
272 {
273   set->del_range (first, last);
274 }
275 
276 /**
277  * hb_set_is_equal:
278  * @set: a set.
279  * @other: other set.
280  *
281  *
282  *
283  * Return value: %TRUE if the two sets are equal, %FALSE otherwise.
284  *
285  * Since: 0.9.7
286  **/
287 hb_bool_t
hb_set_is_equal(const hb_set_t * set,const hb_set_t * other)288 hb_set_is_equal (const hb_set_t *set,
289 		 const hb_set_t *other)
290 {
291   return set->is_equal (other);
292 }
293 
294 /**
295  * hb_set_is_subset:
296  * @set: a set.
297  * @larger_set: other set.
298  *
299  *
300  *
301  * Return value: %TRUE if the @set is a subset of (or equal to) @larger_set, %FALSE otherwise.
302  *
303  * Since: 1.8.1
304  **/
305 hb_bool_t
hb_set_is_subset(const hb_set_t * set,const hb_set_t * larger_set)306 hb_set_is_subset (const hb_set_t *set,
307 		  const hb_set_t *larger_set)
308 {
309   return set->is_subset (larger_set);
310 }
311 
312 /**
313  * hb_set_set:
314  * @set: a set.
315  * @other:
316  *
317  *
318  *
319  * Since: 0.9.2
320  **/
321 void
hb_set_set(hb_set_t * set,const hb_set_t * other)322 hb_set_set (hb_set_t       *set,
323 	    const hb_set_t *other)
324 {
325   set->set (other);
326 }
327 
328 /**
329  * hb_set_union:
330  * @set: a set.
331  * @other:
332  *
333  *
334  *
335  * Since: 0.9.2
336  **/
337 void
hb_set_union(hb_set_t * set,const hb_set_t * other)338 hb_set_union (hb_set_t       *set,
339 	      const hb_set_t *other)
340 {
341   set->union_ (other);
342 }
343 
344 /**
345  * hb_set_intersect:
346  * @set: a set.
347  * @other:
348  *
349  *
350  *
351  * Since: 0.9.2
352  **/
353 void
hb_set_intersect(hb_set_t * set,const hb_set_t * other)354 hb_set_intersect (hb_set_t       *set,
355 		  const hb_set_t *other)
356 {
357   set->intersect (other);
358 }
359 
360 /**
361  * hb_set_subtract:
362  * @set: a set.
363  * @other:
364  *
365  *
366  *
367  * Since: 0.9.2
368  **/
369 void
hb_set_subtract(hb_set_t * set,const hb_set_t * other)370 hb_set_subtract (hb_set_t       *set,
371 		 const hb_set_t *other)
372 {
373   set->subtract (other);
374 }
375 
376 /**
377  * hb_set_symmetric_difference:
378  * @set: a set.
379  * @other:
380  *
381  *
382  *
383  * Since: 0.9.2
384  **/
385 void
hb_set_symmetric_difference(hb_set_t * set,const hb_set_t * other)386 hb_set_symmetric_difference (hb_set_t       *set,
387 			     const hb_set_t *other)
388 {
389   set->symmetric_difference (other);
390 }
391 
392 /**
393  * hb_set_invert:
394  * @set: a set.
395  *
396  *
397  *
398  * Since: 0.9.10
399  *
400  * Deprecated: 1.6.1
401  **/
402 void
hb_set_invert(hb_set_t * set HB_UNUSED)403 hb_set_invert (hb_set_t *set HB_UNUSED)
404 {
405 }
406 
407 /**
408  * hb_set_get_population:
409  * @set: a set.
410  *
411  * Returns the number of numbers in the set.
412  *
413  * Return value: set population.
414  *
415  * Since: 0.9.7
416  **/
417 unsigned int
hb_set_get_population(const hb_set_t * set)418 hb_set_get_population (const hb_set_t *set)
419 {
420   return set->get_population ();
421 }
422 
423 /**
424  * hb_set_get_min:
425  * @set: a set.
426  *
427  * Finds the minimum number in the set.
428  *
429  * Return value: minimum of the set, or %HB_SET_VALUE_INVALID if set is empty.
430  *
431  * Since: 0.9.7
432  **/
433 hb_codepoint_t
hb_set_get_min(const hb_set_t * set)434 hb_set_get_min (const hb_set_t *set)
435 {
436   return set->get_min ();
437 }
438 
439 /**
440  * hb_set_get_max:
441  * @set: a set.
442  *
443  * Finds the maximum number in the set.
444  *
445  * Return value: minimum of the set, or %HB_SET_VALUE_INVALID if set is empty.
446  *
447  * Since: 0.9.7
448  **/
449 hb_codepoint_t
hb_set_get_max(const hb_set_t * set)450 hb_set_get_max (const hb_set_t *set)
451 {
452   return set->get_max ();
453 }
454 
455 /**
456  * hb_set_next:
457  * @set: a set.
458  * @codepoint: (inout):
459  *
460  * Gets the next number in @set that is greater than current value of @codepoint.
461  *
462  * Set @codepoint to %HB_SET_VALUE_INVALID to get started.
463  *
464  * Return value: whether there was a next value.
465  *
466  * Since: 0.9.2
467  **/
468 hb_bool_t
hb_set_next(const hb_set_t * set,hb_codepoint_t * codepoint)469 hb_set_next (const hb_set_t *set,
470 	     hb_codepoint_t *codepoint)
471 {
472   return set->next (codepoint);
473 }
474 
475 /**
476  * hb_set_previous:
477  * @set: a set.
478  * @codepoint: (inout):
479  *
480  * Gets the previous number in @set that is slower than current value of @codepoint.
481  *
482  * Set @codepoint to %HB_SET_VALUE_INVALID to get started.
483  *
484  * Return value: whether there was a previous value.
485  *
486  * Since: 1.8.0
487  **/
488 hb_bool_t
hb_set_previous(const hb_set_t * set,hb_codepoint_t * codepoint)489 hb_set_previous (const hb_set_t *set,
490 		 hb_codepoint_t *codepoint)
491 {
492   return set->previous (codepoint);
493 }
494 
495 /**
496  * hb_set_next_range:
497  * @set: a set.
498  * @first: (out): output first codepoint in the range.
499  * @last: (inout): input current last and output last codepoint in the range.
500  *
501  * Gets the next consecutive range of numbers in @set that
502  * are greater than current value of @last.
503  *
504  * Set @last to %HB_SET_VALUE_INVALID to get started.
505  *
506  * Return value: whether there was a next range.
507  *
508  * Since: 0.9.7
509  **/
510 hb_bool_t
hb_set_next_range(const hb_set_t * set,hb_codepoint_t * first,hb_codepoint_t * last)511 hb_set_next_range (const hb_set_t *set,
512 		   hb_codepoint_t *first,
513 		   hb_codepoint_t *last)
514 {
515   return set->next_range (first, last);
516 }
517 
518 /**
519  * hb_set_previous_range:
520  * @set: a set.
521  * @first: (inout): input current first and output first codepoint in the range.
522  * @last: (out): output last codepoint in the range.
523  *
524  * Gets the previous consecutive range of numbers in @set that
525  * are greater than current value of @last.
526  *
527  * Set @first to %HB_SET_VALUE_INVALID to get started.
528  *
529  * Return value: whether there was a previous range.
530  *
531  * Since: 1.8.0
532  **/
533 hb_bool_t
hb_set_previous_range(const hb_set_t * set,hb_codepoint_t * first,hb_codepoint_t * last)534 hb_set_previous_range (const hb_set_t *set,
535 		       hb_codepoint_t *first,
536 		       hb_codepoint_t *last)
537 {
538   return set->previous_range (first, last);
539 }
540