w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

hb-set.cc
Go to the documentation of this file.
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: Objects 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 APIs to query certain sets of characters or glyphs,
38  * or other integer values.
39  **/
40 
41 
42 /**
43  * hb_set_create: (Xconstructor)
44  *
45  * Creates a new, initially empty set.
46  *
47  * Return value: (transfer full): The new #hb_set_t
48  *
49  * Since: 0.9.2
50  **/
51 hb_set_t *
53 {
54  hb_set_t *set;
55 
56  if (!(set = hb_object_create<hb_set_t> ()))
57  return hb_set_get_empty ();
58 
59  set->init_shallow ();
60 
61  return set;
62 }
63 
64 /**
65  * hb_set_get_empty:
66  *
67  * Fetches the singleton empty #hb_set_t.
68  *
69  * Return value: (transfer full): The empty #hb_set_t
70  *
71  * Since: 0.9.2
72  **/
73 hb_set_t *
75 {
76  return const_cast<hb_set_t *> (&Null (hb_set_t));
77 }
78 
79 /**
80  * hb_set_reference: (skip)
81  * @set: A set
82  *
83  * Increases the reference count on a set.
84  *
85  * Return value: (transfer full): The set
86  *
87  * Since: 0.9.2
88  **/
89 hb_set_t *
91 {
92  return hb_object_reference (set);
93 }
94 
95 /**
96  * hb_set_destroy: (skip)
97  * @set: A set
98  *
99  * Decreases the reference count on a set. When
100  * the reference count reaches zero, the set is
101  * destroyed, freeing all memory.
102  *
103  * Since: 0.9.2
104  **/
105 void
107 {
108  if (!hb_object_destroy (set)) return;
109 
110  set->fini_shallow ();
111 
112  free (set);
113 }
114 
115 /**
116  * hb_set_set_user_data: (skip)
117  * @set: A set
118  * @key: The user-data key to set
119  * @data: A pointer to the user data to set
120  * @destroy: (optional): A callback to call when @data is not needed anymore
121  * @replace: Whether to replace an existing data with the same key
122  *
123  * Attaches a user-data key/data pair to the specified set.
124  *
125  * Return value: %true if success, %false otherwise
126  *
127  * Since: 0.9.2
128  **/
129 hb_bool_t
132  void * data,
133  hb_destroy_func_t destroy,
135 {
136  return hb_object_set_user_data (set, key, data, destroy, replace);
137 }
138 
139 /**
140  * hb_set_get_user_data: (skip)
141  * @set: A set
142  * @key: The user-data key to query
143  *
144  * Fetches the user data associated with the specified key,
145  * attached to the specified set.
146  *
147  * Return value: (transfer none): A pointer to the user data
148  *
149  * Since: 0.9.2
150  **/
151 void *
154 {
155  return hb_object_get_user_data (set, key);
156 }
157 
158 
159 /**
160  * hb_set_allocation_successful:
161  * @set: A set
162  *
163  * Tests whether memory allocation for a set was successful.
164  *
165  * Return value: %true if allocation succeeded, false otherwise
166  *
167  * Since: 0.9.2
168  **/
169 hb_bool_t
171 {
172  return set->successful;
173 }
174 
175 /**
176  * hb_set_clear:
177  * @set: A set
178  *
179  * Clears out the contents of a set.
180  *
181  * Since: 0.9.2
182  **/
183 void
185 {
186  set->clear ();
187 }
188 
189 /**
190  * hb_set_is_empty:
191  * @set: a set.
192  *
193  * Tests whether a set is empty (contains no elements).
194  *
195  * Return value: %true if @set is empty
196  *
197  * Since: 0.9.7
198  **/
199 hb_bool_t
201 {
202  return set->is_empty ();
203 }
204 
205 /**
206  * hb_set_has:
207  * @set: A set
208  * @codepoint: The element to query
209  *
210  * Tests whether @codepoint belongs to @set.
211  *
212  * Return value: %true if @codepoint is in @set, false otherwise
213  *
214  * Since: 0.9.2
215  **/
216 hb_bool_t
217 hb_set_has (const hb_set_t *set,
219 {
220  return set->has (codepoint);
221 }
222 
223 /**
224  * hb_set_add:
225  * @set: A set
226  * @codepoint: The element to add to @set
227  *
228  * Adds @codepoint to @set.
229  *
230  * Since: 0.9.2
231  **/
232 void
235 {
236  set->add (codepoint);
237 }
238 
239 /**
240  * hb_set_add_range:
241  * @set: A set
242  * @first: The first element to add to @set
243  * @last: The final element to add to @set
244  *
245  * Adds all of the elements from @first to @last
246  * (inclusive) to @set.
247  *
248  * Since: 0.9.7
249  **/
250 void
254 {
255  set->add_range (first, last);
256 }
257 
258 /**
259  * hb_set_del:
260  * @set: A set
261  * @codepoint: Removes @codepoint from @set
262  *
263  * Removes @codepoint from @set.
264  *
265  * Since: 0.9.2
266  **/
267 void
270 {
271  set->del (codepoint);
272 }
273 
274 /**
275  * hb_set_del_range:
276  * @set: A set
277  * @first: The first element to remove from @set
278  * @last: The final element to remove from @set
279  *
280  * Removes all of the elements from @first to @last
281  * (inclusive) from @set.
282  *
283  * Since: 0.9.7
284  **/
285 void
289 {
290  set->del_range (first, last);
291 }
292 
293 /**
294  * hb_set_is_equal:
295  * @set: A set
296  * @other: Another set
297  *
298  * Tests whether @set and @other are equal (contain the same
299  * elements).
300  *
301  * Return value: %TRUE if the two sets are equal, %FALSE otherwise.
302  *
303  * Since: 0.9.7
304  **/
305 hb_bool_t
307  const hb_set_t *other)
308 {
309  return set->is_equal (other);
310 }
311 
312 /**
313  * hb_set_is_subset:
314  * @set: A set
315  * @larger_set: Another set
316  *
317  * Tests whether @set is a subset of @larger_set.
318  *
319  * Return value: %TRUE if the @set is a subset of (or equal to) @larger_set, %FALSE otherwise.
320  *
321  * Since: 1.8.1
322  **/
323 hb_bool_t
325  const hb_set_t *larger_set)
326 {
327  return set->is_subset (larger_set);
328 }
329 
330 /**
331  * hb_set_set:
332  * @set: A set
333  * @other: Another set
334  *
335  * Makes the contents of @set equal to the contents of @other.
336  *
337  * Since: 0.9.2
338  **/
339 void
341  const hb_set_t *other)
342 {
343  set->set (other);
344 }
345 
346 /**
347  * hb_set_union:
348  * @set: A set
349  * @other: Another set
350  *
351  * Makes @set the union of @set and @other.
352  *
353  * Since: 0.9.2
354  **/
355 void
357  const hb_set_t *other)
358 {
359  set->union_ (other);
360 }
361 
362 /**
363  * hb_set_intersect:
364  * @set: A set
365  * @other: Another set
366  *
367  * Makes @set the intersection of @set and @other.
368  *
369  * Since: 0.9.2
370  **/
371 void
373  const hb_set_t *other)
374 {
375  set->intersect (other);
376 }
377 
378 /**
379  * hb_set_subtract:
380  * @set: A set
381  * @other: Another set
382  *
383  * Subtracts the contents of @other from @set.
384  *
385  * Since: 0.9.2
386  **/
387 void
389  const hb_set_t *other)
390 {
391  set->subtract (other);
392 }
393 
394 /**
395  * hb_set_symmetric_difference:
396  * @set: A set
397  * @other: Another set
398  *
399  * Makes @set the symmetric difference of @set
400  * and @other.
401  *
402  * Since: 0.9.2
403  **/
404 void
406  const hb_set_t *other)
407 {
409 }
410 
411 #ifndef HB_DISABLE_DEPRECATED
412 /**
413  * hb_set_invert:
414  * @set: A set
415  *
416  * Inverts the contents of @set.
417  *
418  * Since: 0.9.10
419  *
420  * Deprecated: 1.6.1
421  **/
422 void
424 {
425 }
426 #endif
427 
428 /**
429  * hb_set_get_population:
430  * @set: A set
431  *
432  * Returns the number of elements in the set.
433  *
434  * Return value: The population of @set
435  *
436  * Since: 0.9.7
437  **/
438 unsigned int
440 {
441  return set->get_population ();
442 }
443 
444 /**
445  * hb_set_get_min:
446  * @set: A set
447  *
448  * Finds the smallest element in the set.
449  *
450  * Return value: minimum of @set, or %HB_SET_VALUE_INVALID if @set is empty.
451  *
452  * Since: 0.9.7
453  **/
456 {
457  return set->get_min ();
458 }
459 
460 /**
461  * hb_set_get_max:
462  * @set: A set
463  *
464  * Finds the largest element in the set.
465  *
466  * Return value: maximum of @set, or %HB_SET_VALUE_INVALID if @set is empty.
467  *
468  * Since: 0.9.7
469  **/
472 {
473  return set->get_max ();
474 }
475 
476 /**
477  * hb_set_next:
478  * @set: A set
479  * @codepoint: (inout): Input = Code point to query
480  * Output = Code point retrieved
481  *
482  * Fetches the next element in @set that is greater than current value of @codepoint.
483  *
484  * Set @codepoint to %HB_SET_VALUE_INVALID to get started.
485  *
486  * Return value: %true if there was a next value, false otherwise
487  *
488  * Since: 0.9.2
489  **/
490 hb_bool_t
491 hb_set_next (const hb_set_t *set,
493 {
494  return set->next (codepoint);
495 }
496 
497 /**
498  * hb_set_previous:
499  * @set: A set
500  * @codepoint: (inout): Input = Code point to query
501  * Output = Code point retrieved
502  *
503  * Fetches the previous element in @set that is lower than current value of @codepoint.
504  *
505  * Set @codepoint to %HB_SET_VALUE_INVALID to get started.
506  *
507  * Return value: %true if there was a previous value, false otherwise
508  *
509  * Since: 1.8.0
510  **/
511 hb_bool_t
514 {
515  return set->previous (codepoint);
516 }
517 
518 /**
519  * hb_set_next_range:
520  * @set: A set
521  * @first: (out): The first code point in the range
522  * @last: (inout): Input = The current last code point in the range
523  * Output = The last code point in the range
524  *
525  * Fetches the next consecutive range of elements in @set that
526  * are greater than current value of @last.
527  *
528  * Set @last to %HB_SET_VALUE_INVALID to get started.
529  *
530  * Return value: %true if there was a next range, false otherwise
531  *
532  * Since: 0.9.7
533  **/
534 hb_bool_t
538 {
539  return set->next_range (first, last);
540 }
541 
542 /**
543  * hb_set_previous_range:
544  * @set: A set
545  * @first: (inout): Input = The current first code point in the range
546  * Output = The first code point in the range
547  * @last: (out): The last code point in the range
548  *
549  * Fetches the previous consecutive range of elements in @set that
550  * are greater than current value of @last.
551  *
552  * Set @first to %HB_SET_VALUE_INVALID to get started.
553  *
554  * Return value: %true if there was a previous range, false otherwise
555  *
556  * Since: 1.8.0
557  **/
558 hb_bool_t
562 {
563  return set->previous_range (first, last);
564 }
#define free(a)
Definition: decNumber.cpp:310
struct rect data
Definition: dvipdfm.c:64
void replace(char *, char *)
Definition: dvispc.c:2100
@ other
Definition: mtxline.h:22
static int32_t last
Definition: ppagelist.c:29
static int32_t first
Definition: ppagelist.c:29
void(* hb_destroy_func_t)(void *user_data)
Definition: hb-common.h:690
uint32_t hb_codepoint_t
Definition: hb-common.h:106
int hb_bool_t
Definition: hb-common.h:97
#define Null(Type)
Definition: hb-null.hh:94
static void * hb_object_get_user_data(Type *obj, hb_user_data_key_t *key)
Definition: hb-object.hh:329
static bool hb_object_destroy(Type *obj)
Definition: hb-object.hh:274
static Type * hb_object_reference(Type *obj)
Definition: hb-object.hh:264
static bool hb_object_set_user_data(Type *obj, hb_user_data_key_t *key, void *data, hb_destroy_func_t destroy, hb_bool_t replace)
Definition: hb-object.hh:299
void hb_set_add_range(hb_set_t *set, hb_codepoint_t first, hb_codepoint_t last)
Definition: hb-set.cc:251
void hb_set_add(hb_set_t *set, hb_codepoint_t codepoint)
Definition: hb-set.cc:233
hb_bool_t hb_set_is_equal(const hb_set_t *set, const hb_set_t *other)
Definition: hb-set.cc:306
void hb_set_set(hb_set_t *set, const hb_set_t *other)
Definition: hb-set.cc:340
hb_set_t * hb_set_reference(hb_set_t *set)
Definition: hb-set.cc:90
hb_set_t * hb_set_get_empty()
Definition: hb-set.cc:74
void hb_set_symmetric_difference(hb_set_t *set, const hb_set_t *other)
Definition: hb-set.cc:405
hb_bool_t hb_set_has(const hb_set_t *set, hb_codepoint_t codepoint)
Definition: hb-set.cc:217
hb_bool_t hb_set_previous(const hb_set_t *set, hb_codepoint_t *codepoint)
Definition: hb-set.cc:512
hb_codepoint_t hb_set_get_max(const hb_set_t *set)
Definition: hb-set.cc:471
hb_codepoint_t hb_set_get_min(const hb_set_t *set)
Definition: hb-set.cc:455
void hb_set_del(hb_set_t *set, hb_codepoint_t codepoint)
Definition: hb-set.cc:268
void hb_set_union(hb_set_t *set, const hb_set_t *other)
Definition: hb-set.cc:356
void * hb_set_get_user_data(hb_set_t *set, hb_user_data_key_t *key)
Definition: hb-set.cc:152
hb_bool_t hb_set_next_range(const hb_set_t *set, hb_codepoint_t *first, hb_codepoint_t *last)
Definition: hb-set.cc:535
hb_set_t * hb_set_create()
Definition: hb-set.cc:52
void hb_set_invert(hb_set_t *set)
Definition: hb-set.cc:423
void hb_set_subtract(hb_set_t *set, const hb_set_t *other)
Definition: hb-set.cc:388
void hb_set_destroy(hb_set_t *set)
Definition: hb-set.cc:106
hb_bool_t hb_set_is_empty(const hb_set_t *set)
Definition: hb-set.cc:200
unsigned int hb_set_get_population(const hb_set_t *set)
Definition: hb-set.cc:439
void hb_set_intersect(hb_set_t *set, const hb_set_t *other)
Definition: hb-set.cc:372
void hb_set_del_range(hb_set_t *set, hb_codepoint_t first, hb_codepoint_t last)
Definition: hb-set.cc:286
hb_bool_t hb_set_allocation_successful(const hb_set_t *set)
Definition: hb-set.cc:170
hb_bool_t hb_set_next(const hb_set_t *set, hb_codepoint_t *codepoint)
Definition: hb-set.cc:491
void hb_set_clear(hb_set_t *set)
Definition: hb-set.cc:184
hb_bool_t hb_set_is_subset(const hb_set_t *set, const hb_set_t *larger_set)
Definition: hb-set.cc:324
hb_bool_t hb_set_previous_range(const hb_set_t *set, hb_codepoint_t *first, hb_codepoint_t *last)
Definition: hb-set.cc:559
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)
Definition: hb-set.cc:130
#define HB_UNUSED
Definition: hb.hh:260
static int codepoint(lua_State *L)
Definition: lutf8lib.c:100
bool next_range(hb_codepoint_t *first, hb_codepoint_t *last) const
Definition: hb-set.hh:739
void symmetric_difference(const hb_set_t *other)
Definition: hb-set.hh:673
void intersect(const hb_set_t *other)
Definition: hb-set.hh:665
void add(hb_codepoint_t g)
Definition: hb-set.hh:284
void set(const hb_set_t *other)
Definition: hb-set.hh:463
bool next(hb_codepoint_t *codepoint) const
Definition: hb-set.hh:677
void subtract(const hb_set_t *other)
Definition: hb-set.hh:669
bool successful
Definition: hb-set.hh:214
bool is_subset(const hb_set_t *larger_set) const
Definition: hb-set.hh:501
void init_shallow()
Definition: hb-set.hh:219
bool is_equal(const hb_set_t *other) const
Definition: hb-set.hh:474
bool is_empty() const
Definition: hb-set.hh:273
void clear()
Definition: hb-set.hh:265
void del(hb_codepoint_t g)
Definition: hb-set.hh:376
bool previous_range(hb_codepoint_t *first, hb_codepoint_t *last) const
Definition: hb-set.hh:757
void fini_shallow()
Definition: hb-set.hh:231
bool previous(hb_codepoint_t *codepoint) const
Definition: hb-set.hh:708
bool has(hb_codepoint_t k) const
Definition: hb-set.hh:448
unsigned int get_population() const
Definition: hb-set.hh:776
void del_range(hb_codepoint_t a, hb_codepoint_t b)
Definition: hb-set.hh:405
hb_codepoint_t get_min() const
Definition: hb-set.hh:789
hb_codepoint_t get_max() const
Definition: hb-set.hh:797
bool add_range(hb_codepoint_t a, hb_codepoint_t b)
Definition: hb-set.hh:292
void union_(const hb_set_t *other)
Definition: hb-set.hh:661
#define key
Definition: tex2xindy.c:753