24#ifndef __mqtt_properties_h
25#define __mqtt_properties_h
28#include "MQTTProperties.h"
31#include <initializer_list>
61 void copy(
const MQTTProperty& other);
134 explicit property(
const MQTTProperty& cprop) { copy(cprop); }
140 explicit property(MQTTProperty&& cprop) : prop_(cprop) {
141 memset(&cprop, 0,
sizeof(MQTTProperty));
174 const MQTTProperty&
c_struct()
const {
return prop_; }
209 return uint8_t(prop.
c_struct().value.byte);
218 return uint16_t(prop.
c_struct().value.integer2);
228[[deprecated(
"Integer properties are unsigned. Use get<uint16_t>()")]]
inline int16_t
230 return int16_t(prop.
c_struct().value.integer2);
239 return uint32_t(prop.
c_struct().value.integer4);
249[[deprecated(
"Integer properties are unsigned. Use get<uint32_t>()")]]
inline int32_t
251 return int32_t(prop.
c_struct().value.integer4);
260 return (!prop.
c_struct().value.data.data)
281 return std::make_tuple(std::move(name), std::move(value));
295 static constexpr MQTTProperties DFLT_C_STRUCT MQTTProperties_initializer;
298 MQTTProperties props_{DFLT_C_STRUCT};
300 template <
typename T>
303 template <
typename T>
310 const MQTTProperty* curr_;
311 mutable property prop_;
322 prop_ =
property{*curr_};
350 return curr_ != other.curr_;
369 std::memset(&other.props_, 0,
sizeof(MQTTProperties));
375 properties(
const MQTTProperties& cprops) { props_ = ::MQTTProperties_copy(&cprops); }
389 const MQTTProperties&
c_struct()
const {
return props_; }
407 bool empty()
const {
return props_.count == 0; }
414 return property{props_.array[i]};
421 const property at(
size_t i)
const {
422 if (i <
size_t(props_.count))
423 return property{props_.array[i]};
424 throw std::out_of_range{
"propery index"};
430 size_t size()
const {
return size_t(props_.count); }
459 void clear() { ::MQTTProperties_free(&props_); }
466 return ::MQTTProperties_hasProperty(
467 const_cast<MQTTProperties*
>(&props_), MQTTPropertyCodes(propid)
481 return size_t(::MQTTProperties_propertyCount(
482 const_cast<MQTTProperties*
>(&props_), MQTTPropertyCodes(propid)
509 MQTTProperty* prop = MQTTProperties_getPropertyAt(
510 const_cast<MQTTProperties*
>(&props.
c_struct()), MQTTPropertyCodes(propid),
int(idx)
527 return get<T>(props, propid, 0);
Definition properties.h:309
bool operator!=(const const_iterator &other) const noexcept
Definition properties.h:349
const_iterator & operator++() noexcept
Definition properties.h:338
const_iterator operator++(int) noexcept
Definition properties.h:329
const property & operator*() const
Definition properties.h:321
Definition properties.h:293
const property operator[](size_t i) const
Definition properties.h:413
bool contains(property::code propid) const
Definition properties.h:465
const property at(size_t i) const
Definition properties.h:421
properties(std::initializer_list< property > props)
const_iterator end() const
Definition properties.h:445
bool empty() const
Definition properties.h:407
const_iterator cend() const
Definition properties.h:450
properties()
Definition properties.h:358
size_t size() const
Definition properties.h:430
property get(property::code propid, size_t idx=0) const
properties(const properties &other)
Definition properties.h:363
~properties()
Definition properties.h:384
properties(const MQTTProperties &cprops)
Definition properties.h:375
properties & operator=(properties &&rhs)
friend T get(const properties &props, property::code propid, size_t idx)
Definition properties.h:508
void add(const property &prop)
Definition properties.h:455
size_t count(property::code propid) const
Definition properties.h:480
properties & operator=(const properties &rhs)
const MQTTProperties & c_struct() const
Definition properties.h:389
void clear()
Definition properties.h:459
const_iterator cbegin() const
Definition properties.h:440
properties(properties &&other)
Definition properties.h:368
const_iterator begin() const
Definition properties.h:435
Definition properties.h:55
property & operator=(const property &rhs)
const MQTTProperty & c_struct() const
Definition properties.h:174
code
Definition properties.h:70
@ MAXIMUM_QOS
Definition properties.h:91
@ WILL_DELAY_INTERVAL
Definition properties.h:83
@ SERVER_REFERENCE
Definition properties.h:86
@ TOPIC_ALIAS
Definition properties.h:90
@ PAYLOAD_FORMAT_INDICATOR
Definition properties.h:71
@ ASSIGNED_CLIENT_IDENTIFIER
Definition properties.h:78
@ RECEIVE_MAXIMUM
Definition properties.h:88
@ TOPIC_ALIAS_MAXIMUM
Definition properties.h:89
@ REQUEST_PROBLEM_INFORMATION
Definition properties.h:82
@ CONTENT_TYPE
Definition properties.h:73
@ AUTHENTICATION_DATA
Definition properties.h:81
@ RETAIN_AVAILABLE
Definition properties.h:92
@ RESPONSE_INFORMATION
Definition properties.h:85
@ REQUEST_RESPONSE_INFORMATION
Definition properties.h:84
@ SHARED_SUBSCRIPTION_AVAILABLE
Definition properties.h:97
@ REASON_STRING
Definition properties.h:87
@ SUBSCRIPTION_IDENTIFIER
Definition properties.h:76
@ SERVER_KEEP_ALIVE
Definition properties.h:79
@ WILDCARD_SUBSCRIPTION_AVAILABLE
Definition properties.h:95
@ SESSION_EXPIRY_INTERVAL
Definition properties.h:77
@ AUTHENTICATION_METHOD
Definition properties.h:80
@ MAXIMUM_PACKET_SIZE
Definition properties.h:94
@ RESPONSE_TOPIC
Definition properties.h:74
@ SUBSCRIPTION_IDENTIFIERS_AVAILABLE
Definition properties.h:96
@ MESSAGE_EXPIRY_INTERVAL
Definition properties.h:72
@ CORRELATION_DATA
Definition properties.h:75
@ USER_PROPERTY
Definition properties.h:93
const std::type_info & value_type_id()
code type() const
Definition properties.h:179
property & operator=(property &&rhs)
property(code c, int32_t val)
property(const property &other)
Definition properties.h:147
static PAHO_MQTTPP_EXPORT const std::map< code, std::string_view > TYPE_NAME
Definition properties.h:101
property(MQTTProperty &&cprop)
Definition properties.h:140
property(code c, uint32_t val)
Definition properties.h:116
property(const MQTTProperty &cprop)
Definition properties.h:134
property(property &&other)
property(code c, string_ref name, string_ref val)
std::string_view type_name() const
property(code c, string_ref val)
#define PAHO_MQTTPP_EXPORT
Definition export.h:40
Definition async_client.h:60
int16_t get< int16_t >(const property &prop)
Definition properties.h:229
T get(const property &)
Definition properties.h:199
string get< string >(const property &prop)
Definition properties.h:259
uint16_t get< uint16_t >(const property &prop)
Definition properties.h:217
std::bad_cast bad_cast
Definition exception.h:39
uint8_t get< uint8_t >(const property &prop)
Definition properties.h:208
std::string string
Definition types.h:43
std::tuple< string, string > string_pair
Definition properties.h:47
int32_t get< int32_t >(const property &prop)
Definition properties.h:250
std::ostream & operator<<(std::ostream &os, const buffer_ref< T > &buf)
Definition buffer_ref.h:286
string_pair get< string_pair >(const property &prop)
Definition properties.h:270
uint32_t get< uint32_t >(const property &prop)
Definition properties.h:238