hb-set.cc 8.2 KB
Newer Older
B
Behdad Esfahbod 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
/*
 * Copyright © 2012  Google, Inc.
 *
 *  This is part of HarfBuzz, a text shaping library.
 *
 * Permission is hereby granted, without written agreement and without
 * license or royalty fees, to use, copy, modify, and distribute this
 * software and its documentation for any purpose, provided that the
 * above copyright notice and the following two paragraphs appear in
 * all copies of this software.
 *
 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
 * DAMAGE.
 *
 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 *
 * Google Author(s): Behdad Esfahbod
 */

#include "hb-set-private.hh"


B
Behdad Esfahbod 已提交
30 31
/* Public API */

B
Behdad Esfahbod 已提交
32

33
/**
34
 * hb_set_create: (Xconstructor)
35 36 37
 *
 * Return value: (transfer full):
 *
S
Sascha Brawer 已提交
38
 * Since: 0.9.2
39
 **/
B
Behdad Esfahbod 已提交
40
hb_set_t *
B
Behdad Esfahbod 已提交
41
hb_set_create (void)
B
Behdad Esfahbod 已提交
42 43 44 45
{
  hb_set_t *set;

  if (!(set = hb_object_create<hb_set_t> ()))
46
    return hb_set_get_empty ();
B
Behdad Esfahbod 已提交
47

B
Minor  
Behdad Esfahbod 已提交
48
  set->init ();
B
Behdad Esfahbod 已提交
49 50 51 52

  return set;
}

53 54 55
static const hb_set_t _hb_set_nil = {
  HB_OBJECT_HEADER_STATIC,
  true, /* in_error */
B
Behdad Esfahbod 已提交
56
  0, /* population */
57 58 59 60

  {0} /* elts */
};

61 62 63
/**
 * hb_set_get_empty:
 *
64
 * Return value: (transfer full):
65
 *
S
Sascha Brawer 已提交
66
 * Since: 0.9.2
67
 **/
B
Behdad Esfahbod 已提交
68 69 70
hb_set_t *
hb_set_get_empty (void)
{
71
  return const_cast<hb_set_t *> (&_hb_set_nil);
B
Behdad Esfahbod 已提交
72 73
}

74 75 76 77 78 79
/**
 * hb_set_reference: (skip)
 * @set: a set.
 *
 * Return value: (transfer full):
 *
S
Sascha Brawer 已提交
80
 * Since: 0.9.2
81
 **/
B
Behdad Esfahbod 已提交
82 83 84 85 86 87
hb_set_t *
hb_set_reference (hb_set_t *set)
{
  return hb_object_reference (set);
}

88 89 90 91
/**
 * hb_set_destroy: (skip)
 * @set: a set.
 *
S
Sascha Brawer 已提交
92
 * Since: 0.9.2
93
 **/
B
Behdad Esfahbod 已提交
94 95 96 97 98
void
hb_set_destroy (hb_set_t *set)
{
  if (!hb_object_destroy (set)) return;

B
Behdad Esfahbod 已提交
99
  set->fini ();
B
Minor  
Behdad Esfahbod 已提交
100

B
Behdad Esfahbod 已提交
101 102 103
  free (set);
}

104 105 106 107 108
/**
 * hb_set_set_user_data: (skip)
 * @set: a set.
 * @key:
 * @data:
109
 * @destroy:
110 111 112 113
 * @replace:
 *
 * Return value:
 *
S
Sascha Brawer 已提交
114
 * Since: 0.9.2
115
 **/
B
Behdad Esfahbod 已提交
116
hb_bool_t
B
Behdad Esfahbod 已提交
117 118 119 120 121
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)
B
Behdad Esfahbod 已提交
122 123 124 125
{
  return hb_object_set_user_data (set, key, data, destroy, replace);
}

126 127 128 129 130 131 132
/**
 * hb_set_get_user_data: (skip)
 * @set: a set.
 * @key:
 *
 * Return value: (transfer none):
 *
S
Sascha Brawer 已提交
133
 * Since: 0.9.2
134
 **/
B
Behdad Esfahbod 已提交
135
void *
B
Behdad Esfahbod 已提交
136 137
hb_set_get_user_data (hb_set_t           *set,
		      hb_user_data_key_t *key)
B
Behdad Esfahbod 已提交
138 139 140 141 142
{
  return hb_object_get_user_data (set, key);
}


143 144 145 146 147 148 149 150
/**
 * hb_set_allocation_successful:
 * @set: a set.
 *
 * 
 *
 * Return value: 
 *
S
Sascha Brawer 已提交
151
 * Since: 0.9.2
152
 **/
B
Behdad Esfahbod 已提交
153
hb_bool_t
154
hb_set_allocation_successful (const hb_set_t  *set)
B
Behdad Esfahbod 已提交
155
{
156
  return !set->in_error;
B
Behdad Esfahbod 已提交
157 158
}

159 160 161 162 163 164
/**
 * hb_set_clear:
 * @set: a set.
 *
 * 
 *
S
Sascha Brawer 已提交
165
 * Since: 0.9.2
166
 **/
B
Behdad Esfahbod 已提交
167 168 169 170 171 172
void
hb_set_clear (hb_set_t *set)
{
  set->clear ();
}

173 174 175 176 177 178 179 180
/**
 * hb_set_is_empty:
 * @set: a set.
 *
 * 
 *
 * Return value: 
 *
S
Sascha Brawer 已提交
181
 * Since: 0.9.7
182
 **/
B
Behdad Esfahbod 已提交
183
hb_bool_t
B
Behdad Esfahbod 已提交
184
hb_set_is_empty (const hb_set_t *set)
B
Behdad Esfahbod 已提交
185
{
B
Behdad Esfahbod 已提交
186
  return set->is_empty ();
B
Behdad Esfahbod 已提交
187 188
}

189 190 191 192 193 194 195 196 197
/**
 * hb_set_has:
 * @set: a set.
 * @codepoint: 
 *
 * 
 *
 * Return value: 
 *
S
Sascha Brawer 已提交
198
 * Since: 0.9.2
199
 **/
B
Behdad Esfahbod 已提交
200
hb_bool_t
B
Behdad Esfahbod 已提交
201
hb_set_has (const hb_set_t *set,
B
Behdad Esfahbod 已提交
202 203 204 205 206
	    hb_codepoint_t  codepoint)
{
  return set->has (codepoint);
}

207 208 209 210 211 212 213
/**
 * hb_set_add:
 * @set: a set.
 * @codepoint: 
 *
 * 
 *
S
Sascha Brawer 已提交
214
 * Since: 0.9.2
215
 **/
B
Behdad Esfahbod 已提交
216 217 218 219 220 221 222
void
hb_set_add (hb_set_t       *set,
	    hb_codepoint_t  codepoint)
{
  set->add (codepoint);
}

223 224 225 226 227 228 229 230
/**
 * hb_set_add_range:
 * @set: a set.
 * @first: 
 * @last: 
 *
 * 
 *
S
Sascha Brawer 已提交
231
 * Since: 0.9.7
232
 **/
B
Behdad Esfahbod 已提交
233 234 235 236 237 238 239 240
void
hb_set_add_range (hb_set_t       *set,
		  hb_codepoint_t  first,
		  hb_codepoint_t  last)
{
  set->add_range (first, last);
}

241 242 243 244 245 246 247
/**
 * hb_set_del:
 * @set: a set.
 * @codepoint: 
 *
 * 
 *
S
Sascha Brawer 已提交
248
 * Since: 0.9.2
249
 **/
B
Behdad Esfahbod 已提交
250 251 252 253 254 255
void
hb_set_del (hb_set_t       *set,
	    hb_codepoint_t  codepoint)
{
  set->del (codepoint);
}
B
Behdad Esfahbod 已提交
256

257 258 259 260 261 262 263 264
/**
 * hb_set_del_range:
 * @set: a set.
 * @first: 
 * @last: 
 *
 * 
 *
S
Sascha Brawer 已提交
265
 * Since: 0.9.7
266
 **/
B
Behdad Esfahbod 已提交
267 268 269 270 271 272 273 274
void
hb_set_del_range (hb_set_t       *set,
		  hb_codepoint_t  first,
		  hb_codepoint_t  last)
{
  set->del_range (first, last);
}

275 276 277 278 279 280 281 282 283
/**
 * hb_set_is_equal:
 * @set: a set.
 * @other: 
 *
 * 
 *
 * Return value: 
 *
S
Sascha Brawer 已提交
284
 * Since: 0.9.7
285
 **/
B
Behdad Esfahbod 已提交
286
hb_bool_t
B
Behdad Esfahbod 已提交
287 288
hb_set_is_equal (const hb_set_t *set,
		 const hb_set_t *other)
B
Behdad Esfahbod 已提交
289
{
B
Behdad Esfahbod 已提交
290
  return set->is_equal (other);
B
Behdad Esfahbod 已提交
291 292
}

293 294 295 296 297 298 299
/**
 * hb_set_set:
 * @set: a set.
 * @other: 
 *
 * 
 *
S
Sascha Brawer 已提交
300
 * Since: 0.9.2
301
 **/
B
Behdad Esfahbod 已提交
302
void
B
Behdad Esfahbod 已提交
303 304
hb_set_set (hb_set_t       *set,
	    const hb_set_t *other)
B
Behdad Esfahbod 已提交
305 306 307 308
{
  set->set (other);
}

309 310 311 312 313 314 315
/**
 * hb_set_union:
 * @set: a set.
 * @other: 
 *
 * 
 *
S
Sascha Brawer 已提交
316
 * Since: 0.9.2
317
 **/
B
Behdad Esfahbod 已提交
318
void
B
Behdad Esfahbod 已提交
319 320
hb_set_union (hb_set_t       *set,
	      const hb_set_t *other)
B
Behdad Esfahbod 已提交
321 322 323 324
{
  set->union_ (other);
}

325 326 327 328 329 330 331
/**
 * hb_set_intersect:
 * @set: a set.
 * @other: 
 *
 * 
 *
S
Sascha Brawer 已提交
332
 * Since: 0.9.2
333
 **/
B
Behdad Esfahbod 已提交
334
void
B
Behdad Esfahbod 已提交
335 336
hb_set_intersect (hb_set_t       *set,
		  const hb_set_t *other)
B
Behdad Esfahbod 已提交
337 338 339 340
{
  set->intersect (other);
}

341 342 343 344 345 346 347
/**
 * hb_set_subtract:
 * @set: a set.
 * @other: 
 *
 * 
 *
S
Sascha Brawer 已提交
348
 * Since: 0.9.2
349
 **/
B
Behdad Esfahbod 已提交
350
void
B
Behdad Esfahbod 已提交
351 352
hb_set_subtract (hb_set_t       *set,
		 const hb_set_t *other)
B
Behdad Esfahbod 已提交
353 354 355 356
{
  set->subtract (other);
}

357 358 359 360 361 362 363
/**
 * hb_set_symmetric_difference:
 * @set: a set.
 * @other: 
 *
 * 
 *
S
Sascha Brawer 已提交
364
 * Since: 0.9.2
365
 **/
B
Behdad Esfahbod 已提交
366
void
B
Behdad Esfahbod 已提交
367 368
hb_set_symmetric_difference (hb_set_t       *set,
			     const hb_set_t *other)
B
Behdad Esfahbod 已提交
369 370 371 372
{
  set->symmetric_difference (other);
}

373 374 375 376 377 378
/**
 * hb_set_invert:
 * @set: a set.
 *
 * 
 *
S
Sascha Brawer 已提交
379
 * Since: 0.9.10
B
Behdad Esfahbod 已提交
380 381
 *
 * Deprecated: 1.6.1
382
 **/
383 384 385 386 387
void
hb_set_invert (hb_set_t *set)
{
}

388 389 390 391 392 393 394 395
/**
 * hb_set_get_population:
 * @set: a set.
 *
 * Returns the number of numbers in the set.
 *
 * Return value: set population.
 *
S
Sascha Brawer 已提交
396
 * Since: 0.9.7
397
 **/
B
Behdad Esfahbod 已提交
398
unsigned int
399
hb_set_get_population (const hb_set_t *set)
B
Behdad Esfahbod 已提交
400 401 402 403
{
  return set->get_population ();
}

404 405 406 407 408 409 410 411
/**
 * hb_set_get_min:
 * @set: a set.
 *
 * Finds the minimum number in the set.
 *
 * Return value: minimum of the set, or %HB_SET_VALUE_INVALID if set is empty.
 *
S
Sascha Brawer 已提交
412
 * Since: 0.9.7
413
 **/
B
Behdad Esfahbod 已提交
414
hb_codepoint_t
B
Behdad Esfahbod 已提交
415
hb_set_get_min (const hb_set_t *set)
B
Behdad Esfahbod 已提交
416
{
417
  return set->get_min ();
B
Behdad Esfahbod 已提交
418 419
}

420 421 422 423 424 425 426 427
/**
 * hb_set_get_max:
 * @set: a set.
 *
 * Finds the maximum number in the set.
 *
 * Return value: minimum of the set, or %HB_SET_VALUE_INVALID if set is empty.
 *
S
Sascha Brawer 已提交
428
 * Since: 0.9.7
429
 **/
B
Behdad Esfahbod 已提交
430
hb_codepoint_t
B
Behdad Esfahbod 已提交
431
hb_set_get_max (const hb_set_t *set)
B
Behdad Esfahbod 已提交
432
{
433
  return set->get_max ();
B
Behdad Esfahbod 已提交
434
}
B
Behdad Esfahbod 已提交
435

436 437 438 439 440
/**
 * hb_set_next:
 * @set: a set.
 * @codepoint: (inout):
 *
B
Behdad Esfahbod 已提交
441 442 443
 * Gets the next number in @set that is greater than current value of @codepoint.
 *
 * Set @codepoint to %HB_SET_VALUE_INVALID to get started.
444 445 446
 *
 * Return value: whether there was a next value.
 *
S
Sascha Brawer 已提交
447
 * Since: 0.9.2
448
 **/
B
Behdad Esfahbod 已提交
449
hb_bool_t
B
Behdad Esfahbod 已提交
450
hb_set_next (const hb_set_t *set,
B
Behdad Esfahbod 已提交
451 452 453 454
	     hb_codepoint_t *codepoint)
{
  return set->next (codepoint);
}
B
Behdad Esfahbod 已提交
455

B
Behdad Esfahbod 已提交
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475
/**
 * hb_set_previous:
 * @set: a set.
 * @codepoint: (inout):
 *
 * Gets the previous number in @set that is slower than current value of @codepoint.
 *
 * Set @codepoint to %HB_SET_VALUE_INVALID to get started.
 *
 * Return value: whether there was a previous value.
 *
 * Since: 1.8.0
 **/
hb_bool_t
hb_set_previous (const hb_set_t *set,
		 hb_codepoint_t *codepoint)
{
  return set->previous (codepoint);
}

476 477 478 479 480 481 482 483 484
/**
 * hb_set_next_range:
 * @set: a set.
 * @first: (out): output first codepoint in the range.
 * @last: (inout): input current last and output last codepoint in the range.
 *
 * Gets the next consecutive range of numbers in @set that
 * are greater than current value of @last.
 *
B
Behdad Esfahbod 已提交
485 486
 * Set @last to %HB_SET_VALUE_INVALID to get started.
 *
487 488
 * Return value: whether there was a next range.
 *
S
Sascha Brawer 已提交
489
 * Since: 0.9.7
490
 **/
B
Behdad Esfahbod 已提交
491 492 493 494 495 496 497
hb_bool_t
hb_set_next_range (const hb_set_t *set,
		   hb_codepoint_t *first,
		   hb_codepoint_t *last)
{
  return set->next_range (first, last);
}
B
Behdad Esfahbod 已提交
498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520

/**
 * hb_set_previous_range:
 * @set: a set.
 * @first: (inout): input current first and output first codepoint in the range.
 * @last: (out): output last codepoint in the range.
 *
 * Gets the previous consecutive range of numbers in @set that
 * are greater than current value of @last.
 *
 * Set @first to %HB_SET_VALUE_INVALID to get started.
 *
 * Return value: whether there was a previous range.
 *
 * Since: 1.8.0
 **/
hb_bool_t
hb_set_previous_range (const hb_set_t *set,
		       hb_codepoint_t *first,
		       hb_codepoint_t *last)
{
  return set->previous_range (first, last);
}