2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Author : Maxim Mamontov <faust@stargazer.dp.ua>
28 #include <cstddef> // size_t
39 OPTION(const std::string& shortName,
40 const std::string& longName,
41 std::unique_ptr<ACTION> action,
42 const std::string& description);
43 OPTION(const std::string& longName,
44 std::unique_ptr<ACTION> action,
45 const std::string& description);
47 OPTION(OPTION&& rhs) = default;
48 OPTION& operator=(OPTION&& rhs) = default;
50 void Help(size_t level = 0) const;
51 PARSER_STATE Parse(int argc, char** argv, void* data);
52 void ParseValue(const std::string & value);
53 bool Check(const char* arg) const;
54 const std::string& Name() const { return m_longName; }
56 struct ERROR : std::runtime_error
58 explicit ERROR(const std::string & message) noexcept
59 : std::runtime_error(message.c_str()) {}
63 std::string m_shortName;
64 std::string m_longName;
65 std::unique_ptr<ACTION> m_action;
66 std::string m_description;
73 explicit OPTION_BLOCK(const std::string& description)
74 : m_description(description) {}
76 OPTION_BLOCK(OPTION_BLOCK&&) = default;
77 OPTION_BLOCK& operator=(OPTION_BLOCK&&) = default;
79 OPTION_BLOCK& Add(const std::string& shortName,
80 const std::string& longName,
81 std::unique_ptr<ACTION> action,
82 const std::string& description);
83 OPTION_BLOCK& Add(const std::string& longName,
84 std::unique_ptr<ACTION> action,
85 const std::string& description);
87 void Help(size_t level) const;
89 PARSER_STATE Parse(int argc, char** argv, void* data = NULL);
90 void ParseFile(const std::string& filePath);
92 struct ERROR : std::runtime_error
94 explicit ERROR(const std::string & message) noexcept
95 : std::runtime_error(message.c_str()) {}
99 std::vector<OPTION> m_options;
100 std::string m_description;
102 void OptionCallback(const std::string& key, const std::string& value);
108 OPTION_BLOCK& Add(const std::string& description)
109 { m_blocks.push_back(OPTION_BLOCK(description)); return m_blocks.back(); }
110 void Add(OPTION_BLOCK&& block) { m_blocks.push_back(std::move(block)); }
111 void Help(size_t level) const;
112 PARSER_STATE Parse(int argc, char** argv);
115 std::vector<OPTION_BLOCK> m_blocks;
118 } // namespace SGCONF