X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Console%2FParsedCommand.hh;h=14d63a02ce173d1e8956ba35dad042bc1b2be209;hb=01e02e262ea327678dfa0c3f7a66d50ed91924d5;hp=b2fca486797fad5570eb2cf26884b39abc0cec4d;hpb=748363b235c4651b3992cc291a95dc2e18e45724;p=senf.git diff --git a/Console/ParsedCommand.hh b/Console/ParsedCommand.hh index b2fca48..14d63a0 100644 --- a/Console/ParsedCommand.hh +++ b/Console/ParsedCommand.hh @@ -33,6 +33,8 @@ #include #include #include +#include +#include #include "../config.hh" #include "OverloadedCommand.hh" #include "ParseParameter.hh" @@ -51,20 +53,25 @@ namespace console { public: typedef boost::intrusive_ptr ptr; - protected: - ParsedCommandOverloadBase(); - detail::ParameterInfoBase & arg(unsigned n) const; template detail::ParameterInfo & arg(unsigned n) const; + void doc(std::string const & d); + + protected: + ParsedCommandOverloadBase(); + template void addParameter(); private: - virtual void v_help(std::ostream & os) const; + virtual unsigned v_numArguments() const; + virtual void v_argumentDoc(unsigned index, ArgumentDoc & doc) const; + virtual std::string v_doc() const; typedef std::vector Parameters; Parameters parameters_; + std::string doc_; }; template @@ -75,17 +82,167 @@ namespace console { 1)) # include BOOST_PP_ITERATE() + class ParsedCommandAttributorBase + { + public: + OverloadedCommandNode & node() const; + operator OverloadedCommandNode & () const; + + protected: + ParsedCommandAttributorBase(ParsedCommandOverloadBase & overload, unsigned index); + + void argName(std::string const & name) const; + void argDoc(std::string const & doc) const; + template void defaultValue(Type const & value) const; + + ParsedCommandOverloadBase & overload() const; + void overloadDoc(std::string const & doc) const; + + void nodeDoc(std::string const & doc) const; + + private: + ParsedCommandOverloadBase & overload_; + unsigned index_; + }; + + template + class ParsedCommandAttributor + : public ParsedCommandAttributorBase + { + public: + Overload & overload() const; + + protected: + ParsedCommandAttributor(Overload & overload, unsigned index); + + private: + }; + + namespace tag { + BOOST_PARAMETER_KEYWORD(detail, name_); + BOOST_PARAMETER_KEYWORD(detail, description_); + BOOST_PARAMETER_KEYWORD(detail, default_value_); + } + + template + class ParsedAttributeAttributorBase + : public ParsedCommandAttributor + { + public: + Self doc(std::string const & doc) const; + Self overloadDoc(std::string const & doc) const; + + protected: + ParsedAttributeAttributorBase(Overload & overload, unsigned index); + + private: + }; + + template < class Overload, + unsigned index=0, + bool flag=(index < unsigned(Overload::traits::arity)) > + class ParsedAttributeAttributor + : public ParsedAttributeAttributorBase< Overload, + ParsedAttributeAttributor > + { + public: + 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; + typedef ParsedAttributeAttributor next_type; + + typedef OverloadedCommandNode node_type; + typedef ParsedAttributeAttributor return_type; + + typedef boost::parameter::parameters< + tag::detail::name_, + tag::detail::description_, + tag::detail::default_value_> arg_params; + + next_type arg() const; + +# define BOOST_PP_ITERATION_PARAMS_1 \ + (4, (1, 3, SENF_ABSOLUTE_INCLUDE_PATH(Console/ParsedCommand.mpp), 5)) +# include BOOST_PP_ITERATE() + + private: + explicit ParsedAttributeAttributor(Overload & overload); + + template + next_type argInfo(ArgumentPack const & args) const; + + template + next_type argInfo(ArgumentPack const & args, boost::mpl::true_) const; + template + next_type argInfo(ArgumentPack const & args, boost::mpl::false_) const; + + next_type argInfo(std::string const & name, std::string const & doc) const; + next_type argInfo(std::string const & name, std::string const & doc, + value_type const & value) const; + + ParsedAttributeAttributor next() const; + + void defaultValue(value_type const & value) const; + + template + friend class ParsedAttributeAttributor; + + template + friend ParsedAttributeAttributor< + ParsedCommandOverload::traits> > + senf_console_add_node(DirectoryNode & node, std::string const & name, Function fn, int); + + template + friend ParsedAttributeAttributor< + ParsedCommandOverload::traits> > + 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 + class ParsedAttributeAttributor + : public ParsedCommandAttributor< Overload > + { + public: + typedef OverloadedCommandNode node_type; + typedef ParsedAttributeAttributor return_type; + + private: + explicit ParsedAttributeAttributor(Overload & overload); + + template + friend class ParsedAttributeAttributor; + + template + friend ParsedAttributeAttributor< + ParsedCommandOverload::traits> > + senf_console_add_node(DirectoryNode & node, std::string const & name, Function fn, int); + + template + friend ParsedAttributeAttributor< + ParsedCommandOverload::traits> > + 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); + }; + #ifndef DOXYGEN template - ParsedCommandOverload::traits> & + ParsedAttributeAttributor< + ParsedCommandOverload::traits> > senf_console_add_node(DirectoryNode & node, std::string const & name, Function fn, int); template - ParsedCommandOverload::traits> & + ParsedAttributeAttributor< + ParsedCommandOverload::traits> > senf_console_add_node(DirectoryNode & node, Owner & owner, std::string const & name, Function fn, int, - typename boost::enable_if_c::is_member>::type * = 0); + typename boost::enable_if_c< + detail::ParsedCommandTraits::is_member>::type * = 0); #endif @@ -94,6 +251,7 @@ namespace console { #include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP() BOOST_TYPEOF_REGISTER_TEMPLATE(senf::console::ParsedCommandOverload, (class,unsigned)) +BOOST_TYPEOF_REGISTER_TEMPLATE(senf::console::ParsedAttributeAttributor, (class, unsigned, bool)) BOOST_TYPEOF_REGISTER_TEMPLATE(boost::function_traits, 1) ///////////////////////////////hh.e////////////////////////////////////////