X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=senf%2FUtils%2FConsole%2FParsedCommand.hh;h=7571904e4f3b358e5982a147a3fac81939a5c483;hb=18d987b03ac188adf6e1a82ebce2666738f0ff65;hp=45276cb3dfdf455271eb45b048456b8e129e2c18;hpb=601d1f509f5bb24df167a4dd5a20da67a0af9af8;p=senf.git diff --git a/senf/Utils/Console/ParsedCommand.hh b/senf/Utils/Console/ParsedCommand.hh index 45276cb..7571904 100644 --- a/senf/Utils/Console/ParsedCommand.hh +++ b/senf/Utils/Console/ParsedCommand.hh @@ -32,15 +32,15 @@ #include #include -#include +#include #include #include #include #include -#include "../../config.hh" +#include #include "OverloadedCommand.hh" #include "Traits.hh" -#include "../../Utils/type_traits.hh" +#include #include "ParsedCommand.ih" #include "ParsedCommand.mpp" @@ -182,14 +182,15 @@ namespace console { #ifndef DOXYGEN -# define BOOST_PP_ITERATION_PARAMS_1 (4, (0, SENF_CONSOLE_MAX_COMMAND_ARITY, \ - SENF_ABSOLUTE_INCLUDE_PATH(Utils/Console/ParsedCommand.mpp), \ - 1)) +# define BOOST_PP_ITERATION_PARAMS_1 \ + (4, (0, SENF_CONSOLE_MAX_COMMAND_ARITY, \ + SENF_ABSOLUTE_INCLUDE_PATH(Utils/Console/ParsedCommand.mpp), \ + 1)) # include BOOST_PP_ITERATE() #endif - /** \brief Generic ParsedCommandOverladBase attributes + /** \brief Generic ParsedCommandOverloadBase attributes Attributes for parsed commands are not set directly on the node. They are set via a special attributor temporary returned when adding a parsed command to the tree. @@ -200,27 +201,33 @@ namespace console { \see \ref console_autoparse */ class ParsedCommandAttributorBase + : public detail::NodeFactory { public: - OverloadedCommandNode & node() const; ///< Return the node object - operator OverloadedCommandNode & () const; ///< Automatically convert to node object + typedef OverloadedCommandNode node_type; + typedef OverloadedCommandNode & result_type; - protected: - ParsedCommandAttributorBase(ParsedCommandOverloadBase & overload, unsigned index); + OverloadedCommandNode & create(DirectoryNode & dir, std::string const & name) const; - void argName(std::string const & name) const; - void argDoc(std::string const & doc) const; - void typeName(std::string const & doc) const; - void defaultDoc(std::string const & doc) const; + protected: + ParsedCommandAttributorBase(ParsedCommandOverloadBase::ptr overload, unsigned index); + ParsedCommandAttributorBase(ParsedCommandAttributorBase const & other, unsigned index); + void argName(std::string const & name); + void argDoc(std::string const & doc); + void typeName(std::string const & doc); + void defaultDoc(std::string const & doc); + ParsedCommandOverloadBase & overload() const; - void overloadDoc(std::string const & doc) const; - void nodeDoc(std::string const & doc) const; - void shortDoc(std::string const & doc) const; + void overloadDoc(std::string const & doc); + void nodeDoc(std::string const & doc); + void shortDoc(std::string const & doc); private: - ParsedCommandOverloadBase & overload_; + ParsedCommandOverloadBase::ptr overload_; unsigned index_; + boost::optional doc_; + boost::optional shortdoc_; }; /** \brief Non argument dependent ParsedCommandBase attributes @@ -241,7 +248,8 @@ namespace console { Overload & overload() const; ///< Get the command overload protected: - ParsedCommandAttributor(Overload & overload, unsigned index); + ParsedCommandAttributor(typename Overload::ptr overload, unsigned index); + ParsedCommandAttributor(ParsedCommandAttributorBase const & other, unsigned index); private: }; @@ -398,10 +406,10 @@ namespace console { : public ParsedCommandAttributor { public: - Self doc(std::string const & doc) const; ///< Set documentation for all overloads - Self shortdoc(std::string const & doc) const; ///< Set short documentation for all overloads - Self overloadDoc(std::string const & doc) const; ///< Set overload specific documentation - Self formatter(typename Overload::Formatter formatter) const; + Self doc(std::string const & doc); ///< Set documentation for all overloads + Self shortdoc(std::string const & doc); ///< Set short documentation for all overloads + Self overloadDoc(std::string const & doc); ///< Set overload specific documentation + Self formatter(typename Overload::Formatter formatter); ///< Set return value formatter /**< This member is only available, if the \a ReturnType of the installed callback is not \c void. @@ -415,7 +423,8 @@ namespace console { value and writes it properly formated to \a os. */ protected: - ParsedArgumentAttributorBase(Overload & overload, unsigned index); + ParsedArgumentAttributorBase(typename Overload::ptr overload, unsigned index); + ParsedArgumentAttributorBase(ParsedCommandAttributorBase const & other, unsigned index); private: }; @@ -427,12 +436,13 @@ namespace console { : public ParsedCommandAttributor { public: - Self doc(std::string const & doc) const; ///< Set documentation for all overloads - Self shortdoc(std::string const & doc) const; ///< Set short documentation for all overloads - Self overloadDoc(std::string const & doc) const; ///< Set overload specific documentation + Self doc(std::string const & doc); ///< Set documentation for all overloads + Self shortdoc(std::string const & doc); ///< Set short documentation for all overloads + Self overloadDoc(std::string const & doc); ///< Set overload specific documentation protected: - ParsedArgumentAttributorBase(Overload & overload, unsigned index); + ParsedArgumentAttributorBase(typename Overload::ptr overload, unsigned index); + ParsedArgumentAttributorBase(ParsedCommandAttributorBase const & other, unsigned index); private: }; @@ -449,7 +459,7 @@ namespace console { \see \ref console_autoparse */ - template < class Overload, unsigned index, bool flag> + template class ParsedArgumentAttributor : public ParsedArgumentAttributorBase< Overload, ParsedArgumentAttributor > @@ -463,9 +473,6 @@ namespace console { kw::type::parser> arg_params; public: - typedef OverloadedCommandNode node_type; - typedef ParsedArgumentAttributor return_type; - typedef typename senf::function_traits_arg_type< typename Overload::traits, int(index) >::type arg_type; typedef typename senf::remove_cvref< arg_type >::type value_type; @@ -502,43 +509,37 @@ namespace console { #endif private: - explicit ParsedArgumentAttributor(Overload & overload); + explicit ParsedArgumentAttributor(typename Overload::ptr overload); + explicit ParsedArgumentAttributor(ParsedCommandAttributorBase const & other); template - next_type argInfo(ArgumentPack const & args) const; + next_type argInfo(ArgumentPack const & args); template - void argInfo(Kw const &, ArgumentPack const &, boost::mpl::false_) - const; + void argInfo(Kw const &, ArgumentPack const &, boost::mpl::false_); template void argInfo(boost::parameter::keyword const &, - ArgumentPack const & args, boost::mpl::true_) - const; + ArgumentPack const & args, boost::mpl::true_); template void argInfo(boost::parameter::keyword const &, - ArgumentPack const & args, boost::mpl::true_) - const; + ArgumentPack const & args, boost::mpl::true_); template void argInfo(boost::parameter::keyword const &, - ArgumentPack const & args, boost::mpl::true_) - const; + ArgumentPack const & args, boost::mpl::true_); template void argInfo(boost::parameter::keyword const &, - ArgumentPack const & args, boost::mpl::true_) - const; + ArgumentPack const & args, boost::mpl::true_); template void argInfo(boost::parameter::keyword const &, - ArgumentPack const & args, boost::mpl::true_) - const; + ArgumentPack const & args, boost::mpl::true_); template void argInfo(boost::parameter::keyword const &, - ArgumentPack const & args, boost::mpl::true_) - const; + ArgumentPack const & args, boost::mpl::true_); next_type next() const; - void defaultValue(value_type const & value) const; - template void parser(Fn fn) const; + void defaultValue(value_type const & value); + template void parser(Fn fn); template friend class ParsedArgumentAttributor; @@ -558,7 +559,8 @@ namespace console { typedef ParsedArgumentAttributor return_type; private: - explicit ParsedArgumentAttributor(Overload & overload); + explicit ParsedArgumentAttributor(typename Overload::ptr overload); + explicit ParsedArgumentAttributor(ParsedCommandAttributorBase const & other); template friend class ParsedArgumentAttributor; @@ -566,33 +568,74 @@ namespace console { friend class detail::ParsedCommandAddNodeAccess; }; - template - typename detail::ParsedCommandTraits::Attributor - senf_console_add_node(DirectoryNode & node, std::string const & name, Function fn, int, - typename boost::enable_if_c< - detail::ParsedCommandTraits::is_callable>::type * = 0); +#endif + +namespace factory { template - typename detail::ParsedCommandTraits::Attributor - senf_console_add_node(DirectoryNode & node, std::string const & name, - boost::function fn, int); + SimpleOverloadAttributor + Command(boost::function fn, + typename boost::enable_if_c::is_simple>::type * = 0); - template - typename detail::ParsedCommandTraits::Attributor - senf_console_add_node(DirectoryNode & node, Owner & owner, std::string const & name, - Function fn, int, - typename boost::enable_if_c< - detail::ParsedCommandTraits::is_member>::type * = 0); + template + SimpleOverloadAttributor + Command(Function fn, + typename boost::enable_if_c::is_simple>::type * = 0); + + template + SimpleOverloadAttributor + Command(Member memfn, Owner * owner, + typename boost::enable_if >::type * = 0, + typename boost::enable_if_c::is_simple>::type * = 0); + + template + SimpleOverloadAttributor + Command(Member memfn, Owner const * owner, + typename boost::enable_if >::type * = 0, + typename boost::enable_if_c::is_simple>::type * = 0); + + template + typename senf::console::detail::ParsedCommandTraits::Attributor + Command(boost::function fn); + + template + typename senf::console::detail::ParsedCommandTraits::Attributor + Command(Function fn, + typename boost::enable_if_c::is_callable>::type * = 0, + typename boost::disable_if >::type * = 0); + + template + typename senf::console::detail::ParsedCommandTraits::Attributor + Command(boost::function fn); -#endif + template + typename senf::console::detail::ParsedCommandTraits::Attributor + Command(Function fn, + typename boost::enable_if_c::is_callable>::type * = 0, + typename boost::disable_if >::type * = 0); + + template + typename senf::console::detail::ParsedCommandTraits::Attributor + Command(Member memfn, Owner * owner, + typename boost::enable_if >::type * = 0); + + template + typename senf::console::detail::ParsedCommandTraits::Attributor + Command(Member memfn, Owner const * owner, + typename boost::enable_if >::type * = 0); + + template + typename senf::console::detail::ParsedCommandTraits::Attributor + Command(Member memfn, Owner * owner, + typename boost::enable_if >::type * = 0); -}} + template + typename senf::console::detail::ParsedCommandTraits::Attributor + Command(Member memfn, Owner const * owner, + typename boost::enable_if >::type * = 0); -#include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP() -BOOST_TYPEOF_REGISTER_TEMPLATE(senf::console::ParsedCommandOverload, (class,unsigned)) -BOOST_TYPEOF_REGISTER_TEMPLATE(senf::console::ParsedArgumentAttributor, (class, unsigned, bool)) -BOOST_TYPEOF_REGISTER_TEMPLATE(boost::function_traits, 1) +}}} ///////////////////////////////hh.e//////////////////////////////////////// #include "ParsedCommand.cci"