2009-06-08 04:46:07 +02:00
|
|
|
/*
|
|
|
|
|
COMMAND-CLOSURE.hpp - defining execution targets and parameters for commands
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2009-06-08 04:46:07 +02:00
|
|
|
Copyright (C) Lumiera.org
|
|
|
|
|
2009, Hermann Vosseler <Ichthyostega@web.de>
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2009-06-08 04:46:07 +02:00
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License as
|
2010-12-17 23:28:49 +01:00
|
|
|
published by the Free Software Foundation; either version 2 of
|
|
|
|
|
the License, or (at your option) any later version.
|
|
|
|
|
|
2009-06-08 04:46:07 +02:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2009-06-08 04:46:07 +02:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2009-06-08 04:46:07 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @file command-closure.hpp
|
|
|
|
|
** A closure enabling self-contained execution of commands within the ProcDispatcher.
|
2009-08-10 01:32:33 +02:00
|
|
|
** After defining a proc-layer command, at some point the function arguments
|
|
|
|
|
** of the contained operation are "closed" by storing concrete argument values.
|
2011-12-24 05:38:54 +01:00
|
|
|
** These values will be fed later on to the operation when the command is invoked.
|
2009-08-10 01:32:33 +02:00
|
|
|
**
|
2011-12-24 05:38:54 +01:00
|
|
|
** Most of the command machinery accesses this function closure through the generic
|
|
|
|
|
** interface CmdClosure, while, when defining a command, subclasses typed to the specific
|
2016-02-06 16:29:06 +01:00
|
|
|
** function arguments are created. Especially, there is an StorageHolder template,
|
|
|
|
|
** which is used to define the storage for the concrete arguments. This StorageHolder
|
|
|
|
|
** internally contains an OpClosure<SIG> instance (where SIG is the signature of the
|
2009-08-10 01:32:33 +02:00
|
|
|
** actual command operation function), which implements the invocation of the
|
|
|
|
|
** operation function with the stored argument tuple.
|
2009-09-20 18:37:20 +02:00
|
|
|
**
|
2017-04-16 19:21:29 +02:00
|
|
|
** ## Command Closure and Lifecycle
|
2009-09-20 18:37:20 +02:00
|
|
|
** When defining a command, Mutation objects are to be created based on a concrete function.
|
|
|
|
|
** These are stored embedded into a type erasure container, thus disposing the specific type
|
|
|
|
|
** information of the function and function arguments. Each command needs an Mutation object
|
|
|
|
|
** holding the command operation and an UndoMutation holding the undo functor.
|
|
|
|
|
**
|
|
|
|
|
** Later on, any command needs to be made ready for execution by binding it to a specific
|
|
|
|
|
** execution environment, which especially includes the target objects to be mutated by the
|
2011-12-24 05:38:54 +01:00
|
|
|
** command. Effectively, this means "closing" the Mutation (and UNDO) functor(s)) with the
|
2016-02-06 16:29:06 +01:00
|
|
|
** actual function arguments. These arguments are stored embedded within an StorageHolder,
|
|
|
|
|
** which thereby acts as closure. Besides, the StorageHolder also has to accommodate for
|
|
|
|
|
** storage holding the captured UNDO state (memento). Internally the StorageHolder
|
2009-09-20 18:37:20 +02:00
|
|
|
** has to keep track of the actual types, thus allowing to re-construct the concrete
|
|
|
|
|
** function signature when closing the Mutation.
|
|
|
|
|
**
|
2017-04-16 19:21:29 +02:00
|
|
|
** Finally, when invoking the command, it passes a `CmdClosure&` to the Mutation object,
|
2009-09-20 18:37:20 +02:00
|
|
|
** which allows the embedded function to be called with the concrete arguments. Besides
|
|
|
|
|
** just invoking it, a command can also be used like a prototype object. To support this
|
|
|
|
|
** use case it is possible to re-bind to a new set of command arguments, and to create
|
|
|
|
|
** a clone copy of the argument (holder) without disclosing the actual types involved.
|
|
|
|
|
**
|
2009-06-08 04:46:07 +02:00
|
|
|
** @see Command
|
|
|
|
|
** @see ProcDispatcher
|
2016-02-06 18:50:51 +01:00
|
|
|
** @see command-storage-holder.hpp
|
|
|
|
|
** @see command-op-closure.hpp
|
2009-06-08 04:46:07 +02:00
|
|
|
**
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef CONTROL_COMMAND_CLOSURE_H
|
|
|
|
|
#define CONTROL_COMMAND_CLOSURE_H
|
|
|
|
|
|
2009-06-20 09:22:33 +02:00
|
|
|
#include "lib/meta/function-erasure.hpp"
|
2009-08-10 01:32:33 +02:00
|
|
|
#include "proc/control/argument-erasure.hpp"
|
2016-02-06 19:41:21 +01:00
|
|
|
#include "lib/diff/gen-node.hpp"
|
2009-06-08 04:46:07 +02:00
|
|
|
|
2014-04-03 22:42:48 +02:00
|
|
|
#include <memory>
|
2009-06-19 19:11:33 +02:00
|
|
|
#include <string>
|
2009-06-08 04:46:07 +02:00
|
|
|
|
|
|
|
|
|
2009-06-19 19:11:33 +02:00
|
|
|
|
2009-06-08 04:46:07 +02:00
|
|
|
|
2011-12-02 17:50:44 +01:00
|
|
|
namespace proc {
|
2009-06-08 04:46:07 +02:00
|
|
|
namespace control {
|
|
|
|
|
|
2011-12-03 02:56:50 +01:00
|
|
|
using lib::meta::FunErasure;
|
|
|
|
|
using lib::meta::StoreFunction;
|
2009-08-10 01:32:33 +02:00
|
|
|
|
2009-07-19 19:13:25 +02:00
|
|
|
using std::string;
|
2009-07-12 18:55:33 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LUMIERA_ERROR_DECLARE (UNBOUND_ARGUMENTS); ///< Command functor not yet usable, because arguments aren't bound
|
|
|
|
|
|
2009-06-20 09:22:33 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A neutral container internally holding
|
|
|
|
|
* the functor used to implement the Command
|
|
|
|
|
*/
|
|
|
|
|
typedef FunErasure<StoreFunction> CmdFunctor;
|
|
|
|
|
|
2009-10-10 03:10:05 +02:00
|
|
|
class CommandImplCloneBuilder;
|
|
|
|
|
|
|
|
|
|
|
2009-06-19 19:11:33 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Interface */
|
|
|
|
|
class CmdClosure
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
virtual ~CmdClosure() {}
|
2017-04-02 06:33:56 +02:00
|
|
|
explicit operator bool() const { return isValid(); }
|
2009-06-19 19:11:33 +02:00
|
|
|
|
2009-10-10 03:10:05 +02:00
|
|
|
virtual operator string() const =0;
|
|
|
|
|
virtual bool isValid () const =0; ///< does this closure hold a valid argument tuple?
|
|
|
|
|
virtual bool isCaptured () const =0; ///< does this closure hold captured UNDO state?
|
|
|
|
|
virtual bool equals (CmdClosure const&) const =0; ///< is equivalent to the given other closure?
|
|
|
|
|
virtual void bindArguments (Arguments&) =0; ///< store a set of parameter values within this closure
|
2016-01-29 00:59:34 +01:00
|
|
|
virtual void bindArguments (lib::diff::Rec const&) =0; ///< store a set of parameter values, passed as GenNode sequence
|
2017-04-16 19:21:29 +02:00
|
|
|
virtual void unbindArguments() =0; ///< discard any parameters and return to _unbound state_
|
2009-10-10 03:10:05 +02:00
|
|
|
virtual void invoke (CmdFunctor const&) =0; ///< invoke functor using the stored parameter values
|
|
|
|
|
virtual void accept (CommandImplCloneBuilder&) const =0; ///< assist with creating clone closure without disclosing concrete type
|
2009-06-19 19:11:33 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2016-02-07 01:41:40 +01:00
|
|
|
using PClo = std::shared_ptr<CmdClosure>;
|
2009-10-10 03:10:05 +02:00
|
|
|
|
|
|
|
|
|
2009-06-19 19:11:33 +02:00
|
|
|
|
2011-12-02 17:50:44 +01:00
|
|
|
}} // namespace proc::control
|
2016-02-06 18:50:51 +01:00
|
|
|
#endif /*CONTROL_COMMAND_CLOSURE_H*/
|