HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PRM_Conditional.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_Conditional.h ( PRM Library, C++)
7  *
8  * COMMENTS: Conditional information based on a conditional string.
9  */
10 
11 #ifndef __PRM_Conditional__
12 #define __PRM_Conditional__
13 
14 #include "PRM_API.h"
15 
16 #include "PRM_ConditionalType.h"
17 
18 #include <UT/UT_IntArray.h>
19 #include <UT/UT_Map.h>
20 #include <UT/UT_ValArray.h>
21 #include <UT/UT_StringArray.h>
22 #include <UT/UT_Variadic.h>
23 #include <utility>
24 
25 class PRM_Parm;
26 class PRM_ParmList;
27 class PRM_Conditional;
28 
30 {
31  PRM_CONDGROUPTYPE_NONE, // Not a group
32  PRM_CONDGROUPTYPE_SINGLE, // Single group of PRM_Conditional(s)
33  PRM_CONDGROUPTYPE_SWITCHER // Switcher group with a main group + tab groups
34 };
35 
37 {
46 };
47 
48 /// A container class for a set of AND clauses, representing a single brace
49 /// group (e.g "{ foo == 0 bar == 1}"). If one condition inside this class
50 /// fails, the whole conditional clause fails. A list of PRM_ConditionalInfos
51 /// can be stringed together for an OR behavior (e.g. "{foo==0} {bar==1}").
53 {
54 public:
56  { }
58  {
59  operator=(other);
60  }
61 
63  { }
64 
65  int64 getMemoryUsage(bool inclusive) const
66  {
67  int64 mem = 0;
68  mem += myControlParms.getMemoryUsage(false);
69  mem += myControlValues.getMemoryUsage(false);
70  mem += myTestOperators.getMemoryUsage(false);
71  return mem;
72  }
73 
74  // Create a new instance of the conditional information for parameters
75  // contained within multi-parms.
76  PRM_ConditionalInfo *instance(const UT_IntArray &index_list) const;
77 
79  {
80  myControlParms = src.myControlParms;
81  myControlValues = src.myControlValues;
82  myTestOperators = src.myTestOperators;
83 
84  return *this;
85  }
86 
87  void clear()
88  {
89  myControlParms.clear();
90  myControlValues.clear();
91  myTestOperators.clear();
92  }
93  void addCondition(const UT_StringHolder &parm,
94  const UT_StringHolder &value,
96  {
97  myControlParms.append(parm);
98  myControlValues.append(value);
99  myTestOperators.append(op);
100  }
101 
103  { return myControlParms; }
105  { return myControlValues; }
107  { return myTestOperators; }
108 
109 private:
110  UT_StringArray myControlParms;
111  UT_StringArray myControlValues;
112  UT_Array<PRM_ConditionalOperator> myTestOperators;
113 };
114 
115 /// Base class for PRM_Conditional*. It allows passing either PRM_Conditional,
116 /// PRM_ConditionalGroup, or PRM_ConditionalSwitcher to a PRM_Template without
117 /// casting.
119 {
120 public:
121  virtual ~PRM_ConditionalBase() {}
122 
123  // Allows us to avoid an expensive dynamic_cast. See:
124  // http://tinodidriksen.com/2010/04/14/cpp-dynamic-cast-performance/
125  virtual PRM_ConditionalGroupType groupType() const = 0;
126 
127  // Create a new conditional for use within multi-parms. Since the
128  // conditional information may be dependent on the index of the multiparm,
129  // we need to replace any #'s in the conditional infos with the actual
130  // index.
131  virtual PRM_ConditionalBase *instance(
132  const UT_IntArray &index_list)const = 0;
133 
134  virtual PRM_Conditional *getConditional(PRM_ConditionalType type) = 0;
135  virtual const PRM_Conditional*getConditional(
136  PRM_ConditionalType type) const = 0;
137 
138  virtual int64 getMemoryUsage(bool inclusive) const = 0;
139 };
140 
141 
142 /// This class allow setting a single conditional type for a PRM_Template.
143 /// If multiple conditional types are required, use PRM_ConditionalGroup.
145 {
146 public:
149  PRM_Conditional(const PRM_Conditional &other);
150  explicit PRM_Conditional(const char *conditional,
153  ~PRM_Conditional() override;
154 
155  int64 getMemoryUsage(bool inclusive) const override;
156 
158  { return PRM_CONDGROUPTYPE_NONE; }
160  {
161  return myType;
162  }
163 
164  static const char *getName(PRM_ConditionalType type,
165  bool label);
166  const char *getName(bool label) const;
167 
169  const UT_IntArray &indices) const override;
171  PRM_ConditionalType type) override;
173  PRM_ConditionalType type) const override;
174 
175  int entries() const;
176  const PRM_ConditionalInfo *operator()(int index) const;
178 
179  void clear();
180  PRM_ConditionalInfo *createInfo();
181 
182  void getStringFromList(
183  UT_StringHolder &str,
184  const UT_StringArray *validparms = nullptr
185  ) const;
186  void getStringFromList(UT_String &str) const;
187  void getStringFromList(UT_String &str,
188  const UT_StringArray &validparms) const;
189  bool setListFromString(const char *conditional,
191 
192  // Verifies the provided string is in proper conditional format.
193  // Proper format is:
194  // All non-whitespace is enclosed in { }.
195  // Inside brackets, each parm name has a value paired to it.
196  // All open quotes have matching close quotes.
197  static bool verifyConditionalString(const char *conditional,
199 
200  static bool getOperatorFromString(const char *testoperator,
202 
203  static bool isValidOperator(const char *testoperator);
204 
205  bool eval(const PRM_Parm &prm,
206  const PRM_ParmList &pl,
207  const UT_StringArray *skip_parms) const;
208 
209 private:
210  static bool parseOperatorString(const char *&testoperator,
212 
213  static bool parseConditionalString(const char *str,
214  PRM_Conditional *cond,
216 
217  void getStringFromList(UT_WorkBuffer &str,
218  const UT_StringArray *validparms) const;
219 
220  void evalFunction(const PRM_Parm &prm,
221  const PRM_ParmList &pl,
222  const UT_StringRef &function,
223  UT_String &result) const;
224 
225  UT_ValArray<PRM_ConditionalInfo *> myConditionalInfos;
226  PRM_ConditionalType myType;
227 };
228 
229 typedef std::pair<const char *, PRM_ConditionalType> PRM_ConditionalGroupItem;
231 
232 /// This class allow setting multiple conditionals for a PRM_Template.
234 {
235 public:
236  ///
238 
240  { }
241 
243 
244  ~PRM_ConditionalGroup() override;
245 
246  int64 getMemoryUsage(bool inclusive) const override;
247 
249  { return PRM_CONDGROUPTYPE_SINGLE; }
250 
252  const UT_IntArray &indices) const override;
253 
254  void addConditional(const PRM_Conditional &cond);
255  void addConditional(const char *conditional,
258  PRM_ConditionalType type) override;
260  PRM_ConditionalType type) const override;
261 
262  void clear();
263 protected:
264  void instance(PRM_ConditionalGroup *group,
265  const UT_IntArray &index_list) const;
266 
267 private:
268  void addConditional(PRM_Conditional *cond);
269 
270  typedef UT_SortedMap<PRM_ConditionalType, PRM_Conditional *> prm_ConditionalMap;
271 
272  prm_ConditionalMap myConditionals;
273 };
274 
276 {
277 public:
279  : myIndex(index)
280  , myConditional(conditional)
281  , myType(type)
282  {
283  }
284  int myIndex; // Tab index
285  const char *myConditional;
287 };
289 
290 /// This class can be passed to the PRM_Template constructor when constructing
291 /// a template for a folder switcher. This allows the caller to set a different
292 /// conditional for each folder.
294 {
295 public:
297  { }
298 
300  ~PRM_ConditionalSwitcher() override;
301 
302  int64 getMemoryUsage(bool inclusive) const override;
303 
305  { return PRM_CONDGROUPTYPE_SWITCHER; }
307  const UT_IntArray &indices) const override;
308 
309  PRM_Conditional *getTabConditional(
310  int index,
311  PRM_ConditionalType type) const;
312  PRM_ConditionalBase *getTabConditional(int index) const;
313 
314  void setTabConditional(
315  int index,
316  const PRM_ConditionalBase &cond );
317  void addTabConditional(
318  int index,
319  const PRM_Conditional &conditional);
320 
321  void clear();
322 private:
323  typedef UT_SortedMap<int, PRM_ConditionalBase *> prm_SwitcherMap;
324  prm_SwitcherMap myTabConditionals;
325 };
326 
327 
330 
331 
332 #endif
GLsizei GLenum const void * indices
Definition: glcorearb.h:406
virtual ~PRM_ConditionalBase()
GLuint GLsizei const GLchar * label
Definition: glcorearb.h:2545
#define SYS_DEPRECATED(__V__)
const PRM_ConditionalInfo & operator=(const PRM_ConditionalInfo &src)
virtual PRM_Conditional * getConditional(PRM_ConditionalType type)=0
PRM_ConditionalGroupType groupType() const override
**But if you need a result
Definition: thread.h:613
const UT_StringArray & getControlValues() const
PRM_ConditionalType myType
virtual PRM_ConditionalBase * instance(const UT_IntArray &index_list) const =0
< returns > If no error
Definition: snippets.dox:2
virtual int64 getMemoryUsage(bool inclusive) const =0
UT_VariadicT< PRM_ConditionalSwitcherItem > PRM_ConditionalSwitcherArgs
const UT_StringArray & getControlParms() const
std::pair< const char *, PRM_ConditionalType > PRM_ConditionalGroupItem
PRM_ConditionalInfo(PRM_ConditionalInfo &other)
PRM_ConditionalSwitcherItem(int index, const char *conditional, PRM_ConditionalType type)
const UT_Array< PRM_ConditionalOperator > & getTestOperators() const
PXL_API const char * getName(const ColorSpace *space)
Return the name of the color space.
PRM_ConditionalGroupType
PRM_ConditionalGroupType groupType() const override
long long int64
Definition: SYS_Types.h:116
PRM_ConditionalOperator
HUSD_API bool eval(VtValue &val, T &ret_val)
UT_VariadicT< PRM_ConditionalGroupItem > PRM_ConditionalGroupArgs
void addCondition(const UT_StringHolder &parm, const UT_StringHolder &value, PRM_ConditionalOperator op)
PRM_ConditionalGroupType groupType() const override
int64 getMemoryUsage(bool inclusive) const
PRM_ConditionalType
LeafData & operator=(const LeafData &)=delete
GLuint index
Definition: glcorearb.h:786
int64 getMemoryUsage(bool inclusive) const override
This class allow setting multiple conditionals for a PRM_Template.
**If you just want to fire and args
Definition: thread.h:609
Definition: core.h:1131
PRM_ConditionalType getType() const
type
Definition: core.h:1059
#define PRM_API
Definition: PRM_API.h:10
PRM_ConditionalBase * instance(const UT_IntArray &indices) const override
GLenum src
Definition: glcorearb.h:1793