00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 INLINE SparseArray::
00022 SparseArray() : _inverse(false) {
00023 }
00024
00025
00026
00027
00028
00029
00030 INLINE SparseArray::
00031 SparseArray(const SparseArray ©) :
00032 _subranges(copy._subranges),
00033 _inverse(copy._inverse)
00034 {
00035 }
00036
00037
00038
00039
00040
00041
00042 INLINE SparseArray &SparseArray::
00043 operator = (const SparseArray ©) {
00044 _subranges = copy._subranges;
00045 _inverse = copy._inverse;
00046 return *this;
00047 }
00048
00049
00050
00051
00052
00053
00054
00055 INLINE SparseArray SparseArray::
00056 all_on() {
00057 SparseArray result;
00058 result._inverse = true;
00059 return result;
00060 }
00061
00062
00063
00064
00065
00066
00067 INLINE SparseArray SparseArray::
00068 all_off() {
00069 return SparseArray();
00070 }
00071
00072
00073
00074
00075
00076
00077 INLINE SparseArray SparseArray::
00078 lower_on(int on_bits) {
00079 SparseArray result;
00080 result.set_range(0, on_bits);
00081 return result;
00082 }
00083
00084
00085
00086
00087
00088
00089 INLINE SparseArray SparseArray::
00090 bit(int index) {
00091 SparseArray result;
00092 result.set_bit(index);
00093 return result;
00094 }
00095
00096
00097
00098
00099
00100
00101
00102 INLINE SparseArray SparseArray::
00103 range(int low_bit, int size) {
00104 SparseArray result;
00105 result.set_range(low_bit, size);
00106 return result;
00107 }
00108
00109
00110
00111
00112
00113
00114 INLINE SparseArray::
00115 ~SparseArray() {
00116 }
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131 INLINE bool SparseArray::
00132 has_max_num_bits() {
00133 return false;
00134 }
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149 INLINE int SparseArray::
00150 get_max_num_bits() {
00151 nassertr(false, 0);
00152 return 0;
00153 }
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167 INLINE int SparseArray::
00168 get_num_bits() const {
00169 if (_subranges.empty()) {
00170 return 0;
00171 } else {
00172 Subranges::const_iterator si = _subranges.begin() + _subranges.size() - 1;
00173 return (*si)._end;
00174 }
00175 }
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185 INLINE bool SparseArray::
00186 get_bit(int index) const {
00187 return has_any_of(index, 1);
00188 }
00189
00190
00191
00192
00193
00194
00195
00196 INLINE void SparseArray::
00197 set_bit(int index) {
00198 set_range(index, 1);
00199 }
00200
00201
00202
00203
00204
00205
00206
00207 INLINE void SparseArray::
00208 clear_bit(int index) {
00209 clear_range(index, 1);
00210 }
00211
00212
00213
00214
00215
00216
00217
00218 INLINE void SparseArray::
00219 set_bit_to(int index, bool value) {
00220 if (value) {
00221 set_bit(index);
00222 } else {
00223 clear_bit(index);
00224 }
00225 }
00226
00227
00228
00229
00230
00231
00232
00233
00234 INLINE bool SparseArray::
00235 get_highest_bits() const {
00236 return _inverse;
00237 }
00238
00239
00240
00241
00242
00243
00244
00245 INLINE bool SparseArray::
00246 is_zero() const {
00247 if (_inverse) {
00248 return false;
00249 } else {
00250 return _subranges.empty();
00251 }
00252 }
00253
00254
00255
00256
00257
00258
00259
00260 bool SparseArray::
00261 is_all_on() const {
00262 if (_inverse) {
00263 return _subranges.empty();
00264 } else {
00265 return false;
00266 }
00267 }
00268
00269
00270
00271
00272
00273
00274
00275 INLINE bool SparseArray::
00276 has_any_of(int low_bit, int size) const {
00277 if (_inverse) {
00278 return !do_has_all(low_bit, low_bit + size);
00279 } else {
00280 return do_has_any(low_bit, low_bit + size);
00281 }
00282 }
00283
00284
00285
00286
00287
00288
00289
00290 INLINE bool SparseArray::
00291 has_all_of(int low_bit, int size) const {
00292 if (_inverse) {
00293 return !do_has_any(low_bit, low_bit + size);
00294 } else {
00295 return do_has_all(low_bit, low_bit + size);
00296 }
00297 }
00298
00299
00300
00301
00302
00303
00304 INLINE void SparseArray::
00305 set_range(int low_bit, int size) {
00306 if (_inverse) {
00307 return do_remove_range(low_bit, low_bit + size);
00308 } else {
00309 return do_add_range(low_bit, low_bit + size);
00310 }
00311 }
00312
00313
00314
00315
00316
00317
00318 INLINE void SparseArray::
00319 clear_range(int low_bit, int size) {
00320 if (_inverse) {
00321 return do_add_range(low_bit, low_bit + size);
00322 } else {
00323 return do_remove_range(low_bit, low_bit + size);
00324 }
00325 }
00326
00327
00328
00329
00330
00331
00332 INLINE void SparseArray::
00333 set_range_to(bool value, int low_bit, int size) {
00334 if (value) {
00335 set_range(low_bit, size);
00336 } else {
00337 clear_range(low_bit, size);
00338 }
00339 }
00340
00341
00342
00343
00344
00345
00346
00347 void SparseArray::
00348 invert_in_place() {
00349 _inverse = !_inverse;
00350 }
00351
00352
00353
00354
00355
00356
00357 void SparseArray::
00358 clear() {
00359 _subranges.clear();
00360 _inverse = false;
00361 }
00362
00363
00364
00365
00366
00367
00368 INLINE bool SparseArray::
00369 operator == (const SparseArray &other) const {
00370 return compare_to(other) == 0;
00371 }
00372
00373
00374
00375
00376
00377
00378 INLINE bool SparseArray::
00379 operator != (const SparseArray &other) const {
00380 return compare_to(other) != 0;
00381 }
00382
00383
00384
00385
00386
00387
00388
00389
00390 INLINE bool SparseArray::
00391 operator < (const SparseArray &other) const {
00392 return compare_to(other) < 0;
00393 }
00394
00395
00396
00397
00398
00399
00400 INLINE SparseArray SparseArray::
00401 operator & (const SparseArray &other) const {
00402 SparseArray result(*this);
00403 result &= other;
00404 return result;
00405 }
00406
00407
00408
00409
00410
00411
00412 INLINE SparseArray SparseArray::
00413 operator | (const SparseArray &other) const {
00414 SparseArray result(*this);
00415 result |= other;
00416 return result;
00417 }
00418
00419
00420
00421
00422
00423
00424 INLINE SparseArray SparseArray::
00425 operator ^ (const SparseArray &other) const {
00426 SparseArray result(*this);
00427 result ^= other;
00428 return result;
00429 }
00430
00431
00432
00433
00434
00435
00436 INLINE SparseArray SparseArray::
00437 operator ~ () const {
00438 SparseArray result(*this);
00439 result.invert_in_place();
00440 return result;
00441 }
00442
00443
00444
00445
00446
00447
00448 INLINE SparseArray SparseArray::
00449 operator << (int shift) const {
00450 SparseArray result(*this);
00451 result <<= shift;
00452 return result;
00453 }
00454
00455
00456
00457
00458
00459
00460 INLINE SparseArray SparseArray::
00461 operator >> (int shift) const {
00462 SparseArray result(*this);
00463 result >>= shift;
00464 return result;
00465 }
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475 void SparseArray::
00476 operator <<= (int shift) {
00477 do_shift(shift);
00478 }
00479
00480
00481
00482
00483
00484
00485
00486
00487 void SparseArray::
00488 operator >>= (int shift) {
00489 do_shift(-shift);
00490 }
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502 INLINE bool SparseArray::
00503 is_inverse() const {
00504 return _inverse;
00505 }
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517 INLINE int SparseArray::
00518 get_num_subranges() const {
00519 return _subranges.size();
00520 }
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530 INLINE int SparseArray::
00531 get_subrange_begin(int n) const {
00532 nassertr(n >= 0 && n < (int)_subranges.size(), 0);
00533 return _subranges[n]._begin;
00534 }
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544 INLINE int SparseArray::
00545 get_subrange_end(int n) const {
00546 nassertr(n >= 0 && n < (int)_subranges.size(), 0);
00547 return _subranges[n]._end;
00548 }
00549
00550
00551
00552
00553
00554
00555 INLINE SparseArray::Subrange::
00556 Subrange(int begin, int end) :
00557 _begin(begin),
00558 _end(end)
00559 {
00560 }
00561
00562
00563
00564
00565
00566
00567 INLINE bool SparseArray::Subrange::
00568 operator < (const SparseArray::Subrange &other) const {
00569
00570
00571
00572 return _end < other._end;
00573 }
00574