summaryrefslogtreecommitdiffstats
path: root/actions.hpp
diff options
context:
space:
mode:
authorBrad Bishop <bradleyb@fuzziesquirrel.com>2016-11-29 12:31:31 -0500
committerBrad Bishop <bradleyb@fuzziesquirrel.com>2016-12-15 10:43:42 -0500
commit65ffffa9c115d51a0b184f627e8706cdd47f8b16 (patch)
tree89db8fa0ba01db53c01c5a1111a830e0508a26bf /actions.hpp
parent451f8d931a7a10d34c03f4348f64c3057f8d34f3 (diff)
downloadphosphor-inventory-manager-65ffffa9c115d51a0b184f627e8706cdd47f8b16.tar.gz
phosphor-inventory-manager-65ffffa9c115d51a0b184f627e8706cdd47f8b16.zip
Removed duplicated Holder adapters
Refactor copy/pasted action/filter/interface object adapter types into a single templated framework. Change-Id: Iafbd814572a7db13fddc5314617e310fe5f0a062 Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
Diffstat (limited to 'actions.hpp')
-rw-r--r--actions.hpp105
1 files changed, 17 insertions, 88 deletions
diff --git a/actions.hpp b/actions.hpp
index ff08019..0966ee4 100644
--- a/actions.hpp
+++ b/actions.hpp
@@ -2,6 +2,7 @@
#include <utility>
#include <memory>
+#include "utils.hpp"
namespace phosphor
{
@@ -9,106 +10,34 @@ namespace inventory
{
namespace manager
{
-class Manager;
-namespace actions
-{
+class Manager;
namespace details
{
-namespace holder
-{
+using ActionBase = holder::CallableBase<void, Manager&>;
+using ActionBasePtr = std::shared_ptr<ActionBase>;
+template <typename T>
+using Action = holder::CallableHolder<T, void, Manager&>;
-/** @struct Base
- * @brief Event action functor holder base.
+/** @brief make_action
*
- * Provides an un-templated holder for actionsof any type with the correct
- * function call signature.
- */
-struct Base
-{
- Base() = default;
- virtual ~Base() = default;
- Base(const Base&) = delete;
- Base& operator=(const Base&) = delete;
- Base(Base&&) = default;
- Base& operator=(Base&&) = default;
-
- virtual void operator()(Manager &mgr) const = 0;
- virtual void operator()(Manager &mgr)
- {
- const_cast<const Base &>(*this)(mgr);
- }
-};
-
-/** @struct Holder
- * @brief Event action functor holder.
+ * Adapt an action function object.
*
- * Adapts a functor of any type (with the correct function call
- * signature) to a non-templated type usable by the manager for
- * actions.
+ * @param[in] action - The action being adapted.
+ * @returns - The adapted action.
*
- * @tparam T - The functor type.
+ * @tparam T - The type of the action being adapted.
*/
template <typename T>
-struct Holder final : public Base
+auto make_action(T&& action)
{
- Holder() = delete;
- ~Holder() = default;
- Holder(const Holder&) = delete;
- Holder & operator=(const Holder&) = delete;
- Holder(Holder&&) = default;
- Holder& operator=(Holder&&) = default;
- explicit Holder(T &&func) : _func(std::forward<T>(func)) {}
-
- virtual void operator()(Manager &mgr) const override
- {
- _func(mgr);
- }
-
- virtual void operator()(Manager &mgr) override
- {
- _func(mgr);
- }
-
- private:
- T _func;
-};
-
-} // namespace holder
+ return Action<T>::template make_shared<Action<T>>(
+ std::forward<T>(action));
+}
+} // namespace details
-/** @struct Wrapper
- * @brief Provides implicit type conversion from action functors.
- *
- * Converts action functors to ptr-to-holder.
- */
-struct Wrapper
+namespace actions
{
- template <typename T>
- Wrapper(T &&func) :
- _ptr(static_cast<std::shared_ptr<holder::Base>>(
- std::make_shared<holder::Holder<T>>(
- std::forward<T>(func)))) { }
-
- ~Wrapper() = default;
- Wrapper(const Wrapper&) = default;
- Wrapper& operator=(const Wrapper&) = delete;
- Wrapper(Wrapper&&) = default;
- Wrapper& operator=(Wrapper&&) = default;
-
- void operator()(Manager &mgr)
- {
- (*_ptr)(mgr);
- }
- void operator()(Manager &mgr) const
- {
- (*_ptr)(mgr);
- }
-
- private:
- std::shared_ptr<holder::Base> _ptr;
-};
-
-} // namespace details
/** @brief The default action. */
inline void noop(Manager &mgr) noexcept { }
OpenPOWER on IntegriCloud