2009-06-08 04:46:07 +02:00
|
|
|
/*
|
|
|
|
|
COMMAND.hpp - Key abstraction for proc/edit operations and UNDO management
|
|
|
|
|
|
|
|
|
|
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.hpp
|
|
|
|
|
** //TODO
|
|
|
|
|
**
|
|
|
|
|
** @see ProcDispatcher
|
|
|
|
|
** @see Session
|
|
|
|
|
**
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef CONTROL_COMMAND_H
|
|
|
|
|
#define CONTROL_COMMAND_H
|
|
|
|
|
|
2009-07-25 19:21:50 +02:00
|
|
|
#include "pre.hpp"
|
2009-06-08 04:46:07 +02:00
|
|
|
#include "include/symbol.hpp"
|
2009-07-25 19:21:50 +02:00
|
|
|
#include "proc/control/command-binding.hpp"
|
2009-06-19 14:47:37 +02:00
|
|
|
#include "proc/control/command-mutation.hpp"
|
2009-06-08 04:46:07 +02:00
|
|
|
#include "proc/control/command-closure.hpp"
|
2009-07-24 17:50:14 +02:00
|
|
|
#include "lib/bool-checkable.hpp"
|
2009-07-27 02:38:53 +02:00
|
|
|
#include "lib/handle.hpp"
|
2009-06-08 04:46:07 +02:00
|
|
|
|
|
|
|
|
//#include <tr1/memory>
|
2009-08-01 17:14:27 +02:00
|
|
|
#include <string>
|
2009-06-08 04:46:07 +02:00
|
|
|
|
|
|
|
|
///////////////////////////////////////////TODO: define an C-API representation here, make the header multilingual!
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace control {
|
|
|
|
|
|
2009-08-01 17:14:27 +02:00
|
|
|
using std::string;
|
2009-06-08 04:46:07 +02:00
|
|
|
using lumiera::Symbol;
|
|
|
|
|
// using std::tr1::shared_ptr;
|
|
|
|
|
|
2009-07-25 19:21:50 +02:00
|
|
|
LUMIERA_ERROR_DECLARE (UNBOUND_ARGUMENTS); ///< Command functor not yet usable, because arguments aren't bound
|
|
|
|
|
LUMIERA_ERROR_DECLARE (INVALID_COMMAND); ///< Unknown or insufficiently defined command
|
2009-08-01 17:14:27 +02:00
|
|
|
LUMIERA_ERROR_DECLARE (DUPLICATE_COMMAND); ///< Attempt to redefine an already existing command definition
|
2009-07-25 19:21:50 +02:00
|
|
|
LUMIERA_ERROR_DECLARE (INVALID_ARGUMENTS); ///< Arguments provided for binding doesn't match stored command function parameters
|
|
|
|
|
|
|
|
|
|
|
2009-06-08 04:46:07 +02:00
|
|
|
|
2009-07-26 02:00:47 +02:00
|
|
|
class CommandDef;
|
2009-07-24 17:50:14 +02:00
|
|
|
class HandlingPattern;
|
|
|
|
|
|
|
|
|
|
|
2009-06-08 04:46:07 +02:00
|
|
|
/**
|
|
|
|
|
* @todo Type-comment
|
|
|
|
|
*/
|
|
|
|
|
class Command
|
2009-07-29 16:55:15 +02:00
|
|
|
: public com::ArgumentBinder<Command // accepts arbitrary bind(..) calls (with runtime check)
|
|
|
|
|
, lib::BoolCheckable<Command // implicit conversion to bool for status check
|
|
|
|
|
, lib::Handle<CommandImpl> // actually implemented as ref counting Handle
|
|
|
|
|
> >
|
2009-06-08 04:46:07 +02:00
|
|
|
{
|
2009-08-01 02:18:01 +02:00
|
|
|
typedef lib::Handle<CommandImpl> _Handle;
|
2009-06-08 04:46:07 +02:00
|
|
|
|
|
|
|
|
public:
|
2009-07-24 17:50:14 +02:00
|
|
|
/* === command registry === */
|
2009-08-01 17:14:27 +02:00
|
|
|
static Command get (Symbol cmdID);
|
|
|
|
|
static bool remove (Symbol cmdID);
|
|
|
|
|
static bool undef (Symbol cmdID);
|
2009-07-24 17:50:14 +02:00
|
|
|
|
2009-07-26 02:00:47 +02:00
|
|
|
CommandDef storeDef (Symbol newCmdID);
|
2009-07-24 17:50:14 +02:00
|
|
|
|
2009-07-30 03:57:19 +02:00
|
|
|
Command() { } ///< undefined command
|
2009-07-24 17:50:14 +02:00
|
|
|
~Command();
|
|
|
|
|
|
|
|
|
|
void operator() () ;
|
|
|
|
|
void undo () ;
|
|
|
|
|
|
2009-06-19 19:11:33 +02:00
|
|
|
|
2009-07-24 17:50:14 +02:00
|
|
|
/** core operation: invoke the command
|
|
|
|
|
* @param execPattern describes the individual steps
|
|
|
|
|
* necessary to get this command invoked properly
|
|
|
|
|
*/
|
|
|
|
|
void exec (HandlingPattern const& execPattern);
|
2009-06-19 19:11:33 +02:00
|
|
|
|
2009-07-26 02:00:47 +02:00
|
|
|
void execSync ();
|
|
|
|
|
|
2009-07-24 17:50:14 +02:00
|
|
|
HandlingPattern const& getDefaultHandlingPattern() const;
|
2009-06-08 04:46:07 +02:00
|
|
|
|
2009-07-24 17:50:14 +02:00
|
|
|
|
2009-08-01 17:14:27 +02:00
|
|
|
|
|
|
|
|
/* === command lifecycle === */
|
|
|
|
|
|
|
|
|
|
Command& activate (CommandImpl&);
|
|
|
|
|
|
2009-07-25 19:21:50 +02:00
|
|
|
template<typename TYPES>
|
|
|
|
|
void bindArg (Tuple<TYPES> const&);
|
|
|
|
|
|
|
|
|
|
|
2009-07-24 17:50:14 +02:00
|
|
|
/* === diagnostics === */
|
|
|
|
|
|
|
|
|
|
static size_t definition_count();
|
|
|
|
|
static size_t instance_count();
|
|
|
|
|
|
|
|
|
|
bool isValid() const;
|
|
|
|
|
bool canExec() const;
|
|
|
|
|
bool canUndo() const;
|
2009-07-26 02:00:47 +02:00
|
|
|
|
2009-08-01 17:14:27 +02:00
|
|
|
operator string() const;
|
2009-08-01 02:18:01 +02:00
|
|
|
friend bool operator== (Command const&, Command const&);
|
|
|
|
|
|
|
|
|
|
|
2009-07-26 02:00:47 +02:00
|
|
|
protected:
|
2009-08-01 17:14:27 +02:00
|
|
|
static Command fetchDef (Symbol cmdID);
|
2009-07-29 16:55:15 +02:00
|
|
|
|
|
|
|
|
friend class CommandDef;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
2009-07-26 02:00:47 +02:00
|
|
|
|
2009-06-08 04:46:07 +02:00
|
|
|
};
|
|
|
|
|
////////////////TODO currently just fleshing out the API....
|
|
|
|
|
|
2009-07-24 17:50:14 +02:00
|
|
|
|
|
|
|
|
inline void
|
|
|
|
|
Command::operator() ()
|
|
|
|
|
{
|
|
|
|
|
exec (getDefaultHandlingPattern());
|
|
|
|
|
}
|
2009-08-01 02:18:01 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
operator== (Command const& c1, Command const& c2)
|
|
|
|
|
{
|
|
|
|
|
return (!c1 && !c2)
|
|
|
|
|
|| ( c1 && c2 && c1.impl() == c2.impl());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
operator!= (Command const& c1, Command const& c2)
|
|
|
|
|
{
|
|
|
|
|
return ! (c1 == c2);
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-24 17:50:14 +02:00
|
|
|
|
2009-06-08 04:46:07 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace control
|
|
|
|
|
#endif
|