From 8cdeefc37b2e3a53038da74be9d31aced3045313 Mon Sep 17 00:00:00 2001 From: Bert Peters Date: Mon, 9 Apr 2018 13:56:34 +0200 Subject: [PATCH] Replace separate parse function with constructor. --- src/fmri/Options.cpp | 45 +++++++++++++++++++------------------------- src/fmri/Options.hpp | 4 +--- src/fmri/main.cpp | 2 +- 3 files changed, 21 insertions(+), 30 deletions(-) diff --git a/src/fmri/Options.cpp b/src/fmri/Options.cpp index bb3845d..9eadfdf 100644 --- a/src/fmri/Options.cpp +++ b/src/fmri/Options.cpp @@ -48,31 +48,32 @@ static void parse_color(const char *input, Color &targetColor) throw std::invalid_argument(errorBuf); } -Options Options::parse(const int argc, char *const argv[]) +Options::Options(int argc, char * const argv[]): + layerTransparancy_(1), + interactionTransparancy_(1), + pathColor_({1, 1, 1, 0.1}) { using namespace boost::program_options; try { - Options options; - options_description desc("Options"); positional_options_description positionals; positionals.add("input", -1); options_description hidden; hidden.add_options() - ("input", value>(&options.inputPaths)->required()->composing()); + ("input", value>(&inputPaths)->required()->composing()); desc.add_options() ("help,h", "Show this help message") - ("weights,w", value(&options.weightsPath)->required(), "weights file for the network") - ("network,n", value(&options.modelPath)->required(), "caffe model file for the network") - ("labels,l", value(&options.labelsPath), "labels file") - ("means,m", value(&options.meansPath), "means file") + ("weights,w", value(&weightsPath)->required(), "weights file for the network") + ("network,n", value(&modelPath)->required(), "caffe model file for the network") + ("labels,l", value(&labelsPath), "labels file") + ("means,m", value(&meansPath), "means file") ("path-color,p", value(), "color for paths") - ("layer-opacity", value(&options.layerTransparancy_), "Opacity for layers") - ("interaction-opacity", value(&options.interactionTransparancy_), "Opacity for interactions") - ("dump,d", value(&options.dumpPath), "dump convolutional images in this directory"); + ("layer-opacity", value(&layerTransparancy_), "Opacity for layers") + ("interaction-opacity", value(&interactionTransparancy_), "Opacity for interactions") + ("dump,d", value(&dumpPath), "dump convolutional images in this directory"); options_description composed = desc; composed.add(hidden); @@ -88,17 +89,16 @@ Options Options::parse(const int argc, char *const argv[]) notify(vm); if (vm.count("path-color")) { - parse_color(vm["path-color"].as().c_str(), options.pathColor_); + parse_color(vm["path-color"].as().c_str(), pathColor_); } // Sanity checks - check_file(options.modelPath); - check_file(options.weightsPath); - if (!options.meansPath.empty()) check_file(options.meansPath); - if (!options.labelsPath.empty()) check_file(options.labelsPath); - std::for_each(options.inputPaths.begin(), options.inputPaths.end(), check_file); - - return options; + check_file(modelPath); + check_file(weightsPath); + if (!meansPath.empty()) check_file(meansPath); + if (!labelsPath.empty()) check_file(labelsPath); + std::for_each(inputPaths.begin(), inputPaths.end(), check_file); + return; } catch (required_option& e) { if (e.get_option_name() == "--input") { std::cerr << "No input files specified" << std::endl; @@ -150,13 +150,6 @@ std::optional Options::imageDumper() const } } -Options::Options() noexcept : - layerTransparancy_(1), - interactionTransparancy_(1), - pathColor_({1, 1, 1, 0.1}) -{ -} - const Color &Options::pathColor() const { return pathColor_; diff --git a/src/fmri/Options.hpp b/src/fmri/Options.hpp index 2830d54..f64e613 100644 --- a/src/fmri/Options.hpp +++ b/src/fmri/Options.hpp @@ -14,7 +14,7 @@ namespace fmri { class Options { public: - static Options parse(const int argc, char *const argv[]); + Options(const int argc, char *const argv[]); const string& model() const; const string& weights() const; @@ -37,7 +37,5 @@ namespace fmri { string labelsPath; string dumpPath; vector inputPaths; - - Options() noexcept; }; } diff --git a/src/fmri/main.cpp b/src/fmri/main.cpp index 9bf9b24..6a95573 100644 --- a/src/fmri/main.cpp +++ b/src/fmri/main.cpp @@ -59,7 +59,7 @@ int main(int argc, char *argv[]) glutCreateWindow(argv[0]); // Prepare data for simulations - Options options = Options::parse(argc, argv); + Options options(argc, argv); RenderingState::instance().loadOptions(options); loadSimulationData(options);