| 1 |
/* |
| 2 |
* Copyright (c) 2017-2018 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_UTILS_OPTIONBASE |
| 25 |
#define ARM_COMPUTE_UTILS_OPTIONBASE |
| 26 |
|
| 27 |
#include <string> |
| 28 |
|
| 29 |
namespace arm_compute |
| 30 |
{ |
| 31 |
namespace utils |
| 32 |
{ |
| 33 |
/** Abstract base class for a command line option. */ |
| 34 |
class Option |
| 35 |
{ |
| 36 |
public: |
| 37 |
/** Constructor. |
| 38 |
* |
| 39 |
* @param[in] name Name of the option. |
| 40 |
*/ |
| 41 |
Option(std::string name); |
| 42 |
|
| 43 |
/** Constructor. |
| 44 |
* |
| 45 |
* @param[in] name Name of the option. |
| 46 |
* @param[in] is_required Is the option required? |
| 47 |
* @param[in] is_set Has a value been assigned to the option? |
| 48 |
*/ |
| 49 |
Option(std::string name, bool is_required, bool is_set); |
| 50 |
|
| 51 |
/** Default destructor. */ |
| 52 |
virtual ~Option() = default; |
| 53 |
|
| 54 |
/** Parses the given string. |
| 55 |
* |
| 56 |
* @param[in] value String representation as passed on the command line. |
| 57 |
* |
| 58 |
* @return True if the value could be parsed by the specific subclass. |
| 59 |
*/ |
| 60 |
virtual bool parse(std::string value) = 0; |
| 61 |
|
| 62 |
/** Help message for the option. |
| 63 |
* |
| 64 |
* @return String representing the help message for the specific subclass. |
| 65 |
*/ |
| 66 |
virtual std::string help() const = 0; |
| 67 |
|
| 68 |
/** Name of the option. |
| 69 |
* |
| 70 |
* @return Name of the option. |
| 71 |
*/ |
| 72 |
std::string name() const; |
| 73 |
|
| 74 |
/** Set whether the option is required. |
| 75 |
* |
| 76 |
* @param[in] is_required Pass true if the option is required. |
| 77 |
*/ |
| 78 |
void set_required(bool is_required); |
| 79 |
|
| 80 |
/** Set the help message for the option. |
| 81 |
* |
| 82 |
* @param[in] help Option specific help message. |
| 83 |
*/ |
| 84 |
void set_help(std::string help); |
| 85 |
|
| 86 |
/** Is the option required? |
| 87 |
* |
| 88 |
* @return True if the option is required. |
| 89 |
*/ |
| 90 |
bool is_required() const; |
| 91 |
|
| 92 |
/** Has a value been assigned to the option? |
| 93 |
* |
| 94 |
* @return True if a value has been set. |
| 95 |
*/ |
| 96 |
bool is_set() const; |
| 97 |
|
| 98 |
protected: |
| 99 |
std::string _name; |
| 100 |
bool _is_required{false}; |
| 101 |
bool _is_set{false}; |
| 102 |
std::string _help{}; |
| 103 |
}; |
| 104 |
|
| 105 |
inline Option::Option(std::string name) : _name{std::move(name)} |
| 106 |
{ |
| 107 |
} |
| 108 |
|
| 109 |
inline Option::Option(std::string name, bool is_required, bool is_set) |
| 110 |
: _name{std::move(name)}, _is_required{is_required}, _is_set{is_set} |
| 111 |
{ |
| 112 |
} |
| 113 |
|
| 114 |
inline std::string Option::name() const |
| 115 |
{ |
| 116 |
return _name; |
| 117 |
} |
| 118 |
|
| 119 |
inline void Option::set_required(bool is_required) |
| 120 |
{ |
| 121 |
_is_required = is_required; |
| 122 |
} |
| 123 |
|
| 124 |
inline void Option::set_help(std::string help) |
| 125 |
{ |
| 126 |
_help = std::move(help); |
| 127 |
} |
| 128 |
|
| 129 |
inline bool Option::is_required() const |
| 130 |
{ |
| 131 |
return _is_required; |
| 132 |
} |
| 133 |
|
| 134 |
inline bool Option::is_set() const |
| 135 |
{ |
| 136 |
return _is_set; |
| 137 |
} |
| 138 |
} // namespace utils |
| 139 |
} // namespace arm_compute |
| 140 |
#endif /* ARM_COMPUTE_UTILS_OPTIONBASE */ |