// $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 inline template implementation */ #include "ParsedCommand.ih" // Custom includes #include "../Utils/membind.hh" #define prefix_ inline ///////////////////////////////cti.p/////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// // senf::console::ParsedCommandOverloadBase template prefix_ senf::console::detail::ParameterInfo & senf::console::ParsedCommandOverloadBase::arg(unsigned n) const { return static_cast &>(arg(n)); } template prefix_ void senf::console::ParsedCommandOverloadBase::addParameter() { parameters_.push_back(detail::ParameterInfo::create()); } /////////////////////////////////////////////////////////////////////////// // senf::console::ParsedCommandOverload #define BOOST_PP_ITERATION_PARAMS_1 (4, (0, SENF_CONSOLE_MAX_COMMAND_ARITY, \ SENF_ABSOLUTE_INCLUDE_PATH(Console/ParsedCommand.mpp), \ 2)) #include BOOST_PP_ITERATE() /////////////////////////////////////////////////////////////////////////// // namespace members namespace { // What is THIS about ?? // Ok, here's the dope: parsed commands may optionally have an std::ostream & first argument. If // this argument is given, then the function will be called with the console output stream as // it's first argument. // // This is implemented in the following way: ParsedCommandOverload (the class responsible for // calling the callback) will ALWAYS pass the stream as first argument. If the user callback // expects os as it's first argument, 'ignoreOneArg' will be false and the user supplied // function will be directly passed to ParsedCommandOverload. // // If however, it does NOT take an std::ostream first argument, 'ignoreOneArg' will be true and // the create member will use boost::bind to DROP the first argument. template struct CreateParsedCommandOverload {}; template struct CreateParsedCommandOverload { typedef Traits traits; template static typename senf::console::ParsedCommandOverload::ptr create(Function fn) { return senf::console::ParsedCommandOverload::create(fn); }; }; # define BOOST_PP_ITERATION_PARAMS_1 (4, (0, SENF_CONSOLE_MAX_COMMAND_ARITY, \ SENF_ABSOLUTE_INCLUDE_PATH(Console/ParsedCommand.mpp), \ 4)) # include BOOST_PP_ITERATE() } template prefix_ senf::console::ParsedCommandOverload< typename senf::console::detail::ParsedCommandTraits::traits> & senf::console::senf_console_add_node(DirectoryNode & node, std::string const & name, Function fn, int) { OverloadedCommandNode & cmdNode ( node.hasChild(name) ? dynamic_cast(node(name)) : node.add(name, OverloadedCommandNode::create()) ); typedef senf::console::detail::ParsedCommandTraits CmdTraits; return cmdNode.add( CreateParsedCommandOverload< typename CmdTraits::traits, ! CmdTraits::has_ostream_arg>::create(fn) ); } template prefix_ senf::console::ParsedCommandOverload< typename senf::console::detail::ParsedCommandTraits::traits> & senf::console:: senf_console_add_node(DirectoryNode & node, Owner & owner, std::string const & name, Function fn, int, typename boost::enable_if_c::is_member>::type *) { OverloadedCommandNode & cmdNode ( node.hasChild(name) ? dynamic_cast(node(name)) : node.add(name, OverloadedCommandNode::create()) ); typedef senf::console::detail::ParsedCommandTraits CmdTraits; return cmdNode.add( CreateParsedCommandOverload< typename CmdTraits::traits, ! CmdTraits::has_ostream_arg>::create( senf::membind(fn,&owner)) ); } ///////////////////////////////cti.e/////////////////////////////////////// #undef prefix_ // 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: