VisionWorks Toolkit Reference

December 18, 2015 | 1.2 Release

 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
OptionHandler.hpp
Go to the documentation of this file.
1 /*
2 # Copyright (c) 2014, NVIDIA CORPORATION. All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions
6 # are met:
7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above copyright
10 # notice, this list of conditions and the following disclaimer in the
11 # documentation and/or other materials provided with the distribution.
12 # * Neither the name of NVIDIA CORPORATION nor the names of its
13 # contributors may be used to endorse or promote products derived
14 # from this software without specific prior written permission.
15 #
16 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
17 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23 # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
24 # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28 
29 #ifndef NVXIO_OPTIONHANDLER_HPP
30 #define NVXIO_OPTIONHANDLER_HPP
31 
32 #include "Range.hpp"
33 
39 namespace nvxio
40 {
51 {
52 private:
53  template <typename T>
54  struct PairList {
55  typedef std::initializer_list<std::pair<std::string, T>> type;
56  };
57 
58 public:
59  typedef std::unique_ptr<OptionHandler> ptr;
60 
61  virtual ~OptionHandler();
62 
67  virtual std::string getPlaceholder() const = 0;
68 
73  virtual std::string getConstraintString() const;
74 
79  virtual std::string getDefaultString() const = 0;
80 
86  virtual std::string processValue(const std::string &valueStr) const = 0;
87 
97  static ptr string(std::string *result);
98 
109  static ptr integer(int *result, const Range<int> &validRange = ranges::all<int>());
110 
118  static ptr unsignedInteger(unsigned *result, const Range<unsigned> &validRange = ranges::all<unsigned>());
119 
127  static ptr real(float *result, const Range<float> &validRange = ranges::all<float>());
128 
136  static ptr real(double *result, const Range<double> &validRange = ranges::all<double>());
137 
148  static ptr oneOf(std::string *result, std::initializer_list<std::string> allowedValues);
149 
163  /* The roundabout way of specifying the second parameter's type is due to an apparent bug in VC++ 2013.
164  If specified directly as std::initializer_list<std::pair<std::string, T>>, VC++ insists on deducing
165  T from the second argument, and fails. Indirecting it through a metafunction like this is enough to
166  persuade it to deduce T from the first argument instead. */
167  template <typename T>
168  static ptr oneOf(T *result, typename PairList<T>::type allowedValues);
169 };
170 
171 }
172 
173 #include "detail/OptionHandler.hpp"
174 
175 #endif // NVXIO_OPTIONHANDLER_HPP
The Range interface and utility functions.
virtual std::string processValue(const std::string &valueStr) const =0
Processes the value of the option.
static ptr unsignedInteger(unsigned *result, const Range< unsigned > &validRange=ranges::all< unsigned >())
Creates an option handler that accepts argument values that look like unsigned decimal integers...
static ptr string(std::string *result)
Creates an option handler that accepts any argument value and copies it verbatim to the provided vari...
std::unique_ptr< OptionHandler > ptr
virtual std::string getPlaceholder() const =0
Gets a short hint that describes the expected values of the option (i.e., a placeholder for the optio...
virtual std::string getDefaultString() const =0
Gets the default value of the option.
static ptr oneOf(std::string *result, std::initializer_list< std::string > allowedValues)
Creates an option handler that accepts argument values from a certain set and stores them in the prov...
static ptr real(float *result, const Range< float > &validRange=ranges::all< float >())
Creates an option handler that accepts argument values that look like real numbers, converts them to float, and then stores them in the provided variable.
OptionHandler interface.
virtual std::string getConstraintString() const
Gets information about valid values of the option.
virtual ~OptionHandler()
Range class.
Definition: Range.hpp:56
static ptr integer(int *result, const Range< int > &validRange=ranges::all< int >())
Creates an option handler that accepts argument values that look like decimal integers, converts them to int, and then stores them in the provided variable.