1 /*
   2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   3  *
   4  * This code is free software; you can redistribute it and/or modify it
   5  * under the terms of the GNU General Public License version 2 only, as
   6  * published by the Free Software Foundation.  Oracle designates this
   7  * particular file as subject to the "Classpath" exception as provided
   8  * by Oracle in the LICENSE file that accompanied this code.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  */
  24 
  25 // This file is available under and governed by the GNU General Public
  26 // License version 2 only, as published by the Free Software Foundation.
  27 // However, the following notice accompanied the original version of this
  28 // file:
  29 //
  30 /*
  31  * Copyright © 2012  Google, Inc.
  32  *
  33  *  This is part of HarfBuzz, a text shaping library.
  34  *
  35  * Permission is hereby granted, without written agreement and without
  36  * license or royalty fees, to use, copy, modify, and distribute this
  37  * software and its documentation for any purpose, provided that the
  38  * above copyright notice and the following two paragraphs appear in
  39  * all copies of this software.
  40  *
  41  * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
  42  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
  43  * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
  44  * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
  45  * DAMAGE.
  46  *
  47  * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
  48  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  49  * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  50  * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
  51  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  52  *
  53  * Google Author(s): Behdad Esfahbod
  54  */
  55 
  56 #include "hb-set-private.hh"
  57 
  58 
  59 /* Public API */
  60 
  61 
  62 /**
  63  * hb_set_create: (Xconstructor)
  64  *
  65  * Return value: (transfer full):
  66  *
  67  * Since: 0.9.2
  68  **/
  69 hb_set_t *
  70 hb_set_create (void)
  71 {
  72   hb_set_t *set;
  73 
  74   if (!(set = hb_object_create<hb_set_t> ()))
  75     return hb_set_get_empty ();
  76 
  77   set->clear ();
  78 
  79   return set;
  80 }
  81 
  82 /**
  83  * hb_set_get_empty:
  84  *
  85  * Return value: (transfer full):
  86  *
  87  * Since: 0.9.2
  88  **/
  89 hb_set_t *
  90 hb_set_get_empty (void)
  91 {
  92   static const hb_set_t _hb_set_nil = {
  93     HB_OBJECT_HEADER_STATIC,
  94     true, /* in_error */
  95 
  96     {0} /* elts */
  97   };
  98 
  99   return const_cast<hb_set_t *> (&_hb_set_nil);
 100 }
 101 
 102 /**
 103  * hb_set_reference: (skip)
 104  * @set: a set.
 105  *
 106  * Return value: (transfer full):
 107  *
 108  * Since: 0.9.2
 109  **/
 110 hb_set_t *
 111 hb_set_reference (hb_set_t *set)
 112 {
 113   return hb_object_reference (set);
 114 }
 115 
 116 /**
 117  * hb_set_destroy: (skip)
 118  * @set: a set.
 119  *
 120  * Since: 0.9.2
 121  **/
 122 void
 123 hb_set_destroy (hb_set_t *set)
 124 {
 125   if (!hb_object_destroy (set)) return;
 126 
 127   set->fini ();
 128 
 129   free (set);
 130 }
 131 
 132 /**
 133  * hb_set_set_user_data: (skip)
 134  * @set: a set.
 135  * @key:
 136  * @data:
 137  * @destroy (closure data):
 138  * @replace:
 139  *
 140  * Return value:
 141  *
 142  * Since: 0.9.2
 143  **/
 144 hb_bool_t
 145 hb_set_set_user_data (hb_set_t           *set,
 146                       hb_user_data_key_t *key,
 147                       void *              data,
 148                       hb_destroy_func_t   destroy,
 149                       hb_bool_t           replace)
 150 {
 151   return hb_object_set_user_data (set, key, data, destroy, replace);
 152 }
 153 
 154 /**
 155  * hb_set_get_user_data: (skip)
 156  * @set: a set.
 157  * @key:
 158  *
 159  * Return value: (transfer none):
 160  *
 161  * Since: 0.9.2
 162  **/
 163 void *
 164 hb_set_get_user_data (hb_set_t           *set,
 165                       hb_user_data_key_t *key)
 166 {
 167   return hb_object_get_user_data (set, key);
 168 }
 169 
 170 
 171 /**
 172  * hb_set_allocation_successful:
 173  * @set: a set.
 174  *
 175  *
 176  *
 177  * Return value:
 178  *
 179  * Since: 0.9.2
 180  **/
 181 hb_bool_t
 182 hb_set_allocation_successful (const hb_set_t  *set HB_UNUSED)
 183 {
 184   return !set->in_error;
 185 }
 186 
 187 /**
 188  * hb_set_clear:
 189  * @set: a set.
 190  *
 191  *
 192  *
 193  * Since: 0.9.2
 194  **/
 195 void
 196 hb_set_clear (hb_set_t *set)
 197 {
 198   set->clear ();
 199 }
 200 
 201 /**
 202  * hb_set_is_empty:
 203  * @set: a set.
 204  *
 205  *
 206  *
 207  * Return value:
 208  *
 209  * Since: 0.9.7
 210  **/
 211 hb_bool_t
 212 hb_set_is_empty (const hb_set_t *set)
 213 {
 214   return set->is_empty ();
 215 }
 216 
 217 /**
 218  * hb_set_has:
 219  * @set: a set.
 220  * @codepoint:
 221  *
 222  *
 223  *
 224  * Return value:
 225  *
 226  * Since: 0.9.2
 227  **/
 228 hb_bool_t
 229 hb_set_has (const hb_set_t *set,
 230             hb_codepoint_t  codepoint)
 231 {
 232   return set->has (codepoint);
 233 }
 234 
 235 /**
 236  * hb_set_add:
 237  * @set: a set.
 238  * @codepoint:
 239  *
 240  *
 241  *
 242  * Since: 0.9.2
 243  **/
 244 void
 245 hb_set_add (hb_set_t       *set,
 246             hb_codepoint_t  codepoint)
 247 {
 248   set->add (codepoint);
 249 }
 250 
 251 /**
 252  * hb_set_add_range:
 253  * @set: a set.
 254  * @first:
 255  * @last:
 256  *
 257  *
 258  *
 259  * Since: 0.9.7
 260  **/
 261 void
 262 hb_set_add_range (hb_set_t       *set,
 263                   hb_codepoint_t  first,
 264                   hb_codepoint_t  last)
 265 {
 266   set->add_range (first, last);
 267 }
 268 
 269 /**
 270  * hb_set_del:
 271  * @set: a set.
 272  * @codepoint:
 273  *
 274  *
 275  *
 276  * Since: 0.9.2
 277  **/
 278 void
 279 hb_set_del (hb_set_t       *set,
 280             hb_codepoint_t  codepoint)
 281 {
 282   set->del (codepoint);
 283 }
 284 
 285 /**
 286  * hb_set_del_range:
 287  * @set: a set.
 288  * @first:
 289  * @last:
 290  *
 291  *
 292  *
 293  * Since: 0.9.7
 294  **/
 295 void
 296 hb_set_del_range (hb_set_t       *set,
 297                   hb_codepoint_t  first,
 298                   hb_codepoint_t  last)
 299 {
 300   set->del_range (first, last);
 301 }
 302 
 303 /**
 304  * hb_set_is_equal:
 305  * @set: a set.
 306  * @other:
 307  *
 308  *
 309  *
 310  * Return value:
 311  *
 312  * Since: 0.9.7
 313  **/
 314 hb_bool_t
 315 hb_set_is_equal (const hb_set_t *set,
 316                  const hb_set_t *other)
 317 {
 318   return set->is_equal (other);
 319 }
 320 
 321 /**
 322  * hb_set_set:
 323  * @set: a set.
 324  * @other:
 325  *
 326  *
 327  *
 328  * Since: 0.9.2
 329  **/
 330 void
 331 hb_set_set (hb_set_t       *set,
 332             const hb_set_t *other)
 333 {
 334   set->set (other);
 335 }
 336 
 337 /**
 338  * hb_set_union:
 339  * @set: a set.
 340  * @other:
 341  *
 342  *
 343  *
 344  * Since: 0.9.2
 345  **/
 346 void
 347 hb_set_union (hb_set_t       *set,
 348               const hb_set_t *other)
 349 {
 350   set->union_ (other);
 351 }
 352 
 353 /**
 354  * hb_set_intersect:
 355  * @set: a set.
 356  * @other:
 357  *
 358  *
 359  *
 360  * Since: 0.9.2
 361  **/
 362 void
 363 hb_set_intersect (hb_set_t       *set,
 364                   const hb_set_t *other)
 365 {
 366   set->intersect (other);
 367 }
 368 
 369 /**
 370  * hb_set_subtract:
 371  * @set: a set.
 372  * @other:
 373  *
 374  *
 375  *
 376  * Since: 0.9.2
 377  **/
 378 void
 379 hb_set_subtract (hb_set_t       *set,
 380                  const hb_set_t *other)
 381 {
 382   set->subtract (other);
 383 }
 384 
 385 /**
 386  * hb_set_symmetric_difference:
 387  * @set: a set.
 388  * @other:
 389  *
 390  *
 391  *
 392  * Since: 0.9.2
 393  **/
 394 void
 395 hb_set_symmetric_difference (hb_set_t       *set,
 396                              const hb_set_t *other)
 397 {
 398   set->symmetric_difference (other);
 399 }
 400 
 401 /**
 402  * hb_set_invert:
 403  * @set: a set.
 404  *
 405  *
 406  *
 407  * Since: 0.9.10
 408  **/
 409 void
 410 hb_set_invert (hb_set_t *set)
 411 {
 412   set->invert ();
 413 }
 414 
 415 /**
 416  * hb_set_get_population:
 417  * @set: a set.
 418  *
 419  * Returns the number of numbers in the set.
 420  *
 421  * Return value: set population.
 422  *
 423  * Since: 0.9.7
 424  **/
 425 unsigned int
 426 hb_set_get_population (const hb_set_t *set)
 427 {
 428   return set->get_population ();
 429 }
 430 
 431 /**
 432  * hb_set_get_min:
 433  * @set: a set.
 434  *
 435  * Finds the minimum number in the set.
 436  *
 437  * Return value: minimum of the set, or %HB_SET_VALUE_INVALID if set is empty.
 438  *
 439  * Since: 0.9.7
 440  **/
 441 hb_codepoint_t
 442 hb_set_get_min (const hb_set_t *set)
 443 {
 444   return set->get_min ();
 445 }
 446 
 447 /**
 448  * hb_set_get_max:
 449  * @set: a set.
 450  *
 451  * Finds the maximum number in the set.
 452  *
 453  * Return value: minimum of the set, or %HB_SET_VALUE_INVALID if set is empty.
 454  *
 455  * Since: 0.9.7
 456  **/
 457 hb_codepoint_t
 458 hb_set_get_max (const hb_set_t *set)
 459 {
 460   return set->get_max ();
 461 }
 462 
 463 /**
 464  * hb_set_next:
 465  * @set: a set.
 466  * @codepoint: (inout):
 467  *
 468  *
 469  *
 470  * Return value: whether there was a next value.
 471  *
 472  * Since: 0.9.2
 473  **/
 474 hb_bool_t
 475 hb_set_next (const hb_set_t *set,
 476              hb_codepoint_t *codepoint)
 477 {
 478   return set->next (codepoint);
 479 }
 480 
 481 /**
 482  * hb_set_next_range:
 483  * @set: a set.
 484  * @first: (out): output first codepoint in the range.
 485  * @last: (inout): input current last and output last codepoint in the range.
 486  *
 487  * Gets the next consecutive range of numbers in @set that
 488  * are greater than current value of @last.
 489  *
 490  * Return value: whether there was a next range.
 491  *
 492  * Since: 0.9.7
 493  **/
 494 hb_bool_t
 495 hb_set_next_range (const hb_set_t *set,
 496                    hb_codepoint_t *first,
 497                    hb_codepoint_t *last)
 498 {
 499   return set->next_range (first, last);
 500 }