Coverage Report

Created: 2026-03-15 06:44

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/opendnp3/cpp/lib/src/app/ClassField.cpp
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
#include "opendnp3/app/ClassField.h"
21
22
namespace opendnp3
23
{
24
25
ClassField ClassField::None()
26
9.36k
{
27
9.36k
    return ClassField();
28
9.36k
}
29
30
ClassField ClassField::AllClasses()
31
0
{
32
0
    return ClassField(ALL_CLASSES);
33
0
}
34
35
ClassField ClassField::AllEventClasses()
36
0
{
37
0
    return ClassField(EVENT_CLASSES);
38
0
}
39
40
9.36k
ClassField::ClassField() : bitfield(0) {}
41
42
0
ClassField::ClassField(PointClass pc) : bitfield(static_cast<uint8_t>(pc)) {}
43
44
ClassField::ClassField(EventClass ec)
45
1.00k
    : ClassField(false, ec == EventClass::EC1, ec == EventClass::EC2, ec == EventClass::EC3)
46
1.00k
{
47
1.00k
}
48
49
9.90k
ClassField::ClassField(bool class0, bool class1, bool class2, bool class3) : bitfield(0)
50
9.90k
{
51
9.90k
    bitfield = class0 ? ClassField::CLASS_0 : 0;
52
9.90k
    bitfield |= class1 ? ClassField::CLASS_1 : 0;
53
9.90k
    bitfield |= class2 ? ClassField::CLASS_2 : 0;
54
9.90k
    bitfield |= class3 ? ClassField::CLASS_3 : 0;
55
9.90k
}
56
57
0
ClassField::ClassField(uint8_t mask_) : bitfield(mask_ & ALL_CLASSES) {}
58
59
bool ClassField::IsEmpty() const
60
0
{
61
0
    return (bitfield == 0);
62
0
}
63
64
bool ClassField::Intersects(const ClassField& other) const
65
0
{
66
0
    return (bitfield & other.bitfield) != 0;
67
0
}
68
69
ClassField ClassField::OnlyEventClasses() const
70
0
{
71
0
    return ClassField(bitfield & EVENT_CLASSES);
72
0
}
73
74
void ClassField::Set(PointClass pc)
75
0
{
76
0
    bitfield |= static_cast<uint8_t>(pc);
77
0
}
78
79
void ClassField::Clear(const ClassField& field)
80
0
{
81
0
    bitfield &= ~(field.bitfield);
82
0
}
83
84
void ClassField::Set(const ClassField& field)
85
0
{
86
0
    bitfield |= field.bitfield;
87
0
}
88
89
bool ClassField::HasEventType(EventClass ec) const
90
0
{
91
0
    switch (ec)
92
0
    {
93
0
    case (EventClass::EC1):
94
0
        return HasClass1();
95
0
    case (EventClass::EC2):
96
0
        return HasClass2();
97
0
    case (EventClass::EC3):
98
0
        return HasClass3();
99
0
    default:
100
0
        return false;
101
0
    }
102
0
}
103
104
bool ClassField::HasClass0() const
105
0
{
106
0
    return (bitfield & CLASS_0) != 0;
107
0
}
108
109
bool ClassField::HasClass1() const
110
8.90k
{
111
8.90k
    return (bitfield & CLASS_1) != 0;
112
8.90k
}
113
114
bool ClassField::HasClass2() const
115
8.90k
{
116
8.90k
    return (bitfield & CLASS_2) != 0;
117
8.90k
}
118
119
bool ClassField::HasClass3() const
120
8.90k
{
121
8.90k
    return (bitfield & CLASS_3) != 0;
122
8.90k
}
123
124
bool ClassField::HasEventClass() const
125
0
{
126
0
    return (bitfield & EVENT_CLASSES) != 0;
127
0
}
128
129
bool ClassField::HasAnyClass() const
130
0
{
131
0
    return bitfield != 0;
132
0
}
133
134
} // namespace opendnp3