Panda3D
|
00001 // Filename: doubleBitMask.I 00002 // Created by: drose (08Jun00) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 template<class BMType> 00016 TypeHandle DoubleBitMask<BMType>::_type_handle; 00017 00018 //////////////////////////////////////////////////////////////////// 00019 // Function: DoubleBitMask::Constructor 00020 // Access: Published 00021 // Description: 00022 //////////////////////////////////////////////////////////////////// 00023 template<class BMType> 00024 INLINE DoubleBitMask<BMType>:: 00025 DoubleBitMask() { 00026 } 00027 00028 //////////////////////////////////////////////////////////////////// 00029 // Function: DoubleBitMask::Copy Constructor 00030 // Access: Published 00031 // Description: 00032 //////////////////////////////////////////////////////////////////// 00033 template<class BMType> 00034 INLINE DoubleBitMask<BMType>:: 00035 DoubleBitMask(const DoubleBitMask<BMType> ©) : 00036 _lo(copy._lo), 00037 _hi(copy._hi) 00038 { 00039 } 00040 00041 //////////////////////////////////////////////////////////////////// 00042 // Function: DoubleBitMask::Copy Assignment Operator 00043 // Access: Published 00044 // Description: 00045 //////////////////////////////////////////////////////////////////// 00046 template<class BMType> 00047 INLINE DoubleBitMask<BMType> &DoubleBitMask<BMType>:: 00048 operator = (const DoubleBitMask<BMType> ©) { 00049 _lo = copy._lo; 00050 _hi = copy._hi; 00051 return *this; 00052 } 00053 00054 //////////////////////////////////////////////////////////////////// 00055 // Function: DoubleBitMask::Named all_on constructor 00056 // Access: Published, Static 00057 // Description: Returns a DoubleBitMask whose bits are all on. 00058 //////////////////////////////////////////////////////////////////// 00059 template<class BMType> 00060 INLINE DoubleBitMask<BMType> DoubleBitMask<BMType>:: 00061 all_on() { 00062 DoubleBitMask<BMType> result; 00063 result._lo = BitMaskType::all_on(); 00064 result._hi = BitMaskType::all_on(); 00065 return result; 00066 } 00067 00068 //////////////////////////////////////////////////////////////////// 00069 // Function: DoubleBitMask::Named all_on constructor 00070 // Access: Published, Static 00071 // Description: Returns a DoubleBitMask whose bits are all off. 00072 //////////////////////////////////////////////////////////////////// 00073 template<class BMType> 00074 INLINE DoubleBitMask<BMType> DoubleBitMask<BMType>:: 00075 all_off() { 00076 DoubleBitMask<BMType> result; 00077 result._lo.clear(); 00078 result._hi.clear(); 00079 return result; 00080 } 00081 00082 //////////////////////////////////////////////////////////////////// 00083 // Function: DoubleBitMask::Named lower_on constructor 00084 // Access: Published, Static 00085 // Description: Returns a DoubleBitMask whose lower on_bits bits are on. 00086 //////////////////////////////////////////////////////////////////// 00087 template<class BMType> 00088 INLINE DoubleBitMask<BMType> DoubleBitMask<BMType>:: 00089 lower_on(int on_bits) { 00090 if (on_bits <= 0) { 00091 return all_off(); 00092 } else if (on_bits >= num_bits) { 00093 return all_on(); 00094 } 00095 DoubleBitMask<BMType> result; 00096 if (on_bits <= half_bits) { 00097 result._lo = BitMaskType::lower_on(on_bits); 00098 } else { 00099 result._lo = BitMaskType::all_on(); 00100 result._hi = BitMaskType::lower_on(on_bits - half_bits); 00101 } 00102 return result; 00103 } 00104 00105 //////////////////////////////////////////////////////////////////// 00106 // Function: DoubleBitMask::Named bit constructor 00107 // Access: Published, Static 00108 // Description: Returns a DoubleBitMask with only the indicated bit on. 00109 //////////////////////////////////////////////////////////////////// 00110 template<class BMType> 00111 INLINE DoubleBitMask<BMType> DoubleBitMask<BMType>:: 00112 bit(int index) { 00113 DoubleBitMask<BMType> result; 00114 result.set_bit(index); 00115 return result; 00116 } 00117 00118 //////////////////////////////////////////////////////////////////// 00119 // Function: DoubleBitMask::Named range constructor 00120 // Access: Published, Static 00121 // Description: Returns a DoubleBitMask whose size bits, beginning at 00122 // low_bit, are on. 00123 //////////////////////////////////////////////////////////////////// 00124 template<class BMType> 00125 INLINE DoubleBitMask<BMType> DoubleBitMask<BMType>:: 00126 range(int low_bit, int size) { 00127 DoubleBitMask<BMType> result; 00128 result.set_range(low_bit, size); 00129 return result; 00130 } 00131 00132 //////////////////////////////////////////////////////////////////// 00133 // Function: DoubleBitMask::Destructor 00134 // Access: Published 00135 // Description: 00136 //////////////////////////////////////////////////////////////////// 00137 template<class BMType> 00138 INLINE DoubleBitMask<BMType>:: 00139 ~DoubleBitMask() { 00140 } 00141 00142 //////////////////////////////////////////////////////////////////// 00143 // Function: DoubleBitMask::has_max_num_bits 00144 // Access: Published, Static 00145 // Description: Returns true if there is a maximum number of bits 00146 // that may be stored in this structure, false 00147 // otherwise. If this returns true, the number may be 00148 // queried in get_max_num_bits(). 00149 // 00150 // This method always returns true. This method is 00151 // defined so generic programming algorithms can use 00152 // DoubleBitMask or BitArray interchangeably. 00153 //////////////////////////////////////////////////////////////////// 00154 template<class BMType> 00155 INLINE bool DoubleBitMask<BMType>:: 00156 has_max_num_bits() { 00157 return true; 00158 } 00159 00160 //////////////////////////////////////////////////////////////////// 00161 // Function: DoubleBitMask::get_max_num_bits 00162 // Access: Published, Static 00163 // Description: If get_max_num_bits() returned true, this method may 00164 // be called to return the maximum number of bits that 00165 // may be stored in this structure. It is an error to 00166 // call this if get_max_num_bits() return false. 00167 // 00168 // It is never an error to call this method. This 00169 // returns the same thing as get_num_bits(). This 00170 // method is defined so generic programming algorithms 00171 // can use DoubleBitMask or BitArray interchangeably. 00172 //////////////////////////////////////////////////////////////////// 00173 template<class BMType> 00174 INLINE int DoubleBitMask<BMType>:: 00175 get_max_num_bits() { 00176 return num_bits; 00177 } 00178 00179 //////////////////////////////////////////////////////////////////// 00180 // Function: DoubleBitMask::get_num_bits 00181 // Access: Published, Static 00182 // Description: Returns the number of bits available to set in the 00183 // doubleBitMask. 00184 //////////////////////////////////////////////////////////////////// 00185 template<class BMType> 00186 INLINE int DoubleBitMask<BMType>:: 00187 get_num_bits() { 00188 return num_bits; 00189 } 00190 00191 //////////////////////////////////////////////////////////////////// 00192 // Function: DoubleBitMask::get_bit 00193 // Access: Published 00194 // Description: Returns true if the nth bit is set, false if it is 00195 // cleared. index must be in the range [0, 00196 // num_bits). 00197 //////////////////////////////////////////////////////////////////// 00198 template<class BMType> 00199 INLINE bool DoubleBitMask<BMType>:: 00200 get_bit(int index) const { 00201 if (index < half_bits) { 00202 return _lo.get_bit(index); 00203 } else { 00204 return _hi.get_bit(index - half_bits); 00205 } 00206 } 00207 00208 //////////////////////////////////////////////////////////////////// 00209 // Function: DoubleBitMask::set_bit 00210 // Access: Published 00211 // Description: Sets the nth bit on. index must be in the range 00212 // [0, num_bits). 00213 //////////////////////////////////////////////////////////////////// 00214 template<class BMType> 00215 INLINE void DoubleBitMask<BMType>:: 00216 set_bit(int index) { 00217 if (index < half_bits) { 00218 _lo.set_bit(index); 00219 } else { 00220 _hi.set_bit(index - half_bits); 00221 } 00222 } 00223 00224 //////////////////////////////////////////////////////////////////// 00225 // Function: DoubleBitMask::clear_bit 00226 // Access: Published 00227 // Description: Sets the nth bit off. index must be in the range 00228 // [0, num_bits). 00229 //////////////////////////////////////////////////////////////////// 00230 template<class BMType> 00231 INLINE void DoubleBitMask<BMType>:: 00232 clear_bit(int index) { 00233 if (index < half_bits) { 00234 _lo.clear_bit(index); 00235 } else { 00236 _hi.clear_bit(index - half_bits); 00237 } 00238 } 00239 00240 //////////////////////////////////////////////////////////////////// 00241 // Function: DoubleBitMask::set_bit_to 00242 // Access: Published 00243 // Description: Sets the nth bit either on or off, according to the 00244 // indicated bool value. index must be in the range [0, 00245 // num_bits). 00246 //////////////////////////////////////////////////////////////////// 00247 template<class BMType> 00248 INLINE void DoubleBitMask<BMType>:: 00249 set_bit_to(int index, bool value) { 00250 if (index < half_bits) { 00251 _lo.set_bit_to(index, value); 00252 } else { 00253 _hi.set_bit_to(index - half_bits, value); 00254 } 00255 } 00256 00257 //////////////////////////////////////////////////////////////////// 00258 // Function: DoubleBitMask::is_zero 00259 // Access: Published 00260 // Description: Returns true if the entire doubleBitMask is zero, false 00261 // otherwise. 00262 //////////////////////////////////////////////////////////////////// 00263 template<class BMType> 00264 INLINE bool DoubleBitMask<BMType>:: 00265 is_zero() const { 00266 return (_lo.is_zero() && _hi.is_zero()); 00267 } 00268 00269 //////////////////////////////////////////////////////////////////// 00270 // Function: DoubleBitMask::is_all_on 00271 // Access: Published 00272 // Description: Returns true if the entire doubleBitMask is one, false 00273 // otherwise. 00274 //////////////////////////////////////////////////////////////////// 00275 template<class BMType> 00276 INLINE bool DoubleBitMask<BMType>:: 00277 is_all_on() const { 00278 return (_lo.is_all_on() && _hi.is_all_on()); 00279 } 00280 00281 //////////////////////////////////////////////////////////////////// 00282 // Function: DoubleBitMask::extract 00283 // Access: Published 00284 // Description: Returns a word that represents only the indicated 00285 // range of bits within this DoubleBitMask, shifted to the 00286 // least-significant position. 00287 //////////////////////////////////////////////////////////////////// 00288 template<class BMType> 00289 INLINE TYPENAME DoubleBitMask<BMType>::WordType DoubleBitMask<BMType>:: 00290 extract(int low_bit, int size) const { 00291 if (low_bit >= half_bits) { 00292 return _hi.extract(low_bit - half_bits, size); 00293 } else if (low_bit + size < half_bits) { 00294 return _lo.extract(low_bit, size); 00295 } else { 00296 int hi_portion = low_bit + size - half_bits; 00297 int lo_portion = size - hi_portion; 00298 return (_hi.extract(0, hi_portion) << lo_portion) | 00299 _lo.extract(low_bit, lo_portion); 00300 } 00301 } 00302 00303 //////////////////////////////////////////////////////////////////// 00304 // Function: DoubleBitMask::store 00305 // Access: Published 00306 // Description: Stores the indicated word into the indicated range of 00307 // bits with this DoubleBitMask. 00308 //////////////////////////////////////////////////////////////////// 00309 template<class BMType> 00310 INLINE void DoubleBitMask<BMType>:: 00311 store(WordType value, int low_bit, int size) { 00312 if (low_bit >= half_bits) { 00313 _hi.store(value, low_bit - half_bits, size); 00314 } else if (low_bit + size < half_bits) { 00315 _lo.store(value, low_bit, size); 00316 } else { 00317 int hi_portion = low_bit + size - half_bits; 00318 int lo_portion = size - hi_portion; 00319 00320 _hi.store(value >> lo_portion, 0, hi_portion); 00321 _lo.store(value, low_bit, lo_portion); 00322 } 00323 } 00324 00325 //////////////////////////////////////////////////////////////////// 00326 // Function: DoubleBitMask::has_any_of 00327 // Access: Published 00328 // Description: Returns true if any bit in the indicated range is 00329 // set, false otherwise. 00330 //////////////////////////////////////////////////////////////////// 00331 template<class BMType> 00332 INLINE bool DoubleBitMask<BMType>:: 00333 has_any_of(int low_bit, int size) const { 00334 if (low_bit >= half_bits) { 00335 return _hi.has_any_of(low_bit - half_bits, size); 00336 } else if (low_bit + size < half_bits) { 00337 return _lo.has_any_of(low_bit, size); 00338 } else { 00339 int hi_portion = low_bit + size - half_bits; 00340 int lo_portion = size - hi_portion; 00341 return (_hi.has_any_of(0, hi_portion) << lo_portion) || 00342 _lo.has_any_of(low_bit, lo_portion); 00343 } 00344 } 00345 00346 //////////////////////////////////////////////////////////////////// 00347 // Function: DoubleBitMask::has_all_of 00348 // Access: Published 00349 // Description: Returns true if all bits in the indicated range are 00350 // set, false otherwise. 00351 //////////////////////////////////////////////////////////////////// 00352 template<class BMType> 00353 INLINE bool DoubleBitMask<BMType>:: 00354 has_all_of(int low_bit, int size) const { 00355 if (low_bit >= half_bits) { 00356 return _hi.has_all_of(low_bit - half_bits, size); 00357 } else if (low_bit + size < half_bits) { 00358 return _lo.has_all_of(low_bit, size); 00359 } else { 00360 int hi_portion = low_bit + size - half_bits; 00361 int lo_portion = size - hi_portion; 00362 return (_hi.has_all_of(0, hi_portion) << lo_portion) && 00363 _lo.has_all_of(low_bit, lo_portion); 00364 } 00365 } 00366 00367 //////////////////////////////////////////////////////////////////// 00368 // Function: DoubleBitMask::set_range 00369 // Access: Published 00370 // Description: Sets the indicated range of bits on. 00371 //////////////////////////////////////////////////////////////////// 00372 template<class BMType> 00373 INLINE void DoubleBitMask<BMType>:: 00374 set_range(int low_bit, int size) { 00375 if (low_bit >= half_bits) { 00376 _hi.set_range(low_bit - half_bits, size); 00377 } else if (low_bit + size < half_bits) { 00378 _lo.set_range(low_bit, size); 00379 } else { 00380 int hi_portion = low_bit + size - half_bits; 00381 int lo_portion = size - hi_portion; 00382 00383 _hi.set_range(0, hi_portion); 00384 _lo.set_range(low_bit, lo_portion); 00385 } 00386 } 00387 00388 //////////////////////////////////////////////////////////////////// 00389 // Function: DoubleBitMask::clear_range 00390 // Access: Published 00391 // Description: Sets the indicated range of bits off. 00392 //////////////////////////////////////////////////////////////////// 00393 template<class BMType> 00394 INLINE void DoubleBitMask<BMType>:: 00395 clear_range(int low_bit, int size) { 00396 if (low_bit >= half_bits) { 00397 _hi.clear_range(low_bit - half_bits, size); 00398 } else if (low_bit + size < half_bits) { 00399 _lo.clear_range(low_bit, size); 00400 } else { 00401 int hi_portion = low_bit + size - half_bits; 00402 int lo_portion = size - hi_portion; 00403 00404 _hi.clear_range(0, hi_portion); 00405 _lo.clear_range(low_bit, lo_portion); 00406 } 00407 } 00408 00409 //////////////////////////////////////////////////////////////////// 00410 // Function: DoubleBitMask::set_range_to 00411 // Access: Published 00412 // Description: Sets the indicated range of bits to either on or off. 00413 //////////////////////////////////////////////////////////////////// 00414 template<class BMType> 00415 INLINE void DoubleBitMask<BMType>:: 00416 set_range_to(bool value, int low_bit, int size) { 00417 if (value) { 00418 set_range(low_bit, size); 00419 } else { 00420 clear_range(low_bit, size); 00421 } 00422 } 00423 00424 //////////////////////////////////////////////////////////////////// 00425 // Function: DoubleBitMask::get_num_on_bits 00426 // Access: Published 00427 // Description: Returns the number of bits that are set to 1 in the 00428 // mask. 00429 //////////////////////////////////////////////////////////////////// 00430 template<class BMType> 00431 INLINE int DoubleBitMask<BMType>:: 00432 get_num_on_bits() const { 00433 return _lo.get_num_on_bits() + _hi.get_num_on_bits(); 00434 } 00435 00436 //////////////////////////////////////////////////////////////////// 00437 // Function: DoubleBitMask::get_num_off_bits 00438 // Access: Published 00439 // Description: Returns the number of bits that are set to 0 in the 00440 // mask. 00441 //////////////////////////////////////////////////////////////////// 00442 template<class BMType> 00443 INLINE int DoubleBitMask<BMType>:: 00444 get_num_off_bits() const { 00445 return _lo.get_num_off_bits() + _hi.get_num_off_bits(); 00446 } 00447 00448 //////////////////////////////////////////////////////////////////// 00449 // Function: DoubleBitMask::get_lowest_on_bit 00450 // Access: Published 00451 // Description: Returns the index of the lowest 1 bit in the mask. 00452 // Returns -1 if there are no 1 bits. 00453 //////////////////////////////////////////////////////////////////// 00454 template<class BMType> 00455 INLINE int DoubleBitMask<BMType>:: 00456 get_lowest_on_bit() const { 00457 int result = _lo.get_lowest_on_bit(); 00458 if (result == -1) { 00459 result = _hi.get_lowest_on_bit(); 00460 if (result != -1) { 00461 result += half_bits; 00462 } 00463 } 00464 return result; 00465 } 00466 00467 //////////////////////////////////////////////////////////////////// 00468 // Function: DoubleBitMask::get_lowest_off_bit 00469 // Access: Published 00470 // Description: Returns the index of the lowest 0 bit in the mask. 00471 // Returns -1 if there are no 0 bits. 00472 //////////////////////////////////////////////////////////////////// 00473 template<class BMType> 00474 INLINE int DoubleBitMask<BMType>:: 00475 get_lowest_off_bit() const { 00476 int result = _lo.get_lowest_off_bit(); 00477 if (result == -1) { 00478 result = _hi.get_lowest_off_bit(); 00479 if (result != -1) { 00480 result += half_bits; 00481 } 00482 } 00483 return result; 00484 } 00485 00486 //////////////////////////////////////////////////////////////////// 00487 // Function: DoubleBitMask::get_highest_on_bit 00488 // Access: Published 00489 // Description: Returns the index of the highest 1 bit in the mask. 00490 // Returns -1 if there are no 1 bits. 00491 //////////////////////////////////////////////////////////////////// 00492 template<class BMType> 00493 INLINE int DoubleBitMask<BMType>:: 00494 get_highest_on_bit() const { 00495 int result = _hi.get_highest_on_bit(); 00496 if (result == -1) { 00497 result = _lo.get_highest_on_bit(); 00498 } else { 00499 result += half_bits; 00500 } 00501 return result; 00502 } 00503 00504 //////////////////////////////////////////////////////////////////// 00505 // Function: DoubleBitMask::get_highest_off_bit 00506 // Access: Published 00507 // Description: Returns the index of the highest 0 bit in the mask. 00508 // Returns -1 if there are no 0 bits. 00509 //////////////////////////////////////////////////////////////////// 00510 template<class BMType> 00511 INLINE int DoubleBitMask<BMType>:: 00512 get_highest_off_bit() const { 00513 int result = _hi.get_highest_off_bit(); 00514 if (result == -1) { 00515 result = _lo.get_highest_off_bit(); 00516 } else { 00517 result += half_bits; 00518 } 00519 return result; 00520 } 00521 00522 //////////////////////////////////////////////////////////////////// 00523 // Function: DoubleBitMask::get_next_higher_different_bit 00524 // Access: Published 00525 // Description: Returns the index of the next bit in the mask, above 00526 // low_bit, whose value is different that the value of 00527 // low_bit. Returns low_bit again if all bits higher 00528 // than low_bit have the same value. 00529 // 00530 // This can be used to quickly iterate through all of 00531 // the bits in the mask. 00532 //////////////////////////////////////////////////////////////////// 00533 template<class BMType> 00534 INLINE int DoubleBitMask<BMType>:: 00535 get_next_higher_different_bit(int low_bit) const { 00536 if (low_bit > half_bits) { 00537 return _hi.get_next_higher_different_bit(low_bit - half_bits) + half_bits; 00538 } 00539 int result = _lo.get_next_higher_different_bit(low_bit); 00540 if (result != low_bit) { 00541 return result; 00542 } 00543 if (_lo.get_bit(low_bit)) { 00544 result = _hi.get_lowest_off_bit(); 00545 } else { 00546 result = _hi.get_lowest_on_bit(); 00547 } 00548 if (result == -1) { 00549 return low_bit; 00550 } 00551 return result + half_bits; 00552 } 00553 00554 //////////////////////////////////////////////////////////////////// 00555 // Function: DoubleBitMask::invert_in_place 00556 // Access: Published 00557 // Description: Inverts all the bits in the DoubleBitMask. This is 00558 // equivalent to mask = ~mask. 00559 //////////////////////////////////////////////////////////////////// 00560 template<class BMType> 00561 INLINE void DoubleBitMask<BMType>:: 00562 invert_in_place() { 00563 _lo.invert_in_place(); 00564 _hi.invert_in_place(); 00565 } 00566 00567 //////////////////////////////////////////////////////////////////// 00568 // Function: DoubleBitMask::has_bits_in_common 00569 // Access: Published 00570 // Description: Returns true if this DoubleBitMask has any "one" bits in 00571 // common with the other one, false otherwise. 00572 // 00573 // This is equivalent to (mask & other) != 0, but may be 00574 // faster. (Actually, it should only be faster in the 00575 // BitArray case, but this method is provided for the 00576 // benefit of generic programming algorithms). 00577 //////////////////////////////////////////////////////////////////// 00578 template<class BMType> 00579 INLINE bool DoubleBitMask<BMType>:: 00580 has_bits_in_common(const DoubleBitMask<BMType> &other) const { 00581 return _lo.has_bits_in_common(other._lo) || 00582 _hi.has_bits_in_common(other._hi); 00583 } 00584 00585 //////////////////////////////////////////////////////////////////// 00586 // Function: DoubleBitMask::clear 00587 // Access: Published 00588 // Description: Sets all the bits in the DoubleBitMask off. 00589 //////////////////////////////////////////////////////////////////// 00590 template<class BMType> 00591 INLINE void DoubleBitMask<BMType>:: 00592 clear() { 00593 _lo.clear(); 00594 _hi.clear(); 00595 } 00596 00597 //////////////////////////////////////////////////////////////////// 00598 // Function: DoubleBitMask::output 00599 // Access: Published 00600 // Description: Writes the DoubleBitMask out as a binary or a hex number, 00601 // according to the number of bits. 00602 //////////////////////////////////////////////////////////////////// 00603 template<class BMType> 00604 void DoubleBitMask<BMType>:: 00605 output(ostream &out) const { 00606 output_hex(out); 00607 } 00608 00609 //////////////////////////////////////////////////////////////////// 00610 // Function: DoubleBitMask::output_binary 00611 // Access: Published 00612 // Description: Writes the DoubleBitMask out as a binary number, with 00613 // spaces every four bits. 00614 //////////////////////////////////////////////////////////////////// 00615 template<class BMType> 00616 void DoubleBitMask<BMType>:: 00617 output_binary(ostream &out, int spaces_every) const { 00618 _hi.output_binary(out); 00619 out << ' '; 00620 _lo.output_binary(out); 00621 } 00622 00623 //////////////////////////////////////////////////////////////////// 00624 // Function: DoubleBitMask::output_hex 00625 // Access: Published 00626 // Description: Writes the DoubleBitMask out as a hexadecimal number, with 00627 // spaces every four digits. 00628 //////////////////////////////////////////////////////////////////// 00629 template<class BMType> 00630 void DoubleBitMask<BMType>:: 00631 output_hex(ostream &out, int spaces_every) const { 00632 _hi.output_hex(out); 00633 out << ' '; 00634 _lo.output_hex(out); 00635 } 00636 00637 //////////////////////////////////////////////////////////////////// 00638 // Function: DoubleBitMask::write 00639 // Access: Published 00640 // Description: Writes the DoubleBitMask out as a binary or a hex number, 00641 // according to the number of bits. 00642 //////////////////////////////////////////////////////////////////// 00643 template<class BMType> 00644 void DoubleBitMask<BMType>:: 00645 write(ostream &out, int indent_level) const { 00646 indent(out, indent_level) << *this << "\n"; 00647 } 00648 00649 //////////////////////////////////////////////////////////////////// 00650 // Function: DoubleBitMask::operator == 00651 // Access: Published 00652 // Description: 00653 //////////////////////////////////////////////////////////////////// 00654 template<class BMType> 00655 INLINE bool DoubleBitMask<BMType>:: 00656 operator == (const DoubleBitMask<BMType> &other) const { 00657 return _lo == other._lo && _hi == other._hi; 00658 } 00659 00660 //////////////////////////////////////////////////////////////////// 00661 // Function: DoubleBitMask::operator != 00662 // Access: Published 00663 // Description: 00664 //////////////////////////////////////////////////////////////////// 00665 template<class BMType> 00666 INLINE bool DoubleBitMask<BMType>:: 00667 operator != (const DoubleBitMask<BMType> &other) const { 00668 return _lo != other._lo && _hi != other._hi; 00669 } 00670 00671 //////////////////////////////////////////////////////////////////// 00672 // Function: DoubleBitMask::operator < 00673 // Access: Published 00674 // Description: The ordering operator is of limited usefulness with a 00675 // DoubleBitMask, however, it has a definition which places 00676 // all unique DoubleBitMasks into a unique ordering. It may 00677 // be useful when defining ordered STL containers of 00678 // DoubleBitMasks, for instance; and it's required in order to 00679 // export any STL container (ordered or unordered) of 00680 // DoubleBitMask under Windows. 00681 //////////////////////////////////////////////////////////////////// 00682 template<class BMType> 00683 INLINE bool DoubleBitMask<BMType>:: 00684 operator < (const DoubleBitMask<BMType> &other) const { 00685 int cmp = _hi.compare_to(other._hi); 00686 if (cmp != 0) { 00687 return cmp < 0; 00688 } 00689 return _lo < other._lo; 00690 } 00691 00692 //////////////////////////////////////////////////////////////////// 00693 // Function: DoubleBitMask::compare_to 00694 // Access: Published 00695 // Description: Returns a number less than zero if this DoubleBitMask sorts 00696 // before the indicated other DoubleBitMask, greater than zero 00697 // if it sorts after, or 0 if they are equivalent. This 00698 // is based on the same ordering defined by operator <. 00699 //////////////////////////////////////////////////////////////////// 00700 template<class BMType> 00701 INLINE int DoubleBitMask<BMType>:: 00702 compare_to(const DoubleBitMask<BMType> &other) const { 00703 int cmp = _hi.compare_to(other._hi); 00704 if (cmp != 0) { 00705 return cmp; 00706 } 00707 return _lo.compare_to(other._lo); 00708 } 00709 00710 //////////////////////////////////////////////////////////////////// 00711 // Function: DoubleBitMask::operator & 00712 // Access: Published 00713 // Description: 00714 //////////////////////////////////////////////////////////////////// 00715 template<class BMType> 00716 INLINE DoubleBitMask<BMType> DoubleBitMask<BMType>:: 00717 operator & (const DoubleBitMask<BMType> &other) const { 00718 DoubleBitMask<BMType> result(*this); 00719 result &= other; 00720 return result; 00721 } 00722 00723 //////////////////////////////////////////////////////////////////// 00724 // Function: DoubleBitMask::operator | 00725 // Access: Published 00726 // Description: 00727 //////////////////////////////////////////////////////////////////// 00728 template<class BMType> 00729 INLINE DoubleBitMask<BMType> DoubleBitMask<BMType>:: 00730 operator | (const DoubleBitMask<BMType> &other) const { 00731 DoubleBitMask<BMType> result(*this); 00732 result |= other; 00733 return result; 00734 } 00735 00736 //////////////////////////////////////////////////////////////////// 00737 // Function: DoubleBitMask::operator ^ 00738 // Access: Published 00739 // Description: 00740 //////////////////////////////////////////////////////////////////// 00741 template<class BMType> 00742 INLINE DoubleBitMask<BMType> DoubleBitMask<BMType>:: 00743 operator ^ (const DoubleBitMask<BMType> &other) const { 00744 DoubleBitMask<BMType> result(*this); 00745 result ^= other; 00746 return result; 00747 } 00748 00749 //////////////////////////////////////////////////////////////////// 00750 // Function: DoubleBitMask::operator ~ 00751 // Access: Published 00752 // Description: 00753 //////////////////////////////////////////////////////////////////// 00754 template<class BMType> 00755 INLINE DoubleBitMask<BMType> DoubleBitMask<BMType>:: 00756 operator ~ () const { 00757 DoubleBitMask<BMType> result(*this); 00758 result.invert_in_place(); 00759 return result; 00760 } 00761 00762 //////////////////////////////////////////////////////////////////// 00763 // Function: DoubleBitMask::operator << 00764 // Access: Published 00765 // Description: 00766 //////////////////////////////////////////////////////////////////// 00767 template<class BMType> 00768 INLINE DoubleBitMask<BMType> DoubleBitMask<BMType>:: 00769 operator << (int shift) const { 00770 DoubleBitMask<BMType> result(*this); 00771 result <<= shift; 00772 return result; 00773 } 00774 00775 //////////////////////////////////////////////////////////////////// 00776 // Function: DoubleBitMask::operator >> 00777 // Access: Published 00778 // Description: 00779 //////////////////////////////////////////////////////////////////// 00780 template<class BMType> 00781 INLINE DoubleBitMask<BMType> DoubleBitMask<BMType>:: 00782 operator >> (int shift) const { 00783 DoubleBitMask<BMType> result(*this); 00784 result >>= shift; 00785 return result; 00786 } 00787 00788 //////////////////////////////////////////////////////////////////// 00789 // Function: DoubleBitMask::operator &= 00790 // Access: Published 00791 // Description: 00792 //////////////////////////////////////////////////////////////////// 00793 template<class BMType> 00794 INLINE void DoubleBitMask<BMType>:: 00795 operator &= (const DoubleBitMask<BMType> &other) { 00796 _lo &= other._lo; 00797 _hi &= other._hi; 00798 } 00799 00800 //////////////////////////////////////////////////////////////////// 00801 // Function: DoubleBitMask::operator |= 00802 // Access: Published 00803 // Description: 00804 //////////////////////////////////////////////////////////////////// 00805 template<class BMType> 00806 INLINE void DoubleBitMask<BMType>:: 00807 operator |= (const DoubleBitMask<BMType> &other) { 00808 _lo |= other._lo; 00809 _hi |= other._hi; 00810 } 00811 00812 //////////////////////////////////////////////////////////////////// 00813 // Function: DoubleBitMask::operator ^= 00814 // Access: Published 00815 // Description: 00816 //////////////////////////////////////////////////////////////////// 00817 template<class BMType> 00818 INLINE void DoubleBitMask<BMType>:: 00819 operator ^= (const DoubleBitMask<BMType> &other) { 00820 _lo ^= other._lo; 00821 _hi ^= other._hi; 00822 } 00823 00824 //////////////////////////////////////////////////////////////////// 00825 // Function: DoubleBitMask::operator <<= 00826 // Access: Published 00827 // Description: 00828 //////////////////////////////////////////////////////////////////// 00829 template<class BMType> 00830 INLINE void DoubleBitMask<BMType>:: 00831 operator <<= (int shift) { 00832 _hi = (_hi << shift) | ((_lo >> half_bits - shift) & BitMaskType::lower_on(shift)); 00833 _lo <<= shift; 00834 } 00835 00836 //////////////////////////////////////////////////////////////////// 00837 // Function: DoubleBitMask::operator >>= 00838 // Access: Published 00839 // Description: 00840 //////////////////////////////////////////////////////////////////// 00841 template<class BMType> 00842 INLINE void DoubleBitMask<BMType>:: 00843 operator >>= (int shift) { 00844 _lo = (_lo >> shift) | ((_hi & BitMaskType::lower_on(shift)) << half_bits - shift); 00845 _hi >>= shift; 00846 } 00847 00848 //////////////////////////////////////////////////////////////////// 00849 // Function: DoubleBitMask::generate_hash 00850 // Access: Public 00851 // Description: Adds the doubleBitMask to the indicated hash generator. 00852 //////////////////////////////////////////////////////////////////// 00853 template<class BMType> 00854 INLINE void DoubleBitMask<BMType>:: 00855 generate_hash(ChecksumHashGenerator &hashgen) const { 00856 _hi.generate_hash(hashgen); 00857 _lo.generate_hash(hashgen); 00858 } 00859 00860 //////////////////////////////////////////////////////////////////// 00861 // Function: DoubleBitMask::init_type 00862 // Access: Public 00863 // Description: 00864 //////////////////////////////////////////////////////////////////// 00865 template<class BMType> 00866 void DoubleBitMask<BMType>:: 00867 init_type() { 00868 ostringstream str; 00869 str << "DoubleBitMask" << num_bits; 00870 register_type(_type_handle, str.str()); 00871 }