1
0
mirror of https://github.com/codership/wsrep-lib.git synced 2025-07-30 07:23:07 +03:00

Refactored seqno and id classes out of provider.hpp

This commit is contained in:
Teemu Ollakka
2018-06-12 10:20:58 +03:00
parent f506faa360
commit 97d9f93648
14 changed files with 242 additions and 150 deletions

74
include/wsrep/seqno.hpp Normal file
View File

@ -0,0 +1,74 @@
//
// Copyright (C) 2018 Codership Oy <info@codership.com>
//
#ifndef WSREP_SEQNO_HPP
#define WSREP_SEQNO_HPP
#include "exception.hpp"
#include <ostream>
namespace wsrep
{
/*! \class seqno
*
* Sequence number type.
*
* By convention, nil value is zero, negative values are not allowed.
* Relation operators are restricted to < and > on purpose to
* enforce correct use.
*/
class seqno
{
public:
seqno()
: seqno_()
{ }
explicit seqno(long long seqno)
: seqno_(seqno)
{
if (seqno_ < 0)
{
throw wsrep::runtime_error("Negative seqno given");
}
}
long long get() const
{
return seqno_;
}
bool nil() const
{
return (seqno_ == 0);
}
bool operator<(seqno other) const
{
return (seqno_ < other.seqno_);
}
bool operator>(seqno other) const
{
return (seqno_ > other.seqno_);
}
seqno operator+(seqno other) const
{
return (seqno(seqno_ + other.seqno_));
}
static seqno undefined() { return seqno(0); }
private:
long long seqno_;
};
static inline std::ostream& operator<<(std::ostream& os, wsrep::seqno seqno)
{
return (os << seqno.get());
}
}
#endif // WSREP_SEQNO_HPP