From 933e8e204d8451e738a24a678686cfaa826196d9 Mon Sep 17 00:00:00 2001 From: Stanislav Angelovic Date: Thu, 15 Mar 2018 16:22:06 +0100 Subject: [PATCH] Make sure that Variant conversion operator is only present for true D-Bus type represntations in C++ --- include/sdbus-c++/TypeTraits.h | 44 ++++++++++++++++++++++++++++++++++ include/sdbus-c++/Types.h | 3 ++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/include/sdbus-c++/TypeTraits.h b/include/sdbus-c++/TypeTraits.h index b71dc50..0b2aebd 100644 --- a/include/sdbus-c++/TypeTraits.h +++ b/include/sdbus-c++/TypeTraits.h @@ -53,6 +53,8 @@ namespace sdbus { template struct signature_of { + static constexpr bool is_valid = false; + static const std::string str() { // sizeof(_T) < 0 is here to make compiler not being able to figure out @@ -65,6 +67,8 @@ namespace sdbus { template <> struct signature_of { + static constexpr bool is_valid = true; + static const std::string str() { return ""; @@ -74,6 +78,8 @@ namespace sdbus { template <> struct signature_of { + static constexpr bool is_valid = true; + static const std::string str() { return "b"; @@ -83,6 +89,8 @@ namespace sdbus { template <> struct signature_of { + static constexpr bool is_valid = true; + static const std::string str() { return "y"; @@ -92,6 +100,8 @@ namespace sdbus { template <> struct signature_of { + static constexpr bool is_valid = true; + static const std::string str() { return "n"; @@ -101,6 +111,8 @@ namespace sdbus { template <> struct signature_of { + static constexpr bool is_valid = true; + static const std::string str() { return "q"; @@ -110,6 +122,8 @@ namespace sdbus { template <> struct signature_of { + static constexpr bool is_valid = true; + static const std::string str() { return "i"; @@ -119,6 +133,8 @@ namespace sdbus { template <> struct signature_of { + static constexpr bool is_valid = true; + static const std::string str() { return "u"; @@ -128,6 +144,8 @@ namespace sdbus { template <> struct signature_of { + static constexpr bool is_valid = true; + static const std::string str() { return "x"; @@ -137,6 +155,8 @@ namespace sdbus { template <> struct signature_of { + static constexpr bool is_valid = true; + static const std::string str() { return "t"; @@ -146,6 +166,8 @@ namespace sdbus { template <> struct signature_of { + static constexpr bool is_valid = true; + static const std::string str() { return "d"; @@ -155,6 +177,8 @@ namespace sdbus { template <> struct signature_of { + static constexpr bool is_valid = true; + static const std::string str() { return "s"; @@ -164,6 +188,8 @@ namespace sdbus { template <> struct signature_of { + static constexpr bool is_valid = true; + static const std::string str() { return "s"; @@ -173,6 +199,8 @@ namespace sdbus { template struct signature_of { + static constexpr bool is_valid = true; + static const std::string str() { return "s"; @@ -182,6 +210,8 @@ namespace sdbus { template struct signature_of { + static constexpr bool is_valid = true; + static const std::string str() { return "s"; @@ -191,6 +221,8 @@ namespace sdbus { template <> struct signature_of { + static constexpr bool is_valid = true; + static const std::string str() { return "s"; @@ -200,6 +232,8 @@ namespace sdbus { template struct signature_of> { + static constexpr bool is_valid = true; + static const std::string str() { std::initializer_list signatures{signature_of<_ValueTypes>::str()...}; @@ -215,6 +249,8 @@ namespace sdbus { template <> struct signature_of { + static constexpr bool is_valid = true; + static const std::string str() { return "v"; @@ -224,6 +260,8 @@ namespace sdbus { template <> struct signature_of { + static constexpr bool is_valid = true; + static const std::string str() { return "o"; @@ -233,6 +271,8 @@ namespace sdbus { template <> struct signature_of { + static constexpr bool is_valid = true; + static const std::string str() { return "g"; @@ -242,6 +282,8 @@ namespace sdbus { template struct signature_of> { + static constexpr bool is_valid = true; + static const std::string str() { return "a" + signature_of<_Element>::str(); @@ -251,6 +293,8 @@ namespace sdbus { template struct signature_of> { + static constexpr bool is_valid = true; + static const std::string str() { return "a{" + signature_of<_Key>::str() + signature_of<_Value>::str() + "}"; diff --git a/include/sdbus-c++/Types.h b/include/sdbus-c++/Types.h index c2b4765..a9891ed 100644 --- a/include/sdbus-c++/Types.h +++ b/include/sdbus-c++/Types.h @@ -68,7 +68,8 @@ namespace sdbus { return val; } - template + // Only allow conversion operator for true D-Bus type representations in C++ + template ::is_valid>> operator _ValueType() const { return get<_ValueType>();