X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Console%2FParsedCommand.hh;h=af8dfe7041afd67084bb21dc28de9a40d5c1d614;hb=80c6cb7ba9ad7776824c84809f422209adf27331;hp=a4ef2989ff8b30faef1612e021924d020c79ff55;hpb=81a550d520e8531b7f353e1ce0da5b99c249cecb;p=senf.git diff --git a/Console/ParsedCommand.hh b/Console/ParsedCommand.hh index a4ef298..af8dfe7 100644 --- a/Console/ParsedCommand.hh +++ b/Console/ParsedCommand.hh @@ -137,15 +137,13 @@ namespace console { typedef boost::intrusive_ptr ptr; detail::ArgumentInfoBase & arg(unsigned n) const; - template detail::ArgumentInfo & arg(unsigned n) const; void doc(std::string const & d); protected: ParsedCommandOverloadBase(); - template - void addParameter(); + template void addParameter(); private: virtual unsigned v_numArguments() const; @@ -171,8 +169,7 @@ namespace console { \todo Implement automatic binding of member functions for parser and formatter */ - template + template class ParsedCommandOverload : public ParsedCommandOverloadBase { public: @@ -213,14 +210,12 @@ namespace console { void argName(std::string const & name) const; void argDoc(std::string const & doc) const; - template void defaultValue(Type const & value) const; void typeName(std::string const & doc) const; void defaultDoc(std::string const & doc) const; ParsedCommandOverloadBase & overload() const; void overloadDoc(std::string const & doc) const; void nodeDoc(std::string const & doc) const; - template void parser(Fn fn) const; private: ParsedCommandOverloadBase & overload_; @@ -329,42 +324,32 @@ namespace console { assigned in the following way: - - + - - + + - - + + - - + + - - +
command 1 2SyntaxErrorException: invalid number of + command 1 2SyntaxErrorException: invalid number of arguments
command 1 2 3\a a = 1, \n - \a b = \e default, \n - \a c = 2, \n - \a d = \e default, \n - \a e = 3command 1 2 3\a a = 1\a b = \e default\a c = 2\a d = \e default\a e = 3
command 1 2 3 4\a a = 1, \n - \a b = 2, \n - \a c = 3, \n - \a d = \e default, \n - \a e = 4command 1 2 3 4\a a = 1\a b = 2\a c = 3\a d = \e default\a e = 4
command 1 2 3 4 5\a a = 1, \n - \a b = 2, \n - \a c = 3, \n - \a d = 4, \n - \a e = 5command 1 2 3 4 5\a a = 1\a b = 2\a c = 3\a d = 4\a e = 5
command 1 2 3 4 5 6SyntaxErrorException: invalid number of + command 1 2 3 4 5 6SyntaxErrorException: invalid number of arguments
- So, if you assign default values as you are used to - they will work like in C++ and most other languages */ + So, if you use default values as you are used to, + assigning default values to consecutive trailing + arguments, they work like they do in C++ and most other + languages */ BOOST_PARAMETER_KEYWORD(type, type_name) ///< Type name of this arguments type /**< By default, the type of an argument is extracted from the C++ type name by taking the last component of the @@ -413,7 +398,18 @@ namespace console { public: Self doc(std::string const & doc) const; ///< Set documentation for all overloads Self overloadDoc(std::string const & doc) const; ///< Set overload specific documentation - Self formatter(typename Overload::Formatter f) const; ///< Set return value formatter + Self formatter(typename Overload::Formatter formatter) const; + ///< Set return value formatter + /**< This member is only available, if the \a ReturnType of + the installed callback is not \c void. + + If \a ReturnType is not \c void, the \a formatter must + be a callable with a signature compatible with + \code + void formatter(ReturnType const & value, std::ostream & os); + \endcode + The \a formatter takes the return value of the call \a + value and writes it properly formated to \a os. */ protected: ParsedArgumentAttributorBase(Overload & overload, unsigned index); @@ -449,9 +445,7 @@ namespace console { \see \ref console_autoparse */ - template < class Overload, - unsigned index=0, - bool flag=(index < unsigned(Overload::traits::arity)) > + template < class Overload, unsigned index, bool flag> class ParsedArgumentAttributor : public ParsedArgumentAttributorBase< Overload, ParsedArgumentAttributor > @@ -490,7 +484,8 @@ namespace console { Each call to arg() will increment the argument index and advance to the next argument. This member is only - present, if there is an argument at the current. */ + present, if there is an argument at the current + index. */ #ifndef DOXYVEN @@ -544,22 +539,7 @@ namespace console { template friend class ParsedArgumentAttributor; -#ifndef DOXYGEN - - template - friend ParsedArgumentAttributor< - ParsedCommandOverload::traits> > - senf_console_add_node(DirectoryNode & node, std::string const & name, Function fn, int); - - template - friend ParsedArgumentAttributor< - 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); - -#endif + friend class detail::ParsedCommandAddNodeAccess; }; #ifndef DOXYGEN @@ -578,29 +558,20 @@ namespace console { template friend class ParsedArgumentAttributor; - - template - friend ParsedArgumentAttributor< - ParsedCommandOverload::traits> > - senf_console_add_node(DirectoryNode & node, std::string const & name, Function fn, int); - - template - friend ParsedArgumentAttributor< - 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); + + friend class detail::ParsedCommandAddNodeAccess; }; template - ParsedArgumentAttributor< - ParsedCommandOverload::traits> > + typename detail::ParsedCommandTraits::Attributor senf_console_add_node(DirectoryNode & node, std::string const & name, Function fn, int); + template + typename detail::ParsedCommandTraits::Attributor + senf_console_add_node(DirectoryNode & node, std::string const & name, boost::function fn, int); + template - ParsedArgumentAttributor< - ParsedCommandOverload::traits> > + typename detail::ParsedCommandTraits::Attributor senf_console_add_node(DirectoryNode & node, Owner & owner, std::string const & name, Function fn, int, typename boost::enable_if_c<