Panda3D
rangeIterator.cxx
1 // Filename: rangeIterator.cxx
2 // Created by: drose (07Sep03)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "rangeIterator.h"
16 
17 ////////////////////////////////////////////////////////////////////
18 // Function: RangeIterator::Constructor
19 // Access: Public
20 // Description: Constructs an iterator to walk through the codes on
21 // the descriptor. It is important not to modify the
22 // RangeDescription object during the lifetime of the
23 // iterator.
24 ////////////////////////////////////////////////////////////////////
27  _desc(desc)
28 {
29  _it = _desc._range_list.begin();
30  if (_it == _desc._range_list.end()) {
31  _code = -1;
32  } else {
33  _code = (*_it)._from_code;
34  _codes_generated.insert(_code);
35  }
36 }
37 
38 ////////////////////////////////////////////////////////////////////
39 // Function: RangeIterator::next
40 // Access: Public
41 // Description: Advances the iterator to the next code. Returns true
42 // if there is a next code, or false if there are no
43 // mode codes.
44 ////////////////////////////////////////////////////////////////////
45 bool RangeIterator::
46 next() {
47  do {
48  if (_it == _desc._range_list.end()) {
49  return false;
50  }
51 
52  if (_code < (*_it)._to_code) {
53  _code++;
54 
55  } else {
56  _it++;
57  if (_it == _desc._range_list.end()) {
58  _code = -1;
59  return false;
60  }
61 
62  _code = (*_it)._from_code;
63  }
64 
65  // If this code has already been generated, repeat and skip to the
66  // next one.
67  } while (!_codes_generated.insert(_code).second);
68 
69  return true;
70 }
RangeIterator(const RangeDescription &desc)
Constructs an iterator to walk through the codes on the descriptor.
bool next()
Advances the iterator to the next code.
This describes a sparse range of Unicode character codes for conversion that may be specified on the ...