blob: 0b28355aa61caa3f4279acbe7c6735d4a589e33b [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
2 * Copyright (c) 2017 ARM Limited.
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#ifndef __ARM_COMPUTE_TEST_PROGRAM_OPTIONS_H__
25#define __ARM_COMPUTE_TEST_PROGRAM_OPTIONS_H__
26
27#pragma GCC diagnostic push
28#pragma GCC diagnostic ignored "-Weffc++"
29#pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
30#pragma GCC diagnostic ignored "-Wctor-dtor-privacy"
31#include "boost/program_options.hpp"
32#pragma GCC diagnostic pop
33
34#include <random>
35#include <sstream>
36
37namespace arm_compute
38{
39namespace test
40{
41/** Defines available commandline arguments and allows to parse them. */
42class ProgramOptions
43{
44public:
45 /** Defines available options. */
46 ProgramOptions();
47
48 /** Signals if the --help flag has been passed on the commandline. */
49 bool wants_help() const;
50
51 /** Returns a string describing all available options. */
52 std::string get_help() const;
53
54 /** Parses the given arguments and makes them available via @ref get.
55 *
56 * @param[in] argc Number of command line arguments.
57 * @param[in] argv Pointer to the command line arguments.
58 */
59 void parse_commandline(int argc, char **argv);
60
61 /** Sets @p value if it has been specified on the command line.
62 *
63 * @note The type T has to match the type that has been specified for the
64 * command line option.
65 *
66 * @param[in] name Name of the option to query.
67 * @param[out] value Variable to which the value will be assigned.
68 *
69 * @return True if the value is assigned, false otherwise.
70 */
71 template <typename T>
72 bool get(const std::string &name, T &value) const;
73
74protected:
75 /** Allows subclasses to add more specific options
76 *
77 * @param[in] options Boost object containing options and their descriptions
78 */
79 void add_options(const boost::program_options::options_description &options);
80
81private:
82 boost::program_options::options_description _hidden{};
83 boost::program_options::options_description _visible{ "Configuration options" };
84 boost::program_options::positional_options_description _positional{};
85 boost::program_options::variables_map _vm{};
86};
87
88template <typename T>
89bool ProgramOptions::get(const std::string &name, T &value) const
90{
91 if(_vm.count(name) != 0)
92 {
93 value = _vm[name].as<T>();
94 return true;
95 }
96
97 return false;
98}
99} // namespace test
100} // namespace arm_compute
Anthony Barbierac69aa12017-07-03 17:39:37 +0100101#endif /* __ARM_COMPUTE_TEST_PROGRAM_OPTIONS_H__ */