2016-02-07 01:41:40 +01:00
|
|
|
|
/*
|
|
|
|
|
|
COMMAND-SIMPLE-CLOSURE.hpp - demo implementation of command closure
|
|
|
|
|
|
|
Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
* there is no entity "Lumiera.org" which holds any copyrights
* Lumiera source code is provided under the GPL Version 2+
== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''
The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!
The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
|
|
|
|
Copyright (C)
|
|
|
|
|
|
2016, Hermann Vosseler <Ichthyostega@web.de>
|
2016-02-07 01:41:40 +01:00
|
|
|
|
|
Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
* there is no entity "Lumiera.org" which holds any copyrights
* Lumiera source code is provided under the GPL Version 2+
== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''
The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!
The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
|
|
|
|
**Lumiera** is free software; you can redistribute it and/or modify it
|
|
|
|
|
|
under the terms of the GNU General Public License as published by the
|
|
|
|
|
|
Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
|
|
option) any later version. See the file COPYING for further details.
|
2016-02-07 01:41:40 +01:00
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @file command-simple-closure.hpp
|
|
|
|
|
|
** Proof-of-concept implementation of CmdClosure.
|
|
|
|
|
|
** This is used for test only, to invoke an arbitrary matching functor with
|
|
|
|
|
|
** arguments stored embedded within this closure. In the real system, a more
|
|
|
|
|
|
** [elaborate version](\ref StorageHolder) of the same concept is used, with
|
|
|
|
|
|
** the additional complication of managing the UNDO operation as well.
|
|
|
|
|
|
**
|
|
|
|
|
|
** \par historical note
|
|
|
|
|
|
** This proof-of-concept variation was split off in an attempt to improve the
|
|
|
|
|
|
** overall design of the command / closure system. The original design had the
|
|
|
|
|
|
** embedded argument holder also implement the CmdClosure interface, which is
|
|
|
|
|
|
** a clever implementation and code-reuse trick, but otherwise caused confusion.
|
|
|
|
|
|
**
|
|
|
|
|
|
** @see Ticket #301
|
|
|
|
|
|
** @see CommandMutation_test
|
|
|
|
|
|
** @see StorageHolder
|
|
|
|
|
|
** @see OpClosure
|
|
|
|
|
|
**
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef CONTROL_COMMAND_SIMPLE_CLOSURE_H
|
|
|
|
|
|
#define CONTROL_COMMAND_SIMPLE_CLOSURE_H
|
|
|
|
|
|
|
|
|
|
|
|
#include "lib/typed-allocation-manager.hpp"
|
2018-11-15 23:42:43 +01:00
|
|
|
|
#include "steam/control/command-op-closure.hpp"
|
2016-02-07 01:41:40 +01:00
|
|
|
|
#include "lib/opaque-holder.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-11-15 23:55:13 +01:00
|
|
|
|
namespace steam {
|
2016-02-07 01:41:40 +01:00
|
|
|
|
namespace control {
|
2024-03-16 02:04:47 +01:00
|
|
|
|
namespace err = lumiera::error;
|
2016-02-07 01:41:40 +01:00
|
|
|
|
|
|
|
|
|
|
using lib::InPlaceBuffer;
|
|
|
|
|
|
using std::string;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Dummy / proof-of-concept implementation of CmdClosure.
|
|
|
|
|
|
* It is a specifically typed subclass, which serves to hold
|
|
|
|
|
|
* storage for the concrete invocation arguments within an
|
|
|
|
|
|
* inline buffer.
|
|
|
|
|
|
* @note for demonstration and unit testing
|
|
|
|
|
|
* @see StorageHolder real world implementation
|
|
|
|
|
|
*/
|
|
|
|
|
|
template<typename SIG>
|
|
|
|
|
|
class SimpleClosure
|
|
|
|
|
|
: public CmdClosure
|
|
|
|
|
|
{
|
|
|
|
|
|
using ArgHolder = OpClosure<SIG>;
|
|
|
|
|
|
using ArgumentBuff = InPlaceBuffer<ArgHolder>;
|
|
|
|
|
|
|
|
|
|
|
|
using ArgTuple = typename ArgHolder::ArgTuple;
|
2023-08-01 14:52:20 +02:00
|
|
|
|
using Args = typename lib::meta::RebindTupleTypes<ArgTuple>::Seq; // std::tuple<ARGS...> to Types<ARGS...>
|
2016-02-07 01:41:40 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* ====== in-place argument storage ====== */
|
|
|
|
|
|
|
|
|
|
|
|
ArgumentBuff arguments_;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* ==== proxied CmdClosure interface ==== */
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
virtual bool
|
|
|
|
|
|
isValid () const override
|
|
|
|
|
|
{
|
|
|
|
|
|
return arguments_->isValid();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
virtual bool
|
|
|
|
|
|
isCaptured() const override
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** assign a new parameter tuple to this */
|
|
|
|
|
|
virtual void
|
|
|
|
|
|
bindArguments (Arguments& args) override
|
|
|
|
|
|
{
|
|
|
|
|
|
storeTuple (args.get<ArgTuple>());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** assign a new set of parameter values to this.
|
|
|
|
|
|
* @note the values are passed packaged into a sequence
|
|
|
|
|
|
* of GenNode elements. This is the usual way
|
|
|
|
|
|
* arguments are passed from the UI-Bus
|
|
|
|
|
|
*/
|
|
|
|
|
|
virtual void
|
|
|
|
|
|
bindArguments (lib::diff::Rec const& paramData) override
|
|
|
|
|
|
{
|
|
|
|
|
|
storeTuple (buildTuple<Args> (paramData));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-04-16 19:21:29 +02:00
|
|
|
|
/** discard any argument data and return to _empty_ state */
|
|
|
|
|
|
virtual void
|
|
|
|
|
|
unbindArguments() override
|
|
|
|
|
|
{
|
|
|
|
|
|
clearStorage();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-02-07 01:41:40 +01:00
|
|
|
|
|
|
|
|
|
|
virtual void
|
|
|
|
|
|
invoke (CmdFunctor const& func) override
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!isValid())
|
2024-03-16 02:04:47 +01:00
|
|
|
|
throw err::State{"Lifecycle error: can't bind functor, "
|
|
|
|
|
|
"command arguments not yet provided"
|
|
|
|
|
|
, LERR_(UNBOUND_ARGUMENTS)};
|
2016-02-07 01:41:40 +01:00
|
|
|
|
|
|
|
|
|
|
arguments_->invoke(func);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
virtual
|
|
|
|
|
|
operator string() const override
|
|
|
|
|
|
{
|
|
|
|
|
|
return "Command-Closure{ arguments="
|
|
|
|
|
|
+ (arguments_->isValid()? string(*arguments_) : "unbound")
|
|
|
|
|
|
+ " }"
|
|
|
|
|
|
;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** per default, all data within StorageHolder
|
|
|
|
|
|
* is set up in \em empty state. Later on, the
|
|
|
|
|
|
* command arguments are to be provided by #bind ,
|
|
|
|
|
|
* whereas the undo functions will be wired by #tie
|
|
|
|
|
|
*/
|
|
|
|
|
|
SimpleClosure ()
|
|
|
|
|
|
: arguments_()
|
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
|
|
explicit
|
|
|
|
|
|
SimpleClosure (ArgTuple const& args)
|
|
|
|
|
|
: arguments_()
|
|
|
|
|
|
{
|
|
|
|
|
|
storeTuple (args);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SimpleClosure (SimpleClosure const& oAh)
|
|
|
|
|
|
: arguments_()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (oAh.arguments_->isValid()) // don't clone garbage from invalid arguments
|
|
|
|
|
|
arguments_.template create<ArgHolder> (*oAh.arguments_);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
accept (CommandImplCloneBuilder&) const override
|
|
|
|
|
|
{
|
|
|
|
|
|
NOTREACHED();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** has undo state capturing been invoked? */
|
|
|
|
|
|
bool canUndo () const { return false; }
|
|
|
|
|
|
bool empty () const { return !arguments_->isValid(); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** store a new argument tuple within this StorageHolder,
|
|
|
|
|
|
* discarding any previously stored arguments */
|
|
|
|
|
|
void
|
|
|
|
|
|
storeTuple (ArgTuple const& argTup)
|
|
|
|
|
|
{
|
|
|
|
|
|
arguments_.template create<ArgHolder> (argTup);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-04-16 19:21:29 +02:00
|
|
|
|
void
|
|
|
|
|
|
clearStorage ()
|
|
|
|
|
|
{
|
|
|
|
|
|
arguments_.template create<ArgHolder>();
|
|
|
|
|
|
}
|
2016-02-07 01:41:40 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-11-15 23:55:13 +01:00
|
|
|
|
}} // namespace steam::control
|
2016-02-07 01:41:40 +01:00
|
|
|
|
#endif /*CONTROL_COMMAND_SIMPLE_CLOSURE_H*/
|