forked from Kistler-Group/sdbus-cpp
fix: conditional use and tests of span (#411)
This commit is contained in:
@@ -36,9 +36,11 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <map>
|
#include <map>
|
||||||
#if __cplusplus >= 202002L
|
#ifdef __has_include
|
||||||
|
# if __has_include(<span>)
|
||||||
# include <span>
|
# include <span>
|
||||||
# endif
|
# endif
|
||||||
|
#endif
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
@@ -104,7 +106,7 @@ namespace sdbus {
|
|||||||
Message& operator<<(const std::vector<_Element, _Allocator>& items);
|
Message& operator<<(const std::vector<_Element, _Allocator>& items);
|
||||||
template <typename _Element, std::size_t _Size>
|
template <typename _Element, std::size_t _Size>
|
||||||
Message& operator<<(const std::array<_Element, _Size>& items);
|
Message& operator<<(const std::array<_Element, _Size>& items);
|
||||||
#if __cplusplus >= 202002L
|
#ifdef __cpp_lib_span
|
||||||
template <typename _Element, std::size_t _Extent>
|
template <typename _Element, std::size_t _Extent>
|
||||||
Message& operator<<(const std::span<_Element, _Extent>& items);
|
Message& operator<<(const std::span<_Element, _Extent>& items);
|
||||||
#endif
|
#endif
|
||||||
@@ -140,7 +142,7 @@ namespace sdbus {
|
|||||||
Message& operator>>(std::vector<_Element, _Allocator>& items);
|
Message& operator>>(std::vector<_Element, _Allocator>& items);
|
||||||
template <typename _Element, std::size_t _Size>
|
template <typename _Element, std::size_t _Size>
|
||||||
Message& operator>>(std::array<_Element, _Size>& items);
|
Message& operator>>(std::array<_Element, _Size>& items);
|
||||||
#if __cplusplus >= 202002L
|
#ifdef __cpp_lib_span
|
||||||
template <typename _Element, std::size_t _Extent>
|
template <typename _Element, std::size_t _Extent>
|
||||||
Message& operator>>(std::span<_Element, _Extent>& items);
|
Message& operator>>(std::span<_Element, _Extent>& items);
|
||||||
#endif
|
#endif
|
||||||
@@ -339,7 +341,7 @@ namespace sdbus {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __cplusplus >= 202002L
|
#ifdef __cpp_lib_span
|
||||||
template <typename _Element, std::size_t _Extent>
|
template <typename _Element, std::size_t _Extent>
|
||||||
inline Message& Message::operator<<(const std::span<_Element, _Extent>& items)
|
inline Message& Message::operator<<(const std::span<_Element, _Extent>& items)
|
||||||
{
|
{
|
||||||
@@ -498,7 +500,7 @@ namespace sdbus {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __cplusplus >= 202002L
|
#ifdef __cpp_lib_span
|
||||||
template <typename _Element, std::size_t _Extent>
|
template <typename _Element, std::size_t _Extent>
|
||||||
inline Message& Message::operator>>(std::span<_Element, _Extent>& items)
|
inline Message& Message::operator>>(std::span<_Element, _Extent>& items)
|
||||||
{
|
{
|
||||||
|
@@ -35,9 +35,11 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#if __cplusplus >= 202002L
|
#ifdef __has_include
|
||||||
|
# if __has_include(<span>)
|
||||||
# include <span>
|
# include <span>
|
||||||
# endif
|
# endif
|
||||||
|
#endif
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
@@ -399,7 +401,7 @@ namespace sdbus {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#if __cplusplus >= 202002L
|
#ifdef __cpp_lib_span
|
||||||
template <typename _Element, std::size_t _Extent>
|
template <typename _Element, std::size_t _Extent>
|
||||||
struct signature_of<std::span<_Element, _Extent>>
|
struct signature_of<std::span<_Element, _Extent>>
|
||||||
{
|
{
|
||||||
|
@@ -311,7 +311,7 @@ TEST(AMessage, CanCarryDBusArrayOfNontrivialTypesGivenAsStdArray)
|
|||||||
ASSERT_THAT(dataRead, Eq(dataWritten));
|
ASSERT_THAT(dataRead, Eq(dataWritten));
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __cplusplus >= 202002L
|
#ifdef __cpp_lib_span
|
||||||
TEST(AMessage, CanCarryDBusArrayOfTrivialTypesGivenAsStdSpan)
|
TEST(AMessage, CanCarryDBusArrayOfTrivialTypesGivenAsStdSpan)
|
||||||
{
|
{
|
||||||
auto msg = sdbus::createPlainMessage();
|
auto msg = sdbus::createPlainMessage();
|
||||||
@@ -378,7 +378,7 @@ TEST(AMessage, ThrowsWhenDestinationStdArrayIsTooSmallDuringDeserialization)
|
|||||||
ASSERT_THROW(msg >> dataRead, sdbus::Error);
|
ASSERT_THROW(msg >> dataRead, sdbus::Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __cplusplus >= 202002L
|
#ifdef __cpp_lib_span
|
||||||
TEST(AMessage, ThrowsWhenDestinationStdSpanIsTooSmallDuringDeserialization)
|
TEST(AMessage, ThrowsWhenDestinationStdSpanIsTooSmallDuringDeserialization)
|
||||||
{
|
{
|
||||||
auto msg = sdbus::createPlainMessage();
|
auto msg = sdbus::createPlainMessage();
|
||||||
|
@@ -88,13 +88,13 @@ namespace
|
|||||||
TYPE(sdbus::ObjectPath)HAS_DBUS_TYPE_SIGNATURE("o")
|
TYPE(sdbus::ObjectPath)HAS_DBUS_TYPE_SIGNATURE("o")
|
||||||
TYPE(sdbus::Signature)HAS_DBUS_TYPE_SIGNATURE("g")
|
TYPE(sdbus::Signature)HAS_DBUS_TYPE_SIGNATURE("g")
|
||||||
TYPE(sdbus::Variant)HAS_DBUS_TYPE_SIGNATURE("v")
|
TYPE(sdbus::Variant)HAS_DBUS_TYPE_SIGNATURE("v")
|
||||||
|
TYPE(std::variant<int16_t, std::string>)HAS_DBUS_TYPE_SIGNATURE("v")
|
||||||
TYPE(sdbus::UnixFd)HAS_DBUS_TYPE_SIGNATURE("h")
|
TYPE(sdbus::UnixFd)HAS_DBUS_TYPE_SIGNATURE("h")
|
||||||
TYPE(sdbus::Struct<bool>)HAS_DBUS_TYPE_SIGNATURE("(b)")
|
TYPE(sdbus::Struct<bool>)HAS_DBUS_TYPE_SIGNATURE("(b)")
|
||||||
TYPE(sdbus::Struct<uint16_t, double, std::string, sdbus::Variant>)HAS_DBUS_TYPE_SIGNATURE("(qdsv)")
|
TYPE(sdbus::Struct<uint16_t, double, std::string, sdbus::Variant>)HAS_DBUS_TYPE_SIGNATURE("(qdsv)")
|
||||||
TYPE(std::vector<int16_t>)HAS_DBUS_TYPE_SIGNATURE("an")
|
TYPE(std::vector<int16_t>)HAS_DBUS_TYPE_SIGNATURE("an")
|
||||||
TYPE(std::array<int16_t, 3>)HAS_DBUS_TYPE_SIGNATURE("an")
|
TYPE(std::array<int16_t, 3>)HAS_DBUS_TYPE_SIGNATURE("an")
|
||||||
TYPE(std::variant<int16_t, std::string>)HAS_DBUS_TYPE_SIGNATURE("v")
|
#ifdef __cpp_lib_span
|
||||||
#if __cplusplus >= 202002L
|
|
||||||
TYPE(std::span<int16_t>)HAS_DBUS_TYPE_SIGNATURE("an")
|
TYPE(std::span<int16_t>)HAS_DBUS_TYPE_SIGNATURE("an")
|
||||||
#endif
|
#endif
|
||||||
TYPE(SomeEnumClass)HAS_DBUS_TYPE_SIGNATURE("y")
|
TYPE(SomeEnumClass)HAS_DBUS_TYPE_SIGNATURE("y")
|
||||||
@@ -138,13 +138,13 @@ namespace
|
|||||||
, sdbus::ObjectPath
|
, sdbus::ObjectPath
|
||||||
, sdbus::Signature
|
, sdbus::Signature
|
||||||
, sdbus::Variant
|
, sdbus::Variant
|
||||||
|
, std::variant<int16_t, std::string>
|
||||||
, sdbus::UnixFd
|
, sdbus::UnixFd
|
||||||
, sdbus::Struct<bool>
|
, sdbus::Struct<bool>
|
||||||
, sdbus::Struct<uint16_t, double, std::string, sdbus::Variant>
|
, sdbus::Struct<uint16_t, double, std::string, sdbus::Variant>
|
||||||
, std::vector<int16_t>
|
, std::vector<int16_t>
|
||||||
, std::array<int16_t, 3>
|
, std::array<int16_t, 3>
|
||||||
, std::variant<int16_t, std::string>
|
#ifdef __cpp_lib_span
|
||||||
#if __cplusplus >= 202002L
|
|
||||||
, std::span<int16_t>
|
, std::span<int16_t>
|
||||||
#endif
|
#endif
|
||||||
, SomeEnumClass
|
, SomeEnumClass
|
||||||
|
Reference in New Issue
Block a user