X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=senf%2FUtils%2FConsole%2FParsedCommand.cti;h=019ae8a9d9790cad8b7b9ff7d6c806eb29a894e6;hb=d506c3134c5c01272c01608c86b8285176b50226;hp=a35a827be51e2f43b3690b88f406aae6fa721a6c;hpb=601d1f509f5bb24df167a4dd5a20da67a0af9af8;p=senf.git diff --git a/senf/Utils/Console/ParsedCommand.cti b/senf/Utils/Console/ParsedCommand.cti index a35a827..019ae8a 100644 --- a/senf/Utils/Console/ParsedCommand.cti +++ b/senf/Utils/Console/ParsedCommand.cti @@ -1,24 +1,29 @@ // $Id$ // -// Copyright (C) 2008 +// 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. +// The contents of this file are subject to the Fraunhofer FOKUS Public License +// Version 1.0 (the "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// http://senf.berlios.de/license.html // -// 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. +// The Fraunhofer FOKUS Public License Version 1.0 is based on, +// but modifies the Mozilla Public License Version 1.1. +// See the full license text for the amendments. // -// 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. +// Software distributed under the License is distributed on an "AS IS" basis, +// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +// for the specific language governing rights and limitations under the License. +// +// The Original Code is Fraunhofer FOKUS code. +// +// The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. +// (registered association), Hansastraße 27 c, 80686 Munich, Germany. +// All Rights Reserved. +// +// Contributor(s): +// Stefan Bund /** \file \brief ParsedCommand inline template implementation */ @@ -26,14 +31,14 @@ #include "ParsedCommand.ih" // Custom includes -#include "../../Utils/membind.hh" +#include #include -#include "../../Utils/parameter.hh" +#include #define prefix_ inline -///////////////////////////////cti.p/////////////////////////////////////// +//-///////////////////////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////// +//-///////////////////////////////////////////////////////////////////////////////////////////////// // senf::console::detail::ArgumentInfo template @@ -45,7 +50,7 @@ senf::console::detail::ArgumentInfo::create() template prefix_ senf::console::detail::ArgumentInfo::ArgumentInfo() - : ArgumentInfoBase ( ArgumentTraits::description(), + : ArgumentInfoBase ( ArgumentTraits::description(), ArgumentTraits::singleToken ), defaultValue () {} @@ -57,7 +62,7 @@ prefix_ std::string senf::console::detail::ArgumentInfo::defaultV return hasDefault ? ArgumentTraits::str(defaultValue) : ""; } -/////////////////////////////////////////////////////////////////////////// +//-///////////////////////////////////////////////////////////////////////////////////////////////// // senf::console::ParsedCommandOverloadBase template @@ -66,7 +71,7 @@ prefix_ void senf::console::ParsedCommandOverloadBase::addParameter() parameters_.push_back(detail::ArgumentInfo::create()); } -/////////////////////////////////////////////////////////////////////////// +//-///////////////////////////////////////////////////////////////////////////////////////////////// // senf::console::ParsedCommandOverload #define BOOST_PP_ITERATION_PARAMS_1 (4, (0, SENF_CONSOLE_MAX_COMMAND_ARITY, \ @@ -74,7 +79,7 @@ prefix_ void senf::console::ParsedCommandOverloadBase::addParameter() 2)) #include BOOST_PP_ITERATE() -/////////////////////////////////////////////////////////////////////////// +//-///////////////////////////////////////////////////////////////////////////////////////////////// // senf::console::ParsedCommandAttributor template @@ -85,19 +90,23 @@ prefix_ Overload & senf::console::ParsedCommandAttributor::overload() } template -prefix_ -senf::console::ParsedCommandAttributor::ParsedCommandAttributor(Overload & overload, - unsigned index) +prefix_ senf::console::ParsedCommandAttributor:: +ParsedCommandAttributor(typename Overload::ptr overload, unsigned index) : ParsedCommandAttributorBase (overload, index) {} -/////////////////////////////////////////////////////////////////////////// +template +prefix_ senf::console::ParsedCommandAttributor:: +ParsedCommandAttributor(ParsedCommandAttributorBase const & other, unsigned index) + : ParsedCommandAttributorBase (other, index) +{} + +//-///////////////////////////////////////////////////////////////////////////////////////////////// // senf::console::ParsedArgumentAttributorBase template prefix_ Self senf::console::ParsedArgumentAttributorBase::doc(std::string const & doc) - const { this->ParsedCommandAttributorBase::nodeDoc(doc); return static_cast(*this); @@ -106,7 +115,6 @@ senf::console::ParsedArgumentAttributorBase::doc(std:: template prefix_ Self senf::console::ParsedArgumentAttributorBase:: shortdoc(std::string const & doc) - const { this->ParsedCommandAttributorBase::shortDoc(doc); return static_cast(*this); @@ -115,7 +123,6 @@ shortdoc(std::string const & doc) template prefix_ Self senf::console::ParsedArgumentAttributorBase:: overloadDoc(std::string const & doc) - const { this->ParsedCommandAttributorBase::overloadDoc(doc); return static_cast(*this); @@ -124,7 +131,6 @@ overloadDoc(std::string const & doc) template prefix_ Self senf::console::ParsedArgumentAttributorBase:: formatter(typename Overload::Formatter f) - const { this->overload().formatter(f); return static_cast(*this); @@ -133,14 +139,20 @@ formatter(typename Overload::Formatter f) template prefix_ senf::console::ParsedArgumentAttributorBase:: -ParsedArgumentAttributorBase(Overload & overload, unsigned index) +ParsedArgumentAttributorBase(typename Overload::ptr overload, unsigned index) : ParsedCommandAttributor (overload, index) {} +template +prefix_ +senf::console::ParsedArgumentAttributorBase:: +ParsedArgumentAttributorBase(ParsedCommandAttributorBase const & other, unsigned index) + : ParsedCommandAttributor (other, index) +{} + template prefix_ Self senf::console::ParsedArgumentAttributorBase::doc(std::string const & doc) - const { this->ParsedCommandAttributorBase::nodeDoc(doc); return static_cast(*this); @@ -149,7 +161,6 @@ senf::console::ParsedArgumentAttributorBase::doc(std::string template prefix_ Self senf::console::ParsedArgumentAttributorBase:: shortdoc(std::string const & doc) - const { this->ParsedCommandAttributorBase::shortDoc(doc); return static_cast(*this); @@ -158,7 +169,6 @@ shortdoc(std::string const & doc) template prefix_ Self senf::console::ParsedArgumentAttributorBase:: overloadDoc(std::string const & doc) - const { this->ParsedCommandAttributorBase::overloadDoc(doc); return static_cast(*this); @@ -166,12 +176,19 @@ overloadDoc(std::string const & doc) template prefix_ -senf::console::ParsedArgumentAttributorBase:: -ParsedArgumentAttributorBase(Overload & overload, unsigned index) +senf::console::ParsedArgumentAttributorBase:: +ParsedArgumentAttributorBase(typename Overload::ptr overload, unsigned index) : ParsedCommandAttributor (overload, index) {} -/////////////////////////////////////////////////////////////////////////// +template +prefix_ +senf::console::ParsedArgumentAttributorBase:: +ParsedArgumentAttributorBase(ParsedCommandAttributorBase const & other, unsigned index) + : ParsedCommandAttributor (other, index) +{} + +//-///////////////////////////////////////////////////////////////////////////////////////////////// // senf::console::ParsedArgumentAttributor template @@ -187,7 +204,6 @@ template prefix_ typename senf::console::ParsedArgumentAttributor::next_type senf::console::ParsedArgumentAttributor:: argInfo(ArgumentPack const & args) - const { # define ProcessArg(tag) \ argInfo( kw:: tag, args, senf::has_parameter< ArgumentPack, kw::type:: tag >() ) @@ -208,7 +224,6 @@ template template prefix_ void senf::console::ParsedArgumentAttributor:: argInfo(Kw const &, ArgumentPack const &, boost::mpl::false_) - const {} template @@ -216,7 +231,6 @@ template prefix_ void senf::console::ParsedArgumentAttributor:: argInfo(boost::parameter::keyword const &, ArgumentPack const & args, boost::mpl::true_) - const { this->argName(args[kw::name]); } @@ -226,7 +240,6 @@ template prefix_ void senf::console::ParsedArgumentAttributor:: argInfo(boost::parameter::keyword const &, ArgumentPack const & args, boost::mpl::true_) - const { this->argDoc(args[kw::description]); } @@ -236,7 +249,6 @@ template prefix_ void senf::console::ParsedArgumentAttributor:: argInfo(boost::parameter::keyword const &, ArgumentPack const & args, boost::mpl::true_) - const { this->defaultValue(args[kw::default_value]); } @@ -246,7 +258,6 @@ template prefix_ void senf::console::ParsedArgumentAttributor:: argInfo(boost::parameter::keyword const &, ArgumentPack const & args, boost::mpl::true_) - const { this->typeName(args[kw::type_name]); } @@ -256,7 +267,6 @@ template prefix_ void senf::console::ParsedArgumentAttributor:: argInfo(boost::parameter::keyword const &, ArgumentPack const & args, boost::mpl::true_) - const { BOOST_STATIC_ASSERT(( senf::has_parameter::value )); this->defaultDoc(args[kw::default_doc]); @@ -267,16 +277,20 @@ template prefix_ void senf::console::ParsedArgumentAttributor:: argInfo(boost::parameter::keyword const &, ArgumentPack const & args, boost::mpl::true_) - const { this->parser(args[kw::parser]); } template -prefix_ -senf::console::ParsedArgumentAttributor:: -ParsedArgumentAttributor(Overload & overload) - : ParsedArgumentAttributorBase (overload, index) +prefix_ senf::console::ParsedArgumentAttributor:: +ParsedArgumentAttributor(typename Overload::ptr overload) +: ParsedArgumentAttributorBase (overload, index) +{} + +template +prefix_ senf::console::ParsedArgumentAttributor:: +ParsedArgumentAttributor(ParsedCommandAttributorBase const & other) + : ParsedArgumentAttributorBase (other, index) {} template @@ -284,13 +298,12 @@ prefix_ typename senf::console::ParsedArgumentAttributor::n senf::console::ParsedArgumentAttributor::next() const { - return ParsedArgumentAttributor(this->overload()); + return ParsedArgumentAttributor(*this); } template prefix_ void senf::console::ParsedArgumentAttributor:: defaultValue(value_type const & value) - const { this->overload().arg().defaultValue = value; this->overload().arg(index).hasDefault = true; @@ -299,23 +312,29 @@ defaultValue(value_type const & value) template template prefix_ void senf::console::ParsedArgumentAttributor::parser(Fn fn) - const { this->overload().arg().parser = fn; } -/////////////////////////////////////////////////////////////////////////// +//-///////////////////////////////////////////////////////////////////////////////////////////////// // senf::console::ParsedArgumentAttributor template prefix_ senf::console::ParsedArgumentAttributor:: -ParsedArgumentAttributor(Overload & overload) - : ParsedArgumentAttributorBase< +ParsedArgumentAttributor(typename Overload::ptr overload) + : ParsedArgumentAttributorBase< Overload, ParsedArgumentAttributor > (overload, index) {} -/////////////////////////////////////////////////////////////////////////// +template +prefix_ +senf::console::ParsedArgumentAttributor:: +ParsedArgumentAttributor(ParsedCommandAttributorBase const & other) + : ParsedArgumentAttributorBase (other, index) +{} + +//-///////////////////////////////////////////////////////////////////////////////////////////////// // namespace members namespace senf { @@ -326,99 +345,140 @@ namespace detail { struct ParsedCommandAddNodeAccess { - template - static Attributor attributor(Node & node) - { return Attributor(node); } - }; - - // 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 typename Traits::traits traits; - - template - static typename senf::console::ParsedCommandOverload::ptr create(Function fn) - { return senf::console::ParsedCommandOverload::create(fn); }; + template + static Attributor attributor(NodePtr ptr) + { return Attributor(ptr); } }; -# define BOOST_PP_ITERATION_PARAMS_1 (4, (0, SENF_CONSOLE_MAX_COMMAND_ARITY, \ - SENF_ABSOLUTE_INCLUDE_PATH(Utils/Console/ParsedCommand.mpp), \ - 4)) -# include BOOST_PP_ITERATE() - template typename senf::console::detail::ParsedCommandTraits::Attributor - addOverloadedCommandNode(senf::console::DirectoryNode & node, std::string const & name, Fn fn) + addOverloadedCommandNode(Fn fn) { - senf::console::OverloadedCommandNode & cmdNode ( - node.hasChild(name) - ? dynamic_cast(node(name)) - : node.add(name, senf::console::OverloadedCommandNode::create()) ); - typedef senf::console::detail::ParsedCommandTraits CmdTraits; typedef senf::console::ParsedCommandOverload Overload; typedef senf::console::ParsedArgumentAttributor Attributor; - return senf::console::detail::ParsedCommandAddNodeAccess::attributor( - cmdNode.add( CreateParsedCommandOverload::create(fn) ) ); + return detail::ParsedCommandAddNodeAccess::attributor( + CreateParsedCommandOverload::create(fn)); } #endif }}} -#ifndef DOXYGEN +//-///////////////////////////////////////////////////////////////////////////////////////////////// + +template +prefix_ senf::console::SimpleOverloadAttributor +senf::console::factory:: +Command(boost::function fn, + typename boost::enable_if_c::is_simple>::type *) +{ + return SimpleOverloadAttributor(fn); +} template -typename senf::console::detail::ParsedCommandTraits::Attributor -senf::console::senf_console_add_node(DirectoryNode & node, std::string const & name, - Function fn, int, - typename boost::enable_if_c::is_callable>::type *) +prefix_ senf::console::SimpleOverloadAttributor +senf::console::factory:: +Command(Function fn, + typename boost::enable_if_c::is_simple>::type *) +{ + return SimpleOverloadAttributor(fn); +} + +template +prefix_ senf::console::SimpleOverloadAttributor +senf::console::factory:: +Command(Member memfn, Owner * owner, + typename boost::enable_if >::type *, + typename boost::enable_if_c::is_simple>::type *) +{ + return SimpleOverloadAttributor(senf::membind(memfn,owner)); +} + +template +prefix_ senf::console::SimpleOverloadAttributor +senf::console::factory:: +Command(Member memfn, Owner const * owner, + typename boost::enable_if >::type *, + typename boost::enable_if_c::is_simple>::type *) { - return senf::console::detail::addOverloadedCommandNode(node, name, fn); + return SimpleOverloadAttributor(senf::membind(memfn,owner)); +} + +template +prefix_ typename senf::console::detail::ParsedCommandTraits::Attributor +senf::console::factory:: +Command(boost::function fn) +{ + return detail::addOverloadedCommandNode(fn); +} + +template +prefix_ typename senf::console::detail::ParsedCommandTraits::Attributor +senf::console::factory:: +Command(Function fn, + typename boost::enable_if_c::is_callable>::type *, + typename boost::disable_if >::type *) +{ + return detail::addOverloadedCommandNode(fn); } template -typename senf::console::detail::ParsedCommandTraits::Attributor -senf::console::senf_console_add_node(DirectoryNode & node, std::string const & name, - boost::function fn, int) +prefix_ typename senf::console::detail::ParsedCommandTraits::Attributor +senf::console::factory:: +Command(boost::function fn) { - return senf::console::detail::addOverloadedCommandNode(node, name, fn); + return detail::addOverloadedCommandNode(fn); } -template -typename senf::console::detail::ParsedCommandTraits::Attributor -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 *) +template +prefix_ typename senf::console::detail::ParsedCommandTraits::Attributor +senf::console::factory:: +Command(Function fn, + typename boost::enable_if_c::is_callable>::type *, + typename boost::disable_if >::type *) { - return senf::console::detail::addOverloadedCommandNode( - node, name, senf::membind(fn,&owner)); + return detail::addOverloadedCommandNode(fn); } -#endif +template +prefix_ typename senf::console::detail::ParsedCommandTraits::Attributor +senf::console::factory:: +Command(Member memfn, Owner * owner, + typename boost::enable_if >::type *) +{ + return detail::addOverloadedCommandNode(senf::membind(memfn,owner)); +} + +template +prefix_ typename senf::console::detail::ParsedCommandTraits::Attributor +senf::console::factory:: +Command(Member memfn, Owner const * owner, + typename boost::enable_if >::type *) +{ + return detail::addOverloadedCommandNode(senf::membind(memfn,owner)); +} + +template +prefix_ typename senf::console::detail::ParsedCommandTraits::Attributor +senf::console::factory:: +Command(Member memfn, Owner * owner, + typename boost::enable_if >::type *) +{ + return detail::addOverloadedCommandNode(senf::membind(memfn,owner)); +} + +template +prefix_ typename senf::console::detail::ParsedCommandTraits::Attributor +senf::console::factory:: +Command(Member memfn, Owner const * owner, + typename boost::enable_if >::type *) +{ + return detail::addOverloadedCommandNode(senf::membind(memfn,owner)); +} -///////////////////////////////cti.e/////////////////////////////////////// +//-///////////////////////////////////////////////////////////////////////////////////////////////// #undef prefix_