diff -ru src-old/BindStorage.hpp src/BindStorage.hpp --- src-old/BindStorage.hpp 2010-10-10 22:52:14.000000000 +0200 +++ src/BindStorage.hpp 2010-10-10 23:23:05.000000000 +0200 @@ -85,6 +85,16 @@ bool operator()(T1, T2, T3, T4) { return (mo->*mf)(); } + + template + bool operator()(T1, T2, T3, T4, T5) { + return (mo->*mf)(); + } + + template + bool operator()(T1, T2, T3, T4, T5, T6) { + return (mo->*mf)(); + } }; template @@ -115,6 +125,16 @@ bool operator()(T1& t1, T2, T3, T4) { return (mo->*mf)(t1); } + + template + bool operator()(T1, T2, T3, T4, T5) { + return (mo->*mf)(); + } + + template + bool operator()(T1, T2, T3, T4, T5, T6) { + return (mo->*mf)(); + } }; template @@ -140,6 +160,16 @@ bool operator()(T1& t1, T2 t2, T3, T4) { return (mo->*mf)(t1,t2); } + + template + bool operator()(T1, T2, T3, T4, T5) { + return (mo->*mf)(); + } + + template + bool operator()(T1, T2, T3, T4, T5, T6) { + return (mo->*mf)(); + } }; template @@ -160,6 +190,16 @@ bool operator()(T1& t1, T2 t2, T3 t3, T4) { return (mo->*mf)(t1,t2,t3); } + + template + bool operator()(T1, T2, T3, T4, T5) { + return (mo->*mf)(); + } + + template + bool operator()(T1, T2, T3, T4, T5, T6) { + return (mo->*mf)(); + } }; template @@ -175,6 +215,51 @@ bool operator()(T1& t1, T2 t2, T3 t3, T4 t4) { return (mo->*mf)(t1,t2,t3,t4); } + + template + bool operator()(T1, T2, T3, T4, T5) { + return (mo->*mf)(); + } + + template + bool operator()(T1, T2, T3, T4, T5, T6) { + return (mo->*mf)(); + } + }; + + template + struct quickbind_impl + { + F mf; + O mo; + + quickbind_impl(F f, O o) + : mf(f), mo(o) {} + + template + bool operator()(T1, T2, T3, T4, T5) { + return (mo->*mf)(); + } + + template + bool operator()(T1, T2, T3, T4, T5, T6) { + return (mo->*mf)(); + } + }; + + template + struct quickbind_impl + { + F mf; + O mo; + + quickbind_impl(F f, O o) + : mf(f), mo(o) {} + + template + bool operator()(T1, T2, T3, T4, T5, T6) { + return (mo->*mf)(); + } }; @@ -212,6 +297,16 @@ bool operator()(T1, T2, T3, T4) { return mf(); } + + template + bool operator()(T1, T2, T3, T4, T5) { + return mf(); + } + + template + bool operator()(T1, T2, T3, T4, T5, T6) { + return mf(); + } }; template @@ -241,6 +336,16 @@ bool operator()(T1& t1, T2, T3, T4) { return mf(t1); } + + template + bool operator()(T1, T2, T3, T4, T5) { + return mf(); + } + + template + bool operator()(T1, T2, T3, T4, T5, T6) { + return mf(); + } }; template @@ -265,6 +370,16 @@ bool operator()(T1& t1, T2& t2, T3, T4) { return mf(t1,t2); } + + template + bool operator()(T1, T2, T3, T4, T5) { + return mf(); + } + + template + bool operator()(T1, T2, T3, T4, T5, T6) { + return mf(); + } }; template @@ -284,6 +399,16 @@ bool operator()(T1& t1, T2& t2, T3& t3, T4) { return mf(t1,t2,t3); } + + template + bool operator()(T1, T2, T3, T4, T5) { + return mf(); + } + + template + bool operator()(T1, T2, T3, T4, T5, T6) { + return mf(); + } }; template @@ -297,6 +422,49 @@ bool operator()(T1& t1, T2& t2, T3& t3, T4& t4) { return mf(t1,t2,t3,t4); } + + template + bool operator()(T1, T2, T3, T4, T5) { + return mf(); + } + + template + bool operator()(T1, T2, T3, T4, T5, T6) { + return mf(); + } + }; + + template + struct quickbindC_impl + { + F mf; + + quickbindC_impl(F f) + : mf(f) {} + + template + bool operator()(T1, T2, T3, T4, T5) { + return mf(); + } + + template + bool operator()(T1, T2, T3, T4, T5, T6) { + return mf(); + } + }; + + template + struct quickbindC_impl + { + F mf; + + quickbindC_impl(F f) + : mf(f) {} + + template + bool operator()(T1, T2, T3, T4, T5, T6) { + return mf(); + } }; /** @@ -553,6 +721,78 @@ boost::function condition() const {return cond;} }; + template + struct BindStorageImpl<5, ToBind> + { + typedef bool result_type; + typedef typename boost::function_traits::arg1_type arg1_type; + typedef typename boost::function_traits::arg2_type arg2_type; + typedef typename boost::function_traits::arg3_type arg3_type; + typedef typename boost::function_traits::arg4_type arg4_type; + typedef typename boost::function_traits::arg5_type arg5_type; + + // stores the original function pointer + boost::function comm; + boost::function cond; + // Store the arguments. + mutable AStore a1; + mutable AStore a2; + mutable AStore a3; + mutable AStore a4; + mutable AStore a5; + + void store(arg1_type t1, arg2_type t2, arg3_type t3, arg4_type t4, arg5_type t5) { a1(t1); a2(t2); a3(t3); a4(t4); a5(t5);} + bool exec() { return comm( a1(), a2(), a3(), a4(), a5() ); } + bool check() const { return cond( a1(), a2(), a3(), a4(), a5() ); } + + template + void setup(F f, C c, ObjectType t) + { + comm = boost::bind( boost::mem_fn(f), t, _1, _2, _3, _4, _5 ); // allocates + cond = quickbind( c, t); // allocates + } + + boost::function command() const {return comm;} + boost::function condition() const {return cond;} + }; + + template + struct BindStorageImpl<6, ToBind> + { + typedef bool result_type; + typedef typename boost::function_traits::arg1_type arg1_type; + typedef typename boost::function_traits::arg2_type arg2_type; + typedef typename boost::function_traits::arg3_type arg3_type; + typedef typename boost::function_traits::arg4_type arg4_type; + typedef typename boost::function_traits::arg5_type arg5_type; + typedef typename boost::function_traits::arg6_type arg6_type; + + // stores the original function pointer + boost::function comm; + boost::function cond; + // Store the arguments. + mutable AStore a1; + mutable AStore a2; + mutable AStore a3; + mutable AStore a4; + mutable AStore a5; + mutable AStore a6; + + void store(arg1_type t1, arg2_type t2, arg3_type t3, arg4_type t4, arg5_type t5, arg6_type t6) { a1(t1); a2(t2); a3(t3); a4(t4); a5(t5); a6(t6);} + bool exec() { return comm( a1(), a2(), a3(), a4(), a5(), a6() ); } + bool check() const { return cond( a1(), a2(), a3(), a4(), a5(), a6() ); } + + template + void setup(F f, C c, ObjectType t) + { + comm = boost::bind( boost::mem_fn(f), t, _1, _2, _3, _4, _5, _6 ); // allocates + cond = quickbind( c, t); // allocates + } + + boost::function command() const {return comm;} + boost::function condition() const {return cond;} + }; + /** * A helper-class for the Command implementation which stores the @@ -615,6 +855,24 @@ }; template + struct MethodBinderImpl<5,F> + { + template + boost::function operator()(M m, O o) { + return boost::bind( boost::mem_fn(m), o, _1, _2, _3, _4, _5 ); + } + }; + + template + struct MethodBinderImpl<6,F> + { + template + boost::function operator()(M m, O o) { + return boost::bind( boost::mem_fn(m), o, _1, _2, _3, _4, _5, _6 ); + } + }; + + template struct MethodBinder : public MethodBinderImpl::arity, F> {}; diff -ru src-old/CommandFunctors.hpp src/CommandFunctors.hpp --- src-old/CommandFunctors.hpp 2010-10-10 22:52:14.000000000 +0200 +++ src/CommandFunctors.hpp 2010-10-10 23:51:21.000000000 +0200 @@ -317,6 +317,157 @@ } }; + + template + class FunctorImpl<5, FunctionT> + { + public: + typedef typename FunctionT::arg1_type Arg1T; + typedef typename FunctionT::arg2_type Arg2T; + typedef typename FunctionT::arg3_type Arg3T; + typedef typename FunctionT::arg4_type Arg4T; + typedef typename FunctionT::arg5_type Arg5T; + FunctionT fun; + typename DataSource::shared_ptr aa; + typename DataSource::shared_ptr bb; + typename DataSource::shared_ptr cc; + typename DataSource::shared_ptr dd; + typename DataSource::shared_ptr ee; + + FunctorImpl( FunctionT f, DataSource* a = 0, DataSource* b = 0, DataSource* c = 0, DataSource* d = 0 , DataSource* e = 0 ) + : fun( f ), aa(a), bb(b), cc(c), dd(d), ee(e) + { + } + + void setArguments( DataSource* a, DataSource* b, DataSource* c, DataSource* d, DataSource* e ) + { + aa = a; + bb = b; + cc = c; + dd = d; + ee = e; + } + + void readArguments() + { + aa->evaluate(); + bb->evaluate(); + cc->evaluate(); + dd->evaluate(); + ee->evaluate(); + } + + bool execute() + { + Arg1T a = aa->value(); + Arg2T b = bb->value(); + Arg3T c = cc->value(); + Arg4T d = dd->value(); + Arg5T e = ee->value(); + return fun( a, b, c, d, e ); + } + + bool evaluate() + { + Arg1T a = aa->value(); + Arg2T b = bb->value(); + Arg3T c = cc->value(); + Arg4T d = dd->value(); + Arg5T e = ee->value(); + bool r = fun( a, b, c, d, e ); + aa->updated(); + bb->updated(); + cc->updated(); + dd->updated(); + ee->updated(); + return r; + } + + FunctorImpl<5,FunctionT> copy( std::map& alreadyCloned ) const + { + return FunctorImpl( fun, aa->copy( alreadyCloned ), bb->copy(alreadyCloned), cc->copy(alreadyCloned), dd->copy(alreadyCloned), ee->copy(alreadyCloned) ); + } + }; + + + template + class FunctorImpl<6, FunctionT> + { + public: + typedef typename FunctionT::arg1_type Arg1T; + typedef typename FunctionT::arg2_type Arg2T; + typedef typename FunctionT::arg3_type Arg3T; + typedef typename FunctionT::arg4_type Arg4T; + typedef typename FunctionT::arg5_type Arg5T; + typedef typename FunctionT::arg6_type Arg6T; + FunctionT fun; + typename DataSource::shared_ptr aa; + typename DataSource::shared_ptr bb; + typename DataSource::shared_ptr cc; + typename DataSource::shared_ptr dd; + typename DataSource::shared_ptr ee; + typename DataSource::shared_ptr ff; + + FunctorImpl( FunctionT f, DataSource* a = 0, DataSource* b = 0, DataSource* c = 0, DataSource* d = 0 , DataSource* e = 0, DataSource* f_ = 0 ) + : fun( f ), aa(a), bb(b), cc(c), dd(d), ee(e), ff(f_) + { + } + + void setArguments( DataSource* a, DataSource* b, DataSource* c, DataSource* d, DataSource* e, DataSource* f ) + { + aa = a; + bb = b; + cc = c; + dd = d; + ee = e; + ff = f; + } + + void readArguments() + { + aa->evaluate(); + bb->evaluate(); + cc->evaluate(); + dd->evaluate(); + ee->evaluate(); + ff->evaluate(); + } + + bool execute() + { + Arg1T a = aa->value(); + Arg2T b = bb->value(); + Arg3T c = cc->value(); + Arg4T d = dd->value(); + Arg5T e = ee->value(); + Arg6T f = ff->value(); + return fun( a, b, c, d, e, f ); + } + + bool evaluate() + { + Arg1T a = aa->value(); + Arg2T b = bb->value(); + Arg3T c = cc->value(); + Arg4T d = dd->value(); + Arg5T e = ee->value(); + Arg6T f = ff->value(); + bool r = fun( a, b, c, d, e, f ); + aa->updated(); + bb->updated(); + cc->updated(); + dd->updated(); + ee->updated(); + ff->updated(); + return r; + } + + FunctorImpl<6,FunctionT> copy( std::map& alreadyCloned ) const + { + return FunctorImpl( fun, aa->copy( alreadyCloned ), bb->copy(alreadyCloned), cc->copy(alreadyCloned), dd->copy(alreadyCloned), ee->copy(alreadyCloned), ff->copy(alreadyCloned) ); + } + }; + /** * A functor that stores a function, * and DataSources to get the data from. It can be used diff -ru src-old/CommandRepository.hpp src/CommandRepository.hpp --- src-old/CommandRepository.hpp 2010-10-10 22:52:15.000000000 +0200 +++ src/CommandRepository.hpp 2010-10-10 23:35:50.000000000 +0200 @@ -369,6 +369,118 @@ } /** + * Add a Command object, which takes five arguments, to the + * command interface. + * The command is added to the C++ and to the scripting interface. + * + * @param c A pointer to the Command object. + * @param description A user readable description of what this command does. + * @param arg1 A single word name of the first argument. + * @param arg1_description A user readable description of the first argument. + * @param arg2 A single word name of the second argument. + * @param arg2_description A user readable description of the second argument. + * @param arg3 A single word name of the third argument. + * @param arg3_description A user readable description of the third argument. + * @param arg4 A single word name of the fourth argument. + * @param arg4_description A user readable description of the fourth argument. + * @param arg5 A single word name of the fifth argument. + * @param arg5_description A user readable description of the fifth argument. + * + * @return true if the command could be added. + */ + template + bool addCommand( CommandT com, const char* description, + const char* arg1, const char* arg1_description, + const char* arg2, const char* arg2_description, + const char* arg3, const char* arg3_description, + const char* arg4, const char* arg4_description, + const char* arg5, const char* arg5_description) + { + Logger::In in("CommandRepository"); + typedef typename boost::remove_pointer::type CommandVT; + typedef typename boost::add_pointer::type CommandPT; + typedef typename CommandVT::Signature ComSig; + BOOST_STATIC_ASSERT( boost::function_traits::arity == 5 ); + + CommandPT c = this->getpointer(com); + detail::LocalCommand* lc = dynamic_cast*>( c->getCommandImpl() ); + if ( !lc ) { + log(Error) << "Failed to addCommand: '"<< c->getName() <<"' is not a local command." <addCommand( c ) == false ) + return false; + this->add( c->getName(), new detail::OperationFactoryPart5 >( + detail::DataSourceArgsCommand(lc->getCommandFunction(), + lc->getConditionFunction(), + lc->getCommandProcessor(), lc->isInverted() ), + description, arg1, arg1_description, + arg2, arg2_description, + arg3, arg3_description, + arg4, arg4_description, + arg5, arg5_description) ); + return true; + } + + /** + * Add a Command object, which takes six arguments, to the + * command interface. + * The command is added to the C++ and to the scripting interface. + * + * @param c A pointer to the Command object. + * @param description A user readable description of what this command does. + * @param arg1 A single word name of the first argument. + * @param arg1_description A user readable description of the first argument. + * @param arg2 A single word name of the second argument. + * @param arg2_description A user readable description of the second argument. + * @param arg3 A single word name of the third argument. + * @param arg3_description A user readable description of the third argument. + * @param arg4 A single word name of the fourth argument. + * @param arg4_description A user readable description of the fourth argument. + * @param arg5 A single word name of the fifth argument. + * @param arg5_description A user readable description of the fifth argument. + * @param arg6 A single word name of the sixth argument. + * @param arg6_description A user readable description of the sixth argument. + * + * @return true if the command could be added. + */ + template + bool addCommand( CommandT com, const char* description, + const char* arg1, const char* arg1_description, + const char* arg2, const char* arg2_description, + const char* arg3, const char* arg3_description, + const char* arg4, const char* arg4_description, + const char* arg5, const char* arg5_description, + const char* arg6, const char* arg6_description) + { + Logger::In in("CommandRepository"); + typedef typename boost::remove_pointer::type CommandVT; + typedef typename boost::add_pointer::type CommandPT; + typedef typename CommandVT::Signature ComSig; + BOOST_STATIC_ASSERT( boost::function_traits::arity == 6 ); + + CommandPT c = this->getpointer(com); + detail::LocalCommand* lc = dynamic_cast*>( c->getCommandImpl() ); + if ( !lc ) { + log(Error) << "Failed to addCommand: '"<< c->getName() <<"' is not a local command." <addCommand( c ) == false ) + return false; + this->add( c->getName(), new detail::OperationFactoryPart6 >( + detail::DataSourceArgsCommand(lc->getCommandFunction(), + lc->getConditionFunction(), + lc->getCommandProcessor(), lc->isInverted() ), + description, arg1, arg1_description, + arg2, arg2_description, + arg3, arg3_description, + arg4, arg4_description, + arg5, arg5_description, + arg6, arg6_description) ); + return true; + } + + /** * For internal use only. Retrieve a previously added Command. * * @param name The name of the Command diff -ru src-old/DataSourceArgsCommand.hpp src/DataSourceArgsCommand.hpp --- src-old/DataSourceArgsCommand.hpp 2010-10-10 22:52:14.000000000 +0200 +++ src/DataSourceArgsCommand.hpp 2010-10-11 00:17:20.000000000 +0200 @@ -123,6 +123,24 @@ return r; } + template + DataSourceArgsCommand* create(DataSource* a1, DataSource* a2, DataSource* a3, DataSource* a4, DataSource* a5) const + { + DataSourceArgsCommand* r = this->clone(); + r->mcom.setArguments(a1, a2, a3, a4, a5); + r->mcon.setArguments(a1, a2, a3, a4, a5); + return r; + } + + template + DataSourceArgsCommand* create(DataSource* a1, DataSource* a2, DataSource* a3, DataSource* a4, DataSource* a5, DataSource* a6) const + { + DataSourceArgsCommand* r = this->clone(); + r->mcom.setArguments(a1, a2, a3, a4, a5, a6); + r->mcon.setArguments(a1, a2, a3, a4, a5, a6); + return r; + } + bool ready() const { return !minvoked; } diff -ru src-old/Invoker.hpp src/Invoker.hpp --- src-old/Invoker.hpp 2010-10-10 22:52:14.000000000 +0200 +++ src/Invoker.hpp 2010-10-10 23:05:28.000000000 +0200 @@ -106,6 +106,33 @@ }; template + struct InvokerBaseImpl<5,F> + { + typedef typename boost::function_traits::result_type result_type; + typedef typename boost::function::arg1_type arg1_type; + typedef typename boost::function::arg2_type arg2_type; + typedef typename boost::function::arg3_type arg3_type; + typedef typename boost::function::arg4_type arg4_type; + typedef typename boost::function::arg5_type arg5_type; + virtual ~InvokerBaseImpl() {} + virtual result_type operator()(arg1_type a1, arg2_type a2, arg3_type a3, arg4_type a4, arg5_type a5) = 0; + }; + + template + struct InvokerBaseImpl<6,F> + { + typedef typename boost::function_traits::result_type result_type; + typedef typename boost::function::arg1_type arg1_type; + typedef typename boost::function::arg2_type arg2_type; + typedef typename boost::function::arg3_type arg3_type; + typedef typename boost::function::arg4_type arg4_type; + typedef typename boost::function::arg5_type arg5_type; + typedef typename boost::function::arg6_type arg6_type; + virtual ~InvokerBaseImpl() {} + virtual result_type operator()(arg1_type a1, arg2_type a2, arg3_type a3, arg4_type a4, arg5_type a5, arg6_type a6) = 0; + }; + + template struct InvokerBase : public InvokerBaseImpl::arity, F> {}; @@ -199,6 +226,49 @@ }; + template + struct InvokerImpl<5,F,BaseImpl> + : public BaseImpl + { + typedef typename boost::function_traits::result_type result_type; + typedef typename boost::function_traits::arg1_type arg1_type; + typedef typename boost::function_traits::arg2_type arg2_type; + typedef typename boost::function_traits::arg3_type arg3_type; + typedef typename boost::function_traits::arg4_type arg4_type; + typedef typename boost::function_traits::arg5_type arg5_type; + + /** + * Invoke this operator if the method has four arguments. + */ + result_type operator()(arg1_type t1, arg2_type t2, arg3_type t3, arg4_type t4, arg5_type t5) + { + return BaseImpl::template invoke(t1, t2, t3, t4, t5); + } + + }; + + template + struct InvokerImpl<6,F,BaseImpl> + : public BaseImpl + { + typedef typename boost::function_traits::result_type result_type; + typedef typename boost::function_traits::arg1_type arg1_type; + typedef typename boost::function_traits::arg2_type arg2_type; + typedef typename boost::function_traits::arg3_type arg3_type; + typedef typename boost::function_traits::arg4_type arg4_type; + typedef typename boost::function_traits::arg5_type arg5_type; + typedef typename boost::function_traits::arg6_type arg6_type; + + /** + * Invoke this operator if the method has four arguments. + */ + result_type operator()(arg1_type t1, arg2_type t2, arg3_type t3, arg4_type t4, arg5_type t5, arg6_type t6) + { + return BaseImpl::template invoke(t1, t2, t3, t4, t5, t6); + } + + }; + /** * Creates an invocation object with a function * signature to invoke and an implementation in which @@ -342,6 +412,63 @@ ToInvoke impl; }; + template + struct InvokerSignature<5,F,ToInvoke> + { + typedef typename boost::function_traits::result_type result_type; + typedef typename boost::function_traits::arg1_type arg1_type; + typedef typename boost::function_traits::arg2_type arg2_type; + typedef typename boost::function_traits::arg3_type arg3_type; + typedef typename boost::function_traits::arg4_type arg4_type; + typedef typename boost::function_traits::arg5_type arg5_type; + + InvokerSignature() : impl() {} + InvokerSignature(ToInvoke implementation) : impl(implementation) {} + ~InvokerSignature() { } + + /** + * Invoke this operator if the method has four arguments. + */ + result_type operator()(arg1_type t1, arg2_type t2, arg3_type t3, arg4_type t4, arg5_type t5) + { + if (impl) + return (*impl)(t1, t2, t3, t4, t5); + return NA::na(); + } + + protected: + ToInvoke impl; + }; + + template + struct InvokerSignature<6,F,ToInvoke> + { + typedef typename boost::function_traits::result_type result_type; + typedef typename boost::function_traits::arg1_type arg1_type; + typedef typename boost::function_traits::arg2_type arg2_type; + typedef typename boost::function_traits::arg3_type arg3_type; + typedef typename boost::function_traits::arg4_type arg4_type; + typedef typename boost::function_traits::arg5_type arg5_type; + typedef typename boost::function_traits::arg6_type arg6_type; + + InvokerSignature() : impl() {} + InvokerSignature(ToInvoke implementation) : impl(implementation) {} + ~InvokerSignature() { } + + /** + * Invoke this operator if the method has four arguments. + */ + result_type operator()(arg1_type t1, arg2_type t2, arg3_type t3, arg4_type t4, arg5_type t5, arg6_type t6) + { + if (impl) + return (*impl)(t1, t2, t3, t4, t5, t6); + return NA::na(); + } + + protected: + ToInvoke impl; + }; + } } #endif diff -ru src-old/LocalCommand.hpp src/LocalCommand.hpp --- src-old/LocalCommand.hpp 2010-10-10 22:52:14.000000000 +0200 +++ src/LocalCommand.hpp 2010-10-10 23:36:54.000000000 +0200 @@ -137,6 +137,28 @@ minvoked = true; return maccept = (mcp->process( this ) != 0); } + + template + bool invoke( T1 a1, T2 a2, T3 a3, T4 a4, T5 a5 ) { + if (!mcp ||(minvoked && !this->done()) ) // if invoked and not ready. + return false; + this->reset(); + // bind types from Storage + this->store( a1, a2, a3, a4, a5 ); + minvoked = true; + return maccept = (mcp->process( this ) != 0); + } + + template + bool invoke( T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6 ) { + if (!mcp ||(minvoked && !this->done()) ) // if invoked and not ready. + return false; + this->reset(); + // bind types from Storage + this->store( a1, a2, a3, a4, a5, a6 ); + minvoked = true; + return maccept = (mcp->process( this ) != 0); + } }; diff -ru src-old/LocalMethod.hpp src/LocalMethod.hpp --- src-old/LocalMethod.hpp 2010-10-10 22:52:14.000000000 +0200 +++ src/LocalMethod.hpp 2010-10-10 22:57:13.000000000 +0200 @@ -110,6 +110,24 @@ return mmeth(t1, t2, t3, t4); } + /** + * Invoke this operator if the method has five arguments. + */ + template + result_type invoke(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5) + { + return mmeth(t1, t2, t3, t4, t5); + } + + /** + * Invoke this operator if the method has six arguments. + */ + template + result_type invoke(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6) + { + return mmeth(t1, t2, t3, t4, t5, t6); + } + }; /** diff -ru src-old/MethodRepository.hpp src/MethodRepository.hpp --- src-old/MethodRepository.hpp 2010-10-10 22:52:14.000000000 +0200 +++ src/MethodRepository.hpp 2010-10-11 10:51:24.000000000 +0200 @@ -360,6 +360,116 @@ } /** + * Add a local method object to the interface. This version + * of addMethod adds a Method object to the C++ interface and + * to the scripting interface of this component. + * The Method object must refer to a local method function. + * + * @param meth The method object to add. + * @param description A useful description. + * @param arg1 The name of the first argument. + * @param arg1_description The description of the first argument. + * @param arg2 The name of the second argument. + * @param arg2_description The description of the second argument. + * @param arg3 The name of the third argument. + * @param arg3_description The description of the third argument. + * @param arg4 The name of the fourth argument. + * @param arg4_description The description of the fourth argument. + * @param arg5 The name of the fifth argument. + * @param arg5_description The description of the fifth argument. + * + * @return true if it could be added. + */ + template + bool addMethod( MethodT meth, const char* description, + const char* arg1, const char* arg1_description, + const char* arg2, const char* arg2_description, + const char* arg3, const char* arg3_description, + const char* arg4, const char* arg4_description, + const char* arg5, const char* arg5_description) + { + typedef typename boost::remove_pointer::type MethodVT; + typedef typename boost::add_pointer::type MethodPT; + BOOST_STATIC_ASSERT( boost::function_traits::arity == 5 ); + + MethodPT c = this->getpointer(meth); + typedef typename MethodVT::Signature Sig; + const detail::LocalMethod* lm = dynamic_cast< const detail::LocalMethod* >( c->getMethodImpl().get() ); + if ( !lm ) { + log(Error) << "Failed to addMethod: '"<< c->getName() <<"' is not a local method." <addMethod( c ) == false ) + return false; + this->add( c->getName(), new detail::OperationFactoryPart5 >( + detail::DataSourceArgsMethod(lm->getMethodFunction()), + description, + arg1, arg1_description, + arg2, arg2_description, + arg3, arg3_description, + arg4, arg4_description, + arg5, arg5_description) ); + return true; + } + + /** + * Add a local method object to the interface. This version + * of addMethod adds a Method object to the C++ interface and + * to the scripting interface of this component. + * The Method object must refer to a local method function. + * + * @param meth The method object to add. + * @param description A useful description. + * @param arg1 The name of the first argument. + * @param arg1_description The description of the first argument. + * @param arg2 The name of the second argument. + * @param arg2_description The description of the second argument. + * @param arg3 The name of the third argument. + * @param arg3_description The description of the third argument. + * @param arg4 The name of the fourth argument. + * @param arg4_description The description of the fourth argument. + * @param arg5 The name of the fifth argument. + * @param arg5_description The description of the fifth argument. + * @param arg6 The name of the sixth argument. + * @param arg6_description The description of the sixth argument. + * + * @return true if it could be added. + */ + template + bool addMethod( MethodT meth, const char* description, + const char* arg1, const char* arg1_description, + const char* arg2, const char* arg2_description, + const char* arg3, const char* arg3_description, + const char* arg4, const char* arg4_description, + const char* arg5, const char* arg5_description, + const char* arg6, const char* arg6_description) + { + typedef typename boost::remove_pointer::type MethodVT; + typedef typename boost::add_pointer::type MethodPT; + BOOST_STATIC_ASSERT( boost::function_traits::arity == 6 ); + + MethodPT c = this->getpointer(meth); + typedef typename MethodVT::Signature Sig; + const detail::LocalMethod* lm = dynamic_cast< const detail::LocalMethod* >( c->getMethodImpl().get() ); + if ( !lm ) { + log(Error) << "Failed to addMethod: '"<< c->getName() <<"' is not a local method." <addMethod( c ) == false ) + return false; + this->add( c->getName(), new detail::OperationFactoryPart6 >( + detail::DataSourceArgsMethod(lm->getMethodFunction()), + description, + arg1, arg1_description, + arg2, arg2_description, + arg3, arg3_description, + arg4, arg4_description, + arg5, arg5_description, + arg6, arg6_description) ); + return true; + } + + /** * For internal use only. The pointer of the object of which a member function * must be invoked is stored in a DataSource such that the pointer can change * during program execution. Required in scripting for state machines. diff -ru src-old/OperationFactory.hpp src/OperationFactory.hpp --- src-old/OperationFactory.hpp 2010-10-10 22:52:14.000000000 +0200 +++ src/OperationFactory.hpp 2010-10-11 00:08:48.000000000 +0200 @@ -404,6 +404,190 @@ return fun.create(a.get(), b.get(), c.get(), d.get() ); } }; + + template + class OperationFactoryPart5 + : public OperationFactoryPart + { + typedef FunctorT fun_t; + typedef typename FunctorT::traits::arg1_type arg1_type; + typedef typename FunctorT::traits::arg2_type arg2_type; + typedef typename FunctorT::traits::arg3_type arg3_type; + typedef typename FunctorT::traits::arg4_type arg4_type; + typedef typename FunctorT::traits::arg5_type arg5_type; + + fun_t fun; + const char* arg1name; + const char* arg1desc; + const char* arg2name; + const char* arg2desc; + const char* arg3name; + const char* arg3desc; + const char* arg4name; + const char* arg4desc; + const char* arg5name; + const char* arg5desc; + public: + template + OperationFactoryPart5( InitF f, const char* desc, const char* a1n, + const char* a1d, const char* a2n, + const char* a2d, const char* a3n, + const char* a3d, const char* a4n, + const char* a4d, const char* a5n, + const char* a5d ) + : OperationFactoryPart( desc ), fun( f ), + arg1name( a1n ), arg1desc( a1d ), + arg2name( a2n ), arg2desc( a2d ), + arg3name( a3n ), arg3desc( a3d ), + arg4name( a4n ), arg4desc( a4d ), + arg5name( a5n ), arg5desc( a5d ) + { + } + + std::string resultType() const + { + return DataSource::GetType(); + } + + std::vector< ArgumentDescription > getArgumentList( ) const + { + std::vector< ArgumentDescription > mlist; + mlist.push_back( ArgumentDescription( arg1name, arg1desc, DataSource::GetType() ) ); + mlist.push_back( ArgumentDescription( arg2name, arg2desc, DataSource::GetType() ) ); + mlist.push_back( ArgumentDescription( arg3name, arg3desc, DataSource::GetType() ) ); + mlist.push_back( ArgumentDescription( arg4name, arg4desc, DataSource::GetType() ) ); + mlist.push_back( ArgumentDescription( arg5name, arg5desc, DataSource::GetType() ) ); + return mlist; + } + + int arity() const { return 5; } + + ResultT produce(const std::vector& args) const + { + if ( args.size() != 5 ) + ORO_THROW_OR_RETURN(wrong_number_of_args_exception( 5, args.size() ), ResultT()); + + typename DataSource::shared_ptr a = + AdaptDataSource()( DataSourceTypeInfo::getTypeInfo()->convert(args[0]) ); + if ( !a ) + ORO_THROW_OR_RETURN(wrong_types_of_args_exception( 1, DataSource::GetType(), args[0]->getType() ), ResultT()); + typename DataSource::shared_ptr b = + AdaptDataSource()( DataSourceTypeInfo::getTypeInfo()->convert(args[1]) ); + if ( !b ) + ORO_THROW_OR_RETURN(wrong_types_of_args_exception( 2, DataSource::GetType(), args[1]->getType() ), ResultT()); + typename DataSource::shared_ptr c = + AdaptDataSource()( DataSourceTypeInfo::getTypeInfo()->convert(args[2]) ); + if ( !c ) + ORO_THROW_OR_RETURN(wrong_types_of_args_exception( 3, DataSource::GetType(), args[2]->getType() ), ResultT()); + typename DataSource::shared_ptr d = + AdaptDataSource()( DataSourceTypeInfo::getTypeInfo()->convert(args[3]) ); + if ( !d ) + ORO_THROW_OR_RETURN(wrong_types_of_args_exception( 4, DataSource::GetType(), args[3]->getType() ), ResultT()); + typename DataSource::shared_ptr e = + AdaptDataSource()( DataSourceTypeInfo::getTypeInfo()->convert(args[4]) ); + if ( !e ) + ORO_THROW_OR_RETURN(wrong_types_of_args_exception( 5, DataSource::GetType(), args[4]->getType() ), ResultT()); + + return fun.create(a.get(), b.get(), c.get(), d.get(), e.get() ); + } + }; + + template + class OperationFactoryPart6 + : public OperationFactoryPart + { + typedef FunctorT fun_t; + typedef typename FunctorT::traits::arg1_type arg1_type; + typedef typename FunctorT::traits::arg2_type arg2_type; + typedef typename FunctorT::traits::arg3_type arg3_type; + typedef typename FunctorT::traits::arg4_type arg4_type; + typedef typename FunctorT::traits::arg5_type arg5_type; + typedef typename FunctorT::traits::arg6_type arg6_type; + + fun_t fun; + const char* arg1name; + const char* arg1desc; + const char* arg2name; + const char* arg2desc; + const char* arg3name; + const char* arg3desc; + const char* arg4name; + const char* arg4desc; + const char* arg5name; + const char* arg5desc; + const char* arg6name; + const char* arg6desc; + public: + template + OperationFactoryPart6( InitF f, const char* desc, const char* a1n, + const char* a1d, const char* a2n, + const char* a2d, const char* a3n, + const char* a3d, const char* a4n, + const char* a4d, const char* a5n, + const char* a5d, const char* a6n, + const char* a6d ) + : OperationFactoryPart( desc ), fun( f ), + arg1name( a1n ), arg1desc( a1d ), + arg2name( a2n ), arg2desc( a2d ), + arg3name( a3n ), arg3desc( a3d ), + arg4name( a4n ), arg4desc( a4d ), + arg4name( a5n ), arg4desc( a5d ), + arg4name( a6n ), arg4desc( a6d ) + { + } + + std::string resultType() const + { + return DataSource::GetType(); + } + + std::vector< ArgumentDescription > getArgumentList( ) const + { + std::vector< ArgumentDescription > mlist; + mlist.push_back( ArgumentDescription( arg1name, arg1desc, DataSource::GetType() ) ); + mlist.push_back( ArgumentDescription( arg2name, arg2desc, DataSource::GetType() ) ); + mlist.push_back( ArgumentDescription( arg3name, arg3desc, DataSource::GetType() ) ); + mlist.push_back( ArgumentDescription( arg4name, arg4desc, DataSource::GetType() ) ); + mlist.push_back( ArgumentDescription( arg5name, arg5desc, DataSource::GetType() ) ); + mlist.push_back( ArgumentDescription( arg6name, arg6desc, DataSource::GetType() ) ); + return mlist; + } + + int arity() const { return 6; } + + ResultT produce(const std::vector& args) const + { + if ( args.size() != 6 ) + ORO_THROW_OR_RETURN(wrong_number_of_args_exception( 6, args.size() ), ResultT()); + + typename DataSource::shared_ptr a = + AdaptDataSource()( DataSourceTypeInfo::getTypeInfo()->convert(args[0]) ); + if ( !a ) + ORO_THROW_OR_RETURN(wrong_types_of_args_exception( 1, DataSource::GetType(), args[0]->getType() ), ResultT()); + typename DataSource::shared_ptr b = + AdaptDataSource()( DataSourceTypeInfo::getTypeInfo()->convert(args[1]) ); + if ( !b ) + ORO_THROW_OR_RETURN(wrong_types_of_args_exception( 2, DataSource::GetType(), args[1]->getType() ), ResultT()); + typename DataSource::shared_ptr c = + AdaptDataSource()( DataSourceTypeInfo::getTypeInfo()->convert(args[2]) ); + if ( !c ) + ORO_THROW_OR_RETURN(wrong_types_of_args_exception( 3, DataSource::GetType(), args[2]->getType() ), ResultT()); + typename DataSource::shared_ptr d = + AdaptDataSource()( DataSourceTypeInfo::getTypeInfo()->convert(args[3]) ); + if ( !d ) + ORO_THROW_OR_RETURN(wrong_types_of_args_exception( 4, DataSource::GetType(), args[3]->getType() ), ResultT()); + typename DataSource::shared_ptr e = + AdaptDataSource()( DataSourceTypeInfo::getTypeInfo()->convert(args[4]) ); + if ( !e ) + ORO_THROW_OR_RETURN(wrong_types_of_args_exception( 5, DataSource::GetType(), args[4]->getType() ), ResultT()); + typename DataSource::shared_ptr f = + AdaptDataSource()( DataSourceTypeInfo::getTypeInfo()->convert(args[5]) ); + if ( !f ) + ORO_THROW_OR_RETURN(wrong_types_of_args_exception( 6, DataSource::GetType(), args[5]->getType() ), ResultT()); + + return fun.create(a.get(), b.get(), c.get(), d.get(), e.get(), f.get() ); + } + }; /** * @} */