51 template<
typename NUMERIC_TYPE,
typename SIGNED_TYPE>
69 : m_value (value.m_value)
73 SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE>& operator= (NUMERIC_TYPE value)
80 SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE>& operator= (SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE>
const &value)
82 m_value = value.m_value;
88 operator NUMERIC_TYPE ()
const
111 SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> operator++ (
int)
113 SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> retval (m_value);
119 SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> operator-- ()
126 SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> operator-- (
int)
128 SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> retval (m_value);
133 SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE>& operator+= (SIGNED_TYPE value)
139 SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE>& operator-= (SIGNED_TYPE value)
145 SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> operator + (
const SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> &other)
const
147 return SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> (m_value + other.m_value);
150 SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> operator + (SIGNED_TYPE delta)
const
152 return SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> (m_value + delta);
155 SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> operator - (SIGNED_TYPE delta)
const
157 return SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> (m_value - delta);
160 SIGNED_TYPE operator - (
const SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> &other)
const
162 static const NUMERIC_TYPE maxValue = std::numeric_limits<NUMERIC_TYPE>::max ();
163 static const NUMERIC_TYPE halfMaxValue = std::numeric_limits<NUMERIC_TYPE>::max () / 2;
164 if (m_value > other.m_value)
166 NUMERIC_TYPE diff = m_value - other.m_value;
167 if (diff < halfMaxValue)
169 return static_cast<SIGNED_TYPE
> (diff);
177 return -(
static_cast<SIGNED_TYPE
> (maxValue - m_value + 1 + other.m_value));
182 NUMERIC_TYPE diff = other.m_value - m_value;
183 if (diff < halfMaxValue)
189 return -(
static_cast<SIGNED_TYPE
> (diff));
197 return static_cast<SIGNED_TYPE
> (maxValue - other.m_value + 1 + m_value);
212 bool operator > (
const SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> &other)
const
214 static const NUMERIC_TYPE halfMaxValue = std::numeric_limits<NUMERIC_TYPE>::max () / 2;
216 return (((m_value > other.m_value) && (m_value - other.m_value) <= halfMaxValue)
217 || ((other.m_value > m_value) && (other.m_value - m_value) > halfMaxValue));
220 bool operator == (
const SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> &other)
const
222 return (m_value == other.m_value);
225 bool operator != (
const SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> &other)
const
227 return (m_value != other.m_value);
230 bool operator <= (const SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> &other)
const
232 return (!this->
operator> (other));
235 bool operator >= (
const SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> &other)
const
237 return (this->
operator> (other) || this->
operator== (other));
240 bool operator < (const SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> &other)
const
242 return !this->operator> (other) && m_value != other.m_value;
246 template<
typename NUMERIC_TYPE2,
typename SIGNED_TYPE2>
247 friend std::ostream & operator<< (std::ostream& os, const SequenceNumber<NUMERIC_TYPE2, SIGNED_TYPE2> &val);
249 template<
typename NUMERIC_TYPE2,
typename SIGNED_TYPE2>
250 friend std::istream & operator >> (std::istream &is,
const SequenceNumber<NUMERIC_TYPE2, SIGNED_TYPE2> &val);
253 SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE>& operator+= (SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE>
const &value);
254 SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE>& operator-= (SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE>
const &value);
255 SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> operator* (
const SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE>& b)
const;
256 SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> operator/ (
const SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE>& b)
const;
257 SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> operator% (
const SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE>& b)
const;
258 bool operator ! ()
const;
259 bool operator && (
const SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE>& b)
const;
260 bool operator || (
const SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE>& b)
const;
261 SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> operator~ ()
const;
262 SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> operator& (
const SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE>& b)
const;
263 SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> operator| (
const SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE>& b)
const;
264 SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> operator^ (
const SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE>& b)
const;
265 SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> operator<< (const SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE>& b)
const;
266 SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> operator>> (
const SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE>& b)
const;
271 NUMERIC_TYPE m_value;
275 template<
typename NUMERIC_TYPE,
typename SIGNED_TYPE>
277 operator<< (std::ostream& os, const SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> &val)
283 template<
typename NUMERIC_TYPE,
typename SIGNED_TYPE>
284 std::istream &
operator >> (std::istream &is,
const SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> &val)
291 typedef SequenceNumber<uint32_t, int32_t> SequenceNumber32;
292 typedef SequenceNumber<uint16_t, int16_t> SequenceNumber16;
std::istream & operator>>(std::istream &is, Angles &a)
NUMERIC_TYPE GetValue() const
Extracts the numeric value of the sequence number.
Generic "sequence number" class.
SequenceNumber(NUMERIC_TYPE value)
Constructs a SequenceNumber with the given value.