Proc Command handling frontend finished and usable for now

Additional convenience shortcuts and a bit of polishing.
Closes Ticket #300
This commit is contained in:
Fischlurch 2009-10-10 17:53:11 +02:00
parent c6d5f8a0b4
commit cd51e5fef0
8 changed files with 272 additions and 43 deletions

View file

@ -91,6 +91,7 @@ namespace control {
using lumiera::typelist::Types;
using lumiera::typelist::NullType;
using lumiera::typelist::Tuple;
using lumiera::typelist::tuple::makeNullTuple;
@ -101,6 +102,8 @@ namespace control {
typedef function<Command&(ImplInstance const&)> Activation;
template<typename SIG>
struct CompletedDefinition
: AcceptArgumentBindingRet< Command&, SIG // Return type and Argument Signature of the \c bind(..) function
@ -115,19 +118,52 @@ namespace control {
: prototype_(definedCommand)
{
REQUIRE (prototype_);
maybeArm_if_zero_parameters();
TRACE (command_dbg, "Completed definition of %s.", cStr(prototype_));
}
typedef HandlingPattern::ID PattID;
PattID getDefaultHandlingPattern() const { return prototype_.getDefaultHandlingPattern();}
PattID setHandlingPattern (PattID newID) { return prototype_.setHandlingPattern(newID); }
/** allow for defining the default execution pattern,
* which is used by Command::operator() */
CompletedDefinition
setHandlingPattern (PattID newID)
{
prototype_.setHandlingPattern(newID);
return *this;
}
/** allow to bind immediately to a set of arguments.
* @return standard Command handle, usable for invocation
*/
Command&
bindArg (Tuple<CmdArgs> const& params)
{
return prototype_.bindArg(params);
}
/** a completed definition can be retrieved and
* manipulated further through a standard Command handle
*/
operator Command ()
{
return prototype_;
}
private:
/** Helper: automatically "bind" and make executable a command,
* for the case when the command operation takes zero arguments.
* Because even in that case we need to build a CmdClosure internally.
*/
void
maybeArm_if_zero_parameters()
{
if (0 == Tuple<CmdArgs>::SIZE )
prototype_.bindArg (makeNullTuple());
}
};

View file

@ -124,6 +124,17 @@ namespace control {
}
template< typename T1
, typename T2
>
ExecResult //_________________________________
operator() (T1 a1, T2 a2) ///< Invoke command with 2 Arguments
{
com_.bind(a1,a2);
return com_();
}
template< typename T1
, typename T2
, typename T3
@ -134,6 +145,48 @@ namespace control {
com_.bind(a1,a2,a3);
return com_();
}
template< typename T1
, typename T2
, typename T3
, typename T4
>
ExecResult //_________________________________
operator() (T1 a1, T2 a2, T3 a3, T4 a4) ///< Invoke command with 4 Arguments
{
com_.bind(a1,a2,a3,a4);
return com_();
}
template< typename T1
, typename T2
, typename T3
, typename T4
, typename T5
>
ExecResult //_________________________________
operator() (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) ///< Invoke command with 5 Arguments
{
com_.bind(a1,a2,a3,a4,a5);
return com_();
}
template< typename T1
, typename T2
, typename T3
, typename T4
, typename T5
, typename T6
>
ExecResult //_________________________________
operator() (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6) ///< Invoke command with 6 Arguments
{
com_.bind(a1,a2,a3,a4,a5,a6);
return com_();
}
};
}

View file

@ -70,12 +70,18 @@ return: 0
END
TEST "handling pattern basics" HandlingPatternBasics_test <<END
TEST "Handling Pattern basics" HandlingPatternBasics_test <<END
return: 0
END
PLANNED "handling patterns" HandlingPatternStandardImpl_test <<END
PLANNED "Handling Patterns" HandlingPatternStandardImpl_test <<END
return: 0
END
TEST "Command argument binding" CommandBinding_test <<END
out: Command\("test.command3.2"\) \{exec\}
return: 0
END

View file

@ -55,6 +55,7 @@ test_components_SOURCES = \
$(testcomponents_srcdir)/proc/control/command-use1-test.cpp \
$(testcomponents_srcdir)/proc/control/command-use2-test.cpp \
$(testcomponents_srcdir)/proc/control/command-use3-test.cpp \
$(testcomponents_srcdir)/proc/control/command-binding-test.cpp \
$(testcomponents_srcdir)/proc/control/command-registry-test.cpp \
$(testcomponents_srcdir)/proc/control/test-dummy-commands.cpp \
$(testcomponents_srcdir)/proc/control/argument-tuple-accept-test.cpp \

View file

@ -0,0 +1,125 @@
/*
CommandBinding(Test) - special cases of binding command arguments
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.
* *****************************************************/
#include "lib/test/run.hpp"
#include "proc/control/command-def.hpp"
#include "proc/control/test-dummy-commands.hpp"
#include <iostream>
namespace control {
namespace test {
using std::cout;
using std::endl;
/*****************************************************************************
* @test coverage for some specific situations when binding command arguments.
*
* @todo add more test cases...
*
* @see Command
* @see command-basic-test.cpp (simple usage example)
* @see command-use1-test.cpp (various aspects of command use)
*/
class CommandBinding_test : public Test
{
virtual void
run (Arg)
{
uint cnt_defs = Command::definition_count();
uint cnt_inst = Command::instance_count();
zeroArgumentCommand();
Command::remove("test.command3.1");
Command::remove("test.command3.2");
ASSERT (cnt_defs == Command::definition_count());
ASSERT (cnt_inst == Command::instance_count());
}
void
zeroArgumentCommand()
{
command3::check_ = 0;
CommandDef ("test.command3.1")
.operation (command3::operate)
.captureUndo (command3::capture)
.undoOperation (command3::undoIt)
.bind() // spurious bind doesn't hurt
.execSync()
;
ASSERT ( 1 == command3::check_);
CommandDef ("test.command3.2")
.operation (command3::operate)
.captureUndo (command3::capture)
.undoOperation (command3::undoIt)
;
Command com ("test.command3.2");
ASSERT (com.canExec());
cout << string(com) << endl;
com();
ASSERT ( 2 == command3::check_);
com.undo();
ASSERT ( 1 == command3::check_);
Command commi = com.newInstance();
com();
com();
com();
ASSERT ( 4 == command3::check_);
commi.undo(); // it uses the inherited UNDO state
ASSERT ( 1 == command3::check_);
com.undo();
ASSERT ( 3 == command3::check_);
Command::get("test.command3.1").undo();
ASSERT ( 0 == command3::check_);
}
};
/** Register this test class... */
LAUNCHER (CommandBinding_test, "function controller");
}} // namespace control::test

View file

@ -312,12 +312,12 @@ namespace test {
cout << string (Command::get("test.command1.4")) << endl;
cout << string (Command() ) << endl;
CommandDef ("test.command1.5")
.operation (command1::operate)
.captureUndo (command1::capture)
.undoOperation (command1::undoIt);
Command com
= CommandDef ("test.command1.5")
.operation (command1::operate)
.captureUndo (command1::capture)
.undoOperation (command1::undoIt);
Command com("test.command1.5");
cout << string (com) << endl;
com.bind(123);
cout << string (com) << endl;

View file

@ -41,4 +41,10 @@ namespace test {
}
namespace command3 {
ulong check_;
}
}} // namespace control::test

View file

@ -24,10 +24,10 @@
/** @file test-dummy-commands.hpp
** Some dummy command functions used for building unit test cases.
** Any of these functions comes in triples of operation function, undo state
** capturing function and und function. They are placed into a nested test
** capturing function and UNDO function. They are placed into a nested test
** namespace, together with some global variables used as a backdoor to
** verify the effect of calling these functions.
**
**
** @see command-use1-test.cpp
** @see CommandBasic_test simple complete command definition example
**
@ -39,36 +39,9 @@
#define COMMAND_TEST_DUMMY_COMMANDS_H
//#include "pre.hpp"
//#include "lib/test/run.hpp"
#include "lib/error.hpp"
#include "lib/test/test-helper.hpp"
//#include "proc/asset/media.hpp"
//#include "proc/mobject/session.hpp"
//#include "proc/mobject/session/edl.hpp"
//#include "proc/mobject/session/testclip.hpp"
//#include "proc/mobject/test-dummy-mobject.hpp"
//#include "lib/p.hpp"
//#include "proc/mobject/placement.hpp"
//#include "proc/mobject/placement-index.hpp"
//#include "proc/mobject/explicitplacement.hpp"
//#include "proc/control/command-def.hpp"
//#include "lib/lumitime.hpp"
//#include "lib/util.hpp"
//#include <boost/format.hpp>
//#include <iostream>
//#include <cstdlib>
//#include <string>
//using boost::format;
//using lumiera::Time;
//using util::contains;
//using std::string;
//using std::rand;
//using std::cout;
//using std::endl;
#include <tr1/functional>
#include <sstream>
#include <string>
@ -76,19 +49,19 @@
namespace control {
namespace test {
// using lib::test::showSizeof;
using std::ostringstream;
using std::tr1::function;
using std::string;
namespace command1 { ///< test command just adding a given value
extern long check_;
inline void
operate (int someVal)
{
@ -148,6 +121,35 @@ namespace test {
}
namespace command3 { ///< test command taking zero arguments
extern ulong check_;
inline void
operate ()
{
++check_;
}
inline ulong
capture ()
{
return check_;
}
inline void
undoIt (ulong oldVal)
{
check_ = oldVal;
}
}
}} // namespace control::test
#endif