lib/dbus: use std::span

This commit is contained in:
Max Kellermann 2022-06-27 17:25:43 +02:00 committed by Max Kellermann
parent 899eaa3307
commit 062df65b1e
4 changed files with 13 additions and 20 deletions

View File

@ -30,8 +30,7 @@
* OF THE POSSIBILITY OF SUCH DAMAGE. * OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef ODBUS_APPEND_ITER_HXX #pragma once
#define ODBUS_APPEND_ITER_HXX
#include "Iter.hxx" #include "Iter.hxx"
#include "Values.hxx" #include "Values.hxx"
@ -88,12 +87,12 @@ public:
return *this; return *this;
} }
AppendMessageIter &AppendFixedArray(ConstBuffer<uint32_t> value) { AppendMessageIter &AppendFixedArray(std::span<const uint32_t> value) {
return AppendFixedArray(DBUS_TYPE_UINT32, return AppendFixedArray(DBUS_TYPE_UINT32,
value.data, value.size); value.data(), value.size());
} }
AppendMessageIter &Append(ConstBuffer<uint32_t> value) { AppendMessageIter &Append(std::span<const uint32_t> value) {
return AppendMessageIter(*this, DBUS_TYPE_ARRAY, return AppendMessageIter(*this, DBUS_TYPE_ARRAY,
DBUS_TYPE_UINT32_AS_STRING) DBUS_TYPE_UINT32_AS_STRING)
.AppendFixedArray(value) .AppendFixedArray(value)
@ -206,5 +205,3 @@ public:
}; };
} /* namespace ODBus */ } /* namespace ODBus */
#endif

View File

@ -30,11 +30,11 @@
* OF THE POSSIBILITY OF SUCH DAMAGE. * OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef ODBUS_READ_ITER_HXX #pragma once
#define ODBUS_READ_ITER_HXX
#include "Iter.hxx" #include "Iter.hxx"
#include "util/ConstBuffer.hxx"
#include <span>
namespace ODBus { namespace ODBus {
@ -76,7 +76,7 @@ public:
} }
template<typename T> template<typename T>
ConstBuffer<T> GetFixedArray() noexcept { std::span<const T> GetFixedArray() noexcept {
void *value; void *value;
int n_elements; int n_elements;
dbus_message_iter_get_fixed_array(&iter, &value, &n_elements); dbus_message_iter_get_fixed_array(&iter, &value, &n_elements);
@ -136,5 +136,3 @@ public:
}; };
} /* namespace ODBus */ } /* namespace ODBus */
#endif

View File

@ -21,6 +21,7 @@
#include "Message.hxx" #include "Message.hxx"
#include "ReadIter.hxx" #include "ReadIter.hxx"
#include "ObjectManager.hxx" #include "ObjectManager.hxx"
#include "util/SpanCast.hxx"
#include "util/StringAPI.hxx" #include "util/StringAPI.hxx"
#include "util/StringView.hxx" #include "util/StringView.hxx"
#include "util/Compiler.h" #include "util/Compiler.h"
@ -50,7 +51,7 @@ CheckRecursedByteArrayToString(I &&i) noexcept
return nullptr; return nullptr;
auto value = i.template GetFixedArray<char>(); auto value = i.template GetFixedArray<char>();
return { value.data, value.size }; return ToStringView(value);
} }
template<typename I> template<typename I>

View File

@ -30,14 +30,13 @@
* OF THE POSSIBILITY OF SUCH DAMAGE. * OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef ODBUS_VALUES_HXX #pragma once
#define ODBUS_VALUES_HXX
#include "Types.hxx" #include "Types.hxx"
#include "util/ConstBuffer.hxx"
#include <dbus/dbus.h> #include <dbus/dbus.h>
#include <span>
#include <tuple> #include <tuple>
namespace ODBus { namespace ODBus {
@ -95,7 +94,7 @@ template<typename T>
struct WrapFixedArray { struct WrapFixedArray {
using ContainedTraits = TypeTraits<T>; using ContainedTraits = TypeTraits<T>;
using Traits = ArrayTypeTraits<ContainedTraits>; using Traits = ArrayTypeTraits<ContainedTraits>;
ConstBuffer<T> value; std::span<const T> value;
explicit constexpr WrapFixedArray(const T *_data, explicit constexpr WrapFixedArray(const T *_data,
size_t _size) noexcept size_t _size) noexcept
@ -124,5 +123,3 @@ static WrapStruct<T...> Struct(const T&... values) noexcept {
} }
} /* namespace ODBus */ } /* namespace ODBus */
#endif