Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve MQTT_STD_XXX behavior #929

Merged
merged 6 commits into from
Apr 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/mqtt/broker/retained_topic_map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ class retained_topic_map {
void dump(Output &out) {
auto const& direct_index = map.template get<direct_index_tag>();
for (auto const& i : direct_index) {
out << i.parent_id << " " << i.name << " " << (i.value ? "init" : "-") << " " << i.count << std::endl;
out << i.parent_id << " " << i.name << " " << (i.value ? "init" : "-") << " " << i.count << '\n';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this replacement is needed ? Just avoid include ostream ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, seeing that this is the only use of ostream in this file and this function is a debug function.

}
}

Expand Down
19 changes: 4 additions & 15 deletions include/mqtt/broker/security.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/optional.hpp>
#include <boost/iterator/function_output_iterator.hpp>

#include <boost/algorithm/hex.hpp>
Expand Down Expand Up @@ -595,27 +594,17 @@ struct security {

if (is_hash(auth)) {
append_result(
string_view(
make_string_view(
subscription_begin,
static_cast<size_t>(
std::distance(
subscription_begin,
subscription_filter.end()
)
)
subscription_filter.end()
)
);
return result;
}

auto sub = string_view(
auto sub = make_string_view(
subscription_begin,
static_cast<size_t>(
std::distance(
subscription_begin,
subscription_next
)
)
subscription_next
);

if (is_hash(sub)) {
Expand Down
5 changes: 3 additions & 2 deletions include/mqtt/broker/topic_filter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ inline std::size_t topic_filter_tokenizer(string_view str, Output write) {
std::end(str),
[&write](string_view::const_iterator token_begin, string_view::const_iterator token_end) {
return write(
string_view(
make_string_view(
token_begin,
static_cast<std::size_t>(std::distance(token_begin, token_end)))
token_end
)
);
}
);
Expand Down
3 changes: 1 addition & 2 deletions include/mqtt/endpoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <atomic>
#include <algorithm>

#include <boost/any.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/asio.hpp>
#include <boost/lexical_cast.hpp>
Expand Down Expand Up @@ -149,7 +148,7 @@ constexpr bool check_qos_value(publish_options pubopts) {

template<typename ... Params>
constexpr bool should_generate_packet_id(Params const& ... params) {
#if __cplusplus >= 201703L // C++20 date is not determined yet
#if __cplusplus >= 201703L
return (check_qos_value(params) || ...); // defaults to false for empty.
#else // __cplusplus >= 201703L
const bool results[] = {false, check_qos_value(params)... };
Expand Down
6 changes: 3 additions & 3 deletions include/mqtt/shared_ptr_array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ using shared_ptr_array = std::shared_ptr<char []>;
using const_shared_ptr_array = std::shared_ptr<char const []>;

inline shared_ptr_array make_shared_ptr_array(std::size_t size) {
#if __cplusplus > 201703L // C++20 date is not determined yet
#if __cpp_lib_shared_ptr_arrays >= 201707L
return std::make_shared<char[]>(size);
#else // __cplusplus > 201703L
#else // __cpp_lib_shared_ptr_arrays >= 201707L
return std::shared_ptr<char[]>(new char[size]);
#endif // __cplusplus > 201703L
#endif // __cpp_lib_shared_ptr_arrays >= 201707L
}

} // namespace MQTT_NS
Expand Down
28 changes: 28 additions & 0 deletions include/mqtt/string_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#if !defined(MQTT_STRING_VIEW_HPP)
#define MQTT_STRING_VIEW_HPP

#include <iterator>

#include <mqtt/namespace.hpp>

#ifdef MQTT_STD_STRING_VIEW
Expand Down Expand Up @@ -75,4 +77,30 @@ using basic_string_view = boost::basic_string_ref<CharT, Traits>;

#endif // !defined(MQTT_STD_STRING_VIEW)

namespace MQTT_NS {

namespace detail {

template<class T>
T* to_address(T* p) noexcept
{
return p;
}

template<class T>
auto to_address(const T& p) noexcept
{
return detail::to_address(p.operator->());
}

} // namespace detail

// Make a string_view from a pair of iterators.
template<typename Begin, typename End>
string_view make_string_view(Begin begin, End end) {
return string_view(detail::to_address(begin), static_cast<string_view::size_type>(std::distance(begin, end)));
}

} // namespace MQTT_NS

#endif // MQTT_STRING_VIEW_HPP
2 changes: 1 addition & 1 deletion include/mqtt/v5_message.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <numeric>

#include <boost/asio/buffer.hpp>
#include <boost/optional.hpp>
#include <boost/container/static_vector.hpp>
#include <boost/numeric/conversion/cast.hpp>

Expand All @@ -37,6 +36,7 @@
#include <mqtt/packet_id_type.hpp>
#include <mqtt/move.hpp>
#include <mqtt/variant_visit.hpp>
#include <mqtt/optional.hpp>

#if !defined(MQTT_ALWAYS_SEND_REASON_CODE)
#define MQTT_ALWAYS_SEND_REASON_CODE false
Expand Down