Coverage Report

Created: 2025-06-13 06:46

/src/Fast-DDS/include/fastdds/rtps/common/Token.hpp
Line
Count
Source (jump to first uncovered line)
1
// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
/*!
16
 * @file Token.hpp
17
 */
18
#ifndef FASTDDS_RTPS_COMMON__TOKEN_HPP
19
#define FASTDDS_RTPS_COMMON__TOKEN_HPP
20
21
#include <fastdds/fastdds_dll.hpp>
22
#include <fastdds/rtps/common/Property.hpp>
23
#include <fastdds/rtps/common/BinaryProperty.hpp>
24
25
namespace eprosima {
26
namespace fastdds {
27
namespace rtps {
28
29
class DataHolder
30
{
31
public:
32
33
    DataHolder()
34
0
    {
35
0
    }
36
37
    DataHolder(
38
            const DataHolder& data_holder)
39
0
        : class_id_(data_holder.class_id_)
40
0
        , properties_(data_holder.properties_)
41
0
        , binary_properties_(data_holder.binary_properties_)
42
0
    {
43
0
    }
44
45
    DataHolder(
46
            DataHolder&& data_holder)
47
        : class_id_(data_holder.class_id_)
48
        , properties_(data_holder.properties_)
49
        , binary_properties_(data_holder.binary_properties_)
50
0
    {
51
0
    }
52
53
    DataHolder& operator =(
54
            const DataHolder& data_holder)
55
0
    {
56
0
        class_id_ = data_holder.class_id_;
57
0
        properties_ = data_holder.properties_;
58
0
        binary_properties_ = data_holder.binary_properties_;
59
0
60
0
        return *this;
61
0
    }
62
63
    DataHolder& operator =(
64
            DataHolder&& data_holder)
65
0
    {
66
0
        class_id_ = std::move(data_holder.class_id_);
67
0
        properties_ = std::move(data_holder.properties_);
68
0
        binary_properties_ = std::move(data_holder.binary_properties_);
69
0
70
0
        return *this;
71
0
    }
72
73
    bool is_nil() const
74
0
    {
75
0
        return class_id_.empty();
76
0
    }
77
78
    void class_id(
79
            const std::string& class_id)
80
0
    {
81
0
        class_id_ = class_id;
82
0
    }
83
84
    void class_id(
85
            std::string&& class_id)
86
0
    {
87
0
        class_id_ = std::move(class_id);
88
0
    }
89
90
    std::string& class_id()
91
0
    {
92
0
        return class_id_;
93
0
    }
94
95
    const std::string& class_id() const
96
0
    {
97
0
        return class_id_;
98
0
    }
99
100
    const PropertySeq& properties() const
101
0
    {
102
0
        return properties_;
103
0
    }
104
105
    PropertySeq& properties()
106
0
    {
107
0
        return properties_;
108
0
    }
109
110
    const BinaryPropertySeq& binary_properties() const
111
0
    {
112
0
        return binary_properties_;
113
0
    }
114
115
    BinaryPropertySeq& binary_properties()
116
0
    {
117
0
        return binary_properties_;
118
0
    }
119
120
private:
121
122
    std::string class_id_;
123
124
    PropertySeq properties_;
125
126
    BinaryPropertySeq binary_properties_;
127
};
128
129
typedef std::vector<DataHolder> DataHolderSeq;
130
typedef DataHolder Token;
131
typedef Token IdentityToken;
132
typedef Token IdentityStatusToken;
133
typedef Token PermissionsToken;
134
typedef Token AuthenticatedPeerCredentialToken;
135
typedef Token PermissionsCredentialToken;
136
137
class DataHolderHelper
138
{
139
public:
140
141
    static std::string* find_property_value(
142
            DataHolder& data_holder,
143
            const std::string& name);
144
145
    static const std::string* find_property_value(
146
            const DataHolder& data_holder,
147
            const std::string& name);
148
149
    static Property* find_property(
150
            DataHolder& data_holder,
151
            const std::string& name);
152
153
    static const Property* find_property(
154
            const DataHolder& data_holder,
155
            const std::string& name);
156
157
    static std::vector<uint8_t>* find_binary_property_value(
158
            DataHolder& data_holder,
159
            const std::string& name);
160
161
    static const std::vector<uint8_t>* find_binary_property_value(
162
            const DataHolder& data_holder,
163
            const std::string& name);
164
165
    static BinaryProperty* find_binary_property(
166
            DataHolder& data_holder,
167
            const std::string& name);
168
169
    static const BinaryProperty* find_binary_property(
170
            const DataHolder& data_holder,
171
            const std::string& name);
172
173
    static size_t serialized_size(
174
            const DataHolder& data_holder,
175
            size_t current_alignment = 0);
176
177
    static size_t serialized_size(
178
            const DataHolderSeq& data_holders,
179
            size_t current_alignment = 0);
180
181
private:
182
183
    inline static size_t alignment(
184
            size_t current_alignment,
185
            size_t dataSize)
186
0
    {
187
0
        return (dataSize - (current_alignment % dataSize)) & (dataSize - 1);
188
0
    }
189
190
};
191
192
} //namespace rtps
193
} //namespace fastdds
194
} //namespace eprosima
195
196
#endif // FASTDDS_RTPS_COMMON__TOKEN_HPP