Console: More extensible keyword parameter dispatching in arg() attribute
[senf.git] / Console / OverloadedCommand.hh
index e1481e5..1363d52 100644 (file)
@@ -39,6 +39,13 @@ namespace console {
 
     class OverloadedCommandNode;
 
+    struct ArgumentDoc {
+        std::string name;
+        std::string type;
+        std::string defaultValue;
+        std::string doc;
+    };
+
     /** \brief Base class for command overload of OverloadedCommandNode
 
         This class is the base class of the commands which may be added to an
@@ -52,21 +59,32 @@ namespace console {
         // Types
 
         typedef boost::intrusive_ptr<CommandOverload> ptr;
-        typedef CommandNode::Arguments Arguments;
+        typedef boost::intrusive_ptr<CommandOverload const> 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;
+        void argumentDoc(unsigned index, ArgumentDoc & doc) const;
+        std::string doc() const;
+        
+        OverloadedCommandNode & node() const; ///< Access owning node
                                         /**< \pre The command \e must have been added to an
                                              OverloadedCommandNode. */
+        unsigned overloadIndex() const;
 
     protected:
         CommandOverload();
@@ -74,8 +92,10 @@ namespace console {
 #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;
+        virtual void v_argumentDoc(unsigned index, ArgumentDoc & doc) const = 0;
+        virtual std::string v_doc() const = 0;
+        virtual void v_execute(std::ostream & os, ParseCommandInfo const & command) const = 0;
 
     private:
         OverloadedCommandNode * node_;
@@ -99,13 +119,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 <b>must</b> do all syntax checking before doing any
             operation
 
-        \ingroup node_tree
+        \ingroup console_commands
       */
     class OverloadedCommandNode
         : public CommandNode
@@ -118,6 +138,9 @@ namespace console {
         typedef boost::shared_ptr<OverloadedCommandNode const> cptr;
         typedef boost::weak_ptr<OverloadedCommandNode> weak_ptr;
 
+        typedef OverloadedCommandNode node_type;
+        typedef OverloadedCommandNode & return_type;
+
         ///////////////////////////////////////////////////////////////////////////
         ///\name Structors and default members
         ///@{
@@ -136,13 +159,15 @@ namespace console {
         OverloadedCommandNode & doc(std::string const & doc);
                                         ///< Assign global help for all overloads
 
+        unsigned overloadIndex(CommandOverload const & overload);
+
     protected:
 
     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<CommandOverload::ptr> Overloads;
 
@@ -153,7 +178,8 @@ namespace console {
     /** \brief Basic command overload
 
         This is an implementation of CommandOverload which allows to call an arbitrary callback with
-        the correct signature (<tt>void (std::ostream &, Arguments const &)</tt>)
+        the correct signature 
+        (<tt>void (std::ostream &, senf::console::ParseCommandInfo const &)</tt>)
       */
     class SimpleCommandOverload
         : public CommandOverload
@@ -163,7 +189,7 @@ namespace console {
         // Types
 
         typedef boost::intrusive_ptr<SimpleCommandOverload> ptr;
-        typedef boost::function<void (std::ostream &, Arguments const &)> Function;
+        typedef boost::function<void (std::ostream &, ParseCommandInfo const &)> Function;
 
         ///////////////////////////////////////////////////////////////////////////
         ///\name Structors and default members
@@ -184,8 +210,10 @@ namespace console {
     private:
         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_;