1 |
|
---|
2 | #ifndef SEQUENCENUMBER_H
|
---|
3 | #define SEQUENCENUMBER_H
|
---|
4 |
|
---|
5 | #include <stdint.h>
|
---|
6 | #include <iostream>
|
---|
7 |
|
---|
8 | // random
|
---|
9 | #include <boost/random/mersenne_twister.hpp>
|
---|
10 | #include <boost/random/uniform_int.hpp>
|
---|
11 |
|
---|
12 | namespace ariba {
|
---|
13 | namespace overlay {
|
---|
14 |
|
---|
15 | #define MIN_SEQ_NUM 100
|
---|
16 | #define SEQ_NUM_DISABLED 0
|
---|
17 |
|
---|
18 | class SequenceNumber
|
---|
19 | {
|
---|
20 | public:
|
---|
21 | static const SequenceNumber DISABLED;
|
---|
22 |
|
---|
23 | /// constructors
|
---|
24 | SequenceNumber();
|
---|
25 | SequenceNumber(uint32_t seqnum);
|
---|
26 | SequenceNumber(uint64_t seqnum);
|
---|
27 |
|
---|
28 | /// factories
|
---|
29 | static SequenceNumber createRandomSeqNum_Short();
|
---|
30 | static SequenceNumber createRandomSeqNum_Long();
|
---|
31 |
|
---|
32 |
|
---|
33 | /// get type information
|
---|
34 | bool isShortSeqNum() const;
|
---|
35 | bool isLongSeqNum() const;
|
---|
36 | bool isDisabled() const;
|
---|
37 | bool isValid() const;
|
---|
38 |
|
---|
39 |
|
---|
40 | /// operators
|
---|
41 | void increment();
|
---|
42 |
|
---|
43 | /// NOTE: this is also »true« if the long seq_num matches the short seq_num
|
---|
44 | bool operator== (const SequenceNumber& rhs) const;
|
---|
45 |
|
---|
46 | /// NOTE: return value is only meaningful if »isValid() == true« for both values
|
---|
47 | bool operator< (const SequenceNumber& rhs) const;
|
---|
48 |
|
---|
49 | bool isSuccessor(const SequenceNumber& rhs);
|
---|
50 | bool isPredecessor(const SequenceNumber& rhs);
|
---|
51 |
|
---|
52 |
|
---|
53 | /// getter
|
---|
54 | uint32_t getShortSeqNum() const;
|
---|
55 | uint64_t getLongSeqNum() const;
|
---|
56 |
|
---|
57 |
|
---|
58 | /// to string
|
---|
59 | friend std::ostream& operator<< (std::ostream& stream, const SequenceNumber& rhs);
|
---|
60 |
|
---|
61 | private:
|
---|
62 | uint32_t seqnum_32;
|
---|
63 | uint64_t seqnum_64;
|
---|
64 |
|
---|
65 | /// static random_number_generator
|
---|
66 | static boost::mt19937 rng_32bit;
|
---|
67 | static boost::uniform_int<uint32_t> seqnum_distribution_32bit;
|
---|
68 |
|
---|
69 | // XXX NOTE: on later boost versions these are:
|
---|
70 | // boost::random::mt19937
|
---|
71 | // boost::random::uniform_int_distribution<>
|
---|
72 |
|
---|
73 | // NOTE: since the mt19937_64 is not available in this boost version, we
|
---|
74 | // need an addition distribution
|
---|
75 | static boost::uniform_int<uint32_t> distribution_full32bit;
|
---|
76 | };
|
---|
77 |
|
---|
78 |
|
---|
79 | }} // [namespace ariba::overlay]
|
---|
80 |
|
---|
81 | #endif // SEQUENCENUMBER_H
|
---|