• 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-private.hh"
28 
29 
30 
31 /* Public API */
32 
33 
34 hb_set_t *
hb_set_create(void)35 hb_set_create (void)
36 {
37   hb_set_t *set;
38 
39   if (!(set = hb_object_create<hb_set_t> ()))
40     return hb_set_get_empty ();
41 
42   set->clear ();
43 
44   return set;
45 }
46 
47 hb_set_t *
hb_set_get_empty(void)48 hb_set_get_empty (void)
49 {
50   static const hb_set_t _hb_set_nil = {
51     HB_OBJECT_HEADER_STATIC,
52     true, /* in_error */
53 
54     {0} /* elts */
55   };
56 
57   return const_cast<hb_set_t *> (&_hb_set_nil);
58 }
59 
60 hb_set_t *
hb_set_reference(hb_set_t * set)61 hb_set_reference (hb_set_t *set)
62 {
63   return hb_object_reference (set);
64 }
65 
66 void
hb_set_destroy(hb_set_t * set)67 hb_set_destroy (hb_set_t *set)
68 {
69   if (!hb_object_destroy (set)) return;
70 
71   set->fini ();
72 
73   free (set);
74 }
75 
76 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)77 hb_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)
82 {
83   return hb_object_set_user_data (set, key, data, destroy, replace);
84 }
85 
86 void *
hb_set_get_user_data(hb_set_t * set,hb_user_data_key_t * key)87 hb_set_get_user_data (hb_set_t           *set,
88 		      hb_user_data_key_t *key)
89 {
90   return hb_object_get_user_data (set, key);
91 }
92 
93 
94 hb_bool_t
hb_set_allocation_successful(const hb_set_t * set HB_UNUSED)95 hb_set_allocation_successful (const hb_set_t  *set HB_UNUSED)
96 {
97   return !set->in_error;
98 }
99 
100 void
hb_set_clear(hb_set_t * set)101 hb_set_clear (hb_set_t *set)
102 {
103   set->clear ();
104 }
105 
106 hb_bool_t
hb_set_is_empty(const hb_set_t * set)107 hb_set_is_empty (const hb_set_t *set)
108 {
109   return set->is_empty ();
110 }
111 
112 hb_bool_t
hb_set_has(const hb_set_t * set,hb_codepoint_t codepoint)113 hb_set_has (const hb_set_t *set,
114 	    hb_codepoint_t  codepoint)
115 {
116   return set->has (codepoint);
117 }
118 
119 void
hb_set_add(hb_set_t * set,hb_codepoint_t codepoint)120 hb_set_add (hb_set_t       *set,
121 	    hb_codepoint_t  codepoint)
122 {
123   set->add (codepoint);
124 }
125 
126 void
hb_set_add_range(hb_set_t * set,hb_codepoint_t first,hb_codepoint_t last)127 hb_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 
134 void
hb_set_del(hb_set_t * set,hb_codepoint_t codepoint)135 hb_set_del (hb_set_t       *set,
136 	    hb_codepoint_t  codepoint)
137 {
138   set->del (codepoint);
139 }
140 
141 void
hb_set_del_range(hb_set_t * set,hb_codepoint_t first,hb_codepoint_t last)142 hb_set_del_range (hb_set_t       *set,
143 		  hb_codepoint_t  first,
144 		  hb_codepoint_t  last)
145 {
146   set->del_range (first, last);
147 }
148 
149 hb_bool_t
hb_set_is_equal(const hb_set_t * set,const hb_set_t * other)150 hb_set_is_equal (const hb_set_t *set,
151 		 const hb_set_t *other)
152 {
153   return set->is_equal (other);
154 }
155 
156 void
hb_set_set(hb_set_t * set,const hb_set_t * other)157 hb_set_set (hb_set_t       *set,
158 	    const hb_set_t *other)
159 {
160   set->set (other);
161 }
162 
163 void
hb_set_union(hb_set_t * set,const hb_set_t * other)164 hb_set_union (hb_set_t       *set,
165 	      const hb_set_t *other)
166 {
167   set->union_ (other);
168 }
169 
170 void
hb_set_intersect(hb_set_t * set,const hb_set_t * other)171 hb_set_intersect (hb_set_t       *set,
172 		  const hb_set_t *other)
173 {
174   set->intersect (other);
175 }
176 
177 void
hb_set_subtract(hb_set_t * set,const hb_set_t * other)178 hb_set_subtract (hb_set_t       *set,
179 		 const hb_set_t *other)
180 {
181   set->subtract (other);
182 }
183 
184 void
hb_set_symmetric_difference(hb_set_t * set,const hb_set_t * other)185 hb_set_symmetric_difference (hb_set_t       *set,
186 			     const hb_set_t *other)
187 {
188   set->symmetric_difference (other);
189 }
190 
191 void
hb_set_invert(hb_set_t * set)192 hb_set_invert (hb_set_t *set)
193 {
194   set->invert ();
195 }
196 
197 unsigned int
hb_set_get_population(const hb_set_t * set)198 hb_set_get_population (const hb_set_t *set)
199 {
200   return set->get_population ();
201 }
202 
203 hb_codepoint_t
hb_set_get_min(const hb_set_t * set)204 hb_set_get_min (const hb_set_t *set)
205 {
206   return set->get_min ();
207 }
208 
209 hb_codepoint_t
hb_set_get_max(const hb_set_t * set)210 hb_set_get_max (const hb_set_t *set)
211 {
212   return set->get_max ();
213 }
214 
215 hb_bool_t
hb_set_next(const hb_set_t * set,hb_codepoint_t * codepoint)216 hb_set_next (const hb_set_t *set,
217 	     hb_codepoint_t *codepoint)
218 {
219   return set->next (codepoint);
220 }
221 
222 hb_bool_t
hb_set_next_range(const hb_set_t * set,hb_codepoint_t * first,hb_codepoint_t * last)223 hb_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 }
229