-
Notifications
You must be signed in to change notification settings - Fork 446
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#524 Fixed copy and move operations for 'subscribe_options'. Added un…
…it tests.
- Loading branch information
1 parent
17e4ee1
commit 1e7d090
Showing
4 changed files
with
251 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,25 @@ | ||
///////////////////////////////////////////////////////////////////////////// | ||
/// @file response_options.h | ||
/// Implementation of the class 'response_options' | ||
/// @date 26-Aug-2016 | ||
/// @date 26-Aug-2019 | ||
///////////////////////////////////////////////////////////////////////////// | ||
|
||
/******************************************************************************* | ||
* Copyright (c) 2019-2025 Frank Pagliughi <[email protected]> | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* and Eclipse Distribution License v1.0 which accompany this distribution. | ||
* | ||
* The Eclipse Public License is available at | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
* and the Eclipse Distribution License is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
* | ||
* Contributors: | ||
* Frank Pagliughi - initial implementation and documentation | ||
*******************************************************************************/ | ||
|
||
#ifndef __mqtt_response_options_h | ||
#define __mqtt_response_options_h | ||
|
||
|
@@ -70,16 +86,26 @@ class response_options | |
* @param other The other options to copy to this one. | ||
*/ | ||
response_options(const response_options& other); | ||
/** | ||
* Move constructor. | ||
* @param other The other options to move into this one. | ||
*/ | ||
response_options(response_options&& other); | ||
/** | ||
* Copy operator. | ||
* @param rhs The other options to copy to this one. | ||
*/ | ||
response_options& operator=(const response_options& rhs); | ||
/** | ||
* Move operator. | ||
* @param rhs The other options to move into this one. | ||
*/ | ||
response_options& operator=(response_options&& rhs); | ||
/** | ||
* Expose the underlying C struct for the unit tests. | ||
*/ | ||
#if defined(UNIT_TESTS) | ||
const MQTTAsync_responseOptions& c_struct() const { return opts_; } | ||
const auto& c_struct() const { return opts_; } | ||
#endif | ||
/** | ||
* Sets the MQTT protocol version used for the response. | ||
|
@@ -112,6 +138,18 @@ class response_options | |
props_ = std::move(props); | ||
opts_.properties = props_.c_struct(); | ||
} | ||
/** | ||
* Gets the options for a single topic subscription. | ||
* @return The subscribe options. | ||
*/ | ||
subscribe_options get_subscribe_options() const { | ||
return subscribe_options{opts_.subscribeOptions}; | ||
} | ||
/** | ||
* Sets the options for a multi-topic subscription. | ||
* @return The vector of the subscribe options. | ||
*/ | ||
std::vector<subscribe_options> get_subscribe_many_options() const; | ||
/** | ||
* Sets the options for a single topic subscription. | ||
* @param opts The subscribe options. | ||
|
@@ -121,7 +159,15 @@ class response_options | |
* Sets the options for a multi-topic subscription. | ||
* @param opts A vector of the subscribe options. | ||
*/ | ||
void set_subscribe_options(const std::vector<subscribe_options>& opts); | ||
void set_subscribe_many_options(const std::vector<subscribe_options>& opts); | ||
/** | ||
* Sets the options for a multi-topic subscription. | ||
* @param opts A vector of the subscribe options. | ||
* @sa set_subscribe_options | ||
*/ | ||
void set_subscribe_options(const std::vector<subscribe_options>& opts) { | ||
set_subscribe_many_options(opts); | ||
} | ||
}; | ||
|
||
///////////////////////////////////////////////////////////////////////////// | ||
|
@@ -183,6 +229,14 @@ class response_options_builder | |
opts_.set_subscribe_options(opts); | ||
return *this; | ||
} | ||
/** | ||
* Sets the options for a multi-topic subscription. | ||
* @param opts A vector of the subscribe options. | ||
*/ | ||
auto subscribe_many_opts(const std::vector<subscribe_options>& opts) -> self& { | ||
opts_.set_subscribe_options(opts); | ||
return *this; | ||
} | ||
/** | ||
* Sets the options for a multi-topic subscription. | ||
* @param opts A vector of the subscribe options. | ||
|
@@ -192,8 +246,8 @@ class response_options_builder | |
return *this; | ||
} | ||
/** | ||
* Finish building the options and return them. | ||
* @return The option struct as built. | ||
* Finish building the response options and return them. | ||
* @return The response option struct as built. | ||
*/ | ||
response_options finalize() { return opts_; } | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
// response_options.cpp | ||
|
||
/******************************************************************************* | ||
* Copyright (c) 2019-2024 Frank Pagliughi <[email protected]> | ||
* Copyright (c) 2019-2025 Frank Pagliughi <[email protected]> | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
|
@@ -30,18 +30,43 @@ response_options:: | |
} | ||
|
||
response_options::response_options(const response_options& other) | ||
: opts_(other.opts_), tok_(other.tok_), props_(other.props_) | ||
: opts_{other.opts_}, tok_{other.tok_}, props_{other.props_}, subOpts_{other.subOpts_} | ||
{ | ||
update_c_struct(); | ||
} | ||
|
||
response_options::response_options(response_options&& other) | ||
: opts_{other.opts_}, | ||
tok_{std::move(other.tok_)}, | ||
props_{std::move(other.props_)}, | ||
subOpts_{std::move(other.subOpts_)} | ||
{ | ||
update_c_struct(); | ||
} | ||
|
||
response_options& response_options::operator=(const response_options& rhs) | ||
{ | ||
opts_ = rhs.opts_; | ||
tok_ = rhs.tok_; | ||
props_ = rhs.props_; | ||
if (&rhs != this) { | ||
opts_ = rhs.opts_; | ||
tok_ = rhs.tok_; | ||
props_ = rhs.props_; | ||
subOpts_ = rhs.subOpts_; | ||
|
||
update_c_struct(); | ||
update_c_struct(); | ||
} | ||
return *this; | ||
} | ||
|
||
response_options& response_options::operator=(response_options&& rhs) | ||
{ | ||
if (&rhs != this) { | ||
opts_ = rhs.opts_; | ||
tok_ = std::move(rhs.tok_); | ||
props_ = std::move(rhs.props_); | ||
subOpts_ = std::move(rhs.subOpts_); | ||
|
||
update_c_struct(); | ||
} | ||
return *this; | ||
} | ||
|
||
|
@@ -80,7 +105,14 @@ void response_options::set_subscribe_options(const subscribe_options& opts) | |
opts_.subscribeOptions = opts.opts_; | ||
} | ||
|
||
void response_options::set_subscribe_options(const std::vector<subscribe_options>& opts) | ||
std::vector<subscribe_options> response_options::get_subscribe_many_options() const | ||
{ | ||
std::vector<subscribe_options> opts; | ||
for (const auto& opt : subOpts_) opts.push_back(subscribe_options{opt}); | ||
return opts; | ||
} | ||
|
||
void response_options::set_subscribe_many_options(const std::vector<subscribe_options>& opts) | ||
{ | ||
subOpts_.clear(); | ||
for (const auto& opt : opts) subOpts_.push_back(opt.opts_); | ||
|
Oops, something went wrong.