HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CH_Expression.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: Channel Library (C++)
7  *
8  * COMMENTS: This might want to be moved into the utility library
9  * if possible.
10  *
11  * CLASSES:
12  * CH_ExprVariable:
13  * Used for looking up variable names in expressions
14  * CH_Expression:
15  * A class for evaluating expressions.
16  *
17  */
18 
19 #ifndef __CH_Expression_h__
20 #define __CH_Expression_h__
21 
22 #include "CH_API.h"
23 #include "CH_ExprLanguage.h"
24 #include "CH_Support.h"
25 #include <EXPR/EXPR.h>
26 #include <UT/UT_String.h>
27 #include <SYS/SYS_Deprecated.h>
28 #include <SYS/SYS_Types.h>
29 #include <iosfwd>
30 
31 class UT_IStream;
32 class EV_EXPRESSION;
33 class PY_CompiledCode;
34 class UT_StringHolder;
35 
37 {
38 public:
39  CH_Expression(const char *expr, CH_ExprLanguage language);
40  ~CH_Expression();
41 
42  int64 getMemoryUsage(bool inclusive) const;
43 
44  void save(std::ostream &os, int binary, bool compiled) const;
45  bool load(UT_IStream &is);
46 
47  const char *getExpression() const;
48  void setExpression(const char *expr,
49  CH_ExprLanguage language);
50  unsigned getExpressionFlag() const;
51 
52  // THIS FUNCTION IS DEPRECATED!! Only left here for backwards
53  // compatibility. The proper way to mark expression evaluation as time
54  // dependent is to turn on the CH_EXPRTIME flag in the expression callback
55  // using the new func_flags parameter like so: func_flags |= CH_EXPRTIME.
56  //
57  // Old Note: HDK users may rely on setExpressionFlag(), even if we don't
58  // call it directly. It does an non-thread-safe write to the underlying
59  // EV_EXPRESSION flags.
60  SYS_DEPRECATED(17.5) void setExpressionFlag(int flag);
61 
62  CH_ExprLanguage getLanguage() const;
63  void setLanguage(CH_ExprLanguage language);
64 
65  void unresolveLocalVars(int thread);
66 
67  unsigned isCompiled() const;
68  bool isPureCompiled() const;
69 
70  /// Evaluate as a fpreal
71  fpreal evaluate(int thread);
72  /// Evaluate as a string
73  void evaluateString(UT_StringHolder &result, int thread);
74 
75  void dirtyExprCache();
76 
77  bool modified() const;
78 
79  /// These methods checks the flags, you must evaluate the expression
80  /// first.
81  // @{
82  bool usesInValue() const;
83  bool usesOutValue() const;
84  bool usesValues() const;
85  bool usesSlopes() const;
86  bool usesAccels() const;
87  bool usesKnots() const;
88  // @}
89 
90  void buildOpDependencies(void *ref_id, int thread);
91  int changeOpRef(const char *new_fullpath,
92  const char *old_fullpath,
93  const char *old_cwd,
94  const char *chan_name,
95  const char *old_chan_name,
96  int thread);
97 
98  void *getSingleFunctionInstanceData(
99  EV_FUNCTION *func, int thread, UT_String &argument);
100 
101  int findString(const char *str, bool fullword,
102  bool usewildcards) const;
103  int changeString(const char *from, const char *to,
104  bool fullword, int thread);
105 
106  const char *getReferencePath() const;
107  void setReferencePath(const char *path);
108 
109  void forceStringType();
110 
112  : CH_Expression(from.getExpression(),
113  from.getLanguage())
114  {
115  }
116 
118  {
119  const char *src;
120  if ((src = from.getExpression()))
121  setExpression(src, from.getLanguage());
122  return *this;
123  }
124 
125  operator const char *() const { return getExpression(); }
126 
127  // This static method is called to add time dependency flags to the
128  // currently evaluating expression, flag it as using input slopes, etc.
129  // The flags use thread-local storage, so python code making HOM calls
130  // from different threads won't accidentally set each others' flags.
131  static void addExprFlags(int flags, int thread);
132 
133  // This method lets you get at the flags directly. The Python sop,
134  // for example, needs to know if the code set the time-dependent flag
135  // when it evaluated, so it needs to clear the flags beforehand, check
136  // them after the cook, and restore them.
137  static int &exprFlags();
138 
139  // THIS FUNCTION IS DEPRECATED!! Only left here for backwards
140  // compatibility. The proper way to mark expression evaluation as time
141  // dependent is to turn on the CH_EXPRTIME flag in the expression callback
142  // using the new func_flags parameter like so: func_flags |= CH_EXPRTIME.
143  //
144  // Old Note: HDK users may rely on setTimeDependency(), even if we don't
145  // call it directly. It's a shortcut for addExprFlags(CH_EXPRTIME);
146  static SYS_DEPRECATED(10.0) void setTimeDependency();
147 
148 private:
149  void changeExpr(const char *source, int thread);
150 
151  CH_ExprLanguage myLanguage;
152  EV_EXPRESSION *myExpr;
153  PY_CompiledCode *myPyExpr;
154  UT_String myReferencePath;
155 
156  friend std::ostream &operator<<(std::ostream &os, const CH_Expression &d)
157  {
158  d.save(os, 0, false);
159  return os;
160  }
161 };
162 
163 inline unsigned
165 {
166  return myExpr->getFlags();
167 }
168 
169 inline void
171 {
172  myExpr->setFlagsUnsafe(flag);
173 }
174 
175 inline bool
177 {
178  return !myExpr->isEvaluated();
179 }
180 
181 inline bool
183 {
184  return myExpr->hasFlag(CH_EXPRIVALUE);
185 }
186 
187 inline bool
189 {
190  return myExpr->hasFlag(CH_EXPROVALUE);
191 }
192 
193 inline bool
195 {
196  return myExpr->hasFlag(CH_EXPRVALUE);
197 }
198 
199 inline bool
201 {
202  return myExpr->hasFlag(CH_EXPRSLOPE);
203 }
204 
205 inline bool
207 {
208  return myExpr->hasFlag(CH_EXPRACCEL);
209 }
210 
211 inline bool
213 {
214  return myExpr->hasFlag(CH_EXPRKNOTS);
215 }
216 
217 #endif
CE_API bool evaluate(const CE_OSDRefinement &topo, const CE_OSDEvaluator &eval, const cl::Buffer &coarse, const CE_OSDPatchCoords &patch_coords, const CE_FloatArray *refined_data, cl::Buffer &out, cl::Buffer *du, cl::Buffer *dv)
GLbitfield flags
Definition: glcorearb.h:1596
bool usesOutValue() const
#define SYS_DEPRECATED(__V__)
CH_Expression & operator=(const CH_Expression &from)
CH_ExprLanguage
void
Definition: png.h:1083
#define CH_EXPROVALUE
Definition: CH_Support.h:33
#define CH_EXPRACCEL
Definition: CH_Support.h:36
bool modified() const
void setFlagsUnsafe(unsigned int flags)
Definition: EXPR.h:443
const GLuint GLenum const void * binary
Definition: glcorearb.h:1924
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
bool usesKnots() const
bool usesInValue() const
**But if you need a result
Definition: thread.h:622
bool usesSlopes() const
#define CH_EXPRSLOPE
Definition: CH_Support.h:34
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:803
unsigned getExpressionFlag() const
long long int64
Definition: SYS_Types.h:116
#define CH_EXPRKNOTS
Definition: CH_Support.h:37
bool hasFlag(unsigned int bit) const
Definition: EXPR.h:413
CH_ExprLanguage getLanguage() const
**Note that the tasks the is the thread number *for the or if it s being executed by a non pool thread(this *can happen in cases where the whole pool is occupied and the calling *thread contributes to running the work load).**Thread pool.Have fun
GLenum func
Definition: glcorearb.h:783
void save(std::ostream &os, bool binary) const
Save string to stream. Saves as binary if binary is true.
fpreal64 fpreal
Definition: SYS_Types.h:283
#define CH_API
Definition: CH_API.h:10
#define CH_EXPRVALUE
Definition: CH_Support.h:41
CH_Expression(const CH_Expression &from)
bool usesValues() const
void setExpressionFlag(int flag)
#define CH_EXPRIVALUE
Definition: CH_Support.h:32
const char * getExpression() const
unsigned int getFlags() const
Definition: EXPR.h:404
bool usesAccels() const
bool isEvaluated() const
Definition: EXPR.h:415
GLenum src
Definition: glcorearb.h:1793