]> git.stg.codes - stg.git/blobdiff - projects/sgconf/options.h
Ticket. if (!data.tariffConf.changePolicy.empty()) construction added in
[stg.git] / projects / sgconf / options.h
index 696255ff6c58b28c8699e118398759fc8c16b40e..c00707bf2d0887d0e7a279f0125eaeecf47e1071 100644 (file)
@@ -23,6 +23,8 @@
 
 #include <string>
 #include <vector>
+#include <list>
+#include <utility>
 #include <stdexcept>
 #include <cstddef> // size_t
 
@@ -48,8 +50,10 @@ class OPTION
         OPTION & operator=(const OPTION & rhs);
 
         void Help(size_t level = 0) const;
-        PARSER_STATE Parse(int argc, char ** argv);
+        PARSER_STATE Parse(int argc, char ** argv, void * data);
+        void ParseValue(const std::string & value);
         bool Check(const char * arg) const;
+        const std::string & Name() const { return m_longName; }
 
         class ERROR : public std::runtime_error
         {
@@ -68,20 +72,47 @@ class OPTION
 class OPTION_BLOCK
 {
     public:
-        void Add(const std::string & shortName,
-                 const std::string & longName,
-                 ACTION * action,
-                 const std::string & description);
-        void Add(const std::string & longName,
-                 ACTION * action,
-                 const std::string & description);
+        OPTION_BLOCK() {}
+        OPTION_BLOCK(const std::string & description)
+            : m_description(description) {}
+        OPTION_BLOCK & Add(const std::string & shortName,
+                           const std::string & longName,
+                           ACTION * action,
+                           const std::string & description);
+        OPTION_BLOCK & Add(const std::string & longName,
+                           ACTION * action,
+                           const std::string & description);
 
         void Help(size_t level) const;
 
-        PARSER_STATE Parse(int argc, char ** argv);
+        PARSER_STATE Parse(int argc, char ** argv, void * data = NULL);
+        void ParseFile(const std::string & filePath);
+
+        class ERROR : public std::runtime_error
+        {
+            public:
+                ERROR(const std::string & message)
+                    : std::runtime_error(message.c_str()) {}
+        };
 
     private:
         std::vector<OPTION> m_options;
+        std::string m_description;
+
+        void OptionCallback(const std::string & key, const std::string & value);
+};
+
+class OPTION_BLOCKS
+{
+    public:
+        OPTION_BLOCK & Add(const std::string & description)
+        { m_blocks.push_back(OPTION_BLOCK(description)); return m_blocks.back(); }
+        void Add(const OPTION_BLOCK & block) { m_blocks.push_back(block); }
+        void Help(size_t level) const;
+        PARSER_STATE Parse(int argc, char ** argv);
+
+    private:
+        std::list<OPTION_BLOCK> m_blocks;
 };
 
 } // namespace SGCONF