2009-10-09 17:54:31 +02:00
|
|
|
/*
|
|
|
|
|
COMMAND-IMPL-CLONE-BUILDER.hpp - Cloning command implementation without disclosing concrete type
|
|
|
|
|
|
|
|
|
|
Copyright (C) Lumiera.org
|
|
|
|
|
2009, Hermann Vosseler <Ichthyostega@web.de>
|
|
|
|
|
|
|
|
|
|
This program 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.
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @file command-impl-clone-builder.hpp
|
|
|
|
|
** Helper for creating an implementation clone, based on the visitor pattern.
|
|
|
|
|
** This file deals with the problem of creating a clone from top level without
|
|
|
|
|
** any specific type information. While generally this means passing down the
|
|
|
|
|
** allocation interface, the specific problem here is that multiple parts of the
|
|
|
|
|
** command implementation need to be cloned and re-wired with the cloned partners,
|
|
|
|
|
** which requires re-creating the specifically typed context used at initial setup.
|
|
|
|
|
**
|
|
|
|
|
** Ticket #301 : it may well be that the need for such a facility is a symptom of
|
|
|
|
|
** misaligned design, but I rather doubt so -- because both the memento holder and
|
|
|
|
|
** the command closure need a specifically typed context, and there is no reason
|
|
|
|
|
** for combining them into a single facility.
|
|
|
|
|
**
|
|
|
|
|
** @see CommandRegistry#createCloneImpl
|
|
|
|
|
** @see CommandImpl
|
|
|
|
|
** @see ArgumentHolder#createClone
|
|
|
|
|
** @see command-clone-builder-test.cpp
|
|
|
|
|
**
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef CONTROL_COMMAND_IMPL_CLONE_BUILDER_H
|
|
|
|
|
#define CONTROL_COMMAND_IMPL_CLONE_BUILDER_H
|
|
|
|
|
|
|
|
|
|
//#include "proc/control/command.hpp"
|
|
|
|
|
//#include "proc/control/command-closure.hpp"
|
|
|
|
|
#include "proc/control/command-mutation.hpp"
|
|
|
|
|
#include "lib/typed-allocation-manager.hpp"
|
|
|
|
|
//#include "lib/bool-checkable.hpp"
|
|
|
|
|
|
|
|
|
|
#include <boost/noncopyable.hpp>
|
|
|
|
|
//#include <boost/operators.hpp>
|
|
|
|
|
|
|
|
|
|
#include <tr1/memory>
|
|
|
|
|
//#include <tr1/functional>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace control {
|
|
|
|
|
|
|
|
|
|
using lib::TypedAllocationManager;
|
|
|
|
|
// using std::tr1::function;
|
|
|
|
|
using std::tr1::shared_ptr;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Visitor to support creating a CommandImpl clone.
|
|
|
|
|
* Created and managed by CommandRegistry, on clone creation
|
|
|
|
|
* an instance of this builder object is passed down to re-gain
|
|
|
|
|
* a fully typed context, necessary for re-wiring the undo functors
|
|
|
|
|
* and the memento storage within the cloned parts.
|
|
|
|
|
*/
|
|
|
|
|
class CommandImplCloneBuilder
|
|
|
|
|
// : public lib::BoolCheckable<CommandImpl
|
|
|
|
|
// , boost::noncopyable
|
|
|
|
|
// >
|
2009-10-09 19:50:16 +02:00
|
|
|
: public boost::noncopyable
|
2009-10-09 17:54:31 +02:00
|
|
|
{
|
2009-10-09 19:50:16 +02:00
|
|
|
TypedAllocationManager& allocator_;
|
|
|
|
|
shared_ptr<CmdClosure> newClo_;
|
2009-10-09 17:54:31 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename ARG>
|
|
|
|
|
struct _Type
|
|
|
|
|
{
|
|
|
|
|
typedef typename ARG::SIG_op SIG_op;
|
|
|
|
|
typedef typename ARG::SIG_cap SIG_cap;
|
|
|
|
|
typedef typename ARG::SIG_undo SIG_undo;
|
|
|
|
|
|
|
|
|
|
typedef function<SIG_op> Func_op;
|
|
|
|
|
typedef function<SIG_cap> Func_cap;
|
|
|
|
|
typedef function<SIG_undo> Func_undo;
|
|
|
|
|
};
|
|
|
|
|
#define _TY(_ID_) typename _Type<ARG>::_ID_
|
|
|
|
|
|
|
|
|
|
public:
|
2009-10-09 19:50:16 +02:00
|
|
|
CommandImplCloneBuilder (TypedAllocationManager allo)
|
|
|
|
|
: allocator_(allo)
|
|
|
|
|
, newClo_()
|
2009-10-09 17:54:31 +02:00
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
|
2009-10-09 19:50:16 +02:00
|
|
|
/** visit the CommandImpl given as reference
|
|
|
|
|
* to re-gain the contained Closure type context
|
|
|
|
|
*/
|
2009-10-09 17:54:31 +02:00
|
|
|
void
|
2009-10-09 19:50:16 +02:00
|
|
|
visit (CommandImpl const& sourceImpl)
|
2009-10-09 17:54:31 +02:00
|
|
|
{
|
2009-10-09 19:50:16 +02:00
|
|
|
UNIMPLEMENTED ("get access to source context");
|
2009-10-09 17:54:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-10-09 19:50:16 +02:00
|
|
|
/** to be executed from within the specifically typed context
|
|
|
|
|
* of a concrete command ArgumentHolder; prepare the objects
|
|
|
|
|
* necessary to re-build a "clone" of the UNDO-Functor.
|
|
|
|
|
*/
|
|
|
|
|
template<typename ARG>
|
|
|
|
|
void
|
|
|
|
|
buildCloneContext (shared_ptr<ARG> pArgHolder)
|
2009-10-09 17:54:31 +02:00
|
|
|
{
|
2009-10-09 19:50:16 +02:00
|
|
|
UNIMPLEMENTED ("how to reflect context back");
|
|
|
|
|
newClo_ = pArgHolder;
|
2009-10-09 17:54:31 +02:00
|
|
|
}
|
|
|
|
|
|
2009-10-09 19:50:16 +02:00
|
|
|
#undef _TY
|
2009-10-09 17:54:31 +02:00
|
|
|
|
|
|
|
|
|
2009-10-09 19:50:16 +02:00
|
|
|
/** after visitation: use pre-built bits to provide a cloned UndoFunctor */
|
|
|
|
|
UndoMutation const&
|
|
|
|
|
clonedUndoMutation ()
|
2009-10-09 17:54:31 +02:00
|
|
|
{
|
2009-10-09 19:50:16 +02:00
|
|
|
UNIMPLEMENTED (" getNewUndoMutation ()" );
|
2009-10-09 17:54:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-10-09 19:50:16 +02:00
|
|
|
/** after visitation: provide cloned ArgumentHolder,
|
|
|
|
|
* but already stripped down to the generic usage type */
|
|
|
|
|
shared_ptr<CmdClosure> const&
|
|
|
|
|
clonedClosuere ()
|
2009-10-09 17:54:31 +02:00
|
|
|
{
|
2009-10-09 19:50:16 +02:00
|
|
|
REQUIRE (newClo_);
|
|
|
|
|
return newClo_;
|
2009-10-09 17:54:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace control
|
|
|
|
|
#endif
|