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 **/
49hb_set_t *
50hb_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 **/
69hb_set_t *
70hb_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 **/
83hb_set_t *
84hb_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 **/
95void
96hb_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 **/
117hb_bool_t
118hb_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 **/
136void *
137hb_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 **/
154hb_bool_t
155hb_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 **/
168void
169hb_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 **/
184hb_bool_t
185hb_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 **/
201hb_bool_t
202hb_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 **/
217void
218hb_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 **/
234void
235hb_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 **/
251void
252hb_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 **/
268void
269hb_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 **/
287hb_bool_t
288hb_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 **/
305hb_bool_t
306hb_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 **/
321void
322hb_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 **/
337void
338hb_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 **/
353void
354hb_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 **/
369void
370hb_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 **/
385void
386hb_set_symmetric_difference (hb_set_t *set,
387 const hb_set_t *other)
388{
389 set->symmetric_difference (other);
390}
391
392#ifndef HB_DISABLE_DEPRECATED
393/**
394 * hb_set_invert:
395 * @set: a set.
396 *
397 *
398 *
399 * Since: 0.9.10
400 *
401 * Deprecated: 1.6.1
402 **/
403void
404hb_set_invert (hb_set_t *set HB_UNUSED)
405{
406}
407#endif
408
409/**
410 * hb_set_get_population:
411 * @set: a set.
412 *
413 * Returns the number of numbers in the set.
414 *
415 * Return value: set population.
416 *
417 * Since: 0.9.7
418 **/
419unsigned int
420hb_set_get_population (const hb_set_t *set)
421{
422 return set->get_population ();
423}
424
425/**
426 * hb_set_get_min:
427 * @set: a set.
428 *
429 * Finds the minimum number in the set.
430 *
431 * Return value: minimum of the set, or %HB_SET_VALUE_INVALID if set is empty.
432 *
433 * Since: 0.9.7
434 **/
435hb_codepoint_t
436hb_set_get_min (const hb_set_t *set)
437{
438 return set->get_min ();
439}
440
441/**
442 * hb_set_get_max:
443 * @set: a set.
444 *
445 * Finds the maximum number in the set.
446 *
447 * Return value: minimum of the set, or %HB_SET_VALUE_INVALID if set is empty.
448 *
449 * Since: 0.9.7
450 **/
451hb_codepoint_t
452hb_set_get_max (const hb_set_t *set)
453{
454 return set->get_max ();
455}
456
457/**
458 * hb_set_next:
459 * @set: a set.
460 * @codepoint: (inout):
461 *
462 * Gets the next number in @set that is greater than current value of @codepoint.
463 *
464 * Set @codepoint to %HB_SET_VALUE_INVALID to get started.
465 *
466 * Return value: whether there was a next value.
467 *
468 * Since: 0.9.2
469 **/
470hb_bool_t
471hb_set_next (const hb_set_t *set,
472 hb_codepoint_t *codepoint)
473{
474 return set->next (codepoint);
475}
476
477/**
478 * hb_set_previous:
479 * @set: a set.
480 * @codepoint: (inout):
481 *
482 * Gets the previous number in @set that is lower than current value of @codepoint.
483 *
484 * Set @codepoint to %HB_SET_VALUE_INVALID to get started.
485 *
486 * Return value: whether there was a previous value.
487 *
488 * Since: 1.8.0
489 **/
490hb_bool_t
491hb_set_previous (const hb_set_t *set,
492 hb_codepoint_t *codepoint)
493{
494 return set->previous (codepoint);
495}
496
497/**
498 * hb_set_next_range:
499 * @set: a set.
500 * @first: (out): output first codepoint in the range.
501 * @last: (inout): input current last and output last codepoint in the range.
502 *
503 * Gets the next consecutive range of numbers in @set that
504 * are greater than current value of @last.
505 *
506 * Set @last to %HB_SET_VALUE_INVALID to get started.
507 *
508 * Return value: whether there was a next range.
509 *
510 * Since: 0.9.7
511 **/
512hb_bool_t
513hb_set_next_range (const hb_set_t *set,
514 hb_codepoint_t *first,
515 hb_codepoint_t *last)
516{
517 return set->next_range (first, last);
518}
519
520/**
521 * hb_set_previous_range:
522 * @set: a set.
523 * @first: (inout): input current first and output first codepoint in the range.
524 * @last: (out): output last codepoint in the range.
525 *
526 * Gets the previous consecutive range of numbers in @set that
527 * are less than current value of @first.
528 *
529 * Set @first to %HB_SET_VALUE_INVALID to get started.
530 *
531 * Return value: whether there was a previous range.
532 *
533 * Since: 1.8.0
534 **/
535hb_bool_t
536hb_set_previous_range (const hb_set_t *set,
537 hb_codepoint_t *first,
538 hb_codepoint_t *last)
539{
540 return set->previous_range (first, last);
541}
542