Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
| 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 | #include "ProgramOptions.h" |
| 25 | |
| 26 | #include "TypePrinter.h" |
| 27 | #include "TypeReader.h" |
| 28 | |
| 29 | #include "arm_compute/core/Types.h" |
| 30 | |
| 31 | #include <random> |
| 32 | #include <sstream> |
| 33 | |
| 34 | namespace arm_compute |
| 35 | { |
| 36 | namespace test |
| 37 | { |
| 38 | ProgramOptions::ProgramOptions() |
| 39 | { |
| 40 | boost::program_options::options_description generic("Generic options"); |
Georgios Pinitas | 7b7858d | 2017-06-21 16:44:24 +0100 | [diff] [blame] | 41 | generic.add_options()("help", "Print help message")("seed", boost::program_options::value<std::random_device::result_type>()->default_value(std::random_device()()), "Seed for the tensor library"); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 42 | |
| 43 | _visible.add(generic); |
| 44 | |
| 45 | _hidden.add_options()("path", boost::program_options::value<std::string>(), "Path from where to load the asset/s"); |
| 46 | |
| 47 | _positional.add("path", 1); |
| 48 | } |
| 49 | |
| 50 | void ProgramOptions::add_options(const boost::program_options::options_description &options) |
| 51 | { |
| 52 | _visible.add(options); |
| 53 | } |
| 54 | |
| 55 | bool ProgramOptions::wants_help() const |
| 56 | { |
| 57 | return (_vm.count("help") != 0); |
| 58 | } |
| 59 | |
| 60 | std::string ProgramOptions::get_help() const |
| 61 | { |
| 62 | std::stringstream help; |
| 63 | help << _visible; |
| 64 | |
| 65 | return help.str(); |
| 66 | } |
| 67 | |
| 68 | void ProgramOptions::parse_commandline(int argc, char **argv) |
| 69 | { |
| 70 | boost::program_options::options_description all; |
| 71 | all.add(_visible).add(_hidden); |
| 72 | |
| 73 | boost::program_options::store(boost::program_options::command_line_parser(argc, argv) |
| 74 | .options(all) |
| 75 | .positional(_positional) |
| 76 | .allow_unregistered() |
| 77 | .run(), |
| 78 | _vm); |
| 79 | |
| 80 | if(_vm.count("help") == 0 && _vm.count("path") == 0) |
| 81 | { |
| 82 | throw boost::program_options::required_option("PATH"); |
| 83 | } |
| 84 | |
| 85 | boost::program_options::notify(_vm); |
| 86 | } |
| 87 | } // namespace test |
| 88 | } // namespace arm_compute |