From 062df65b1eeb40961233a266df2f3043e81cf012 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 27 Jun 2022 17:25:43 +0200 Subject: [PATCH] lib/dbus: use std::span --- src/lib/dbus/AppendIter.hxx | 11 ++++------- src/lib/dbus/ReadIter.hxx | 10 ++++------ src/lib/dbus/UDisks2.cxx | 3 ++- src/lib/dbus/Values.hxx | 9 +++------ 4 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/lib/dbus/AppendIter.hxx b/src/lib/dbus/AppendIter.hxx index b3dc28747..bfad53c92 100644 --- a/src/lib/dbus/AppendIter.hxx +++ b/src/lib/dbus/AppendIter.hxx @@ -30,8 +30,7 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef ODBUS_APPEND_ITER_HXX -#define ODBUS_APPEND_ITER_HXX +#pragma once #include "Iter.hxx" #include "Values.hxx" @@ -88,12 +87,12 @@ public: return *this; } - AppendMessageIter &AppendFixedArray(ConstBuffer value) { + AppendMessageIter &AppendFixedArray(std::span value) { return AppendFixedArray(DBUS_TYPE_UINT32, - value.data, value.size); + value.data(), value.size()); } - AppendMessageIter &Append(ConstBuffer value) { + AppendMessageIter &Append(std::span value) { return AppendMessageIter(*this, DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32_AS_STRING) .AppendFixedArray(value) @@ -206,5 +205,3 @@ public: }; } /* namespace ODBus */ - -#endif diff --git a/src/lib/dbus/ReadIter.hxx b/src/lib/dbus/ReadIter.hxx index ceb7675c6..f1b81e874 100644 --- a/src/lib/dbus/ReadIter.hxx +++ b/src/lib/dbus/ReadIter.hxx @@ -30,11 +30,11 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef ODBUS_READ_ITER_HXX -#define ODBUS_READ_ITER_HXX +#pragma once #include "Iter.hxx" -#include "util/ConstBuffer.hxx" + +#include namespace ODBus { @@ -76,7 +76,7 @@ public: } template - ConstBuffer GetFixedArray() noexcept { + std::span GetFixedArray() noexcept { void *value; int n_elements; dbus_message_iter_get_fixed_array(&iter, &value, &n_elements); @@ -136,5 +136,3 @@ public: }; } /* namespace ODBus */ - -#endif diff --git a/src/lib/dbus/UDisks2.cxx b/src/lib/dbus/UDisks2.cxx index 0ff7cb19a..3ff5f3318 100644 --- a/src/lib/dbus/UDisks2.cxx +++ b/src/lib/dbus/UDisks2.cxx @@ -21,6 +21,7 @@ #include "Message.hxx" #include "ReadIter.hxx" #include "ObjectManager.hxx" +#include "util/SpanCast.hxx" #include "util/StringAPI.hxx" #include "util/StringView.hxx" #include "util/Compiler.h" @@ -50,7 +51,7 @@ CheckRecursedByteArrayToString(I &&i) noexcept return nullptr; auto value = i.template GetFixedArray(); - return { value.data, value.size }; + return ToStringView(value); } template diff --git a/src/lib/dbus/Values.hxx b/src/lib/dbus/Values.hxx index 013fa812e..bc5b95576 100644 --- a/src/lib/dbus/Values.hxx +++ b/src/lib/dbus/Values.hxx @@ -30,14 +30,13 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef ODBUS_VALUES_HXX -#define ODBUS_VALUES_HXX +#pragma once #include "Types.hxx" -#include "util/ConstBuffer.hxx" #include +#include #include namespace ODBus { @@ -95,7 +94,7 @@ template struct WrapFixedArray { using ContainedTraits = TypeTraits; using Traits = ArrayTypeTraits; - ConstBuffer value; + std::span value; explicit constexpr WrapFixedArray(const T *_data, size_t _size) noexcept @@ -124,5 +123,3 @@ static WrapStruct Struct(const T&... values) noexcept { } } /* namespace ODBus */ - -#endif