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_Pair.h>
23 #include <UT/UT_Variadic.h>
24 #include <map>
25 
26 class PRM_Parm;
27 class PRM_ParmList;
28 class PRM_Conditional;
29 
31 {
32  PRM_CONDGROUPTYPE_NONE, // Not a group
33  PRM_CONDGROUPTYPE_SINGLE, // Single group of PRM_Conditional(s)
34  PRM_CONDGROUPTYPE_SWITCHER // Switcher group with a main group + tab groups
35 };
36 
38 {
47 };
48 
49 /// A container class for a set of AND clauses, representing a single brace
50 /// group (e.g "{ foo == 0 bar == 1}"). If one condition inside this class
51 /// fails, the whole conditional clause fails. A list of PRM_ConditionalInfos
52 /// can be stringed together for an OR behavior (e.g. "{foo==0} {bar==1}").
54 {
55 public:
57  { }
59  {
60  operator=(other);
61  }
62 
64  { }
65 
66  int64 getMemoryUsage(bool inclusive) const
67  {
68  int64 mem = 0;
69  mem += myControlParms.getMemoryUsage(false);
70  mem += myControlValues.getMemoryUsage(false);
71  mem += myTestOperators.getMemoryUsage(false);
72  return mem;
73  }
74 
75  // Create a new instance of the conditional information for parameters
76  // contained within multi-parms.
77  PRM_ConditionalInfo *instance(const UT_IntArray &index_list) const;
78 
80  {
81  myControlParms = src.myControlParms;
82  myControlValues = src.myControlValues;
83  myTestOperators = src.myTestOperators;
84 
85  return *this;
86  }
87 
88  void clear()
89  {
90  myControlParms.clear();
91  myControlValues.clear();
92  myTestOperators.clear();
93  }
94  void addCondition(const UT_StringHolder &parm,
95  const UT_StringHolder &value,
97  {
98  myControlParms.append(parm);
99  myControlValues.append(value);
100  myTestOperators.append(op);
101  }
102 
104  { return myControlParms; }
106  { return myControlValues; }
108  { return myTestOperators; }
109 
110 private:
111  UT_StringArray myControlParms;
112  UT_StringArray myControlValues;
113  UT_Array<PRM_ConditionalOperator> myTestOperators;
114 };
115 
116 /// Base class for PRM_Conditional*. It allows passing either PRM_Conditional,
117 /// PRM_ConditionalGroup, or PRM_ConditionalSwitcher to a PRM_Template without
118 /// casting.
120 {
121 public:
122  virtual ~PRM_ConditionalBase() {}
123 
124  // Allows us to avoid an expensive dynamic_cast. See:
125  // http://tinodidriksen.com/2010/04/14/cpp-dynamic-cast-performance/
126  virtual PRM_ConditionalGroupType groupType() const = 0;
127 
128  // Create a new conditional for use within multi-parms. Since the
129  // conditional information may be dependent on the index of the multiparm,
130  // we need to replace any #'s in the conditional infos with the actual
131  // index.
132  virtual PRM_ConditionalBase *instance(
133  const UT_IntArray &index_list)const = 0;
134 
135  virtual PRM_Conditional *getConditional(PRM_ConditionalType type) = 0;
136  virtual const PRM_Conditional*getConditional(
137  PRM_ConditionalType type) const = 0;
138 
139  virtual int64 getMemoryUsage(bool inclusive) const = 0;
140 };
141 
142 
143 /// This class allow setting a single conditional type for a PRM_Template.
144 /// If multiple conditional types are required, use PRM_ConditionalGroup.
146 {
147 public:
150  PRM_Conditional(const PRM_Conditional &other);
151  explicit PRM_Conditional(const char *conditional,
154  virtual ~PRM_Conditional();
155 
156  virtual int64 getMemoryUsage(bool inclusive) const;
157 
159  { return PRM_CONDGROUPTYPE_NONE; }
161  {
162  return myType;
163  }
164 
165  static const char *getName(PRM_ConditionalType type,
166  bool label);
167  const char *getName(bool label) const;
168 
169  PRM_ConditionalBase *instance(const UT_IntArray &index_list) const;
172 
173  int entries() const;
174  const PRM_ConditionalInfo *operator()(int index) const;
175  const PRM_Conditional &operator=(const PRM_Conditional &src);
176 
177  void clear();
178  PRM_ConditionalInfo *createInfo();
179 
180  void getStringFromList(
181  UT_StringHolder &str,
182  const UT_StringArray *validparms = nullptr
183  ) const;
184  void getStringFromList(UT_String &str) const;
185  void getStringFromList(UT_String &str,
186  const UT_StringArray &validparms) const;
187  bool setListFromString(const char *conditional,
188  UT_StringHolder &error);
189 
190  // Verifies the provided string is in proper conditional format.
191  // Proper format is:
192  // All non-whitespace is enclosed in { }.
193  // Inside brackets, each parm name has a value paired to it.
194  // All open quotes have matching close quotes.
195  static bool verifyConditionalString(const char *conditional,
196  UT_StringHolder &error);
197 
198  static bool getOperatorFromString(const char *testoperator,
200 
201  static bool isValidOperator(const char *testoperator);
202 
203  bool eval(const PRM_Parm &prm,
204  const PRM_ParmList &pl,
205  const UT_StringArray *skip_parms) const;
206 
207 private:
208  static bool parseOperatorString(const char *&testoperator,
210 
211  static bool parseConditionalString(const char *str,
212  PRM_Conditional *cond,
213  UT_StringHolder &error);
214 
215  void getStringFromList(UT_WorkBuffer &str,
216  const UT_StringArray *validparms) const;
217 
218  void evalFunction(const PRM_Parm &prm,
219  const PRM_ParmList &pl,
220  const UT_StringRef &function,
221  UT_String &result) const;
222 
223  UT_ValArray<PRM_ConditionalInfo *> myConditionalInfos;
224  PRM_ConditionalType myType;
225 };
226 
229 
230 /// This class allow setting multiple conditionals for a PRM_Template.
232 {
233 public:
234  ///
236 
238  { }
239 
241 
242  virtual ~PRM_ConditionalGroup();
243 
244  virtual int64 getMemoryUsage(bool inclusive) const;
245 
247  { return PRM_CONDGROUPTYPE_SINGLE; }
248 
249  virtual PRM_ConditionalBase *instance(const UT_IntArray &index_list) const;
250 
251  void addConditional(const PRM_Conditional &cond);
252  void addConditional(const char *conditional,
256 
257  void clear();
258 protected:
259  void instance(PRM_ConditionalGroup *group,
260  const UT_IntArray &index_list) const;
261 
262 private:
263  void addConditional(PRM_Conditional *cond);
264 
265  typedef UT_SortedMap<PRM_ConditionalType, PRM_Conditional *> prm_ConditionalMap;
266 
267  prm_ConditionalMap myConditionals;
268 };
269 
271 {
272 public:
274  : myIndex(index)
275  , myConditional(conditional)
276  , myType(type)
277  {
278  }
279  int myIndex; // Tab index
280  const char *myConditional;
282 };
284 
285 /// This class can be passed to the PRM_Template constructor when constructing
286 /// a template for a folder switcher. This allows the caller to set a different
287 /// conditional for each folder.
289 {
290 public:
292  { }
293 
295  virtual ~PRM_ConditionalSwitcher();
296 
297  virtual int64 getMemoryUsage(bool inclusive) const;
298 
300  { return PRM_CONDGROUPTYPE_SWITCHER; }
301  virtual PRM_ConditionalBase *instance(const UT_IntArray &index_list) const;
302 
303  PRM_Conditional *getTabConditional(
304  int index,
305  PRM_ConditionalType type) const;
306  PRM_ConditionalBase *getTabConditional(int index) const;
307 
308  void setTabConditional(
309  int index,
310  const PRM_ConditionalBase &cond );
311  void addTabConditional(
312  int index,
313  const PRM_Conditional &conditional);
314 
315  void clear();
316 private:
317  typedef UT_SortedMap<int, PRM_ConditionalBase *> prm_SwitcherMap;
318  prm_SwitcherMap myTabConditionals;
319 };
320 
321 
324 
325 
326 #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
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:107
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
PRM_ConditionalType
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