HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PRM_Range.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: PRM_Range.h (Parameter Library)
7  *
8  * COMMENTS:
9  * This parameter is used to set upper and lower limits on
10  * parameters. For simplicity only floating point numbers are
11  * used. These limits are not actually enforced by the parmeter
12  * library. But maybe they should. Discuss.
13  */
14 
15 
16 #ifndef __PRM_RANGE__
17 #define __PRM_RANGE__
18 
19 #include "PRM_API.h"
20 #include <SYS/SYS_Types.h>
21 
23 {
24  PRM_RANGE_FREE = 0x0, // ie range is ignored.
25  PRM_RANGE_UI = 0x1, // For some UI (sliders, etc) only
26  PRM_RANGE_PRM = 0x2, // Strictly enforced by PRM, too
28 };
29 
31 {
32 public:
33  PRM_Range(PRM_RangeFlag theminflag = PRM_RANGE_UI, fpreal themin = 0,
34  PRM_RangeFlag themaxflag = PRM_RANGE_UI, fpreal themax = 1)
35  {
36  myMinFlag = theminflag;
37  myMin = themin;
38  myMaxFlag = themaxflag;
39  myMax = themax;
40  }
41 
42  bool hasParmMin() const
43  {
44  return ((myMinFlag & PRM_RANGE_PRM) != 0);
45  }
46  bool hasParmMax() const
47  {
48  return ((myMaxFlag & PRM_RANGE_PRM) != 0);
49  }
50 
52  {
53  if (myMinFlag != PRM_RANGE_FREE)
54  return myMin;
55  return -SYS_FPREAL_MAX;
56  }
58  {
59  if (myMaxFlag != PRM_RANGE_FREE)
60  return myMax;
61  return SYS_FPREAL_MAX;
62  }
63 
64  bool hasUIMin() const
65  {
66  return ((myMinFlag & PRM_RANGE_UI) != 0);
67  }
68  bool hasUIMax() const
69  {
70  return ((myMaxFlag & PRM_RANGE_UI) != 0);
71  }
72 
73  fpreal getUIMin() const { return getParmMin(); }
74  fpreal getUIMax() const { return getParmMax(); }
75 
76  void constrain( fpreal &v ) const
77  {
78  if (hasParmMin() && v < myMin)
79  v = myMin;
80  else if (hasParmMax() && v > myMax)
81  v = myMax;
82  }
83 
84  void constrain( bool hasRangeMin, bool hasRangeMax, fpreal &v ) const
85  {
86  if (hasRangeMin && v < myMin)
87  v = myMin;
88  else if (hasRangeMax && v > myMax)
89  v = myMax;
90  }
91 
92 private:
93  PRM_RangeFlag myMinFlag;
94  PRM_RangeFlag myMaxFlag;
95  fpreal myMin;
96  fpreal myMax;
97 };
98 
99 #endif
void constrain(bool hasRangeMin, bool hasRangeMax, fpreal &v) const
Definition: PRM_Range.h:84
const GLdouble * v
Definition: glcorearb.h:837
PRM_Range(PRM_RangeFlag theminflag=PRM_RANGE_UI, fpreal themin=0, PRM_RangeFlag themaxflag=PRM_RANGE_UI, fpreal themax=1)
Definition: PRM_Range.h:33
bool hasUIMax() const
Definition: PRM_Range.h:68
fpreal getParmMin() const
Definition: PRM_Range.h:51
fpreal getParmMax() const
Definition: PRM_Range.h:57
bool hasParmMax() const
Definition: PRM_Range.h:46
PRM_RangeFlag
Definition: PRM_Range.h:22
void constrain(fpreal &v) const
Definition: PRM_Range.h:76
fpreal getUIMin() const
Definition: PRM_Range.h:73
fpreal getUIMax() const
Definition: PRM_Range.h:74
#define SYS_FPREAL_MAX
Definition: SYS_Types.h:286
fpreal64 fpreal
Definition: SYS_Types.h:277
#define PRM_API
Definition: PRM_API.h:10
bool hasParmMin() const
Definition: PRM_Range.h:42
bool hasUIMin() const
Definition: PRM_Range.h:64