From 4cfab2eaa03976dcbd2c5875a61903f8032a7769 Mon Sep 17 00:00:00 2001 From: Delalande Ivan Date: Thu, 12 Jul 2012 11:36:34 +0200 Subject: [PATCH] Externalised the CLI parsing. --- Makefile.am | 2 +- configure.ac | 2 +- src/configuration.cc | 1 + src/configuration.hh | 17 ++++++++++++++ src/main.cc | 54 ++++++++++++++++++++++++++++++++++---------- 5 files changed, 62 insertions(+), 14 deletions(-) create mode 100644 src/configuration.cc create mode 100644 src/configuration.hh diff --git a/Makefile.am b/Makefile.am index 17c30ed..31f486b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -23,7 +23,7 @@ prpa_LDADD = \ lib/libfilterSample.a \ lib/libencoder.a -prpa_SOURCES = src/main.cc +prpa_SOURCES = src/main.cc src/configuration.cc prpa_LDFLAGS = \ $(BOOST_LDFLAGS) \ diff --git a/configure.ac b/configure.ac index 41b3279..b1da88e 100644 --- a/configure.ac +++ b/configure.ac @@ -14,7 +14,7 @@ AC_CONFIG_MACRO_DIR([m4]) # Look for a C++ compiler.CXXFLAGS_save="$CXXFLAGS" AC_PROG_CXX AC_PROG_RANLIB -CXXFLAGS="$CXXFLAGS_save" +CXXFLAGS="$CXXFLAGS_save -std=c++11 -g" AC_ARG_ENABLE(debug, [ --enable-debug compile with debugging support], diff --git a/src/configuration.cc b/src/configuration.cc new file mode 100644 index 0000000..a9234d0 --- /dev/null +++ b/src/configuration.cc @@ -0,0 +1 @@ +#include "configuration.hh" diff --git a/src/configuration.hh b/src/configuration.hh new file mode 100644 index 0000000..de7efdb --- /dev/null +++ b/src/configuration.hh @@ -0,0 +1,17 @@ +#ifndef CONFIGURATION_HH_ +# define CONFIGURATION_HH_ + +# include +# include + +class Configuration +{ + public: + std::list input; + std::string output; + std::string codec; + std::list filters; + private: +}; + +#endif /* !CONFIGURATION_HH_ */ diff --git a/src/main.cc b/src/main.cc index d6c979f..5b2f3d6 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1,12 +1,15 @@ #include #include +#include +#include + +#include "configuration.hh" #include "encoder/video.hh" #include "encoder/video_reader.hh" #include "encoder/video_writer.hh" -int -main (int argc, char** argv) +bool parse_cli(Configuration& conf, int argc, char** argv) { namespace po = boost::program_options; @@ -14,10 +17,10 @@ main (int argc, char** argv) po::options_description desc("Allowed options"); desc.add_options() ("help,h", "produce help message") - ("filter,f", po::value > (), "apply a filter") - ("input-file,i", po::value > (), "file to treat") - ("output,o", po::value > (), "output file") - ("codec,c", po::value > (), "output codec") + ("filter,f", po::value>(), "apply a filter") + ("input-file,i", po::value>(), "file to treat") + ("output,o", po::value(), "output file") + ("codec,c", po::value(), "output codec") ; // Handle ./prpa file.avi instead of ./prpa --input-file=file.avi @@ -34,7 +37,7 @@ main (int argc, char** argv) catch (po::invalid_command_line_syntax e) { std::cerr << argv[0] << ": " << e.what() << std::endl; - return 1; + return false; } po::notify(vm); @@ -42,7 +45,7 @@ main (int argc, char** argv) if (argc <= 1 || vm.count("help")) { std::cout << desc << "\n"; - return 1; + return false; } // GO! @@ -60,11 +63,38 @@ main (int argc, char** argv) else std::cout << 0 << std::endl; - VideoReader vr(vm["input-file"].as >()[0]); + /* Store configuration */ + conf.output = std::string(vm["output"].as()); + conf.codec = std::string(vm["codec"].as()); + + std::vector vs; + if (vm.count("input-file")) + { + vs = vm["input-file"].as>(); + for (auto it = vs.begin(); it != vs.end(); ++it) + conf.input.push_back(std::string(*it)); + } + + if (vm.count("filter")) + { + vs = vm["filter"].as> (); + for (auto it = vs.begin(); it != vs.end(); ++it) + conf.filters.push_back(std::string(*it)); + } + + return true; +} + +int main (int argc, char** argv) +{ + Configuration conf = Configuration(); + + if (!parse_cli(conf, argc, argv)) + return 1; + + VideoReader vr(conf.input.front()); VideoWriter vw = VideoWriter(); - vw.open(vm["output"].as >()[0], - vm["codec"].as >()[0], - vr.fps_get(), vr.width_get(), vr.height_get()); + vw.open(conf.output, conf.codec, vr.fps_get(), vr.width_get(), vr.height_get()); vw.copy(vr); vw.write();