X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Console%2FOverloadedCommand.hh;h=db94afec2e7d360a5adee08ccd0c7d1d8380e402;hb=456ee576285b76aa46240f8001f426757810dcc1;hp=e1481e5dda99bf5e44ea0fef8d793f22f182f26e;hpb=18ebf1e9edb34f1aa8a32173275421a5d54400f7;p=senf.git diff --git a/Console/OverloadedCommand.hh b/Console/OverloadedCommand.hh index e1481e5..db94afe 100644 --- a/Console/OverloadedCommand.hh +++ b/Console/OverloadedCommand.hh @@ -39,6 +39,17 @@ namespace console { class OverloadedCommandNode; + /** \brief Documentation for a single argument + + This struct is used by CommandOverload::argumentDoc() + */ + struct ArgumentDoc { + std::string name; ///< Argument name + std::string type; ///< Argument type (string representation) + std::string defaultValue; ///< Default value (string representation) or empty string + std::string doc; ///< Documentation for this argument + }; + /** \brief Base class for command overload of OverloadedCommandNode This class is the base class of the commands which may be added to an @@ -52,30 +63,67 @@ namespace console { // Types typedef boost::intrusive_ptr ptr; - typedef CommandNode::Arguments Arguments; + typedef boost::intrusive_ptr cptr; /////////////////////////////////////////////////////////////////////////// virtual ~CommandOverload(); - void operator()(std::ostream & os, Arguments const & arguments); + void execute(std::ostream & os, ParseCommandInfo const & command); ///< Call the overload /**< If the \a arguments are not acceptable for this - overload, a SyntaxErrorException must be thrown. */ - void help(std::ostream & os); ///< Provide help for this specific overload + overload, a SyntaxErrorException must be thrown. + Same as operator()() */ - OverloadedCommandNode & node(); ///< Access owning node + void operator()(std::ostream & os, ParseCommandInfo const & command); + ///< Call the overload + /**< If the \a arguments are not acceptable for this + overload, a SyntaxErrorException must be thrown. + Same as execute() */ + + unsigned numArguments() const; ///< Number of arguments this overload takes + void argumentDoc(unsigned index, ArgumentDoc & doc) const; + ///< Get information on argument \a index + /**< The information is returned in \e doc. \e doc must be + empty before this call. + \pre \a index < numArguments() + \param[in] index Argument index + \param[outp doc Argument documentation */ + + std::string doc() const; ///< Get overload documentation + + OverloadedCommandNode & node() const; ///< Access owning node /**< \pre The command \e must have been added to an OverloadedCommandNode. */ + unsigned overloadIndex() const; ///< Get index of overload in it's OverloadedCommandNode + protected: CommandOverload(); #ifndef DOXYGEN private: #endif - virtual void v_help(std::ostream & os) const = 0; - virtual void v_execute(std::ostream & os, Arguments const & arguments) const = 0; + virtual unsigned v_numArguments() const = 0; + ///< Return the number of arguments + /**< This member must be implemented in the derived class to + return the number of arguments, the command expects. */ + + virtual void v_argumentDoc(unsigned index, ArgumentDoc & doc) const = 0; + ///< Return argument documentation + /**< The member must be implemented int the derived class to + return all documentation information for the \a + index'th parameter in \a doc. */ + + virtual std::string v_doc() const = 0; + ///< Return overload documentation + /**< This member must be implemented in the derived class to + return the overloads documentation string. */ + + virtual void v_execute(std::ostream & os, ParseCommandInfo const & command) const = 0; + ///< Execute the overload + /**< This member must be implemented in the derived class + o execute the overload. */ private: OverloadedCommandNode * node_; @@ -99,13 +147,13 @@ namespace console { cmd.add(senf::console::SimpleCommandOverload::create(&anotherCallback)); \endcode - However, this facility is mostly used not directly but indirectly (and automatically) when + However, this facility is normally used not directly but indirectly (and automatically) when adding argument parsing callbacks. \warning For this to work, the commands must do all syntax checking before doing any operation - \ingroup node_tree + \ingroup console_commands */ class OverloadedCommandNode : public CommandNode @@ -118,6 +166,9 @@ namespace console { typedef boost::shared_ptr cptr; typedef boost::weak_ptr weak_ptr; + typedef OverloadedCommandNode node_type; + typedef OverloadedCommandNode & return_type; + /////////////////////////////////////////////////////////////////////////// ///\name Structors and default members ///@{ @@ -130,19 +181,22 @@ namespace console { template Command & add(boost::intrusive_ptr overload); ///< Add an additional overload - ptr thisptr(); - cptr thisptr() const; - OverloadedCommandNode & doc(std::string const & doc); ///< Assign global help for all overloads - protected: + unsigned overloadIndex(CommandOverload const & overload); + ///< Return the overload index for \a overload + /**< overloadIndex returns the index of \a overload in the + internal list of overloads. */ + + ptr thisptr(); + cptr thisptr() const; private: OverloadedCommandNode(); virtual void v_help(std::ostream & output) const; - virtual void v_execute(std::ostream & output, Arguments const & arguments) const; + virtual void v_execute(std::ostream & output, ParseCommandInfo const & command) const; typedef std::vector Overloads; @@ -153,7 +207,8 @@ namespace console { /** \brief Basic command overload This is an implementation of CommandOverload which allows to call an arbitrary callback with - the correct signature (void (std::ostream &, Arguments const &)) + the correct signature + (void (std::ostream &, senf::console::ParseCommandInfo const &)) */ class SimpleCommandOverload : public CommandOverload @@ -163,7 +218,7 @@ namespace console { // Types typedef boost::intrusive_ptr ptr; - typedef boost::function Function; + typedef boost::function Function; /////////////////////////////////////////////////////////////////////////// ///\name Structors and default members @@ -179,13 +234,13 @@ namespace console { SimpleCommandOverload & doc(std::string const & doc); ///< Assign overload specific documentation - protected: - private: - SimpleCommandOverload(Function fn); + explicit SimpleCommandOverload(Function fn); - virtual void v_help(std::ostream & os) const; - virtual void v_execute(std::ostream & os, Arguments const & arguments) const; + virtual unsigned v_numArguments() const; + virtual void v_argumentDoc(unsigned index, ArgumentDoc & doc) const; + virtual std::string v_doc() const; + virtual void v_execute(std::ostream & os, ParseCommandInfo const & command) const; Function fn_; std::string doc_;