2009-06-28 15:27:27 +02:00
|
|
|
|
/*
|
2016-02-06 16:29:06 +01:00
|
|
|
|
COMMAND-STORAGE-HOLDER.hpp - specifically typed container for storage of command arguments
|
2010-12-17 23:28:49 +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
|
|
|
|
Copyright (C)
|
|
|
|
|
|
2009, Hermann Vosseler <Ichthyostega@web.de>
|
2010-12-17 23:28:49 +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.
|
2010-12-17 23:28:49 +01:00
|
|
|
|
|
2009-06-28 15:27:27 +02:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-06 16:29:06 +01:00
|
|
|
|
/** @file command-storage-holder.hpp
|
2009-08-10 01:32:33 +02:00
|
|
|
|
** A passive container record holding the actual command arguments & UNDO state.
|
2016-02-06 16:29:06 +01:00
|
|
|
|
** Effectively, this is the top level CmdClosure Implementation, which in turn
|
|
|
|
|
|
** delegates to sub-closures for the operation arguments and for UNDO management.
|
2009-06-28 15:27:27 +02:00
|
|
|
|
** While all command objects themselves have a common type (type erasure),
|
2009-07-20 07:03:18 +02:00
|
|
|
|
** the actual argument tuple and the state memento for UNDO can't. Especially,
|
2009-06-28 15:27:27 +02:00
|
|
|
|
** the size of arguments and memento will depend on their respective types.
|
|
|
|
|
|
** Thus, to manage somehow the storage of this data, we create a common holder,
|
2009-07-20 07:03:18 +02:00
|
|
|
|
** which can than be managed by a custom allocator / object pool.
|
2009-06-28 15:27:27 +02:00
|
|
|
|
**
|
|
|
|
|
|
** @see Command
|
2009-07-20 07:03:18 +02:00
|
|
|
|
** @see CmdClosure storage of command arguments
|
|
|
|
|
|
** @see MementoTie wiring of UNDO functions & memento
|
|
|
|
|
|
** @see UndoMutation execution of UNDO
|
2009-06-28 15:27:27 +02:00
|
|
|
|
** @see command-argument-test.cpp
|
|
|
|
|
|
**
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-06 16:29:06 +01:00
|
|
|
|
#ifndef CONTROL_COMMAND_STORAGE_HOLDER_H
|
|
|
|
|
|
#define CONTROL_COMMAND_STORAGE_HOLDER_H
|
2009-06-28 15:27:27 +02:00
|
|
|
|
|
2009-10-02 23:12:36 +02:00
|
|
|
|
#include "lib/typed-allocation-manager.hpp"
|
2018-11-15 23:42:43 +01:00
|
|
|
|
#include "steam/control/command-op-closure.hpp"
|
|
|
|
|
|
#include "steam/control/memento-tie.hpp"
|
|
|
|
|
|
#include "steam/control/command-impl-clone-builder.hpp"
|
2009-07-19 05:47:36 +02:00
|
|
|
|
#include "lib/opaque-holder.hpp"
|
2009-06-28 15:27:27 +02:00
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-11-15 23:55:13 +01:00
|
|
|
|
namespace steam {
|
2009-06-28 15:27:27 +02:00
|
|
|
|
namespace control {
|
2024-03-16 02:04:47 +01:00
|
|
|
|
namespace err = lumiera::error;
|
2009-06-28 15:27:27 +02:00
|
|
|
|
|
2009-07-19 05:47:36 +02:00
|
|
|
|
using lib::InPlaceBuffer;
|
2009-07-20 05:09:46 +02:00
|
|
|
|
using std::string;
|
2009-07-19 05:47:36 +02:00
|
|
|
|
|
2009-06-28 15:27:27 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-07-12 18:55:33 +02:00
|
|
|
|
/**
|
2016-02-06 16:29:06 +01:00
|
|
|
|
* This is "the" top level CmdClosure implementation.
|
|
|
|
|
|
* It is a specifically typed CmdClosure, which serves for
|
2009-07-12 18:55:33 +02:00
|
|
|
|
* actually allocating storage to hold the command arguments
|
2018-11-15 21:13:52 +01:00
|
|
|
|
* and the UNDO state (memento) for Steam-Layer commands.
|
2016-02-06 16:29:06 +01:00
|
|
|
|
* Both the contained components within StorageHolder
|
2009-07-18 19:36:32 +02:00
|
|
|
|
* can be in \em empty state; there are no distinct
|
2016-02-06 16:29:06 +01:00
|
|
|
|
* lifecycle limitations. StorageHolder is part
|
2018-11-15 21:13:52 +01:00
|
|
|
|
* of Steam-Layer command's implementation
|
2009-07-20 07:03:18 +02:00
|
|
|
|
* and should not be used standalone.
|
2009-07-12 18:55:33 +02:00
|
|
|
|
*/
|
2009-06-28 15:27:27 +02:00
|
|
|
|
template<typename SIG, typename MEM>
|
2016-02-06 16:29:06 +01:00
|
|
|
|
class StorageHolder
|
2016-02-07 01:41:40 +01:00
|
|
|
|
: public CmdClosure
|
2009-06-28 15:27:27 +02:00
|
|
|
|
{
|
2016-02-06 16:29:06 +01:00
|
|
|
|
using ArgHolder = OpClosure<SIG>;
|
2016-01-29 00:59:34 +01:00
|
|
|
|
using MemHolder = MementoTie<SIG,MEM>;
|
2009-07-19 05:47:36 +02:00
|
|
|
|
|
2016-02-07 01:41:40 +01:00
|
|
|
|
using ArgumentBuff = InPlaceBuffer<ArgHolder>;
|
|
|
|
|
|
using MementoBuff = InPlaceBuffer<MemHolder>;
|
2009-07-19 05:47:36 +02:00
|
|
|
|
|
2025-07-05 20:08:18 +02:00
|
|
|
|
using ArgTuple = ArgHolder::ArgTuple;
|
|
|
|
|
|
using Args = lib::meta::RebindTupleTypes<ArgTuple>::Seq; // std::tuple<ARGS...> to Types<ARGS...>
|
2009-07-19 05:47:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* ====== in-place storage buffers ====== */
|
|
|
|
|
|
|
|
|
|
|
|
ArgumentBuff arguments_;
|
|
|
|
|
|
MementoBuff memento_;
|
2009-07-12 18:55:33 +02:00
|
|
|
|
|
|
|
|
|
|
|
2009-07-19 05:47:36 +02:00
|
|
|
|
|
|
|
|
|
|
/* ==== proxied CmdClosure interface ==== */
|
2009-07-12 18:55:33 +02:00
|
|
|
|
|
2009-07-20 07:03:18 +02:00
|
|
|
|
public:
|
2016-01-29 00:59:34 +01:00
|
|
|
|
virtual bool
|
|
|
|
|
|
isValid () const override
|
2009-07-12 18:55:33 +02:00
|
|
|
|
{
|
2009-07-19 05:47:36 +02:00
|
|
|
|
return arguments_->isValid();
|
2009-07-12 18:55:33 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-01-29 00:59:34 +01:00
|
|
|
|
virtual bool
|
|
|
|
|
|
isCaptured() const override
|
2009-09-21 03:33:56 +02:00
|
|
|
|
{
|
|
|
|
|
|
return memento_->isValid();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-07-12 18:55:33 +02:00
|
|
|
|
|
2009-08-04 02:25:50 +02:00
|
|
|
|
/** assign a new parameter tuple to this */
|
2016-01-29 00:59:34 +01:00
|
|
|
|
virtual void
|
|
|
|
|
|
bindArguments (Arguments& args) override
|
|
|
|
|
|
{
|
2016-02-06 19:42:41 +01:00
|
|
|
|
storeTuple (args.get<ArgTuple>());
|
2016-01-29 00:59:34 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** 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
|
|
|
|
|
|
{
|
2016-02-06 19:42:41 +01:00
|
|
|
|
storeTuple (buildTuple<Args> (paramData));
|
2016-01-29 00:59:34 +01:00
|
|
|
|
}
|
2009-08-04 02:25:50 +02:00
|
|
|
|
|
2017-04-16 19:21:29 +02:00
|
|
|
|
/** discard any argument data and return to _empty_ state */
|
|
|
|
|
|
virtual void
|
|
|
|
|
|
unbindArguments() override
|
|
|
|
|
|
{
|
|
|
|
|
|
clearStorage();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2009-08-04 02:25:50 +02:00
|
|
|
|
|
2016-01-29 00:59:34 +01:00
|
|
|
|
virtual void
|
|
|
|
|
|
invoke (CmdFunctor const& func) override
|
2009-07-12 18:55:33 +02:00
|
|
|
|
{
|
2009-07-19 05:47:36 +02:00
|
|
|
|
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)};
|
2009-07-12 18:55:33 +02:00
|
|
|
|
|
2009-09-21 03:15:06 +02:00
|
|
|
|
arguments_->invoke(func);
|
2009-07-12 18:55:33 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-01-29 00:59:34 +01:00
|
|
|
|
virtual
|
|
|
|
|
|
operator string() const override
|
2009-07-12 18:55:33 +02:00
|
|
|
|
{
|
|
|
|
|
|
return "Command-State{ arguments="
|
2016-02-07 01:41:40 +01:00
|
|
|
|
+ (arguments_->isValid()? string(*arguments_) : "unbound")
|
2009-07-19 08:32:49 +02:00
|
|
|
|
+ ", "+string(*memento_)+"}"
|
2009-07-12 18:55:33 +02:00
|
|
|
|
;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-07-20 07:03:18 +02:00
|
|
|
|
|
2016-02-06 16:29:06 +01:00
|
|
|
|
/** per default, all data within StorageHolder
|
2009-07-12 18:55:33 +02:00
|
|
|
|
* 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
|
|
|
|
|
|
*/
|
2016-02-06 16:29:06 +01:00
|
|
|
|
StorageHolder ()
|
2009-07-19 05:47:36 +02:00
|
|
|
|
: arguments_()
|
|
|
|
|
|
, memento_()
|
2009-07-12 18:55:33 +02:00
|
|
|
|
{ }
|
|
|
|
|
|
|
2016-02-07 01:41:40 +01:00
|
|
|
|
/** copy construction allowed(but no assignment).
|
|
|
|
|
|
* @remarks rationale is to support immutable argument values,
|
|
|
|
|
|
* which means default/copy construction is OK
|
|
|
|
|
|
*/
|
2016-02-06 16:29:06 +01:00
|
|
|
|
StorageHolder (StorageHolder const& oAh)
|
2009-07-20 07:03:18 +02:00
|
|
|
|
: arguments_()
|
|
|
|
|
|
, memento_()
|
|
|
|
|
|
{
|
2025-06-07 23:59:57 +02:00
|
|
|
|
if (oAh.arguments_->isValid()) // don't clone garbage from invalid arguments
|
2009-10-05 06:07:21 +02:00
|
|
|
|
arguments_.template create<ArgHolder> (*oAh.arguments_);
|
|
|
|
|
|
|
2025-06-07 23:59:57 +02:00
|
|
|
|
// memento can be cloned as-is, irrespective of activation state
|
2009-07-20 07:03:18 +02:00
|
|
|
|
memento_.template create<MemHolder> (*oAh.memento_);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-02-07 01:41:40 +01:00
|
|
|
|
|
|
|
|
|
|
/** copy construction allowed(but no assignment)*/
|
|
|
|
|
|
StorageHolder& operator= (StorageHolder const&) = delete;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-10-10 04:24:27 +02:00
|
|
|
|
/** assist with creating a clone copy;
|
|
|
|
|
|
* this results in invocation of the copy ctor */
|
|
|
|
|
|
void
|
2016-01-29 00:59:34 +01:00
|
|
|
|
accept (CommandImplCloneBuilder& visitor) const override
|
2009-08-09 04:12:46 +02:00
|
|
|
|
{
|
2009-10-10 04:24:27 +02:00
|
|
|
|
visitor.buildCloneContext (*this);
|
2009-08-09 04:12:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2009-07-20 07:03:18 +02:00
|
|
|
|
|
2009-07-12 18:55:33 +02:00
|
|
|
|
/** has undo state capturing been invoked? */
|
2009-07-19 05:47:36 +02:00
|
|
|
|
bool canUndo () const { return memento_->isValid(); }
|
|
|
|
|
|
bool empty () const { return !arguments_->isValid(); }
|
2009-07-12 18:55:33 +02:00
|
|
|
|
|
|
|
|
|
|
|
2016-02-06 16:29:06 +01:00
|
|
|
|
/** store a new argument tuple within this StorageHolder,
|
2009-09-20 18:37:20 +02:00
|
|
|
|
* discarding any previously stored arguments */
|
2009-07-12 18:55:33 +02:00
|
|
|
|
void
|
2009-10-02 23:49:15 +02:00
|
|
|
|
storeTuple (ArgTuple const& argTup)
|
2009-07-12 18:55:33 +02:00
|
|
|
|
{
|
2009-07-19 05:47:36 +02:00
|
|
|
|
arguments_.template create<ArgHolder> (argTup);
|
2009-07-12 18:55:33 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-04-16 19:21:29 +02:00
|
|
|
|
void
|
|
|
|
|
|
clearStorage ()
|
|
|
|
|
|
{
|
|
|
|
|
|
arguments_.template create<ArgHolder>();
|
|
|
|
|
|
memento_->clear();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2009-07-12 18:55:33 +02:00
|
|
|
|
|
2025-07-05 20:08:18 +02:00
|
|
|
|
using SIG_op = CommandSignature<SIG,MEM>::OperateSig;
|
|
|
|
|
|
using SIG_cap = CommandSignature<SIG,MEM>::CaptureSig;
|
|
|
|
|
|
using SIG_undo = CommandSignature<SIG,MEM>::UndoOp_Sig;
|
2009-06-28 15:27:27 +02:00
|
|
|
|
|
2009-07-12 18:55:33 +02:00
|
|
|
|
/** create a new memento storage wiring, discarding existing memento state.
|
|
|
|
|
|
* @note any bound undo/capture functions based on the previously held MementoTie
|
|
|
|
|
|
* are silently invalidated; using them will likely cause memory corruption! */
|
|
|
|
|
|
MementoTie<SIG,MEM>&
|
2009-07-19 08:32:49 +02:00
|
|
|
|
tie (function<SIG_undo> const& undoFunc,
|
2009-07-12 18:55:33 +02:00
|
|
|
|
function<SIG_cap> const& captureFunc)
|
|
|
|
|
|
{
|
2009-07-19 05:47:36 +02:00
|
|
|
|
return memento_.template create<MemHolder> (undoFunc,captureFunc);
|
|
|
|
|
|
}
|
2009-07-19 08:32:49 +02:00
|
|
|
|
|
2009-10-10 04:24:27 +02:00
|
|
|
|
/** just re-access an existing memento storage wiring.
|
|
|
|
|
|
* Used when cloning the closure */
|
|
|
|
|
|
MementoTie<SIG,MEM>&
|
|
|
|
|
|
getMementoWiring ()
|
|
|
|
|
|
{
|
|
|
|
|
|
return *memento_;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2009-06-28 15:27:27 +02:00
|
|
|
|
|
2009-07-18 19:36:32 +02:00
|
|
|
|
|
|
|
|
|
|
/** direct "backdoor" access to stored memento value.
|
2009-07-20 05:09:46 +02:00
|
|
|
|
* @throw LUMIERA_ERROR_MISSING_MEMENTO when invoked
|
|
|
|
|
|
* prior to \c tie(..) and capturing any state */
|
2009-07-18 19:36:32 +02:00
|
|
|
|
MEM&
|
|
|
|
|
|
memento ()
|
|
|
|
|
|
{
|
2009-07-19 05:47:36 +02:00
|
|
|
|
return memento_->getState();
|
2009-07-18 19:36:32 +02:00
|
|
|
|
}
|
2009-06-28 15:27:27 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-11-15 23:55:13 +01:00
|
|
|
|
}} // namespace steam::control
|
2016-02-06 16:29:06 +01:00
|
|
|
|
#endif /*CONTROL_COMMAND_STORAGE_HOLDER_H*/
|