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