/* COMMAND-MUTATION.hpp - functor encapsulating the actual operation of proc-Command Copyright (C) Lumiera.org 2009, Hermann Vosseler 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-mutation.hpp ** The core of a Proc-Layer command: functor containing the actual operation to be executed. ** //TODO ** ** @see Command ** @see ProcDispatcher ** */ #ifndef CONTROL_COMMAND_MUTATION_H #define CONTROL_COMMAND_MUTATION_H //#include "pre.hpp" #include "lib/error.hpp" #include "proc/control/command-closure.hpp" //#include #include #include #include #include namespace control { // using lumiera::Symbol; // using std::tr1::shared_ptr; using boost::scoped_ptr; using std::tr1::function; using std::ostream; using std::string; /** * @todo Type-comment */ class Mutation { PClo clo_; public: template Mutation (function const& func) { UNIMPLEMENTED ("build a Mutation functor object, thereby erasing the concrete function signature type"); } virtual ~Mutation() {} virtual Mutation& close (CmdClosure const& closure) { UNIMPLEMENTED ("accept and store a parameter closure"); return *this; } void operator() () { UNIMPLEMENTED ("invoke the Mutation functor"); } /* == diagnostics == */ typedef PClo Mutation::*_unspecified_bool_type; /** implicit conversion to "bool" */ operator _unspecified_bool_type() const { return isValid()? &Mutation::clo_ : 0; } // never throws bool operator! () const { return !isValid(); } // ditto operator string() const { return isValid()? string (*clo_) : "Mutation(state missing)"; } protected: virtual bool isValid () const { UNIMPLEMENTED ("mutation lifecycle"); } }; inline ostream& operator<< (ostream& os, const Mutation& muta) { return os << string(muta); } /** * @todo Type-comment */ class UndoMutation : public Mutation { scoped_ptr memento_; public: template UndoMutation (function const& undoFunc, function const& captureFunc) : Mutation(undoFunc) { UNIMPLEMENTED ("build a undo Mutation functor object"); } UndoMutation (UndoMutation const& o) : Mutation(*this), memento_(o.memento_->clone().get()) { } UndoMutation& operator= (UndoMutation const& o) { Mutation::operator= (o); memento_.reset(o.memento_->clone().get()); return *this; } Mutation& captureState () { UNIMPLEMENTED ("invoke the state capturing Functor"); } CmdClosure& getMemento() { UNIMPLEMENTED ("return the closure serving as memento"); } }; ////////////////TODO currently just fleshing out the API.... LUMIERA_ERROR_DECLARE (UNBOUND_ARGUMENTS); ///< Mutation functor not yet usable, because arguments aren't bound LUMIERA_ERROR_DECLARE (MISSING_MEMENTO); ///< Undo functor not yet usable, because no undo state has been captured } // namespace control #endif