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