X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Console%2FOverloadedCommand.hh;h=a9671206ea00aff872fffebc1ffe15c7ee9f063c;hb=748363b235c4651b3992cc291a95dc2e18e45724;hp=a255eb588ed16239caa5c55f607d43efb0eadedd;hpb=30c1daf8a1c404209210f76a9a54bcfde443603b;p=senf.git diff --git a/Console/OverloadedCommand.hh b/Console/OverloadedCommand.hh index a255eb5..a967120 100644 --- a/Console/OverloadedCommand.hh +++ b/Console/OverloadedCommand.hh @@ -39,7 +39,10 @@ namespace console { class OverloadedCommandNode; - /** \brief + /** \brief Base class for command overload of OverloadedCommandNode + + This class is the base class of the commands which may be added to an + OverloadedCommandNode. */ class CommandOverload : public senf::intrusive_refcount @@ -49,16 +52,28 @@ namespace console { // Types typedef boost::intrusive_ptr ptr; - typedef CommandNode::Arguments Arguments; /////////////////////////////////////////////////////////////////////////// virtual ~CommandOverload(); - void operator()(std::ostream & os, Arguments const & arguments); - void help(std::ostream & os); + 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. + Same as operator()() */ + + 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() */ - OverloadedCommandNode & node(); + void help(std::ostream & os); ///< Provide help for this specific overload + + OverloadedCommandNode & node(); ///< Access owning node + /**< \pre The command \e must have been added to an + OverloadedCommandNode. */ protected: CommandOverload(); @@ -67,7 +82,7 @@ namespace console { private: #endif virtual void v_help(std::ostream & os) const = 0; - virtual void v_execute(std::ostream & os, Arguments const & arguments) const = 0; + virtual void v_execute(std::ostream & os, ParseCommandInfo const & command) const = 0; private: OverloadedCommandNode * node_; @@ -77,9 +92,22 @@ namespace console { /** \brief Command node which allows multiple registered callbacks - OverloadedCommand is like SimpleCommand but allows to register multiple commands to a single - node. This works by calling each command in the list consecutively until no 'SyntaxError' - exception is thrown. + OverloadedCommandNode is like SimpleCommandNode but allows to register multiple commands to + a single node. This works by calling each command in the list consecutively until no + 'SyntaxErrorException' exception is thrown. + + This works by first adding an OverloadedCommandNode to the directory in question and then + adding commands to that node. Commands are derived from CommandOverload. + \code + senf::console::DirectoryNode & dir (...); + senf::console::OverloadedCommandNode & cmd ( + dir.add("cmd", senf::console::OverloadedCommandNode::create()) ); + cmd.add(senf::console::SimpleCommandOverload::create(&callback)); + cmd.add(senf::console::SimpleCommandOverload::create(&anotherCallback)); + \endcode + + However, this facility is mostly 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 @@ -105,13 +133,15 @@ namespace console { ///@} /////////////////////////////////////////////////////////////////////////// - - void add(CommandOverload::ptr overload); + + 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: @@ -119,7 +149,7 @@ namespace console { 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; @@ -127,7 +157,11 @@ namespace console { std::string doc_; }; - /** \brief + /** \brief Basic command overload + + This is an implementation of CommandOverload which allows to call an arbitrary callback with + the correct signature + (void (std::ostream &, senf::console::ParseCommandInfo const &)) */ class SimpleCommandOverload : public CommandOverload @@ -137,18 +171,21 @@ namespace console { // Types typedef boost::intrusive_ptr ptr; - typedef boost::function Function; + typedef boost::function Function; /////////////////////////////////////////////////////////////////////////// ///\name Structors and default members ///@{ static SimpleCommandOverload::ptr create(Function fn); + ///< Create new SimpleCommandOverload + /**< \param[in] fn callback to call */ ///@} /////////////////////////////////////////////////////////////////////////// SimpleCommandOverload & doc(std::string const & doc); + ///< Assign overload specific documentation protected: @@ -156,7 +193,7 @@ namespace console { SimpleCommandOverload(Function fn); virtual void v_help(std::ostream & os) const; - virtual void v_execute(std::ostream & os, Arguments const & arguments) const; + virtual void v_execute(std::ostream & os, ParseCommandInfo const & command) const; Function fn_; std::string doc_; @@ -167,7 +204,7 @@ namespace console { ///////////////////////////////hh.e//////////////////////////////////////// #include "OverloadedCommand.cci" //#include "OverloadedCommand.ct" -//#include "OverloadedCommand.cti" +#include "OverloadedCommand.cti" #endif