Coverage Report

Created: 2022-08-24 06:19

/src/Fast-DDS/include/fastdds/rtps/common/Property.h
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 Property.h
17
 */
18
#ifndef _FASTDDS_RTPS_COMMON_PROPERTYQOS_H_
19
#define _FASTDDS_RTPS_COMMON_PROPERTYQOS_H_
20
21
#include <string>
22
#include <vector>
23
24
namespace eprosima {
25
namespace fastrtps {
26
namespace rtps {
27
28
class Property
29
{
30
public:
31
32
    Property()
33
0
    {
34
0
    }
35
36
    Property(
37
            const Property& property)
38
        : name_(property.name_)
39
        , value_(property.value_)
40
        , propagate_(property.propagate_)
41
0
    {
42
0
    }
43
44
    Property(
45
            Property&& property)
46
        : name_(std::move(property.name_))
47
        , value_(std::move(property.value_))
48
        , propagate_(property.propagate_)
49
0
    {
50
0
    }
51
52
    Property(
53
            const std::string& name,
54
            const std::string& value)
55
        : name_(name)
56
        , value_(value)
57
0
    {
58
0
    }
59
60
    Property(
61
            std::string&& name,
62
            std::string&& value)
63
        : name_(std::move(name))
64
        , value_(std::move(value))
65
0
    {
66
0
    }
67
68
    Property& operator =(
69
            const Property& property)
70
0
    {
71
0
        name_ = property.name_;
72
0
        value_ = property.value_;
73
0
        propagate_ = property.propagate_;
74
0
        return *this;
75
0
    }
76
77
    Property& operator =(
78
            Property&& property)
79
0
    {
80
0
        name_ = std::move(property.name_);
81
0
        value_ = std::move(property.value_);
82
0
        propagate_ = property.propagate_;
83
0
        return *this;
84
0
    }
85
86
    bool operator ==(
87
            const Property& b) const
88
0
    {
89
0
        return (this->name_ == b.name_) &&
90
0
               (this->value_ == b.value_);
91
0
    }
92
93
    void name(
94
            const std::string& name)
95
0
    {
96
0
        name_ = name;
97
0
    }
98
99
    void name(
100
            std::string&& name)
101
0
    {
102
0
        name_ = std::move(name);
103
0
    }
104
105
    const std::string& name() const
106
0
    {
107
0
        return name_;
108
0
    }
109
110
    std::string& name()
111
0
    {
112
0
        return name_;
113
0
    }
114
115
    void value(
116
            const std::string& value)
117
0
    {
118
0
        value_ = value;
119
0
    }
120
121
    void value(
122
            std::string&& value)
123
0
    {
124
0
        value_ = std::move(value);
125
0
    }
126
127
    const std::string& value() const
128
0
    {
129
0
        return value_;
130
0
    }
131
132
    std::string& value()
133
0
    {
134
0
        return value_;
135
0
    }
136
137
    void propagate(
138
            bool propagate)
139
0
    {
140
0
        propagate_ = propagate;
141
0
    }
142
143
    bool propagate() const
144
0
    {
145
0
        return propagate_;
146
0
    }
147
148
    bool& propagate()
149
0
    {
150
0
        return propagate_;
151
0
    }
152
153
private:
154
155
    std::string name_;
156
157
    std::string value_;
158
159
    bool propagate_ = false;
160
};
161
162
typedef std::vector<Property> PropertySeq;
163
164
class PropertyHelper
165
{
166
public:
167
168
    static size_t serialized_size(
169
            const Property& property,
170
            size_t current_alignment = 0)
171
0
    {
172
0
        if (property.propagate())
173
0
        {
174
0
            size_t initial_alignment = current_alignment;
175
0
176
0
            current_alignment += 4 + alignment(current_alignment, 4) + property.name().size() + 1;
177
0
            current_alignment += 4 + alignment(current_alignment, 4) + property.value().size() + 1;
178
0
179
0
            return current_alignment - initial_alignment;
180
0
        }
181
0
        else
182
0
        {
183
0
            return 0;
184
0
        }
185
0
    }
186
187
    static size_t serialized_size(
188
            const PropertySeq& properties,
189
            size_t current_alignment = 0)
190
0
    {
191
0
        size_t initial_alignment = current_alignment;
192
0
193
0
        current_alignment += 4 + alignment(current_alignment, 4);
194
0
        for (auto property = properties.begin(); property != properties.end(); ++property)
195
0
        {
196
0
            current_alignment += serialized_size(*property, current_alignment);
197
0
        }
198
0
199
0
        return current_alignment - initial_alignment;
200
0
    }
201
202
private:
203
204
    inline static size_t alignment(
205
            size_t current_alignment,
206
            size_t dataSize)
207
0
    {
208
0
        return (dataSize - (current_alignment % dataSize)) & (dataSize - 1);
209
0
    }
210
211
};
212
213
} //namespace eprosima
214
} //namespace fastrtps
215
} //namespace rtps
216
217
#endif // _FASTDDS_RTPS_COMMON_PROPERTYQOS_H_