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  {
112  const char *src;
113  if ((src = from.getExpression()))
114  setExpression(src, from.getLanguage());
115  return *this;
116  }
117 
118  operator const char *() const { return getExpression(); }
119 
120  // This static method is called to add time dependency flags to the
121  // currently evaluating expression, flag it as using input slopes, etc.
122  // The flags use thread-local storage, so python code making HOM calls
123  // from different threads won't accidentally set each others' flags.
124  static void addExprFlags(int flags, int thread);
125 
126  // This method lets you get at the flags directly. The Python sop,
127  // for example, needs to know if the code set the time-dependent flag
128  // when it evaluated, so it needs to clear the flags beforehand, check
129  // them after the cook, and restore them.
130  static int &exprFlags();
131 
132  // THIS FUNCTION IS DEPRECATED!! Only left here for backwards
133  // compatibility. The proper way to mark expression evaluation as time
134  // dependent is to turn on the CH_EXPRTIME flag in the expression callback
135  // using the new func_flags parameter like so: func_flags |= CH_EXPRTIME.
136  //
137  // Old Note: HDK users may rely on setTimeDependency(), even if we don't
138  // call it directly. It's a shortcut for addExprFlags(CH_EXPRTIME);
139  static SYS_DEPRECATED(10.0) void setTimeDependency();
140 
141 private:
142  void changeExpr(const char *source, int thread);
143 
144  CH_ExprLanguage myLanguage;
145  EV_EXPRESSION *myExpr;
146  PY_CompiledCode *myPyExpr;
147  UT_String myReferencePath;
148 
149  friend std::ostream &operator<<(std::ostream &os, const CH_Expression &d)
150  {
151  d.save(os, 0, false);
152  return os;
153  }
154 };
155 
156 inline unsigned
158 {
159  return myExpr->getFlags();
160 }
161 
162 inline void
164 {
165  myExpr->setFlagsUnsafe(flag);
166 }
167 
168 inline bool
170 {
171  return !myExpr->isEvaluated();
172 }
173 
174 inline bool
176 {
177  return myExpr->hasFlag(CH_EXPRIVALUE);
178 }
179 
180 inline bool
182 {
183  return myExpr->hasFlag(CH_EXPROVALUE);
184 }
185 
186 inline bool
188 {
189  return myExpr->hasFlag(CH_EXPRVALUE);
190 }
191 
192 inline bool
194 {
195  return myExpr->hasFlag(CH_EXPRSLOPE);
196 }
197 
198 inline bool
200 {
201  return myExpr->hasFlag(CH_EXPRACCEL);
202 }
203 
204 inline bool
206 {
207  return myExpr->hasFlag(CH_EXPRKNOTS);
208 }
209 
210 #endif
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:30
#define CH_EXPRACCEL
Definition: CH_Support.h:33
bool modified() const
void setFlagsUnsafe(unsigned int flags)
Definition: EXPR.h:438
const GLuint GLenum const void * binary
Definition: glcorearb.h:1923
GLsizei const GLchar *const * path
Definition: glcorearb.h:3340
bool usesKnots() const
bool usesInValue() const
bool usesSlopes() const
#define CH_EXPRSLOPE
Definition: CH_Support.h:31
GLenum src
Definition: glcorearb.h:1792
GLuint64EXT * result
Definition: glew.h:14311
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:802
unsigned getExpressionFlag() const
long long int64
Definition: SYS_Types.h:116
GLbitfield flags
Definition: glcorearb.h:1595
#define CH_EXPRKNOTS
Definition: CH_Support.h:34
bool hasFlag(unsigned int bit) const
Definition: EXPR.h:408
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:782
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:38
bool usesValues() const
void setExpressionFlag(int flag)
#define CH_EXPRIVALUE
Definition: CH_Support.h:29
#define const
Definition: zconf.h:214
const char * getExpression() const
unsigned int getFlags() const
Definition: EXPR.h:399
bool usesAccels() const
bool isEvaluated() const
Definition: EXPR.h:410