blob: 5f427a5d8e0b6e61e55ff464d90fdc05ec255ff5 [file] [log] [blame]
Behdad Esfahbod0b08adb2012-04-23 22:41:09 -04001/*
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
Behdad Esfahbod6c6ccaf2012-04-24 14:21:15 -040031/* Public API */
32
Behdad Esfahbod0b08adb2012-04-23 22:41:09 -040033
34hb_set_t *
Behdad Esfahbodaec89de2012-11-15 16:15:42 -080035hb_set_create (void)
Behdad Esfahbod0b08adb2012-04-23 22:41:09 -040036{
37 hb_set_t *set;
38
39 if (!(set = hb_object_create<hb_set_t> ()))
Behdad Esfahbodf06ab8a2012-06-05 12:31:51 -040040 return hb_set_get_empty ();
Behdad Esfahbod0b08adb2012-04-23 22:41:09 -040041
42 set->clear ();
43
44 return set;
45}
46
47hb_set_t *
48hb_set_get_empty (void)
49{
Behdad Esfahbodf06ab8a2012-06-05 12:31:51 -040050 static const hb_set_t _hb_set_nil = {
51 HB_OBJECT_HEADER_STATIC,
Behdad Esfahbod8165f272013-01-02 22:50:36 -060052 true, /* in_error */
Behdad Esfahbodf06ab8a2012-06-05 12:31:51 -040053
54 {0} /* elts */
55 };
56
57 return const_cast<hb_set_t *> (&_hb_set_nil);
Behdad Esfahbod0b08adb2012-04-23 22:41:09 -040058}
59
60hb_set_t *
61hb_set_reference (hb_set_t *set)
62{
63 return hb_object_reference (set);
64}
65
66void
67hb_set_destroy (hb_set_t *set)
68{
69 if (!hb_object_destroy (set)) return;
70
Behdad Esfahboda5e39fe2012-04-25 00:14:46 -040071 set->fini ();
72
Behdad Esfahbod0b08adb2012-04-23 22:41:09 -040073 free (set);
74}
75
76hb_bool_t
Behdad Esfahbodaec89de2012-11-15 16:15:42 -080077hb_set_set_user_data (hb_set_t *set,
78 hb_user_data_key_t *key,
79 void * data,
80 hb_destroy_func_t destroy,
81 hb_bool_t replace)
Behdad Esfahbod0b08adb2012-04-23 22:41:09 -040082{
83 return hb_object_set_user_data (set, key, data, destroy, replace);
84}
85
86void *
Behdad Esfahbodaec89de2012-11-15 16:15:42 -080087hb_set_get_user_data (hb_set_t *set,
88 hb_user_data_key_t *key)
Behdad Esfahbod0b08adb2012-04-23 22:41:09 -040089{
90 return hb_object_get_user_data (set, key);
91}
92
93
94hb_bool_t
Behdad Esfahbodaec89de2012-11-15 16:15:42 -080095hb_set_allocation_successful (const hb_set_t *set HB_UNUSED)
Behdad Esfahbod0b08adb2012-04-23 22:41:09 -040096{
Behdad Esfahbod8165f272013-01-02 22:50:36 -060097 return !set->in_error;
Behdad Esfahbod0b08adb2012-04-23 22:41:09 -040098}
99
100void
101hb_set_clear (hb_set_t *set)
102{
103 set->clear ();
104}
105
106hb_bool_t
Behdad Esfahbodaec89de2012-11-15 16:15:42 -0800107hb_set_is_empty (const hb_set_t *set)
Behdad Esfahbod6c6ccaf2012-04-24 14:21:15 -0400108{
Behdad Esfahbodaec89de2012-11-15 16:15:42 -0800109 return set->is_empty ();
Behdad Esfahbod6c6ccaf2012-04-24 14:21:15 -0400110}
111
112hb_bool_t
Behdad Esfahbodaec89de2012-11-15 16:15:42 -0800113hb_set_has (const hb_set_t *set,
Behdad Esfahbod0b08adb2012-04-23 22:41:09 -0400114 hb_codepoint_t codepoint)
115{
116 return set->has (codepoint);
117}
118
119void
120hb_set_add (hb_set_t *set,
121 hb_codepoint_t codepoint)
122{
123 set->add (codepoint);
124}
125
126void
Behdad Esfahbodaec89de2012-11-15 16:15:42 -0800127hb_set_add_range (hb_set_t *set,
128 hb_codepoint_t first,
129 hb_codepoint_t last)
130{
131 set->add_range (first, last);
132}
133
134void
Behdad Esfahbod0b08adb2012-04-23 22:41:09 -0400135hb_set_del (hb_set_t *set,
136 hb_codepoint_t codepoint)
137{
138 set->del (codepoint);
139}
Behdad Esfahbod6c6ccaf2012-04-24 14:21:15 -0400140
Behdad Esfahbodaec89de2012-11-15 16:15:42 -0800141void
142hb_set_del_range (hb_set_t *set,
143 hb_codepoint_t first,
144 hb_codepoint_t last)
Behdad Esfahbod6c6ccaf2012-04-24 14:21:15 -0400145{
Behdad Esfahbodaec89de2012-11-15 16:15:42 -0800146 set->del_range (first, last);
147}
148
149hb_bool_t
150hb_set_is_equal (const hb_set_t *set,
151 const hb_set_t *other)
152{
153 return set->is_equal (other);
Behdad Esfahbod6c6ccaf2012-04-24 14:21:15 -0400154}
155
156void
Behdad Esfahbodaec89de2012-11-15 16:15:42 -0800157hb_set_set (hb_set_t *set,
158 const hb_set_t *other)
Behdad Esfahbod6c6ccaf2012-04-24 14:21:15 -0400159{
160 set->set (other);
161}
162
163void
Behdad Esfahbodaec89de2012-11-15 16:15:42 -0800164hb_set_union (hb_set_t *set,
165 const hb_set_t *other)
Behdad Esfahbod6c6ccaf2012-04-24 14:21:15 -0400166{
167 set->union_ (other);
168}
169
170void
Behdad Esfahbodaec89de2012-11-15 16:15:42 -0800171hb_set_intersect (hb_set_t *set,
172 const hb_set_t *other)
Behdad Esfahbod6c6ccaf2012-04-24 14:21:15 -0400173{
174 set->intersect (other);
175}
176
177void
Behdad Esfahbodaec89de2012-11-15 16:15:42 -0800178hb_set_subtract (hb_set_t *set,
179 const hb_set_t *other)
Behdad Esfahbod6c6ccaf2012-04-24 14:21:15 -0400180{
181 set->subtract (other);
182}
183
Behdad Esfahbod62c3e112012-05-25 13:48:00 -0400184void
Behdad Esfahbodaec89de2012-11-15 16:15:42 -0800185hb_set_symmetric_difference (hb_set_t *set,
186 const hb_set_t *other)
Behdad Esfahbod62c3e112012-05-25 13:48:00 -0400187{
188 set->symmetric_difference (other);
189}
190
Behdad Esfahbod8165f272013-01-02 22:50:36 -0600191void
192hb_set_invert (hb_set_t *set)
193{
194 set->invert ();
195}
196
Behdad Esfahbodaec89de2012-11-15 16:15:42 -0800197unsigned int
Behdad Esfahbodac064a22012-11-21 01:14:19 -0500198hb_set_get_population (const hb_set_t *set)
Behdad Esfahbodaec89de2012-11-15 16:15:42 -0800199{
200 return set->get_population ();
201}
202
Behdad Esfahbod6c6ccaf2012-04-24 14:21:15 -0400203hb_codepoint_t
Behdad Esfahbodaec89de2012-11-15 16:15:42 -0800204hb_set_get_min (const hb_set_t *set)
Behdad Esfahbod6c6ccaf2012-04-24 14:21:15 -0400205{
Behdad Esfahbodf039e792012-05-17 20:55:12 -0400206 return set->get_min ();
Behdad Esfahbod6c6ccaf2012-04-24 14:21:15 -0400207}
208
209hb_codepoint_t
Behdad Esfahbodaec89de2012-11-15 16:15:42 -0800210hb_set_get_max (const hb_set_t *set)
Behdad Esfahbod6c6ccaf2012-04-24 14:21:15 -0400211{
Behdad Esfahbodf039e792012-05-17 20:55:12 -0400212 return set->get_max ();
Behdad Esfahbod6c6ccaf2012-04-24 14:21:15 -0400213}
Behdad Esfahbod29ce4462012-05-25 14:17:54 -0400214
215hb_bool_t
Behdad Esfahbodaec89de2012-11-15 16:15:42 -0800216hb_set_next (const hb_set_t *set,
Behdad Esfahbod29ce4462012-05-25 14:17:54 -0400217 hb_codepoint_t *codepoint)
218{
219 return set->next (codepoint);
220}
Behdad Esfahbodaec89de2012-11-15 16:15:42 -0800221
222hb_bool_t
223hb_set_next_range (const hb_set_t *set,
224 hb_codepoint_t *first,
225 hb_codepoint_t *last)
226{
227 return set->next_range (first, last);
228}