1 /*
2  * Copyright (C) 2018 Codership Oy <info@codership.com>
3  *
4  * This file is part of wsrep-lib.
5  *
6  * Wsrep-lib is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * Wsrep-lib is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with wsrep-lib.  If not, see <https://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef WSREP_SEQNO_HPP
21 #define WSREP_SEQNO_HPP
22 
23 #include <iosfwd>
24 
25 namespace wsrep
26 {
27     /** @class seqno
28      *
29      * Sequence number type.
30      */
31     class seqno
32     {
33     public:
34         typedef long long native_type;
35 
seqno()36         seqno()
37             : seqno_(-1)
38         { }
39 
seqno(long long seqno)40         explicit seqno(long long seqno)
41             : seqno_(seqno)
42         { }
43 
get() const44         long long get() const
45         {
46             return seqno_;
47         }
48 
is_undefined() const49         bool is_undefined() const
50         {
51             return (seqno_ == -1);
52         }
53 
operator <(seqno other) const54         bool operator<(seqno other) const
55         {
56             return (seqno_ < other.seqno_);
57         }
58 
operator >(seqno other) const59         bool operator>(seqno other) const
60         {
61             return (seqno_ > other.seqno_);
62         }
63 
operator <=(seqno other) const64         bool operator<=(seqno other) const
65         {
66             return !(seqno_ > other.seqno_);
67         }
68 
operator >=(seqno other) const69         bool operator>=(seqno other) const
70         {
71             return !(seqno_ < other.seqno_);
72         }
73 
operator ==(seqno other) const74         bool operator==(seqno other) const
75         {
76             return (seqno_ == other.seqno_);
77         }
operator !=(seqno other) const78         bool operator!=(seqno other) const
79         {
80             return !(seqno_ == other.seqno_);
81         }
operator +(seqno other) const82         seqno operator+(seqno other) const
83         {
84             return (seqno(seqno_ + other.seqno_));
85         }
operator +(long long other) const86         seqno operator+(long long other) const
87         {
88             return (*this + seqno(other));
89         }
undefined()90         static seqno undefined() { return seqno(-1); }
91 
92     private:
93         native_type seqno_;
94     };
95 
96     std::ostream& operator<<(std::ostream& os, wsrep::seqno seqno);
97 }
98 
99 #endif // WSREP_SEQNO_HPP
100