Coverage Report

Created: 2026-01-17 06:53

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/opendnp3/cpp/lib/src/SequenceNum.h
Line
Count
Source
1
/*
2
 * Copyright 2013-2022 Step Function I/O, LLC
3
 *
4
 * Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
5
 * LLC (https://stepfunc.io) under one or more contributor license agreements.
6
 * See the NOTICE file distributed with this work for additional information
7
 * regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
8
 * this file to you under the Apache License, Version 2.0 (the "License"); you
9
 * may not use this file except in compliance with the License. You may obtain
10
 * a copy of the License at:
11
 *
12
 * http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20
#ifndef OPENDNP3_SEQUENCENUM_H
21
#define OPENDNP3_SEQUENCENUM_H
22
23
namespace opendnp3
24
{
25
26
/** represents a sequence number
27
 */
28
template<class T, T Modulus> class SequenceNum
29
{
30
    inline static T Next(T seq)
31
38.5k
    {
32
38.5k
        return (seq + 1) % Modulus;
33
38.5k
    }
34
35
public:
36
    uint8_t Get() const
37
0
    {
38
0
        return this->seq;
39
0
    }
40
41
    operator uint8_t() const
42
2.07k
    {
43
2.07k
        return this->seq;
44
2.07k
    }
45
46
7.46k
    SequenceNum() : seq(0) {}
47
48
38.5k
    SequenceNum(T value) : seq(value) {}
49
50
    bool Equals(T other) const
51
    {
52
        return other == this->seq;
53
    }
54
55
    void Increment()
56
38.5k
    {
57
38.5k
        this->seq = Next(this->seq);
58
38.5k
    }
59
60
    void Reset()
61
    {
62
        this->seq = 0;
63
    }
64
65
    SequenceNum Next() const
66
    {
67
        return SequenceNum(Next(seq));
68
    }
69
70
protected:
71
    T seq;
72
};
73
74
} // namespace opendnp3
75
76
#endif