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 
36 {
37 public:
38  CH_Expression(const char *expr, CH_ExprLanguage language);
39  ~CH_Expression();
40 
41  int64 getMemoryUsage(bool inclusive) const;
42 
43  void save(std::ostream &os, int binary, bool compiled) const;
44  bool load(UT_IStream &is);
45 
46  const char *getExpression() const;
47  void setExpression(const char *expr,
48  CH_ExprLanguage language);
49  unsigned getExpressionFlag() const;
50 
51  // THIS FUNCTION IS DEPRECATED!! Only left here for backwards
52  // compatibility. The proper way to mark expression evaluation as time
53  // dependent is to turn on the CH_EXPRTIME flag in the expression callback
54  // using the new func_flags parameter like so: func_flags |= CH_EXPRTIME.
55  //
56  // Old Note: HDK users may rely on setExpressionFlag(), even if we don't
57  // call it directly. It does an non-thread-safe write to the underlying
58  // EV_EXPRESSION flags.
59  SYS_DEPRECATED(17.5) void setExpressionFlag(int flag);
60 
61  CH_ExprLanguage getLanguage() const;
62  void setLanguage(CH_ExprLanguage language);
63 
64  void unresolveLocalVars(int thread);
65 
66  unsigned isCompiled() const;
67  bool isPureCompiled() const;
68 
69  /// Evaluate as a fpreal
70  fpreal evaluate(int thread);
71  /// Evaluate as a string
72  void evaluateString(UT_String &result, int thread);
73 
74  void dirtyExprCache();
75 
76  bool modified() const;
77 
78  /// These methods checks the flags, you must evaluate the expression
79  /// first.
80  // @{
81  bool usesInValue() const;
82  bool usesOutValue() const;
83  bool usesValues() const;
84  bool usesSlopes() const;
85  bool usesAccels() const;
86  bool usesKnots() const;
87  // @}
88 
89  void buildOpDependencies(void *ref_id, int thread);
90  int changeOpRef(const char *new_fullpath,
91  const char *old_fullpath,
92  const char *old_cwd,
93  const char *chan_name,
94  const char *old_chan_name,
95  int thread);
96 
97  void *getSingleFunctionInstanceData(
98  EV_FUNCTION *func, int thread, UT_String &argument);
99 
100  int findString(const char *str, bool fullword,
101  bool usewildcards) const;
102  int changeString(const char *from, const char *to,
103  bool fullword, int thread);
104 
105  const char *getReferencePath() const;
106  void setReferencePath(const char *path);
107 
108  void forceStringType();
109 
111  : CH_Expression(from.getExpression(),
112  from.getLanguage())
113  {
114  }
115 
117  {
118  const char *src;
119  if ((src = from.getExpression()))
120  setExpression(src, from.getLanguage());
121  return *this;
122  }
123 
124  operator const char *() const { return getExpression(); }
125 
126  // This static method is called to add time dependency flags to the
127  // currently evaluating expression, flag it as using input slopes, etc.
128  // The flags use thread-local storage, so python code making HOM calls
129  // from different threads won't accidentally set each others' flags.
130  static void addExprFlags(int flags, int thread);
131 
132  // This method lets you get at the flags directly. The Python sop,
133  // for example, needs to know if the code set the time-dependent flag
134  // when it evaluated, so it needs to clear the flags beforehand, check
135  // them after the cook, and restore them.
136  static int &exprFlags();
137 
138  // THIS FUNCTION IS DEPRECATED!! Only left here for backwards
139  // compatibility. The proper way to mark expression evaluation as time
140  // dependent is to turn on the CH_EXPRTIME flag in the expression callback
141  // using the new func_flags parameter like so: func_flags |= CH_EXPRTIME.
142  //
143  // Old Note: HDK users may rely on setTimeDependency(), even if we don't
144  // call it directly. It's a shortcut for addExprFlags(CH_EXPRTIME);
145  static SYS_DEPRECATED(10.0) void setTimeDependency();
146 
147 private:
148  void changeExpr(const char *source, int thread);
149 
150  CH_ExprLanguage myLanguage;
151  EV_EXPRESSION *myExpr;
152  PY_CompiledCode *myPyExpr;
153  UT_String myReferencePath;
154 
155  friend std::ostream &operator<<(std::ostream &os, const CH_Expression &d)
156  {
157  d.save(os, 0, false);
158  return os;
159  }
160 };
161 
162 inline unsigned
164 {
165  return myExpr->getFlags();
166 }
167 
168 inline void
170 {
171  myExpr->setFlagsUnsafe(flag);
172 }
173 
174 inline bool
176 {
177  return !myExpr->isEvaluated();
178 }
179 
180 inline bool
182 {
183  return myExpr->hasFlag(CH_EXPRIVALUE);
184 }
185 
186 inline bool
188 {
189  return myExpr->hasFlag(CH_EXPROVALUE);
190 }
191 
192 inline bool
194 {
195  return myExpr->hasFlag(CH_EXPRVALUE);
196 }
197 
198 inline bool
200 {
201  return myExpr->hasFlag(CH_EXPRSLOPE);
202 }
203 
204 inline bool
206 {
207  return myExpr->hasFlag(CH_EXPRACCEL);
208 }
209 
210 inline bool
212 {
213  return myExpr->hasFlag(CH_EXPRKNOTS);
214 }
215 
216 #endif
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:442
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:613
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:412
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:277
#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
#define const
Definition: zconf.h:214
const char * getExpression() const
unsigned int getFlags() const
Definition: EXPR.h:403
bool usesAccels() const
bool isEvaluated() const
Definition: EXPR.h:414
GLenum src
Definition: glcorearb.h:1793