Panda3D
|
00001 // Filename: rangeIterator.cxx 00002 // Created by: drose (07Sep03) 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 #include "rangeIterator.h" 00016 00017 //////////////////////////////////////////////////////////////////// 00018 // Function: RangeIterator::Constructor 00019 // Access: Public 00020 // Description: Constructs an iterator to walk through the codes on 00021 // the descriptor. It is important not to modify the 00022 // RangeDescription object during the lifetime of the 00023 // iterator. 00024 //////////////////////////////////////////////////////////////////// 00025 RangeIterator:: 00026 RangeIterator(const RangeDescription &desc) : 00027 _desc(desc) 00028 { 00029 _it = _desc._range_list.begin(); 00030 if (_it == _desc._range_list.end()) { 00031 _code = -1; 00032 } else { 00033 _code = (*_it)._from_code; 00034 _codes_generated.insert(_code); 00035 } 00036 } 00037 00038 //////////////////////////////////////////////////////////////////// 00039 // Function: RangeIterator::next 00040 // Access: Public 00041 // Description: Advances the iterator to the next code. Returns true 00042 // if there is a next code, or false if there are no 00043 // mode codes. 00044 //////////////////////////////////////////////////////////////////// 00045 bool RangeIterator:: 00046 next() { 00047 do { 00048 if (_it == _desc._range_list.end()) { 00049 return false; 00050 } 00051 00052 if (_code < (*_it)._to_code) { 00053 _code++; 00054 00055 } else { 00056 _it++; 00057 if (_it == _desc._range_list.end()) { 00058 _code = -1; 00059 return false; 00060 } 00061 00062 _code = (*_it)._from_code; 00063 } 00064 00065 // If this code has already been generated, repeat and skip to the 00066 // next one. 00067 } while (!_codes_generated.insert(_code).second); 00068 00069 return true; 00070 }