aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2017-06-25 19:27:58 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2017-06-25 19:27:58 +0300
commitbe0973bb367c5644e9ecc57043f2b6aa49a3dcb9 (patch)
tree061223783abb5ebc98bfc9d115a97ed6bd04c268
parentrefactor command-line parameters parsing (diff)
downloadwinapi-debug-be0973bb367c5644e9ecc57043f2b6aa49a3dcb9.tar.gz
winapi-debug-be0973bb367c5644e9ecc57043f2b6aa49a3dcb9.zip
code style
-rw-r--r--utils/command_line.hpp117
-rw-r--r--utils/pdb_descr.hpp47
2 files changed, 79 insertions, 85 deletions
diff --git a/utils/command_line.hpp b/utils/command_line.hpp
index 8a5cf93..352c210 100644
--- a/utils/command_line.hpp
+++ b/utils/command_line.hpp
@@ -15,75 +15,72 @@
#include <ostream>
#include <string>
-namespace
+class SettingsParser
{
- class SettingsParser
+public:
+ explicit SettingsParser(const std::string& argv0)
+ : prog_name{extract_filename(argv0)}
{
- public:
- explicit SettingsParser(const std::string& argv0)
- : prog_name{extract_filename(argv0)}
- {
- visible.add_options()
- ("help,h",
- "show this message and exit");
- }
+ visible.add_options()
+ ("help,h",
+ "show this message and exit");
+ }
- virtual ~SettingsParser() = default;
+ virtual ~SettingsParser() = default;
- virtual const char* get_short_description() const
- {
- return "[--option VALUE]...";
- }
+ virtual const char* get_short_description() const
+ {
+ return "[--option VALUE]...";
+ }
- virtual void parse(int argc, char* argv[])
- {
- boost::program_options::options_description all;
- all.add(hidden).add(visible);
- boost::program_options::variables_map vm;
- boost::program_options::store(
- boost::program_options::command_line_parser{argc, argv}
- .options(all)
- .positional(positional)
- .run(),
- vm);
- if (vm.count("help"))
- exit_with_usage = true;
- else
- boost::program_options::notify(vm);
- }
+ virtual void parse(int argc, char* argv[])
+ {
+ boost::program_options::options_description all;
+ all.add(hidden).add(visible);
+ boost::program_options::variables_map vm;
+ boost::program_options::store(
+ boost::program_options::command_line_parser{argc, argv}
+ .options(all)
+ .positional(positional)
+ .run(),
+ vm);
+ if (vm.count("help"))
+ exit_with_usage = true;
+ else
+ boost::program_options::notify(vm);
+ }
- bool exit_with_usage = false;
+ bool exit_with_usage = false;
- void usage() const
- {
- std::cout << *this;
- }
+ void usage() const
+ {
+ std::cout << *this;
+ }
- void usage_error(const std::exception& e) const
- {
- std::cerr << "usage error: " << e.what() << '\n';
- std::cerr << *this;
- }
+ void usage_error(const std::exception& e) const
+ {
+ std::cerr << "usage error: " << e.what() << '\n';
+ std::cerr << *this;
+ }
- protected:
- boost::program_options::options_description hidden;
- boost::program_options::options_description visible;
- boost::program_options::positional_options_description positional;
+protected:
+ boost::program_options::options_description hidden;
+ boost::program_options::options_description visible;
+ boost::program_options::positional_options_description positional;
- private:
- static std::string extract_filename(const std::string& path)
- {
- return boost::filesystem::path{path}.filename().string();
- }
+private:
+ static std::string extract_filename(const std::string& path)
+ {
+ return boost::filesystem::path{path}.filename().string();
+ }
- const std::string prog_name;
+ const std::string prog_name;
- friend std::ostream& operator<<(std::ostream& os, const SettingsParser& parser)
- {
- const auto short_descr = parser.get_short_description();
- os << "usage: " << parser.prog_name << ' ' << short_descr << '\n';
- os << parser.visible;
- return os;
- }
- };
-}
+ friend std::ostream& operator<<(std::ostream& os, const SettingsParser& parser)
+ {
+ const auto short_descr = parser.get_short_description();
+ os << "usage: " << parser.prog_name << ' ' << short_descr << '\n';
+ os << parser.visible;
+ return os;
+ }
+};
diff --git a/utils/pdb_descr.hpp b/utils/pdb_descr.hpp
index 58261a0..cde815a 100644
--- a/utils/pdb_descr.hpp
+++ b/utils/pdb_descr.hpp
@@ -15,37 +15,34 @@
#include <string>
#include <vector>
-namespace
+struct PDB
{
- struct PDB
- {
- pdb::Address online_base;
- std::string path;
+ pdb::Address online_base;
+ std::string path;
- static PDB parse(std::string src)
- {
- static constexpr auto sep = ',';
+ static PDB parse(std::string src)
+ {
+ static constexpr auto sep = ',';
- const auto sep_pos = src.find(sep);
- if (sep_pos == std::string::npos)
- boost::throw_exception(boost::program_options::invalid_option_value{src});
+ const auto sep_pos = src.find(sep);
+ if (sep_pos == std::string::npos)
+ boost::throw_exception(boost::program_options::invalid_option_value{src});
- pdb::Address online_base;
- if (!pdb::parse_address(online_base, src.substr(0, sep_pos)))
- boost::throw_exception(boost::program_options::invalid_option_value{src});
+ pdb::Address online_base;
+ if (!pdb::parse_address(online_base, src.substr(0, sep_pos)))
+ boost::throw_exception(boost::program_options::invalid_option_value{src});
- return {online_base, src.substr(sep_pos + 1)};
- }
+ return {online_base, src.substr(sep_pos + 1)};
+ }
- static pdb::Address parse_address(const std::string& src)
- {
- pdb::Address dest;
- if (!pdb::parse_address(dest, src))
- boost::throw_exception(boost::program_options::invalid_option_value{src});
- return dest;
- }
- };
-}
+ static pdb::Address parse_address(const std::string& src)
+ {
+ pdb::Address dest;
+ if (!pdb::parse_address(dest, src))
+ boost::throw_exception(boost::program_options::invalid_option_value{src});
+ return dest;
+ }
+};
namespace boost
{