From a9cb417320fa1ca6784a0dbe726cfa8c43df7ee4 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sat, 1 Apr 2017 19:26:23 +0200 Subject: [PATCH] Enable move-initialisation on command activation --- src/lib/handle.hpp | 7 +++++++ src/proc/control/command-def.hpp | 8 ++++---- src/proc/control/command-setup.cpp | 2 +- src/proc/control/command.cpp | 10 ++++++---- src/proc/control/command.hpp | 6 +++++- 5 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/lib/handle.hpp b/src/lib/handle.hpp index 0d800f3ac..b46e340cb 100644 --- a/src/lib/handle.hpp +++ b/src/lib/handle.hpp @@ -127,6 +127,13 @@ namespace lib { return *this; } + Handle& + activate(shared_ptr && impl) + { + smPtr_ = move (impl); + return *this; + } + /** deactivate this handle, so it isn't tied any longer * to the associated implementation or service object. * When all handles have either been deactivated or diff --git a/src/proc/control/command-def.hpp b/src/proc/control/command-def.hpp index 04805e789..512b80f44 100644 --- a/src/proc/control/command-def.hpp +++ b/src/proc/control/command-def.hpp @@ -99,7 +99,7 @@ namespace control { namespace stage { ///< helpers for building up a command definition using ImplInstance = shared_ptr; - using Activation = function; + using Activation = function; @@ -211,7 +211,7 @@ namespace control { ImplInstance completedDef = registry.newCommandImpl(operFunctor_ ,captFunctor_ ,undoFunctor_); - return CompletedDefinition (activatePrototype_(completedDef)); + return CompletedDefinition {activatePrototype_(move (completedDef))}; } }; @@ -318,9 +318,9 @@ namespace control { /** callback from completed command definition stage: * "arm up" the command handle object and register it * with the CommandRegistry. */ - Command& activate (PImpl const& completedDef) + Command& activate (PImpl && completedDef) { - prototype_.activate (completedDef, id_); + prototype_.activate (move (completedDef), id_); ENSURE (prototype_); return prototype_; } diff --git a/src/proc/control/command-setup.cpp b/src/proc/control/command-setup.cpp index dd69cbf02..073f9f4ca 100644 --- a/src/proc/control/command-setup.cpp +++ b/src/proc/control/command-setup.cpp @@ -206,7 +206,7 @@ namespace control { REQUIRE (instance and instance.canExec()); dispatcher_.enqueue(move (instance)); - instance.close(); + ENSURE (not instance); } diff --git a/src/proc/control/command.cpp b/src/proc/control/command.cpp index 3c62d8ea2..7fb0138c8 100644 --- a/src/proc/control/command.cpp +++ b/src/proc/control/command.cpp @@ -50,11 +50,13 @@ #include "proc/control/command-impl-clone-builder.hpp" #include "proc/control/handling-pattern.hpp" +#include #include #include using std::ostringstream; using std::string; +using std::move; using util::cStr; using util::_Fmt; @@ -158,14 +160,14 @@ namespace control { * @param cmdID new ID for creating a separate command registration when provided * @throw error::Logic when \c this is already activated. */ void - Command::activate (shared_ptr const& implFrame, Symbol cmdID) + Command::activate (shared_ptr && implFrame, Symbol cmdID) { REQUIRE (implFrame); if (this->isValid()) duplicate_detected (cmdID); - _Handle::activate (implFrame); + _Handle::activate (move (implFrame)); if (cmdID) CommandRegistry::instance().track (cmdID, *this); @@ -185,7 +187,7 @@ namespace control { duplicate_detected (newCmdID); Command cloneDefinition; - cloneDefinition.activate (registry.createCloneImpl(this->impl()), newCmdID); + cloneDefinition.activate (move (registry.createCloneImpl(this->impl())), newCmdID); ENSURE (cloneDefinition); return cloneDefinition; } @@ -200,7 +202,7 @@ namespace control { shared_ptr cloneImpl = registry.createCloneImpl(this->impl()); Command clone; - clone.activate (cloneImpl); + clone.activate (move (cloneImpl)); ENSURE (clone); return clone; } diff --git a/src/proc/control/command.hpp b/src/proc/control/command.hpp index dc57232b3..2106b0dab 100644 --- a/src/proc/control/command.hpp +++ b/src/proc/control/command.hpp @@ -130,6 +130,10 @@ namespace control { ~Command(); // default copy acceptable + Command (Command &&) = default; + Command (Command const&) = default; + Command& operator= (Command &&) = default; + Command& operator= (Command const&) = default; @@ -192,7 +196,7 @@ namespace control { protected: static Command fetchDef (Symbol cmdID); - void activate (shared_ptr const&, Symbol cmdID =0); + void activate (shared_ptr &&, Symbol cmdID =0); friend class CommandDef; //...invoking those two functions during definition stage