X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=senf%2FUtils%2FConsole%2FParsedCommand.cti;h=1d36bb441e694f3c0467a819f9f7d596bbf2002d;hb=6aae6e526573187ece558842e928578e5aa4cc4c;hp=a35a827be51e2f43b3690b88f406aae6fa721a6c;hpb=601d1f509f5bb24df167a4dd5a20da67a0af9af8;p=senf.git diff --git a/senf/Utils/Console/ParsedCommand.cti b/senf/Utils/Console/ParsedCommand.cti index a35a827..1d36bb4 100644 --- a/senf/Utils/Console/ParsedCommand.cti +++ b/senf/Utils/Console/ParsedCommand.cti @@ -1,6 +1,6 @@ // $Id$ // -// Copyright (C) 2008 +// Copyright (C) 2008 // Fraunhofer Institute for Open Communication Systems (FOKUS) // Competence Center NETwork research (NET), St. Augustin, GERMANY // Stefan Bund @@ -26,9 +26,9 @@ #include "ParsedCommand.ih" // Custom includes -#include "../../Utils/membind.hh" +#include #include -#include "../../Utils/parameter.hh" +#include #define prefix_ inline ///////////////////////////////cti.p/////////////////////////////////////// @@ -45,7 +45,7 @@ senf::console::detail::ArgumentInfo::create() template prefix_ senf::console::detail::ArgumentInfo::ArgumentInfo() - : ArgumentInfoBase ( ArgumentTraits::description(), + : ArgumentInfoBase ( ArgumentTraits::description(), ArgumentTraits::singleToken ), defaultValue () {} @@ -85,19 +85,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 +110,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 +118,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 +126,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 +134,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 +156,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 +164,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,11 +171,18 @@ 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 @@ -187,7 +199,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 +219,6 @@ template template prefix_ void senf::console::ParsedArgumentAttributor:: argInfo(Kw const &, ArgumentPack const &, boost::mpl::false_) - const {} template @@ -216,7 +226,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 +235,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 +244,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 +253,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 +262,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 +272,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 +293,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,7 +307,6 @@ defaultValue(value_type const & value) template template prefix_ void senf::console::ParsedArgumentAttributor::parser(Fn fn) - const { this->overload().arg().parser = fn; } @@ -310,11 +317,18 @@ prefix_ void senf::console::ParsedArgumentAttributor::parse 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 @@ -326,97 +340,138 @@ 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_