2015-06-21 21:02:10 -07:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
/* Copyright (c) FIRST 2015. All Rights Reserved. */
|
|
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
|
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
#ifndef NT_SEQNUM_H_
|
|
|
|
|
#define NT_SEQNUM_H_
|
|
|
|
|
|
|
|
|
|
namespace NtImpl {
|
|
|
|
|
|
|
|
|
|
class SequenceNumber
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
explicit SequenceNumber(unsigned int val) : m_val(val) {}
|
|
|
|
|
unsigned int GetVal() const { return m_val; }
|
|
|
|
|
|
|
|
|
|
SequenceNumber& operator++()
|
|
|
|
|
{
|
|
|
|
|
++m_val;
|
|
|
|
|
if (m_val > 0xffff)
|
|
|
|
|
m_val = 0;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
SequenceNumber operator++(int)
|
|
|
|
|
{
|
|
|
|
|
SequenceNumber tmp(*this);
|
|
|
|
|
operator++();
|
|
|
|
|
return tmp;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-22 23:16:58 -07:00
|
|
|
friend bool operator< (const SequenceNumber& lhs,
|
|
|
|
|
const SequenceNumber& rhs);
|
|
|
|
|
friend bool operator> (const SequenceNumber& lhs,
|
|
|
|
|
const SequenceNumber& rhs);
|
|
|
|
|
friend bool operator<= (const SequenceNumber& lhs,
|
|
|
|
|
const SequenceNumber& rhs);
|
|
|
|
|
friend bool operator>= (const SequenceNumber& lhs,
|
|
|
|
|
const SequenceNumber& rhs);
|
|
|
|
|
friend bool operator== (const SequenceNumber& lhs,
|
|
|
|
|
const SequenceNumber& rhs);
|
|
|
|
|
friend bool operator!= (const SequenceNumber& lhs,
|
|
|
|
|
const SequenceNumber& rhs);
|
2015-06-21 21:02:10 -07:00
|
|
|
private:
|
|
|
|
|
unsigned int m_val;
|
|
|
|
|
};
|
|
|
|
|
|
2015-06-22 23:16:58 -07:00
|
|
|
bool operator< (const SequenceNumber& lhs, const SequenceNumber& rhs);
|
|
|
|
|
bool operator> (const SequenceNumber& lhs, const SequenceNumber& rhs);
|
2015-06-21 21:02:10 -07:00
|
|
|
|
2015-06-22 23:16:58 -07:00
|
|
|
inline bool operator<= (const SequenceNumber& lhs, const SequenceNumber& rhs)
|
2015-06-21 21:02:10 -07:00
|
|
|
{
|
|
|
|
|
return lhs == rhs || lhs < rhs;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-22 23:16:58 -07:00
|
|
|
inline bool operator>= (const SequenceNumber& lhs, const SequenceNumber& rhs)
|
2015-06-21 21:02:10 -07:00
|
|
|
{
|
|
|
|
|
return lhs == rhs || lhs > rhs;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-22 23:16:58 -07:00
|
|
|
inline bool operator== (const SequenceNumber& lhs, const SequenceNumber& rhs)
|
2015-06-21 21:02:10 -07:00
|
|
|
{
|
|
|
|
|
return lhs.m_val == rhs.m_val;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-22 23:16:58 -07:00
|
|
|
inline bool operator!= (const SequenceNumber& lhs, const SequenceNumber& rhs)
|
2015-06-21 21:02:10 -07:00
|
|
|
{
|
|
|
|
|
return lhs.m_val != rhs.m_val;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace NtImpl
|
|
|
|
|
|
|
|
|
|
#endif /* NT_SEQNUM_H_ */
|