#include <Iguana/Utilities/classlib/utils/Sequence.h>
Public Member Functions | ||||
T | current (void) const | |||
Get the current sequence value. | ||||
void | limits (const Range< T > &value) | |||
Set the sequence value range to value. | ||||
Range< T > | limits (void) const | |||
Return the current sequence value range. | ||||
T | next (void) | |||
Generate the next sequence value. | ||||
void | reset (void) | |||
Resets the current value to the low limit and clears the wrapped() flag. | ||||
Sequence (const Range< T > &limits, bool wraps=false) | ||||
| ||||
Sequence (T low, T high, bool wraps=false) | ||||
| ||||
Sequence (bool wraps=false) | ||||
Initialize a Sequence. | ||||
bool | wrapped (void) | |||
Check if the sequence has wrapped. | ||||
void | wraps (bool value) | |||
Set the current wrap mode to value. | ||||
bool | wraps (void) const | |||
Return the current wrap mode. | ||||
Private Attributes | ||||
T | m_current | |||
Range< T > | m_limits | |||
bool | m_wrapped | |||
bool | m_wraps | |||
Friends | ||||
logstream & | operator<< (logstream &log, const Sequence &s) |
Each invocation of a Sequence generates a value in a range. The sequence starts at the lowest value and after that ever increasing values are produced. When the upper limit has been reached, the behaviour depends on the wraps flag.
Definition at line 35 of file Sequence.h.
lat::Sequence< T >::Sequence | ( | bool | wraps = false |
) | [inline] |
Initialize a Sequence.
If no limits are given, the entire range of T
is used. The current value is set to the low limit; the next call to next() will return one higher than that.
wraps | Flag indicating whether the sequence should wrap when the upper limit has been reached and the next() value is requested. If the flag is false , overflow throws an exception. Otherwise the sequence wraps back to the low limit. |
Definition at line 105 of file Sequence.h.
References ASSERT, lat::Sequence< T >::m_current, and lat::Sequence< T >::m_limits.
00106 : m_limits (IntTraits<T>::Min, IntTraits<T>::Max), 00107 m_current (IntTraits<T>::Min), 00108 m_wraps (wraps), 00109 m_wrapped (false) 00110 { 00111 ASSERT (m_limits.low () < m_limits.high ()); 00112 ASSERT (m_current >= m_limits.low ()); 00113 ASSERT (m_current <= m_limits.high ()); 00114 }
lat::Sequence< T >::Sequence | ( | T | low, | |
T | high, | |||
bool | wraps = false | |||
) | [inline] |
low,high | The range of sequence values. |
Definition at line 119 of file Sequence.h.
References ASSERT, lat::Sequence< T >::m_current, and lat::Sequence< T >::m_limits.
00120 : m_limits (low, high), 00121 m_current (low), 00122 m_wraps (wraps), 00123 m_wrapped (false) 00124 { 00125 ASSERT (m_limits.low () < m_limits.high ()); 00126 ASSERT (m_current >= m_limits.low ()); 00127 ASSERT (m_current <= m_limits.high ()); 00128 }
lat::Sequence< T >::Sequence | ( | const Range< T > & | limits, | |
bool | wraps = false | |||
) | [inline] |
limits | The range of sequence values. |
Definition at line 133 of file Sequence.h.
References ASSERT, lat::Sequence< T >::m_current, and lat::Sequence< T >::m_limits.
00134 : m_limits (limits), 00135 m_current (limits.low ()), 00136 m_wraps (wraps), 00137 m_wrapped (false) 00138 { 00139 ASSERT (m_limits.low () < m_limits.high ()); 00140 ASSERT (m_current >= m_limits.low ()); 00141 ASSERT (m_current <= m_limits.high ()); 00142 }
T lat::Sequence< T >::current | ( | void | ) | const [inline] |
Get the current sequence value.
Definition at line 232 of file Sequence.h.
References ASSERT, lat::Sequence< T >::m_current, and lat::Sequence< T >::m_limits.
00233 { 00234 ASSERT (m_limits.low () < m_limits.high ()); 00235 ASSERT (m_current >= m_limits.low ()); 00236 ASSERT (m_current <= m_limits.high ()); 00237 return m_current; 00238 }
void lat::Sequence< T >::limits | ( | const Range< T > & | value | ) | [inline] |
Set the sequence value range to value.
If the current value does not fall into this range, it is corrected to be either the low or the high limit, whichever is closer. If the current value is modified, the wrapped() flag is set. No std::range_error exception is thrown.
Definition at line 157 of file Sequence.h.
References ASSERT, lat::Range< T >::high(), lat::Sequence< T >::limits(), lat::Range< T >::low(), lat::Sequence< T >::m_current, lat::Sequence< T >::m_limits, and lat::Sequence< T >::m_wrapped.
00158 { 00159 ASSERT (m_limits.low () < m_limits.high ()); 00160 ASSERT (m_current >= m_limits.low ()); 00161 ASSERT (m_current <= m_limits.high ()); 00162 ASSERT (value.low () < value.high ()); 00163 00164 m_limits = limits; 00165 if (m_current < m_limits.low ()) 00166 { 00167 m_wrapped = true; 00168 m_current = m_limits.low (); 00169 } 00170 else if (m_current > m_limits.high ()) 00171 { 00172 m_wrapped = true; 00173 m_current = m_limits.high (); 00174 } 00175 }
Range< T > lat::Sequence< T >::limits | ( | void | ) | const [inline] |
Return the current sequence value range.
Definition at line 147 of file Sequence.h.
References lat::Sequence< T >::m_limits.
Referenced by lat::Sequence< T >::limits().
00148 { return m_limits; }
T lat::Sequence< T >::next | ( | void | ) | [inline] |
Generate the next sequence value.
Wrapping is considered if the current value already equals to the upper limit. If wrapping mode is on, the value is reset to the low limit of the range, and wrapped() is set to true
; otherwise std::range_error is thrown.
Subsequent calls to current() will return the same value.
Definition at line 207 of file Sequence.h.
References ASSERT, lat::Sequence< T >::m_current, lat::Sequence< T >::m_limits, lat::Sequence< T >::m_wrapped, and lat::Sequence< T >::m_wraps.
00208 { 00209 ASSERT (m_limits.low () < m_limits.high ()); 00210 ASSERT (m_current >= m_limits.low ()); 00211 ASSERT (m_current <= m_limits.high ()); 00212 00213 if (m_current == m_limits.high ()) 00214 if (m_wraps) 00215 { 00216 m_wrapped = true; 00217 m_current = m_limits.low (); 00218 } 00219 else 00220 throw std::range_error ("Sequence upper limit reached"); 00221 else 00222 ++m_current; 00223 00224 ASSERT (m_current >= m_limits.low ()); 00225 ASSERT (m_current <= m_limits.high ()); 00226 return m_current; 00227 }
void lat::Sequence< T >::reset | ( | void | ) | [inline] |
Resets the current value to the low limit and clears the wrapped() flag.
Definition at line 244 of file Sequence.h.
References ASSERT, lat::Sequence< T >::m_current, lat::Sequence< T >::m_limits, and lat::Sequence< T >::m_wrapped.
00245 { 00246 ASSERT (m_limits.low () < m_limits.high ()); 00247 ASSERT (m_current >= m_limits.low ()); 00248 ASSERT (m_current <= m_limits.high ()); 00249 00250 m_current = m_limits.low (); 00251 m_wrapped = false; 00252 00253 ASSERT (m_limits.low () < m_limits.high ()); 00254 ASSERT (m_current >= m_limits.low ()); 00255 ASSERT (m_current <= m_limits.high ()); 00256 }
bool lat::Sequence< T >::wrapped | ( | void | ) | [inline] |
Check if the sequence has wrapped.
The flag is automatically cleared as a side effect.
Definition at line 194 of file Sequence.h.
References lat::Sequence< T >::m_wrapped.
void lat::Sequence< T >::wraps | ( | bool | value | ) | [inline] |
Set the current wrap mode to value.
If it is true
, the value next from the upper limit rolls back to the low limit.
Definition at line 187 of file Sequence.h.
References lat::Sequence< T >::m_wraps.
bool lat::Sequence< T >::wraps | ( | void | ) | const [inline] |
Return the current wrap mode.
If true
, the value next from the upper limit rolls back to the low limit.
Definition at line 181 of file Sequence.h.
References lat::Sequence< T >::m_wraps.
00182 { return m_wraps; }
T lat::Sequence< T >::m_current [private] |
Definition at line 60 of file Sequence.h.
Referenced by lat::Sequence< T >::current(), lat::Sequence< T >::limits(), lat::Sequence< T >::next(), lat::Sequence< T >::reset(), and lat::Sequence< T >::Sequence().
Range<T> lat::Sequence< T >::m_limits [private] |
Definition at line 59 of file Sequence.h.
Referenced by lat::Sequence< T >::current(), lat::Sequence< T >::limits(), lat::Sequence< T >::next(), lat::Sequence< T >::reset(), and lat::Sequence< T >::Sequence().
bool lat::Sequence< T >::m_wrapped [private] |
Definition at line 62 of file Sequence.h.
Referenced by lat::Sequence< T >::limits(), lat::Sequence< T >::next(), lat::Sequence< T >::reset(), and lat::Sequence< T >::wrapped().
bool lat::Sequence< T >::m_wraps [private] |
Definition at line 61 of file Sequence.h.
Referenced by lat::Sequence< T >::next(), and lat::Sequence< T >::wraps().