@@ -30,149 +30,189 @@ namespace rtps {
3030
3131class BinaryProperty
3232{
33- public:
34-
35- BinaryProperty () : propagate_(false ) {}
36-
37- BinaryProperty (const BinaryProperty& property) :
38- name_ (property.name_),
39- value_ (property.value_),
40- propagate_ (property.propagate_) {}
41-
42- BinaryProperty (BinaryProperty&& property) :
43- name_ (std::move(property.name_)),
44- value_ (std::move(property.value_)),
45- propagate_ (property.propagate_) {}
46-
47- BinaryProperty (const std::string& name,
48- const std::vector<uint8_t >& value) :
49- name_ (name), value_(value) {}
50-
51- BinaryProperty (std::string&& name,
52- std::vector<uint8_t >&& value) :
53- name_ (std::move(name)), value_(std::move(value)) {}
54-
55- BinaryProperty& operator =(const BinaryProperty& property)
56- {
57- name_ = property.name_ ;
58- value_ = property.value_ ;
59- propagate_ = property.propagate_ ;
60- return *this ;
61- }
62-
63- BinaryProperty& operator =(BinaryProperty&& property)
64- {
65- name_ = std::move (property.name_ );
66- value_ = std::move (property.value_ );
67- propagate_ = property.propagate_ ;
68- return *this ;
69- }
70-
71- bool operator ==(const BinaryProperty& b) const
72- {
73- return (this ->name_ == b.name_ ) &&
74- (this ->value_ == b.value_ );
75- }
76-
77- void name (const std::string& name)
78- {
79- name_ = name;
80- }
81-
82- void name (std::string&& name)
83- {
84- name_ = std::move (name);
85- }
86-
87- const std::string& name () const
88- {
89- return name_;
90- }
91-
92- std::string& name ()
93- {
94- return name_;
95- }
96-
97- void value (const std::vector<uint8_t >& value)
98- {
99- value_ = value;
100- }
101-
102- void value (std::vector<uint8_t >&& value)
103- {
104- value_ = std::move (value);
105- }
106-
107- const std::vector<uint8_t >& value () const
108- {
109- return value_;
110- }
111-
112- std::vector<uint8_t >& value ()
113- {
114- return value_;
115- }
116-
117- void propagate (bool propagate)
118- {
119- propagate_ = propagate;
120- }
121-
122- bool propagate () const
123- {
124- return propagate_;
125- }
126-
127- bool & propagate ()
128- {
129- return propagate_;
130- }
131-
132- private:
133-
134- std::string name_;
135-
136- std::vector<uint8_t > value_;
137-
138- bool propagate_;
33+ public:
34+
35+ BinaryProperty ()
36+ : propagate_(false )
37+ {
38+ }
39+
40+ BinaryProperty (
41+ const BinaryProperty& property)
42+ : name_(property.name_)
43+ , value_(property.value_)
44+ , propagate_(property.propagate_)
45+ {
46+ }
47+
48+ BinaryProperty (
49+ BinaryProperty&& property)
50+ : name_(std::move(property.name_))
51+ , value_(std::move(property.value_))
52+ , propagate_(property.propagate_)
53+ {
54+ }
55+
56+ BinaryProperty (
57+ const std::string& name,
58+ const std::vector<uint8_t >& value)
59+ : name_(name)
60+ , value_(value)
61+ {
62+ }
63+
64+ BinaryProperty (
65+ std::string&& name,
66+ std::vector<uint8_t >&& value)
67+ : name_(std::move(name))
68+ , value_(std::move(value))
69+ {
70+ }
71+
72+ BinaryProperty& operator =(
73+ const BinaryProperty& property)
74+ {
75+ name_ = property.name_ ;
76+ value_ = property.value_ ;
77+ propagate_ = property.propagate_ ;
78+ return *this ;
79+ }
80+
81+ BinaryProperty& operator =(
82+ BinaryProperty&& property)
83+ {
84+ name_ = std::move (property.name_ );
85+ value_ = std::move (property.value_ );
86+ propagate_ = property.propagate_ ;
87+ return *this ;
88+ }
89+
90+ bool operator ==(
91+ const BinaryProperty& b) const
92+ {
93+ return (this ->name_ == b.name_ ) &&
94+ (this ->value_ == b.value_ );
95+ }
96+
97+ void name (
98+ const std::string& name)
99+ {
100+ name_ = name;
101+ }
102+
103+ void name (
104+ std::string&& name)
105+ {
106+ name_ = std::move (name);
107+ }
108+
109+ const std::string& name () const
110+ {
111+ return name_;
112+ }
113+
114+ std::string& name ()
115+ {
116+ return name_;
117+ }
118+
119+ void value (
120+ const std::vector<uint8_t >& value)
121+ {
122+ value_ = value;
123+ }
124+
125+ void value (
126+ std::vector<uint8_t >&& value)
127+ {
128+ value_ = std::move (value);
129+ }
130+
131+ const std::vector<uint8_t >& value () const
132+ {
133+ return value_;
134+ }
135+
136+ std::vector<uint8_t >& value ()
137+ {
138+ return value_;
139+ }
140+
141+ void propagate (
142+ bool propagate)
143+ {
144+ propagate_ = propagate;
145+ }
146+
147+ bool propagate () const
148+ {
149+ return propagate_;
150+ }
151+
152+ bool & propagate ()
153+ {
154+ return propagate_;
155+ }
156+
157+ private:
158+
159+ std::string name_;
160+
161+ std::vector<uint8_t > value_;
162+
163+ bool propagate_;
139164};
140165
141166typedef std::vector<BinaryProperty> BinaryPropertySeq;
142167
143168class BinaryPropertyHelper
144169{
145- public:
170+ public:
146171
147- static size_t serialized_size (const BinaryProperty& binary_property, size_t current_alignment = 0 )
172+ static size_t serialized_size (
173+ const BinaryProperty& binary_property,
174+ size_t current_alignment = 0 )
175+ {
176+ if (binary_property.propagate ())
148177 {
149- if (binary_property.propagate ())
150- {
151- size_t initial_alignment = current_alignment;
178+ size_t initial_alignment = current_alignment;
152179
153- current_alignment += 4 + alignment (current_alignment, 4 ) + binary_property.name ().size () + 1 ;
154- current_alignment += 4 + alignment (current_alignment, 4 ) + binary_property.value ().size ();
180+ current_alignment += 4 + alignment (current_alignment, 4 ) + binary_property.name ().size () + 1 ;
181+ current_alignment += 4 + alignment (current_alignment, 4 ) + binary_property.value ().size ();
155182
156- return current_alignment - initial_alignment;
157- }
158- else
159- return 0 ;
183+ return current_alignment - initial_alignment;
160184 }
161-
162- static size_t serialized_size (const BinaryPropertySeq& binary_properties, size_t current_alignment = 0 )
185+ else
163186 {
164- size_t initial_alignment = current_alignment;
187+ return 0 ;
188+ }
189+ }
165190
166- current_alignment += 4 + alignment (current_alignment, 4 );
167- for (auto binary_property = binary_properties.begin (); binary_property != binary_properties.end (); ++binary_property)
168- current_alignment += serialized_size (*binary_property, current_alignment);
191+ static size_t serialized_size (
192+ const BinaryPropertySeq& binary_properties,
193+ size_t current_alignment = 0 )
194+ {
195+ size_t initial_alignment = current_alignment;
169196
170- return current_alignment - initial_alignment;
197+ current_alignment += 4 + alignment (current_alignment, 4 );
198+ for (auto binary_property = binary_properties.begin (); binary_property != binary_properties.end ();
199+ ++binary_property)
200+ {
201+ current_alignment += serialized_size (*binary_property, current_alignment);
171202 }
172203
173- private:
204+ return current_alignment - initial_alignment;
205+ }
206+
207+ private:
208+
209+ inline static size_t alignment (
210+ size_t current_alignment,
211+ size_t dataSize)
212+ {
213+ return (dataSize - (current_alignment % dataSize)) & (dataSize - 1 );
214+ }
174215
175- inline static size_t alignment (size_t current_alignment, size_t dataSize) { return (dataSize - (current_alignment % dataSize)) & (dataSize-1 );}
176216};
177217
178218} // namespace rtps
0 commit comments