diff options
author | Brad Bishop <bradleyb@fuzziesquirrel.com> | 2018-11-21 12:57:51 -0500 |
---|---|---|
committer | Brad Bishop <bradleyb@fuzziesquirrel.com> | 2018-11-21 12:59:21 -0500 |
commit | 25d54b5102241117915d18c612ce03cde20d2c5b (patch) | |
tree | 5f5a399c3bb4e17fb35ee9a4ef943d265d9b9fc1 | |
parent | 6e94b65268382de661512646668d8e32ec73d755 (diff) | |
download | phosphor-inventory-manager-25d54b5102241117915d18c612ce03cde20d2c5b.tar.gz phosphor-inventory-manager-25d54b5102241117915d18c612ce03cde20d2c5b.zip |
Replace std::experimental::any with std::any
This is possible and preferrable now with the switch to c++17.
Change-Id: I0c314ae9a85c8c34274cc971e63b17988db31a2b
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
-rw-r--r-- | manager.cpp | 9 | ||||
-rw-r--r-- | manager.hpp | 51 | ||||
-rw-r--r-- | types.hpp | 2 |
3 files changed, 30 insertions, 32 deletions
diff --git a/manager.cpp b/manager.cpp index c138d40..dcd2e48 100644 --- a/manager.cpp +++ b/manager.cpp @@ -280,15 +280,14 @@ void Manager::createObjects( updateObjects(objs); } -any_ns::any& Manager::getInterfaceHolder(const char* path, - const char* interface) +std::any& Manager::getInterfaceHolder(const char* path, const char* interface) { - return const_cast<any_ns::any&>( + return const_cast<std::any&>( const_cast<const Manager*>(this)->getInterfaceHolder(path, interface)); } -const any_ns::any& Manager::getInterfaceHolder(const char* path, - const char* interface) const +const std::any& Manager::getInterfaceHolder(const char* path, + const char* interface) const { std::string p{path}; auto oit = _refs.find(_root + p); diff --git a/manager.hpp b/manager.hpp index 1213267..c9f14a0 100644 --- a/manager.hpp +++ b/manager.hpp @@ -5,6 +5,7 @@ #include "serialize.hpp" #include "types.hpp" +#include <any> #include <map> #include <memory> #include <sdbusplus/server.hpp> @@ -62,8 +63,8 @@ struct HasProperties< }; template <typename T, std::enable_if_t<HasProperties<T>::value, bool> = true> -any_ns::any propMake(sdbusplus::bus::bus& bus, const char* path, - const Interface& props) +std::any propMake(sdbusplus::bus::bus& bus, const char* path, + const Interface& props) { using InterfaceVariant = std::map<std::string, PropertiesVariantType<T>>; @@ -73,20 +74,20 @@ any_ns::any propMake(sdbusplus::bus::bus& bus, const char* path, v.emplace(p.first, convertVariant<PropertiesVariantType<T>>(p.second)); } - return any_ns::any(std::make_shared<T>(bus, path, v)); + return std::any(std::make_shared<T>(bus, path, v)); } template <typename T, std::enable_if_t<!HasProperties<T>::value, bool> = false> -any_ns::any propMake(sdbusplus::bus::bus& bus, const char* path, - const Interface& props) +std::any propMake(sdbusplus::bus::bus& bus, const char* path, + const Interface& props) { - return any_ns::any(std::make_shared<T>(bus, path)); + return std::any(std::make_shared<T>(bus, path)); } template <typename T, std::enable_if_t<HasProperties<T>::value, bool> = true> -void propAssign(const Interface& props, any_ns::any& holder) +void propAssign(const Interface& props, std::any& holder) { - auto& iface = *any_ns::any_cast<std::shared_ptr<T>&>(holder); + auto& iface = *std::any_cast<std::shared_ptr<T>&>(holder); for (const auto& p : props) { iface.setPropertyByName( @@ -95,36 +96,36 @@ void propAssign(const Interface& props, any_ns::any& holder) } template <typename T, std::enable_if_t<!HasProperties<T>::value, bool> = false> -void propAssign(const Interface& props, any_ns::any& holder) +void propAssign(const Interface& props, std::any& holder) { } template <typename T, std::enable_if_t<HasProperties<T>::value, bool> = true> void propSerialize(const std::string& path, const std::string& iface, - const any_ns::any& holder) + const std::any& holder) { - const auto& object = *any_ns::any_cast<const std::shared_ptr<T>&>(holder); + const auto& object = *std::any_cast<const std::shared_ptr<T>&>(holder); cereal::serialize(path, iface, object); } template <typename T, std::enable_if_t<!HasProperties<T>::value, bool> = false> void propSerialize(const std::string& path, const std::string& iface, - const any_ns::any& holder) + const std::any& holder) { cereal::serialize(path, iface); } template <typename T, std::enable_if_t<HasProperties<T>::value, bool> = true> void propDeSerialize(const std::string& path, const std::string& iface, - any_ns::any& holder) + std::any& holder) { - auto& object = *any_ns::any_cast<std::shared_ptr<T>&>(holder); + auto& object = *std::any_cast<std::shared_ptr<T>&>(holder); cereal::deserialize(path, iface, object); } template <typename T, std::enable_if_t<!HasProperties<T>::value, bool> = false> void propDeSerialize(const std::string& path, const std::string& iface, - any_ns::any& holder) + std::any& holder) { } @@ -140,25 +141,25 @@ void propDeSerialize(const std::string& path, const std::string& iface, template <typename T> struct MakeInterface { - static any_ns::any make(sdbusplus::bus::bus& bus, const char* path, - const Interface& props) + static std::any make(sdbusplus::bus::bus& bus, const char* path, + const Interface& props) { return propMake<T>(bus, path, props); } - static void assign(const Interface& props, any_ns::any& holder) + static void assign(const Interface& props, std::any& holder) { propAssign<T>(props, holder); } static void serialize(const std::string& path, const std::string& iface, - const any_ns::any& holder) + const std::any& holder) { propSerialize<T>(path, iface, holder); } static void deserialize(const std::string& path, const std::string& iface, - any_ns::any& holder) + std::any& holder) { propDeSerialize<T>(path, iface, holder); } @@ -253,7 +254,7 @@ class Manager final : public ServerObject<ManagerIface> using SigArg = SigArgs::value_type::element_type; private: - using InterfaceComposite = std::map<std::string, any_ns::any>; + using InterfaceComposite = std::map<std::string, std::any>; using ObjectReferences = std::map<std::string, InterfaceComposite>; using Events = std::vector<EventInfo>; @@ -282,8 +283,8 @@ class Manager final : public ServerObject<ManagerIface> * * @returns A weak reference to the holder instance. */ - const any_ns::any& getInterfaceHolder(const char*, const char*) const; - any_ns::any& getInterfaceHolder(const char*, const char*); + const std::any& getInterfaceHolder(const char*, const char*) const; + std::any& getInterfaceHolder(const char*, const char*); /** @brief Provides weak references to interface holders. * @@ -299,13 +300,13 @@ class Manager final : public ServerObject<ManagerIface> auto& getInterface(const char* path, const char* interface) { auto& holder = getInterfaceHolder(path, interface); - return *any_ns::any_cast<std::shared_ptr<T>&>(holder); + return *std::any_cast<std::shared_ptr<T>&>(holder); } template <typename T> auto& getInterface(const char* path, const char* interface) const { auto& holder = getInterfaceHolder(path, interface); - return *any_ns::any_cast<T>(holder); + return *std::any_cast<T>(holder); } /** @brief Add or update interfaces on DBus. */ @@ -1,6 +1,5 @@ #pragma once -#include <experimental/any> #include <functional> #include <map> #include <sdbusplus/message.hpp> @@ -14,7 +13,6 @@ namespace manager { class Manager; -namespace any_ns = std::experimental; /** @brief Inventory manager supported property types. */ using InterfaceVariantType = |