VisionWorks Toolkit Reference

April 8, 2016 | 1.4 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-2016, 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 <NVXIO/Export.hpp>
33 
34 #include "Range.hpp"
35 
41 namespace nvxio
42 {
52 class NVXIO_EXPORT OptionHandler
53 {
54 private:
55  template <typename T>
56  struct PairList
57  {
58  typedef std::initializer_list<std::pair<std::string, T>> type;
59  };
60 
61 public:
62  typedef std::unique_ptr<OptionHandler> ptr;
63 
64  virtual ~OptionHandler();
65 
70  virtual std::string getPlaceholder() const = 0;
71 
76  virtual std::string getConstraintString() const;
77 
82  virtual std::string getDefaultString() const = 0;
83 
89  virtual std::string processValue(const std::string &valueStr) const = 0;
90 
100  static ptr string(std::string *result);
101 
112  static ptr integer(int *result, const Range<int> &validRange = ranges::all<int>());
113 
121  static ptr unsignedInteger(unsigned *result, const Range<unsigned> &validRange = ranges::all<unsigned>());
122 
130  static ptr real(float *result, const Range<float> &validRange = ranges::all<float>());
131 
139  static ptr real(double *result, const Range<double> &validRange = ranges::all<double>());
140 
151  static ptr oneOf(std::string *result, std::initializer_list<std::string> allowedValues);
152 
161  template <typename T, typename It>
162  static ptr oneOf(T *result, It first, It last);
163 
177  /* The roundabout way of specifying the second parameter's type is due to an apparent bug in VC++ 2013.
178  If specified directly as std::initializer_list<std::pair<std::string, T>>, VC++ insists on deducing
179  T from the second argument, and fails. Indirecting it through a metafunction like this is enough to
180  persuade it to deduce T from the first argument instead. */
181  template <typename T>
182  static ptr oneOf(T *result, typename PairList<T>::type allowedValues);
183 };
184 
185 }
186 
187 #include "detail/OptionHandler.hpp"
188 
189 #endif // NVXIO_OPTIONHANDLER_HPP
The Range interface and utility functions.
std::unique_ptr< OptionHandler > ptr
OptionHandler interface.
Range class.
Definition: Range.hpp:56