HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_ProgramOptions.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_ProgramOptions.h ( UT Library, C++)
7  *
8  * COMMENTS: Wrapper for hboost::program_options.
9  */
10 
11 #ifndef __UT_ProgramOptions__
12 #define __UT_ProgramOptions__
13 
14 #include <hboost/program_options.hpp>
15 #include <SYS/SYS_Math.h>
16 
17 namespace UT_ProgramOptions = hboost::program_options;
18 
19 namespace hboost
20 {
21  namespace program_options
22  {
23  /// Class to implement a multi-token with a fixed number of arguments.
24  /// Instead of having a multitoken() parameter which can take any number of
25  /// arguments, this can be used to limit the number of arguments to a fixed
26  /// range.
27  /// Example usage: @code
28  /// // A fixed vector of 2 integers
29  /// ( "res,r", fixedSizeMultiToken<std::vector<int>>(2) )
30  /// // A fixed vector of 2 strings
31  /// ( "colorspace", fixedSizeMultiToken<std::vector<std::string>>(2) )
32  /// // A fixed vector of 3 floats
33  /// ( "position-xyz", fixedSizeMultiToken<std::vector<fpreal>>(3) )
34  /// // Allow 2 or 3 arguments
35  /// ( "uv", fixedSizeMultiToken<std::vector<fpreal>>(2, 3) )
36  /// @endcode
37  template <typename T, typename charT = char>
38  class fixedSizeTypedValue : public program_options::typed_value<T, charT>
39  {
40  using base = program_options::typed_value<T, charT>;
41  public:
43  : myMin(min)
44  , myMax(SYSmax(min, max))
45  , base(t)
46  {
47  base::multitoken();
48  }
49  uint min_tokens() const override final { return myMin; }
50  uint max_tokens() const override final { return myMax; }
51  private:
52  uint myMin, myMax;
53  };
54 
55  template <typename T>
56  fixedSizeTypedValue<T> *
58  {
59  return new fixedSizeTypedValue<T>(nullptr, min, max);
60  }
61 
62  template <typename T>
63  fixedSizeTypedValue<T> *
65  {
66  return new fixedSizeTypedValue<T>(store, min, max);
67  }
68  } // namespace program_options
69 } // namespace hboost
70 
71 #endif // __UT_ProgramOptions__
#define SYSmax(a, b)
Definition: SYS_Math.h:1570
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
fixedSizeTypedValue< T > * fixedSizeMultiToken(uint min, uint max=0)
GLdouble t
Definition: glad.h:2397
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
fixedSizeTypedValue(T *t, uint min, uint max=0)
unsigned int uint
Definition: SYS_Types.h:45