2 * Copyright © 2012 Google, Inc.
4 * This is part of HarfBuzz, a text shaping library.
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.
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
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.
24 * Google Author(s): Behdad Esfahbod
33 * @short_description: Objects representing a set of integers
36 * Set objects represent a mathematical set of integer values. They are
37 * used in non-shaping APIs to query certain sets of characters or glyphs,
38 * or other integer values.
43 * hb_set_create: (Xconstructor)
45 * Creates a new, initially empty set.
47 * Return value: (transfer full): The new #hb_set_t
56 if (!(set = hb_object_create<hb_set_t> ()))
57 return hb_set_get_empty ();
67 * Fetches the singleton empty #hb_set_t.
69 * Return value: (transfer full): The empty #hb_set_t
76 return const_cast<hb_set_t *> (&Null (hb_set_t));
80 * hb_set_reference: (skip)
83 * Increases the reference count on a set.
85 * Return value: (transfer full): The set
90 hb_set_reference (hb_set_t *set)
92 return hb_object_reference (set);
96 * hb_set_destroy: (skip)
99 * Decreases the reference count on a set. When
100 * the reference count reaches zero, the set is
101 * destroyed, freeing all memory.
106 hb_set_destroy (hb_set_t *set)
108 if (!hb_object_destroy (set)) return;
110 set->fini_shallow ();
116 * hb_set_set_user_data: (skip)
118 * @key: The user-data key to set
119 * @data: A pointer to the user data to set
120 * @destroy: (nullable): A callback to call when @data is not needed anymore
121 * @replace: Whether to replace an existing data with the same key
123 * Attaches a user-data key/data pair to the specified set.
125 * Return value: %true if success, %false otherwise
130 hb_set_set_user_data (hb_set_t *set,
131 hb_user_data_key_t *key,
133 hb_destroy_func_t destroy,
136 return hb_object_set_user_data (set, key, data, destroy, replace);
140 * hb_set_get_user_data: (skip)
142 * @key: The user-data key to query
144 * Fetches the user data associated with the specified key,
145 * attached to the specified set.
147 * Return value: (transfer none): A pointer to the user data
152 hb_set_get_user_data (hb_set_t *set,
153 hb_user_data_key_t *key)
155 return hb_object_get_user_data (set, key);
160 * hb_set_allocation_successful:
163 * Tests whether memory allocation for a set was successful.
165 * Return value: %true if allocation succeeded, %false otherwise
170 hb_set_allocation_successful (const hb_set_t *set)
172 return !set->in_error ();
179 * Allocate a copy of @set.
181 * Return value: Newly-allocated set.
186 hb_set_copy (const hb_set_t *set)
188 hb_set_t *copy = hb_set_create ();
197 * Clears out the contents of a set.
202 hb_set_clear (hb_set_t *set)
204 /* Immutible-safe. */
212 * Tests whether a set is empty (contains no elements).
214 * Return value: %true if @set is empty
219 hb_set_is_empty (const hb_set_t *set)
221 return set->is_empty ();
227 * @codepoint: The element to query
229 * Tests whether @codepoint belongs to @set.
231 * Return value: %true if @codepoint is in @set, %false otherwise
236 hb_set_has (const hb_set_t *set,
237 hb_codepoint_t codepoint)
239 return set->has (codepoint);
245 * @codepoint: The element to add to @set
247 * Adds @codepoint to @set.
252 hb_set_add (hb_set_t *set,
253 hb_codepoint_t codepoint)
255 /* Immutible-safe. */
256 set->add (codepoint);
262 * @first: The first element to add to @set
263 * @last: The final element to add to @set
265 * Adds all of the elements from @first to @last
266 * (inclusive) to @set.
271 hb_set_add_range (hb_set_t *set,
272 hb_codepoint_t first,
275 /* Immutible-safe. */
276 set->add_range (first, last);
282 * @codepoint: Removes @codepoint from @set
284 * Removes @codepoint from @set.
289 hb_set_del (hb_set_t *set,
290 hb_codepoint_t codepoint)
292 /* Immutible-safe. */
293 set->del (codepoint);
299 * @first: The first element to remove from @set
300 * @last: The final element to remove from @set
302 * Removes all of the elements from @first to @last
303 * (inclusive) from @set.
305 * If @last is #HB_SET_VALUE_INVALID, then all values
306 * greater than or equal to @first are removed.
311 hb_set_del_range (hb_set_t *set,
312 hb_codepoint_t first,
315 /* Immutible-safe. */
316 set->del_range (first, last);
322 * @other: Another set
324 * Tests whether @set and @other are equal (contain the same
327 * Return value: %true if the two sets are equal, %false otherwise.
332 hb_set_is_equal (const hb_set_t *set,
333 const hb_set_t *other)
335 return set->is_equal (*other);
341 * @larger_set: Another set
343 * Tests whether @set is a subset of @larger_set.
345 * Return value: %true if the @set is a subset of (or equal to) @larger_set, %false otherwise.
350 hb_set_is_subset (const hb_set_t *set,
351 const hb_set_t *larger_set)
353 return set->is_subset (*larger_set);
359 * @other: Another set
361 * Makes the contents of @set equal to the contents of @other.
366 hb_set_set (hb_set_t *set,
367 const hb_set_t *other)
369 /* Immutible-safe. */
376 * @other: Another set
378 * Makes @set the union of @set and @other.
383 hb_set_union (hb_set_t *set,
384 const hb_set_t *other)
386 /* Immutible-safe. */
387 set->union_ (*other);
393 * @other: Another set
395 * Makes @set the intersection of @set and @other.
400 hb_set_intersect (hb_set_t *set,
401 const hb_set_t *other)
403 /* Immutible-safe. */
404 set->intersect (*other);
410 * @other: Another set
412 * Subtracts the contents of @other from @set.
417 hb_set_subtract (hb_set_t *set,
418 const hb_set_t *other)
420 /* Immutible-safe. */
421 set->subtract (*other);
425 * hb_set_symmetric_difference:
427 * @other: Another set
429 * Makes @set the symmetric difference of @set
435 hb_set_symmetric_difference (hb_set_t *set,
436 const hb_set_t *other)
438 /* Immutible-safe. */
439 set->symmetric_difference (*other);
446 * Inverts the contents of @set.
451 hb_set_invert (hb_set_t *set)
453 /* Immutible-safe. */
458 * hb_set_get_population:
461 * Returns the number of elements in the set.
463 * Return value: The population of @set
468 hb_set_get_population (const hb_set_t *set)
470 return set->get_population ();
477 * Finds the smallest element in the set.
479 * Return value: minimum of @set, or #HB_SET_VALUE_INVALID if @set is empty.
484 hb_set_get_min (const hb_set_t *set)
486 return set->get_min ();
493 * Finds the largest element in the set.
495 * Return value: maximum of @set, or #HB_SET_VALUE_INVALID if @set is empty.
500 hb_set_get_max (const hb_set_t *set)
502 return set->get_max ();
508 * @codepoint: (inout): Input = Code point to query
509 * Output = Code point retrieved
511 * Fetches the next element in @set that is greater than current value of @codepoint.
513 * Set @codepoint to #HB_SET_VALUE_INVALID to get started.
515 * Return value: %true if there was a next value, %false otherwise
520 hb_set_next (const hb_set_t *set,
521 hb_codepoint_t *codepoint)
523 return set->next (codepoint);
529 * @codepoint: (inout): Input = Code point to query
530 * Output = Code point retrieved
532 * Fetches the previous element in @set that is lower than current value of @codepoint.
534 * Set @codepoint to #HB_SET_VALUE_INVALID to get started.
536 * Return value: %true if there was a previous value, %false otherwise
541 hb_set_previous (const hb_set_t *set,
542 hb_codepoint_t *codepoint)
544 return set->previous (codepoint);
550 * @first: (out): The first code point in the range
551 * @last: (inout): Input = The current last code point in the range
552 * Output = The last code point in the range
554 * Fetches the next consecutive range of elements in @set that
555 * are greater than current value of @last.
557 * Set @last to #HB_SET_VALUE_INVALID to get started.
559 * Return value: %true if there was a next range, %false otherwise
564 hb_set_next_range (const hb_set_t *set,
565 hb_codepoint_t *first,
566 hb_codepoint_t *last)
568 return set->next_range (first, last);
572 * hb_set_previous_range:
574 * @first: (inout): Input = The current first code point in the range
575 * Output = The first code point in the range
576 * @last: (out): The last code point in the range
578 * Fetches the previous consecutive range of elements in @set that
579 * are greater than current value of @last.
581 * Set @first to #HB_SET_VALUE_INVALID to get started.
583 * Return value: %true if there was a previous range, %false otherwise
588 hb_set_previous_range (const hb_set_t *set,
589 hb_codepoint_t *first,
590 hb_codepoint_t *last)
592 return set->previous_range (first, last);