diff options
| author | William A. Kennington III <wak@google.com> | 2018-11-26 09:50:13 -0800 |
|---|---|---|
| committer | William A. Kennington III <wak@google.com> | 2019-04-05 15:14:52 -0700 |
| commit | 4274c117dd2866ac60508f438e7427f99dee6be4 (patch) | |
| tree | 5d3dbdc73b7e716aa6ade15dde0a2a5ec6e3cc6d | |
| parent | 8515eae7adcb9811ba271d05d82f66d48b1df082 (diff) | |
| download | sdbusplus-4274c117dd2866ac60508f438e7427f99dee6be4.tar.gz sdbusplus-4274c117dd2866ac60508f438e7427f99dee6be4.zip | |
std::variant: Remove uses of the variant_ns
Now that we are using std::variant we should reference it directly
instead of using our own namespace alias.
Tested:
Built and ran through unit tests.
Change-Id: Ic3fd62ea74cf808b85ad7b7ffcce8c0a0bfb125d
Signed-off-by: William A. Kennington III <wak@google.com>
| -rw-r--r-- | example/asio-example.cpp | 15 | ||||
| -rw-r--r-- | sdbusplus/message/append.hpp | 6 | ||||
| -rw-r--r-- | sdbusplus/message/read.hpp | 8 | ||||
| -rw-r--r-- | sdbusplus/message/types.hpp | 2 | ||||
| -rw-r--r-- | test/message/append.cpp | 13 | ||||
| -rw-r--r-- | test/message/read.cpp | 29 | ||||
| -rw-r--r-- | tools/sdbusplus/property.py | 3 | ||||
| -rw-r--r-- | tools/sdbusplus/templates/interface.mako.server.cpp.in | 7 | ||||
| -rw-r--r-- | tools/sdbusplus/templates/interface.mako.server.hpp | 9 |
9 files changed, 50 insertions, 42 deletions
diff --git a/example/asio-example.cpp b/example/asio-example.cpp index 61916a5..0e20f41 100644 --- a/example/asio-example.cpp +++ b/example/asio-example.cpp @@ -10,8 +10,9 @@ #include <sdbusplus/exception.hpp> #include <sdbusplus/server.hpp> #include <sdbusplus/timer.hpp> +#include <variant> -using variant = sdbusplus::message::variant<int, std::string>; +using variant = std::variant<int, std::string>; int foo(int test) { @@ -65,15 +66,13 @@ void do_start_async_method_call_one( yield[ec], "xyz.openbmc_project.asio-test", "/xyz/openbmc_project/test", "org.freedesktop.DBus.Properties", "Get", "xyz.openbmc_project.test", "int"); - if (!ec && sdbusplus::message::variant_ns::get<int>(testValue) == 24) + if (!ec && std::get<int>(testValue) == 24) { std::cout << "async call to Properties.Get serialized via yield OK!\n"; } else { - std::cout << "ec = " << ec << ": " - << sdbusplus::message::variant_ns::get<int>(testValue) - << "\n"; + std::cout << "ec = " << ec << ": " << std::get<int>(testValue) << "\n"; } conn->yield_method_call<void>( yield[ec], "xyz.openbmc_project.asio-test", "/xyz/openbmc_project/test", @@ -83,15 +82,13 @@ void do_start_async_method_call_one( yield[ec], "xyz.openbmc_project.asio-test", "/xyz/openbmc_project/test", "org.freedesktop.DBus.Properties", "Get", "xyz.openbmc_project.test", "int"); - if (!ec && sdbusplus::message::variant_ns::get<int>(testValue) == 42) + if (!ec && std::get<int>(testValue) == 42) { std::cout << "async call to Properties.Get serialized via yield OK!\n"; } else { - std::cout << "ec = " << ec << ": " - << sdbusplus::message::variant_ns::get<int>(testValue) - << "\n"; + std::cout << "ec = " << ec << ": " << std::get<int>(testValue) << "\n"; } } diff --git a/sdbusplus/message/append.hpp b/sdbusplus/message/append.hpp index 32d4b46..058e277 100644 --- a/sdbusplus/message/append.hpp +++ b/sdbusplus/message/append.hpp @@ -8,6 +8,8 @@ #include <sdbusplus/utility/tuple_to_array.hpp> #include <sdbusplus/utility/type_traits.hpp> #include <tuple> +#include <type_traits> +#include <variant> namespace sdbusplus { @@ -96,7 +98,7 @@ struct can_append_multiple<std::tuple<Args...>> : std::false_type }; // variant needs to be broken down into components. template <typename... Args> -struct can_append_multiple<variant<Args...>> : std::false_type +struct can_append_multiple<std::variant<Args...>> : std::false_type { }; @@ -288,7 +290,7 @@ struct append_single<std::tuple<Args...>> /** @brief Specialization of append_single for std::variant. */ template <typename... Args> -struct append_single<variant<Args...>> +struct append_single<std::variant<Args...>> { template <typename S, typename = std::enable_if_t<0 < sizeof...(Args)>> static void op(sdbusplus::SdBusInterface* intf, sd_bus_message* m, S&& s) diff --git a/sdbusplus/message/read.hpp b/sdbusplus/message/read.hpp index 7a99570..5e2b899 100644 --- a/sdbusplus/message/read.hpp +++ b/sdbusplus/message/read.hpp @@ -6,7 +6,11 @@ #include <sdbusplus/message/types.hpp> #include <sdbusplus/utility/tuple_to_array.hpp> #include <sdbusplus/utility/type_traits.hpp> +#include <string> #include <tuple> +#include <type_traits> +#include <utility> +#include <variant> namespace sdbusplus { @@ -100,7 +104,7 @@ struct can_read_multiple<std::tuple<Args...>> : std::false_type }; // variant needs to be broken down into components. template <typename... Args> -struct can_read_multiple<variant<Args...>> : std::false_type +struct can_read_multiple<std::variant<Args...>> : std::false_type { }; @@ -371,7 +375,7 @@ struct read_single<std::tuple<Args...>> /** @brief Specialization of read_single for std::variant. */ template <typename... Args> -struct read_single<variant<Args...>> +struct read_single<std::variant<Args...>> { template <typename S, typename S1, typename... Args1> static void read(sdbusplus::SdBusInterface* intf, sd_bus_message* m, S&& s) diff --git a/sdbusplus/message/types.hpp b/sdbusplus/message/types.hpp index eb7407f..bd5946b 100644 --- a/sdbusplus/message/types.hpp +++ b/sdbusplus/message/types.hpp @@ -264,7 +264,7 @@ struct type_id<std::tuple<Args...>> }; template <typename... Args> -struct type_id<variant<Args...>> : tuple_type_id<SD_BUS_TYPE_VARIANT> +struct type_id<std::variant<Args...>> : tuple_type_id<SD_BUS_TYPE_VARIANT> { }; diff --git a/test/message/append.cpp b/test/message/append.cpp index 12c0bf3..edae342 100644 --- a/test/message/append.cpp +++ b/test/message/append.cpp @@ -8,6 +8,7 @@ #include <string> #include <tuple> #include <unordered_map> +#include <variant> #include <vector> #include <gmock/gmock.h> @@ -16,7 +17,6 @@ namespace { -namespace variant_ns = sdbusplus::message::variant_ns; using testing::Eq; using testing::MatcherCast; using testing::Pointee; @@ -323,7 +323,7 @@ TEST_F(AppendTest, Variant) { const bool b1 = false; const std::string s2{"asdf"}; - const sdbusplus::message::variant<int, std::string, bool> v1{b1}, v2{s2}; + const std::variant<int, std::string, bool> v1{b1}, v2{s2}; { testing::InSequence seq; @@ -341,7 +341,7 @@ TEST_F(AppendTest, LargeCombo) { std::vector<std::array<std::string, 3>> vas{{"a", "b", "c"}, {"d", "", "e"}}; - std::map<std::string, sdbusplus::message::variant<int, double>> msv = { + std::map<std::string, std::variant<int, double>> msv = { {"a", 3.3}, {"b", 1}, {"c", 4.4}}; { @@ -364,18 +364,17 @@ TEST_F(AppendTest, LargeCombo) { expect_open_container(SD_BUS_TYPE_DICT_ENTRY, "sv"); expect_basic_string(SD_BUS_TYPE_STRING, sv.first.c_str()); - if (variant_ns::holds_alternative<int>(sv.second)) + if (std::holds_alternative<int>(sv.second)) { expect_open_container(SD_BUS_TYPE_VARIANT, "i"); - expect_basic<int>(SD_BUS_TYPE_INT32, - variant_ns::get<int>(sv.second)); + expect_basic<int>(SD_BUS_TYPE_INT32, std::get<int>(sv.second)); expect_close_container(); } else { expect_open_container(SD_BUS_TYPE_VARIANT, "d"); expect_basic<double>(SD_BUS_TYPE_DOUBLE, - variant_ns::get<double>(sv.second)); + std::get<double>(sv.second)); expect_close_container(); } expect_close_container(); diff --git a/test/message/read.cpp b/test/message/read.cpp index 55808d8..b973ba4 100644 --- a/test/message/read.cpp +++ b/test/message/read.cpp @@ -9,6 +9,7 @@ #include <string> #include <tuple> #include <unordered_map> +#include <variant> #include <vector> #include <gmock/gmock.h> @@ -17,7 +18,6 @@ namespace { -namespace variant_ns = sdbusplus::message::variant_ns; using testing::DoAll; using testing::Return; using testing::StrEq; @@ -477,7 +477,7 @@ TEST_F(ReadTest, Variant) { const bool b1 = false; const std::string s2{"asdf"}; - const sdbusplus::message::variant<int, std::string, bool> v1{b1}, v2{s2}; + const std::variant<int, std::string, bool> v1{b1}, v2{s2}; { testing::InSequence seq; @@ -494,7 +494,7 @@ TEST_F(ReadTest, Variant) expect_exit_container(); } - sdbusplus::message::variant<int, std::string, bool> ret_v1, ret_v2; + std::variant<int, std::string, bool> ret_v1, ret_v2; new_message().read(ret_v1, ret_v2); EXPECT_EQ(v1, ret_v1); EXPECT_EQ(v2, ret_v2); @@ -507,7 +507,7 @@ TEST_F(ReadTest, VariantVerifyError) expect_verify_type(SD_BUS_TYPE_VARIANT, "i", -EINVAL); } - sdbusplus::message::variant<int, bool> ret; + std::variant<int, bool> ret; EXPECT_THROW(new_message().read(ret), sdbusplus::exception::SdBusError); } @@ -520,7 +520,7 @@ TEST_F(ReadTest, VariantSkipUnmatched) expect_skip("v"); } - sdbusplus::message::variant<int, bool> ret; + std::variant<int, bool> ret; new_message().read(ret); } @@ -533,7 +533,7 @@ TEST_F(ReadTest, VariantSkipError) expect_skip("v", -EINVAL); } - sdbusplus::message::variant<int, bool> ret; + std::variant<int, bool> ret; EXPECT_THROW(new_message().read(ret), sdbusplus::exception::SdBusError); } @@ -545,7 +545,7 @@ TEST_F(ReadTest, VariantEnterError) expect_enter_container(SD_BUS_TYPE_VARIANT, "i", -EINVAL); } - sdbusplus::message::variant<int, bool> ret; + std::variant<int, bool> ret; EXPECT_THROW(new_message().read(ret), sdbusplus::exception::SdBusError); } @@ -559,7 +559,7 @@ TEST_F(ReadTest, VariantExitError) expect_exit_container(-EINVAL); } - sdbusplus::message::variant<int, bool> ret; + std::variant<int, bool> ret; EXPECT_THROW(new_message().read(ret), sdbusplus::exception::SdBusError); } @@ -569,8 +569,8 @@ TEST_F(ReadTest, LargeCombo) {"a", "b", "c"}, {"d", "", "e"}, }; - const std::map<std::string, sdbusplus::message::variant<int, double>> msv = - {{"a", 3.3}, {"b", 1}, {"c", 4.4}}; + const std::map<std::string, std::variant<int, double>> msv = { + {"a", 3.3}, {"b", 1}, {"c", 4.4}}; { testing::InSequence seq; @@ -597,12 +597,11 @@ TEST_F(ReadTest, LargeCombo) expect_at_end(false, 0); expect_enter_container(SD_BUS_TYPE_DICT_ENTRY, "sv"); expect_basic<const char*>(SD_BUS_TYPE_STRING, sv.first.c_str()); - if (variant_ns::holds_alternative<int>(sv.second)) + if (std::holds_alternative<int>(sv.second)) { expect_verify_type(SD_BUS_TYPE_VARIANT, "i", true); expect_enter_container(SD_BUS_TYPE_VARIANT, "i"); - expect_basic<int>(SD_BUS_TYPE_INT32, - variant_ns::get<int>(sv.second)); + expect_basic<int>(SD_BUS_TYPE_INT32, std::get<int>(sv.second)); expect_exit_container(); } else @@ -611,7 +610,7 @@ TEST_F(ReadTest, LargeCombo) expect_verify_type(SD_BUS_TYPE_VARIANT, "d", true); expect_enter_container(SD_BUS_TYPE_VARIANT, "d"); expect_basic<double>(SD_BUS_TYPE_DOUBLE, - variant_ns::get<double>(sv.second)); + std::get<double>(sv.second)); expect_exit_container(); } expect_exit_container(); @@ -621,7 +620,7 @@ TEST_F(ReadTest, LargeCombo) } std::vector<std::set<std::string>> ret_vas; - std::map<std::string, sdbusplus::message::variant<int, double>> ret_msv; + std::map<std::string, std::variant<int, double>> ret_msv; new_message().read(ret_vas, ret_msv); EXPECT_EQ(vas, ret_vas); EXPECT_EQ(msv, ret_msv); diff --git a/tools/sdbusplus/property.py b/tools/sdbusplus/property.py index 661bce4..e5071ff 100644 --- a/tools/sdbusplus/property.py +++ b/tools/sdbusplus/property.py @@ -132,8 +132,7 @@ class Property(NamedElement, Renderer): 'params': 0}, 'array': {'cppName': 'std::vector', 'params': 1}, 'struct': {'cppName': 'std::tuple', 'params': -1}, - 'variant': {'cppName': 'sdbusplus::message::variant', - 'params': -1}, + 'variant': {'cppName': 'std::variant', 'params': -1}, 'dict': {'cppName': 'std::map', 'params': 2}, 'enum': {'cppName': 'enum', 'params': 1, 'noparse': True}} diff --git a/tools/sdbusplus/templates/interface.mako.server.cpp.in b/tools/sdbusplus/templates/interface.mako.server.cpp.in index a47ff38..5af2749 100644 --- a/tools/sdbusplus/templates/interface.mako.server.cpp.in +++ b/tools/sdbusplus/templates/interface.mako.server.cpp.in @@ -1,7 +1,12 @@ #include <algorithm> +#include <map> #include <sdbusplus/sdbus.hpp> #include <sdbusplus/server.hpp> #include <sdbusplus/exception.hpp> +#include <string> +#include <tuple> +#include <variant> + #include <${"/".join(interface.name.split('.') + [ 'server.hpp' ])}> % for m in interface.methods + interface.properties + interface.signals: ${ m.cpp_prototype(loader, interface=interface, ptype='callback-cpp-includes') } @@ -61,7 +66,7 @@ void ${classname}::setPropertyByName(const std::string& _name, % for p in interface.properties: if (_name == "${p.name}") { - auto& v = message::variant_ns::get<${p.cppTypeParam(interface.name)}>(\ + auto& v = std::get<${p.cppTypeParam(interface.name)}>(\ val); ${p.camelCase}(v, skipSignal); return; diff --git a/tools/sdbusplus/templates/interface.mako.server.hpp b/tools/sdbusplus/templates/interface.mako.server.hpp index 93cf6e7..e5b17ea 100644 --- a/tools/sdbusplus/templates/interface.mako.server.hpp +++ b/tools/sdbusplus/templates/interface.mako.server.hpp @@ -1,8 +1,11 @@ #pragma once -#include <tuple> -#include <systemd/sd-bus.h> +#include <map> +#include <string> #include <sdbusplus/sdbus.hpp> #include <sdbusplus/server.hpp> +#include <systemd/sd-bus.h> +#include <tuple> +#include <variant> % for m in interface.methods + interface.properties + interface.signals: ${ m.cpp_prototype(loader, interface=interface, ptype='callback-hpp-includes') } % endfor @@ -58,7 +61,7 @@ class ${classname} % endfor % if interface.properties: - using PropertiesVariant = sdbusplus::message::variant< + using PropertiesVariant = std::variant< ${",\n ".join(setOfPropertyTypes())}>; /** @brief Constructor to initialize the object from a map of |

