Coverage Report

Created: 2022-08-24 06:19

/src/Fast-DDS/include/fastdds/rtps/common/Token.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 Token.h
17
 */
18
#ifndef _FASTDDS_RTPS_COMMON_TOKEN_H_
19
#define _FASTDDS_RTPS_COMMON_TOKEN_H_
20
21
#include <fastrtps/fastrtps_dll.h>
22
#include <fastdds/rtps/common/Property.h>
23
#include <fastdds/rtps/common/BinaryProperty.h>
24
25
namespace eprosima {
26
namespace fastrtps {
27
namespace rtps {
28
29
class DataHolder
30
{
31
    public:
32
33
0
        DataHolder() {}
34
35
        DataHolder(const DataHolder& data_holder) :
36
            class_id_(data_holder.class_id_),
37
            properties_(data_holder.properties_),
38
0
            binary_properties_(data_holder.binary_properties_) {}
39
40
        DataHolder(DataHolder&& data_holder) :
41
            class_id_(data_holder.class_id_),
42
            properties_(data_holder.properties_),
43
0
            binary_properties_(data_holder.binary_properties_) {}
44
45
        DataHolder& operator=(const DataHolder& data_holder)
46
0
        {
47
0
            class_id_ = data_holder.class_id_;
48
0
            properties_ = data_holder.properties_;
49
0
            binary_properties_ = data_holder.binary_properties_;
50
0
51
0
            return *this;
52
0
        }
53
54
        DataHolder& operator=(DataHolder&& data_holder)
55
0
        {
56
0
            class_id_ = std::move(data_holder.class_id_);
57
0
            properties_ = std::move(data_holder.properties_);
58
0
            binary_properties_ = std::move(data_holder.binary_properties_);
59
0
60
0
            return *this;
61
0
        }
62
63
        bool is_nil() const
64
0
        {
65
0
            return class_id_.empty();
66
0
        }
67
68
        void class_id(const std::string& class_id)
69
0
        {
70
0
            class_id_ = class_id;
71
0
        }
72
73
        void class_id(std::string&& class_id)
74
0
        {
75
0
            class_id_ = std::move(class_id);
76
0
        }
77
78
        std::string& class_id()
79
0
        {
80
0
            return class_id_;
81
0
        }
82
83
        const std::string& class_id() const
84
0
        {
85
0
            return class_id_;
86
0
        }
87
88
        const PropertySeq& properties() const
89
0
        {
90
0
            return properties_;
91
0
        }
92
93
        PropertySeq& properties()
94
0
        {
95
0
            return properties_;
96
0
        }
97
98
        const BinaryPropertySeq& binary_properties() const
99
0
        {
100
0
            return binary_properties_;
101
0
        }
102
103
        BinaryPropertySeq& binary_properties()
104
0
        {
105
0
            return binary_properties_;
106
0
        }
107
108
    private:
109
110
        std::string class_id_;
111
112
        PropertySeq properties_;
113
114
        BinaryPropertySeq binary_properties_;
115
};
116
117
typedef std::vector<DataHolder> DataHolderSeq;
118
typedef DataHolder Token;
119
typedef Token IdentityToken;
120
typedef Token IdentityStatusToken;
121
typedef Token PermissionsToken;
122
typedef Token AuthenticatedPeerCredentialToken;
123
typedef Token PermissionsCredentialToken;
124
125
class DataHolderHelper
126
{
127
    public:
128
129
        static std::string* find_property_value(DataHolder& data_holder, const std::string& name);
130
131
        static const std::string* find_property_value(const DataHolder& data_holder, const std::string& name);
132
133
        static Property* find_property(DataHolder& data_holder, const std::string& name);
134
135
        static const Property* find_property(const DataHolder& data_holder, const std::string& name);
136
137
        static std::vector<uint8_t>* find_binary_property_value(DataHolder& data_holder, const std::string& name);
138
139
        static const std::vector<uint8_t>* find_binary_property_value(const DataHolder& data_holder, const std::string& name);
140
141
        static BinaryProperty* find_binary_property(DataHolder& data_holder, const std::string& name);
142
143
        static const BinaryProperty* find_binary_property(const DataHolder& data_holder, const std::string& name);
144
145
        static size_t serialized_size(const DataHolder& data_holder, size_t current_alignment = 0);
146
147
        static size_t serialized_size(const DataHolderSeq& data_holders, size_t current_alignment = 0);
148
149
    private:
150
151
0
        inline static size_t alignment(size_t current_alignment, size_t dataSize) { return (dataSize - (current_alignment % dataSize)) & (dataSize-1);}
152
};
153
154
} //namespace rtps
155
} //namespace fastrtps
156
} //namespace eprosima
157
158
#endif // _FASTDDS_RTPS_COMMON_TOKEN_H_