]> git.stg.codes - stg.git/blobdiff - projects/sgconf/api_action.h
Move strategy into job.
[stg.git] / projects / sgconf / api_action.h
index 55b384479fa8bbf0b7f005dc8dc73687d82dc2ff..7fc22bcad40c57b18b0ac05c68be953ce28fd1c4 100644 (file)
@@ -61,17 +61,25 @@ class COMMANDS
 class API_ACTION : public ACTION
 {
     public:
+        struct PARAM
+        {
+            PARAM(const std::string & n,
+                  const std::string & s,
+                  const std::string & l)
+                : name(n),
+                  shortDescr(s),
+                  longDescr(l)
+            {}
+            std::string name;
+            std::string shortDescr;
+            std::string longDescr;
+        };
+
         API_ACTION(COMMANDS & commands,
                    const std::string & paramDescription,
                    bool needArgument,
-                   const OPTION_BLOCK& suboptions,
-                   API_FUNCTION funPtr)
-            : m_commands(commands),
-              m_description(paramDescription),
-              m_argument(needArgument ? "1" : ""), // Hack
-              m_suboptions(suboptions),
-              m_funPtr(funPtr)
-        {}
+                   const std::vector<PARAM> & params,
+                   API_FUNCTION funPtr);
         API_ACTION(COMMANDS & commands,
                    const std::string & paramDescription,
                    bool needArgument,
@@ -82,12 +90,10 @@ class API_ACTION : public ACTION
               m_funPtr(funPtr)
         {}
 
-        virtual ACTION * Clone() const { return new API_ACTION(*this); }
-
-        virtual std::string ParamDescription() const { return m_description; }
-        virtual std::string DefaultDescription() const { return ""; }
-        virtual OPTION_BLOCK & Suboptions() { return m_suboptions; }
-        virtual PARSER_STATE Parse(int argc, char ** argv);
+        std::string ParamDescription() const override { return m_description; }
+        std::string DefaultDescription() const override { return ""; }
+        OPTION_BLOCK & Suboptions() override { return m_suboptions; }
+        PARSER_STATE Parse(int argc, char ** argv, void * /*data*/) override;
 
     private:
         COMMANDS & m_commands;
@@ -99,19 +105,35 @@ class API_ACTION : public ACTION
 };
 
 inline
-ACTION * MakeAPIAction(COMMANDS & commands,
+std::unique_ptr<ACTION> MakeAPIAction(COMMANDS & commands,
+                       const std::string & paramDescription,
+                       const std::vector<API_ACTION::PARAM> & params,
+                       API_FUNCTION funPtr)
+{
+return std::make_unique<API_ACTION>(commands, paramDescription, true, params, funPtr);
+}
+
+inline
+std::unique_ptr<ACTION> MakeAPIAction(COMMANDS & commands,
+                       const std::vector<API_ACTION::PARAM> & params,
+                       API_FUNCTION funPtr)
+{
+return std::make_unique<API_ACTION>(commands, "", false, params, funPtr);
+}
+
+inline
+std::unique_ptr<ACTION> MakeAPIAction(COMMANDS & commands,
                        const std::string & paramDescription,
-                       bool needArgument,
                        API_FUNCTION funPtr)
 {
-return new API_ACTION(commands, paramDescription, needArgument, funPtr);
+return std::make_unique<API_ACTION>(commands, paramDescription, true, funPtr);
 }
 
 inline
-ACTION * MakeAPIAction(COMMANDS & commands,
+std::unique_ptr<ACTION> MakeAPIAction(COMMANDS & commands,
                        API_FUNCTION funPtr)
 {
-return new API_ACTION(commands, "", false, funPtr);
+return std::make_unique<API_ACTION>(commands, "", false, funPtr);
 }
 
 }