From fe530235a2120b9eb13e31da6d3fab661b53d21d Mon Sep 17 00:00:00 2001 From: Phuntsok Drak-pa Date: Wed, 27 Mar 2019 13:33:22 +0100 Subject: [PATCH] edited some functions' signature (best practices) --- include/genimg/common.hh | 5 +++-- include/genimg/parseargs.hh | 3 ++- src/common.cc | 6 ++++-- src/methods.cc | 4 ++-- src/parseargs.cc | 18 +++++++++--------- 5 files changed, 20 insertions(+), 16 deletions(-) diff --git a/include/genimg/common.hh b/include/genimg/common.hh index 779fc76..049e9cf 100644 --- a/include/genimg/common.hh +++ b/include/genimg/common.hh @@ -7,8 +7,9 @@ #include #include -std::pair init_image(std::string const &); +[[nodiscard]] std::pair +init_image(std::string const &) noexcept; -double euclidian_distance(cv::Mat const &, cv::Mat const &); +[[nodiscard]] double euclidian_distance(cv::Mat const &, cv::Mat const &); #endif /* GENETIC_IMAGE_INCLUDE_GENIMG_COMMON_HH_ */ diff --git a/include/genimg/parseargs.hh b/include/genimg/parseargs.hh index e92c982..575f9a3 100644 --- a/include/genimg/parseargs.hh +++ b/include/genimg/parseargs.hh @@ -4,7 +4,8 @@ #include #include -std::tuple +[[nodiscard]] std::tuple parse_args(int, char **); #endif /* GENETIC_IMAGE_INCLUDE_GENIMG_PARSEARGS_HH_ */ diff --git a/src/common.cc b/src/common.cc index 1e08b53..1c32777 100644 --- a/src/common.cc +++ b/src/common.cc @@ -3,7 +3,8 @@ #include #include -std::pair init_image(std::string const &t_input_file) { +[[nodiscard]] std::pair +init_image(std::string const &t_input_file) noexcept { cv::Mat input_image = cv::imread(t_input_file, cv::IMREAD_COLOR); if (!input_image.data) { spdlog::critical("Could not open or find image!\n"); @@ -17,7 +18,8 @@ std::pair init_image(std::string const &t_input_file) { return std::make_pair(std::move(input_image), process_image); } -double euclidian_distance(cv::Mat const &t_img1, cv::Mat const &t_img2) { +[[nodiscard]] double euclidian_distance(cv::Mat const &t_img1, + cv::Mat const &t_img2) { double euclidian = 0.0; for (auto itr1 = t_img1.begin(), itr2 = t_img2.begin(); itr1 != t_img1.end() && itr2 != t_img2.end(); diff --git a/src/methods.cc b/src/methods.cc index 1c58569..5f0619b 100644 --- a/src/methods.cc +++ b/src/methods.cc @@ -30,7 +30,7 @@ void adjustSize(cv::Mat const &t_process_img, cv::Point &t_top_left, int size) { } } -cv::Scalar randomColor() { +[[nodiscard]] cv::Scalar randomColor() { static std::uniform_int_distribution<> dis(0, 255); return cv::Scalar(rand() % 255, rand() % 255, rand() % 255); } @@ -56,7 +56,7 @@ void threadedGetColor(cv::Mat &t_reference, ColorSet &t_colors, int t_h) { } } -ColorSet getColorSet(cv::Mat &t_reference) { +[[nodiscard]] ColorSet getColorSet(cv::Mat &t_reference) { ColorSet res{}; for (int h = 0; h < t_reference.size().height; h += thread_nbr) { std::vector thread_list{}; diff --git a/src/parseargs.cc b/src/parseargs.cc index 0e177ad..fe735e7 100644 --- a/src/parseargs.cc +++ b/src/parseargs.cc @@ -18,16 +18,16 @@ void processFilenames(po::variables_map const &vm, path const &t_input, } } -std::tuple parse_args(int t_ac, char **t_av) { +[[nodiscard]] std::tuple parse_args(int t_ac, + char **t_av) { po::options_description desc("Allowed options"); - desc.add_options() - ("help,h", "Display this help message") - ("input,i", po::value(), "Input image") - ("output,o", po::value(), - "Image output path (default: input path + \"_output\")") - ("method,m", po::value(), "Method number to be used (default: 1)") - ("iterations,n", po::value(), "Number of iterations (default: 5000)") - ("verbose,v", "Enables verbosity"); + desc.add_options()("help,h", "Display this help message")( + "input,i", po::value(), + "Input image")("output,o", po::value(), + "Image output path (default: input path + \"_output\")")( + "method,m", po::value(), "Method number to be used (default: 1)")( + "iterations,n", po::value(), + "Number of iterations (default: 5000)")("verbose,v", "Enables verbosity"); po::variables_map vm; po::store(po::parse_command_line(t_ac, t_av, desc), vm); po::notify(vm);