From 8fae13fe2c6bd341cbd0081d2e7140509b23c692 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Thu, 4 May 2017 03:03:47 +0300 Subject: refactoring --- utils/block_cmd_parser.hpp | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) (limited to 'utils/block_cmd_parser.hpp') diff --git a/utils/block_cmd_parser.hpp b/utils/block_cmd_parser.hpp index ef92dce..70452e3 100644 --- a/utils/block_cmd_parser.hpp +++ b/utils/block_cmd_parser.hpp @@ -27,18 +27,14 @@ namespace class Settings { public: - aes::Algorithm get_algorithm() const { return algorithm; } - aes::Mode get_mode() const { return mode; } + aes::Algorithm algorithm = AES_AES128; + aes::Mode mode = AES_ECB; - bool use_boxes() const { return use_boxes_flag; } - bool verbose() const { return verbose_flag; } + bool use_boxes = false; + bool verbose = false; private: - aes::Algorithm algorithm; - aes::Mode mode; - - bool use_boxes_flag = false; - bool verbose_flag = false; + Settings() = default; friend class CommandLineParser; }; @@ -46,21 +42,23 @@ namespace class CommandLineParser { public: - CommandLineParser(const std::string& argv0) - : prog_name(boost::filesystem::path(argv0).filename().string()) - , options("Options") + explicit CommandLineParser(const std::string& argv0) + : prog_name{boost::filesystem::path{argv0}.filename().string()} + , options{"Options"} { } - void parse(Settings& settings, int argc, char** argv, std::vector& inputs) + Settings parse(int argc, char** argv, std::vector& inputs) { + Settings settings; + namespace po = boost::program_options; options.add_options() - ("help,h", "show this message and exit") - ("use-boxes,b", po::bool_switch(&settings.use_boxes_flag)->default_value(false), "use the \"boxes\" interface") - ("mode,m", po::value(&settings.mode)->required(), "set mode of operation") + ("help,h", "show this message and exit") + ("use-boxes,b", po::bool_switch(&settings.use_boxes)->default_value(false), "use the \"boxes\" interface") + ("mode,m", po::value(&settings.mode)->required(), "set mode of operation") ("algorithm,a", po::value(&settings.algorithm)->required(), "set algorithm") - ("verbose,v", po::bool_switch(&settings.verbose_flag)->default_value(false), "enable verbose output"); + ("verbose,v", po::bool_switch(&settings.verbose)->default_value(false), "enable verbose output"); std::vector args; @@ -83,15 +81,16 @@ namespace if (vm.count("help")) { help_flag = true; - return; + return settings; } po::notify(vm); parse_inputs(settings, inputs, std::deque( std::make_move_iterator(args.begin()), - std::make_move_iterator(args.end()) - )); + std::make_move_iterator(args.end()))); + + return settings; } bool exit_with_usage() const { return help_flag; } @@ -109,7 +108,7 @@ namespace std::string iv_string; - if (aes::mode_requires_initialization_vector(settings.get_mode())) + if (aes::mode_requires_init_vector(settings.mode)) { if (args.empty()) { @@ -134,7 +133,7 @@ namespace args.pop_front(); } - if (aes::mode_requires_initialization_vector(settings.get_mode())) + if (aes::mode_requires_init_vector(settings.mode)) { inputs.emplace_back( std::move(key_string), -- cgit v1.2.3