// $Id$ // // Copyright (C) 2008 // Fraunhofer Institute for Open Communication Systems (FOKUS) // Competence Center NETwork research (NET), St. Augustin, GERMANY // Stefan Bund // // 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., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /** \file \brief ParsedCommand Boost.Preprocesser external iteration include */ #if !BOOST_PP_IS_ITERATING && !defined(MPP_ParsedCommand_) #define MPP_ParsedCommand_ 1 // Custom includes #include #include #include #include #include #include #include #include #include #include #include // ///////////////////////////mpp.p//////////////////////////////////////// #elif BOOST_PP_IS_ITERATING // //////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////// // Local Macros #define mpp_ArgTypeN(n) BOOST_PP_CAT(BOOST_PP_CAT(arg, BOOST_PP_INC(n)), _type) #define mpp_ArgN(n) BOOST_PP_CAT(arg, BOOST_PP_INC(n)) #define mpp_ArgTypes_(z,n,d) typename traits::mpp_ArgTypeN(n) #define mpp_TrailingArgTypes() BOOST_PP_ENUM_TRAILING( BOOST_PP_ITERATION(), mpp_ArgTypes_, _ ) #define mpp_Args_(z,n,d) boost::cref(mpp_ArgN(n)) #define mpp_TrailingArgs() BOOST_PP_ENUM_TRAILING( BOOST_PP_ITERATION(), mpp_Args_, _ ) #define mpp_BindArgs_(z,n,d) BOOST_PP_CAT( _, BOOST_PP_INC(BOOST_PP_INC(n))) #define mpp_TrailingBindArgs() BOOST_PP_ENUM_TRAILING( BOOST_PP_ITERATION(), mpp_BindArgs_, _ ) // //////////////////////////////////////////////////////////////////////// #if BOOST_PP_ITERATION_FLAGS()==1 // ////////////////////////////////////// // //////////////////////////////////////////////////////////////////////// // Header file (.hh) template class ParsedCommandOverload : public ParsedCommandOverloadBase { public: typedef boost::intrusive_ptr ptr; typedef FunctionTraits traits; typedef boost::function Function; # define mpp_l(z,n,d) \ typedef typename senf::remove_cvref< typename traits::mpp_ArgTypeN(n) >::type \ mpp_ArgTypeN(n); BOOST_PP_REPEAT( BOOST_PP_ITERATION(), mpp_l, _ ) # undef mpp_l static ptr create(Function fn); protected: private: ParsedCommandOverload(Function fn); virtual void v_execute(std::ostream & os, ParseCommandInfo const & command) const; Function function_; }; // //////////////////////////////////////////////////////////////////////// #elif BOOST_PP_ITERATION_FLAGS()==2 // //////////////////////////////////// // //////////////////////////////////////////////////////////////////////// // inline template implementation (.cti) template prefix_ typename senf::console::ParsedCommandOverload::ptr senf::console::ParsedCommandOverload::create(Function fn) { return ptr(new ParsedCommandOverload(fn)); } template prefix_ senf::console::ParsedCommandOverload:: ParsedCommandOverload(Function fn) : function_ (fn) { # define mpp_l(z,n,d) addParameter< mpp_ArgTypeN(n) >(); BOOST_PP_REPEAT( BOOST_PP_ITERATION(), mpp_l, _ ) # undef mpp_l } // //////////////////////////////////////////////////////////////////////// #elif BOOST_PP_ITERATION_FLAGS()==3 // //////////////////////////////////// // //////////////////////////////////////////////////////////////////////// // non-inline template implementation (.ct) template prefix_ void senf::console::ParsedCommandOverload:: v_execute(std::ostream & os, ParseCommandInfo const & command) const { if ( command.arguments().size() > BOOST_PP_ITERATION() ) throw SyntaxErrorException("invalid number of arguments"); int nDefaults ( BOOST_PP_ITERATION() - command.arguments().size() ); typedef typename boost::range_const_reverse_iterator::type riterator; riterator i (boost::rbegin(command.arguments())); riterator const i_end (boost::rend(command.arguments())); # define mpp_l(z,n,d) \ mpp_ArgTypeN(n) mpp_ArgN(n) (arg< mpp_ArgTypeN(n) >( n ).defaultValue); \ if (! arg(n).hasDefault || nDefaults-- <= 0) { \ if (i == i_end) \ throw SyntaxErrorException("invalid number of arguments"); \ if (arg< mpp_ArgTypeN(n) >(n).parser) \ arg< mpp_ArgTypeN(n) >(n).parser( *(i++), mpp_ArgN(n) ); \ else \ ArgumentTraits< mpp_ArgTypeN(n) >::parse( *(i++), mpp_ArgN(n) ); \ } # define mpp_l_(z,n,d) mpp_l(z, BOOST_PP_SUB(BOOST_PP_DEC(BOOST_PP_ITERATION()), n), d) BOOST_PP_REPEAT( BOOST_PP_ITERATION(), mpp_l_, _ ) # undef mpp_l # undef mpp_l_ detail::CheckVoidReturn::call( boost::bind(function_, boost::ref(os) mpp_TrailingArgs()), os ); } // //////////////////////////////////////////////////////////////////////// #elif BOOST_PP_ITERATION_FLAGS()==4 // //////////////////////////////////// // //////////////////////////////////////////////////////////////////////// // CreateParsedCommandOverload template struct CreateParsedCommandOverload { typedef Traits traits; template static typename senf::console::ParsedCommandOverload::ptr create(Function fn) { return senf::console::ParsedCommandOverload::create( boost::bind(fn mpp_TrailingBindArgs()) ); } }; // //////////////////////////////////////////////////////////////////////// #elif BOOST_PP_ITERATION_FLAGS()==5 // //////////////////////////////////// // //////////////////////////////////////////////////////////////////////// // Create keyword arg forwarding functions template next_type arg ( BOOST_PP_ENUM_BINARY_PARAMS( BOOST_PP_ITERATION(), A, const & a ), typename arg_params::match< BOOST_PP_ENUM_PARAMS( BOOST_PP_ITERATION(), A ) >::type kw = arg_params()) const { return argInfo( kw(BOOST_PP_ENUM_PARAMS( BOOST_PP_ITERATION(), a )) ); } // //////////////////////////////////////////////////////////////////////// #endif // ///////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////// // Undefine local Macros #undef mpp_TrailingArgs #undef mpp_Args_ #undef mpp_TrailingArgTypes #undef mpp_ArgTypes_ #undef mpp_ArgN #undef mpp_ArgTypeN // //////////////////////////////////////////////////////////////////////// #endif // ///////////////////////////////////////////////////////////////// // ///////////////////////////mpp.e//////////////////////////////////////// // Local Variables: // mode: c++ // fill-column: 100 // comment-column: 40 // c-file-style: "senf" // indent-tabs-mode: nil // ispell-local-dictionary: "american" // compile-command: "scons -u test" // End: