HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PDG_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  * COMMENTS:
7  */
8 
9 #ifndef __PDG_CONDITIONAL_H__
10 #define __PDG_CONDITIONAL_H__
11 
12 #include "PDG_API.h"
13 
14 #include "PDG_BasePattern.h"
15 
16 #include <UT/UT_Array.h>
17 #include <UT/UT_NonCopyable.h>
18 #include <UT/UT_StringHolder.h>
19 #include <UT/UT_UniquePtr.h>
20 
21 class PDG_NodeInterface;
22 class PDG_Port;
23 
24 /*
25  * Conditional expression for PDG node templates
26  */
28 {
29 public:
30  /// Constructs a new conditional expression from the input string
32 
33  /// Checks if the condition is true or false for the specified node
34  /// interface
35  bool match(const PDG_NodeInterface* interface,
36  bool expression_default=true) const;
37 
38  /// Resets the condition to the specified pattern
39  bool reset(const UT_StringHolder& pattern);
40 
41 private:
42  enum Operation
43  {
44  eEQ,
45  eNE,
46  eLT,
47  eLE,
48  eGT,
49  eGE,
50  };
51 
52  enum ConjunctionState
53  {
54  eBegin,
55  eName,
56  eOperator,
57  eValue
58  };
59 
60  struct Condition
61  {
62  UT_StringHolder myPortName;
63 
64  UT_StringHolder myString;
65  fpreal myFloat;
66  exint myInteger;
67 
68  Operation myOperation;
69  bool myHasFloat;
70  bool myHasInteger;
71  };
72 
75 
76 private:
77  template <typename T>
78  static bool compare(const T& left, const T& right, Operation op)
79  {
80  switch (op)
81  {
82  case eEQ:
83  return (left == right);
84  case eLT:
85  return (left < right);
86  case eLE:
87  return (left <= right);
88  case eGT:
89  return (left > right);
90  case eGE:
91  return (left >= right);
92  case eNE:
93  return (left != right);
94  default:
95  return false;
96  }
97  }
98 
99  bool parse(const UT_StringHolder& pattern);
100  bool matchPort(const Condition& condition,
101  const PDG_Port* port) const;
102 
103  bool parseConjunction(Conjunction& conjunction,
104  const UT_StringView& view,
105  int& index);
106  bool addCondition(Conjunction& conjunction,
107  const UT_WorkBuffer& name,
108  const UT_WorkBuffer& op,
109  const UT_WorkBuffer& value);
110 private:
111  Disjunction myConditions;
112 };
113 
114 #endif
GLint left
Definition: glcorearb.h:2005
#define PDG_API
Definition: PDG_API.h:23
GLdouble right
Definition: glad.h:2817
void reset(const UT_StringHolder &pattern)
Resets the pattern.
int64 exint
Definition: SYS_Types.h:125
CompareResults OIIO_API compare(const ImageBuf &A, const ImageBuf &B, float failthresh, float warnthresh, ROI roi={}, int nthreads=0)
A utility class to do read-only operations on a subset of an existing string.
Definition: UT_StringView.h:39
GLuint const GLchar * name
Definition: glcorearb.h:786
GLushort pattern
Definition: glad.h:2583
Operator path display.
fpreal64 fpreal
Definition: SYS_Types.h:277
GLuint index
Definition: glcorearb.h:786
Definition: core.h:982
Definition: core.h:1131