18#ifndef FASTDDS_RTPS_COMMON__PROPERTY_HPP
19#define FASTDDS_RTPS_COMMON__PROPERTY_HPP
40 : name_(property.name_)
41 , value_(property.value_)
42 , propagate_(property.propagate_)
48 : name_(
std::move(property.name_))
49 , value_(
std::move(property.value_))
50 , propagate_(property.propagate_)
55 const std::string&
name,
56 const std::string&
value,
77 name_ =
property.name_;
78 value_ =
property.value_;
79 propagate_ =
property.propagate_;
86 name_ = std::move(property.name_);
87 value_ = std::move(property.value_);
88 propagate_ =
property.propagate_;
95 return (this->name_ == b.name_) &&
96 (this->value_ == b.value_);
100 const std::string&
name)
108 name_ = std::move(
name);
111 const std::string&
name()
const
122 const std::string&
value)
130 value_ = std::move(
value);
165 bool propagate_ =
false;
176 size_t current_alignment = 0)
180 size_t initial_alignment = current_alignment;
182 current_alignment += 4 + alignment(current_alignment, 4) +
property.name().size() + 1;
183 current_alignment += 4 + alignment(current_alignment, 4) +
property.value().size() + 1;
185 return current_alignment - initial_alignment;
195 size_t current_alignment = 0)
197 size_t initial_alignment = current_alignment;
199 current_alignment += 4 + alignment(current_alignment, 4);
200 for (
auto property = properties.begin(); property != properties.end(); ++property)
205 return current_alignment - initial_alignment;
210 inline static size_t alignment(
211 size_t current_alignment,
214 return (dataSize - (current_alignment % dataSize)) & (dataSize - 1);
235 template<
typename exception_t>
238 const bool& check_upper_bound,
239 const int& upper_bound,
240 const bool& check_lower_bound,
241 const int& lower_bound,
242 const exception_t& exception)
245 std::function<
int(
const Property& property)>(
248 return std::stoi(property.
value());
272 template<
typename exception_t>
275 const bool& check_upper_bound,
276 const double& upper_bound,
277 const bool& check_lower_bound,
278 const double& lower_bound,
279 const exception_t& exception)
282 std::function<
double(
const Property& property)>(
285 return std::stod(property.
value());
298 template <
typename value_t,
299 typename exception_t>
300 inline static value_t parse_value(
301 const std::function<value_t(
const Property&)>& conversor,
303 const bool& check_upper_bound,
304 const value_t& upper_bound,
305 const bool& check_lower_bound,
306 const value_t& lower_bound,
307 const exception_t& exception)
311 value_t converted_value = conversor(property);
313 if (check_lower_bound && converted_value < lower_bound)
315 throw exception_t(
"Value '" + property.
value() +
316 "' for " + property.
name() +
" must be greater or equal to " +
317 std::to_string(lower_bound));
320 if (check_upper_bound && converted_value > upper_bound)
322 throw exception_t(
"Value '" + property.
value() +
323 "' for " + property.
name() +
" must be lower or equal to " +
324 std::to_string(upper_bound));
327 return converted_value;
329 catch (
const std::invalid_argument&)
333 catch (
const std::out_of_range&)
Definition Property.hpp:171
static size_t serialized_size(const PropertySeq &properties, size_t current_alignment=0)
Definition Property.hpp:193
static size_t serialized_size(const Property &property, size_t current_alignment=0)
Definition Property.hpp:174
Definition Property.hpp:31
Property & operator=(const Property &property)
Definition Property.hpp:74
void name(std::string &&name)
Definition Property.hpp:105
const std::string & name() const
Definition Property.hpp:111
Property(std::string &&name, std::string &&value, bool propagate=false)
Definition Property.hpp:64
void value(const std::string &value)
Definition Property.hpp:121
std::string & value()
Definition Property.hpp:138
Property()
Definition Property.hpp:34
const std::string & value() const
Definition Property.hpp:133
Property(const std::string &name, const std::string &value, bool propagate=false)
Definition Property.hpp:54
std::string & name()
Definition Property.hpp:116
void value(std::string &&value)
Definition Property.hpp:127
bool & propagate()
Definition Property.hpp:154
Property(const Property &property)
Definition Property.hpp:38
void name(const std::string &name)
Definition Property.hpp:99
Property(Property &&property)
Definition Property.hpp:46
bool propagate() const
Definition Property.hpp:149
void propagate(bool propagate)
Definition Property.hpp:143
bool operator==(const Property &b) const
Definition Property.hpp:92
std::vector< Property > PropertySeq
Definition Property.hpp:168
Definition EntityId_t.hpp:388
Definition Property.hpp:220
static double as_double(const Property &property, const bool &check_upper_bound, const double &upper_bound, const bool &check_lower_bound, const double &lower_bound, const exception_t &exception)
Parse a property value as a double.
Definition Property.hpp:273
static int as_int(const Property &property, const bool &check_upper_bound, const int &upper_bound, const bool &check_lower_bound, const int &lower_bound, const exception_t &exception)
Parse a property value as an integer.
Definition Property.hpp:236