HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 #include <UT/UT_IntArray.h>
16 #include <UT/UT_Map.h>
17 #include <UT/UT_ValArray.h>
18 #include <UT/UT_StringArray.h>
19 #include <UT/UT_Pair.h>
20 #include <UT/UT_Variadic.h>
21 #include <map>
22 
23 class PRM_Parm;
24 class PRM_ParmList;
25 class PRM_Conditional;
26 
28 {
29  PRM_CONDTYPE_DISABLE = 0, // disable_when
30  PRM_CONDTYPE_HIDE, // hide_when
31 
32  NB_PRM_CONDTYPES // Must be the last.
33 };
34 
36 {
37  PRM_CONDGROUPTYPE_NONE, // Not a group
38  PRM_CONDGROUPTYPE_SINGLE, // Single group of PRM_Conditional(s)
39  PRM_CONDGROUPTYPE_SWITCHER // Switcher group with a main group + tab groups
40 };
41 
43 {
52 };
53 
54 /// A container class for a set of AND clauses, representing a single brace
55 /// group (e.g "{ foo == 0 bar == 1}"). If one condition inside this class
56 /// fails, the whole conditional clause fails. A list of PRM_ConditionalInfos
57 /// can be stringed together for an OR behavior (e.g. "{foo==0} {bar==1}").
59 {
60 public:
62  { }
64  {
65  operator=(other);
66  }
67 
69  { }
70 
71  int64 getMemoryUsage(bool inclusive) const
72  {
73  int64 mem = 0;
74  mem += myControlParms.getMemoryUsage(false);
75  mem += myControlValues.getMemoryUsage(false);
76  mem += myTestOperators.getMemoryUsage(false);
77  return mem;
78  }
79 
80  // Create a new instance of the conditional information for parameters
81  // contained within multi-parms.
82  PRM_ConditionalInfo *instance(const UT_IntArray &index_list) const;
83 
85  {
86  myControlParms = src.myControlParms;
87  myControlValues = src.myControlValues;
88  myTestOperators = src.myTestOperators;
89 
90  return *this;
91  }
92 
93  void clear()
94  {
95  myControlParms.clear();
96  myControlValues.clear();
97  myTestOperators.clear();
98  }
99  void addCondition(const UT_StringHolder &parm,
100  const UT_StringHolder &value,
102  {
103  myControlParms.append(parm);
104  myControlValues.append(value);
105  myTestOperators.append(op);
106  }
107 
109  { return myControlParms; }
111  { return myControlValues; }
113  { return myTestOperators; }
114 
115 private:
116  UT_StringArray myControlParms;
117  UT_StringArray myControlValues;
118  UT_Array<PRM_ConditionalOperator> myTestOperators;
119 };
120 
121 /// Base class for PRM_Conditional*. It allows passing either PRM_Conditional,
122 /// PRM_ConditionalGroup, or PRM_ConditionalSwitcher to a PRM_Template without
123 /// casting.
125 {
126 public:
127  virtual ~PRM_ConditionalBase() {}
128 
129  // Allows us to avoid an expensive dynamic_cast. See:
130  // http://tinodidriksen.com/2010/04/14/cpp-dynamic-cast-performance/
131  virtual PRM_ConditionalGroupType groupType() const = 0;
132 
133  // Create a new conditional for use within multi-parms. Since the
134  // conditional information may be dependent on the index of the multiparm,
135  // we need to replace any #'s in the conditional infos with the actual
136  // index.
137  virtual PRM_ConditionalBase *instance(
138  const UT_IntArray &index_list)const = 0;
139 
140  virtual PRM_Conditional *getConditional(PRM_ConditionalType type) = 0;
141  virtual const PRM_Conditional*getConditional(
142  PRM_ConditionalType type) const = 0;
143 
144  virtual int64 getMemoryUsage(bool inclusive) const = 0;
145 };
146 
147 
148 /// This class allow setting a single conditional type for a PRM_Template.
149 /// If multiple conditional types are required, use PRM_ConditionalGroup.
151 {
152 public:
155  PRM_Conditional(const PRM_Conditional &other);
156  explicit PRM_Conditional(const char *conditional,
159  virtual ~PRM_Conditional();
160 
161  virtual int64 getMemoryUsage(bool inclusive) const;
162 
164  { return PRM_CONDGROUPTYPE_NONE; }
166  {
167  return myType;
168  }
169 
170  static const char *getName(PRM_ConditionalType type,
171  bool label);
172  const char *getName(bool label) const;
173 
174  PRM_ConditionalBase *instance(const UT_IntArray &index_list) const;
177 
178  int entries() const;
179  const PRM_ConditionalInfo *operator()(int index) const;
180  const PRM_Conditional &operator=(const PRM_Conditional &src);
181 
182  void clear();
183  PRM_ConditionalInfo *createInfo();
184 
185  void getStringFromList(UT_String &str) const;
186  void getStringFromList(UT_String &str,
187  const UT_StringArray &validparms) const;
188  bool setListFromString(const char *conditional,
189  UT_StringHolder &error);
190 
191  // Verifies the provided string is in proper conditional format.
192  // Proper format is:
193  // All non-whitespace is enclosed in { }.
194  // Inside brackets, each parm name has a value paired to it.
195  // All open quotes have matching close quotes.
196  static bool verifyConditionalString(const char *conditional,
197  UT_StringHolder &error);
198 
199  static bool getOperatorFromString(const char *testoperator,
201 
202  static bool isValidOperator(const char *testoperator);
203 
204  bool eval(const PRM_Parm &prm,
205  const PRM_ParmList &pl,
206  const UT_StringArray *skip_parms) const;
207 
208 private:
209  static bool parseOperatorString(const char *&testoperator,
211 
212  static bool parseConditionalString(const char *str,
213  PRM_Conditional *cond,
214  UT_StringHolder &error);
215 
216  void getStringFromList(UT_String &str,
217  const UT_StringArray *validparms) const;
218 
219  void evalFunction(const PRM_Parm &prm,
220  const PRM_ParmList &pl,
221  const UT_StringRef &function,
222  UT_String &result) const;
223 
224  UT_ValArray<PRM_ConditionalInfo *> myConditionalInfos;
225  PRM_ConditionalType myType;
226 };
227 
230 
231 /// This class allow setting multiple conditionals for a PRM_Template.
233 {
234 public:
235  ///
237 
239  { }
240 
242 
243  virtual ~PRM_ConditionalGroup();
244 
245  virtual int64 getMemoryUsage(bool inclusive) const;
246 
248  { return PRM_CONDGROUPTYPE_SINGLE; }
249 
250  virtual PRM_ConditionalBase *instance(const UT_IntArray &index_list) const;
251 
252  void addConditional(const PRM_Conditional &cond);
253  void addConditional(const char *conditional,
257 
258  void clear();
259 protected:
260  void instance(PRM_ConditionalGroup *group,
261  const UT_IntArray &index_list) const;
262 
263 private:
264  void addConditional(PRM_Conditional *cond);
265 
266  typedef UT_SortedMap<PRM_ConditionalType, PRM_Conditional *> prm_ConditionalMap;
267 
268  prm_ConditionalMap myConditionals;
269 };
270 
272 {
273 public:
275  : myIndex(index)
276  , myConditional(conditional)
277  , myType(type)
278  {
279  }
280  int myIndex; // Tab index
281  const char *myConditional;
283 };
285 
286 /// This class can be passed to the PRM_Template constructor when constructing
287 /// a template for a folder switcher. This allows the caller to set a different
288 /// conditional for each folder.
290 {
291 public:
293  { }
294 
296  virtual ~PRM_ConditionalSwitcher();
297 
298  virtual int64 getMemoryUsage(bool inclusive) const;
299 
301  { return PRM_CONDGROUPTYPE_SWITCHER; }
302  virtual PRM_ConditionalBase *instance(const UT_IntArray &index_list) const;
303 
304  PRM_Conditional *getTabConditional(
305  int index,
306  PRM_ConditionalType type) const;
307  PRM_ConditionalBase *getTabConditional(int index) const;
308 
309  void setTabConditional(
310  int index,
311  const PRM_ConditionalBase &cond );
312  void addTabConditional(
313  int index,
314  const PRM_Conditional &conditional);
315 
316  void clear();
317 private:
318  typedef UT_SortedMap<int, PRM_ConditionalBase *> prm_SwitcherMap;
319  prm_SwitcherMap myTabConditionals;
320 };
321 
322 
325 
326 
327 #endif
virtual ~PRM_ConditionalBase()
GLuint GLsizei const GLchar * label
Definition: glcorearb.h:2544
#define SYS_DEPRECATED(__V__)
UT_Pair< const char *, PRM_ConditionalType > PRM_ConditionalGroupItem
const PRM_ConditionalInfo & operator=(const PRM_ConditionalInfo &src)
virtual PRM_ConditionalBase * instance(const UT_IntArray &index_list) const
virtual PRM_Conditional * getConditional(PRM_ConditionalType type)=0
PRM_ConditionalType
virtual PRM_ConditionalGroupType groupType() const
virtual PRM_ConditionalGroupType groupType() const
const UT_StringArray & getControlValues() const
PRM_ConditionalType myType
virtual PRM_ConditionalBase * instance(const UT_IntArray &index_list) const =0
virtual int64 getMemoryUsage(bool inclusive) const =0
long long int64
Definition: SYS_Types.h:100
UT_VariadicT< PRM_ConditionalSwitcherItem > PRM_ConditionalSwitcherArgs
const UT_StringArray & getControlParms() const
PRM_ConditionalInfo(PRM_ConditionalInfo &other)
PRM_ConditionalSwitcherItem(int index, const char *conditional, PRM_ConditionalType type)
const UT_Array< PRM_ConditionalOperator > & getTestOperators() const
PRM_ConditionalGroupType
virtual PRM_ConditionalGroupType groupType() const
PRM_ConditionalOperator
UT_VariadicT< PRM_ConditionalGroupItem > PRM_ConditionalGroupArgs
void addCondition(const UT_StringHolder &parm, const UT_StringHolder &value, PRM_ConditionalOperator op)
GLsizei const GLfloat * value
Definition: glcorearb.h:823
png_infop png_sPLT_tpp entries
Definition: png.h:2481
int64 getMemoryUsage(bool inclusive) const
GLuint index
Definition: glcorearb.h:785
virtual int64 getMemoryUsage(bool inclusive) const
This class allow setting multiple conditionals for a PRM_Template.
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
PRM_ConditionalType getType() const
#define PRM_API
Definition: PRM_API.h:10
GLenum src
Definition: glcorearb.h:1792