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 <EXPR/EXPR.h>
25 #include <UT/UT_String.h>
26 #include <SYS/SYS_Deprecated.h>
27 #include <SYS/SYS_Types.h>
28 #include <iosfwd>
29 
30 class UT_IStream;
31 class EV_EXPRESSION;
32 class PY_CompiledCode;
33 
35 {
36 public:
37  CH_Expression(const char *expr, CH_ExprLanguage language);
38  ~CH_Expression();
39 
40  int64 getMemoryUsage(bool inclusive) const;
41 
42  void save(std::ostream &os, int binary, bool compiled) const;
43  bool load(UT_IStream &is);
44 
45  const char *getExpression() const;
46  void setExpression(const char *expr,
47  CH_ExprLanguage language);
48  unsigned getExpressionFlag() const;
49 
50  // THIS FUNCTION IS DEPRECATED!! Only left here for backwards
51  // compatibility. The proper way to mark expression evaluation as time
52  // dependent is to turn on the CH_EXPRTIME flag in the expression callback
53  // using the new func_flags parameter like so: func_flags |= CH_EXPRTIME.
54  //
55  // Old Note: HDK users may rely on setExpressionFlag(), even if we don't
56  // call it directly. It does an non-thread-safe write to the underlying
57  // EV_EXPRESSION flags.
58  SYS_DEPRECATED(17.5) void setExpressionFlag(int flag);
59 
60  CH_ExprLanguage getLanguage() const;
61  void setLanguage(CH_ExprLanguage language);
62 
63  void unresolveLocalVars(int thread);
64 
65  unsigned isCompiled() const;
66  bool isPureCompiled() const;
67 
68  /// Evaluate as a fpreal
69  fpreal evaluate(int thread);
70  /// Evaluate as a string
71  void evaluateString(UT_String &result, int thread);
72 
73  void dirtyExprCache();
74 
75  int modified() const;
76  int usesInValue();
77  int usesOutValue();
78  int usesValues();
79  int usesSlopes();
80  int usesAccels();
81  int usesKnots();
82 
83  void buildOpDependencies(void *ref_id, int thread);
84  int changeOpRef(const char *new_fullpath,
85  const char *old_fullpath,
86  const char *old_cwd,
87  const char *chan_name,
88  const char *old_chan_name,
89  int thread);
90 
91  void *getSingleFunctionInstanceData(
92  EV_FUNCTION *func, int thread, UT_String &argument);
93 
94  int findString(const char *str, bool fullword,
95  bool usewildcards) const;
96  int changeString(const char *from, const char *to,
97  bool fullword, int thread);
98 
99  const char *getReferencePath() const;
100  void setReferencePath(const char *path);
101 
102  void forceStringType();
103 
105  {
106  const char *src;
107  if ((src = from.getExpression()))
108  setExpression(src, from.getLanguage());
109  return *this;
110  }
111 
112  operator const char *() const { return getExpression(); }
113 
114  // This static method is called to add time dependency flags to the
115  // currently evaluating expression, flag it as using input slopes, etc.
116  // The flags use thread-local storage, so python code making HOM calls
117  // from different threads won't accidentally set each others' flags.
118  static void addExprFlags(int flags, int thread);
119 
120  // This method lets you get at the flags directly. The Python sop,
121  // for example, needs to know if the code set the time-dependent flag
122  // when it evaluated, so it needs to clear the flags beforehand, check
123  // them after the cook, and restore them.
124  static int &exprFlags();
125 
126  // THIS FUNCTION IS DEPRECATED!! Only left here for backwards
127  // compatibility. The proper way to mark expression evaluation as time
128  // dependent is to turn on the CH_EXPRTIME flag in the expression callback
129  // using the new func_flags parameter like so: func_flags |= CH_EXPRTIME.
130  //
131  // Old Note: HDK users may rely on setTimeDependency(), even if we don't
132  // call it directly. It's a shortcut for addExprFlags(CH_EXPRTIME);
133  static SYS_DEPRECATED(10.0) void setTimeDependency();
134 
135 private:
136  void changeExpr(const char *source, int thread);
137 
138  CH_ExprLanguage myLanguage;
139  EV_EXPRESSION *myExpr;
140  PY_CompiledCode *myPyExpr;
141  UT_String myReferencePath;
142 
143  friend std::ostream &operator<<(std::ostream &os, const CH_Expression &d)
144  {
145  d.save(os, 0, false);
146  return os;
147  }
148 };
149 
150 inline unsigned
152 {
153  return myExpr->getFlags();
154 }
155 
156 inline void
158 {
159  myExpr->setFlagsUnsafe(flag);
160 }
161 
162 inline int
164 {
165  return !myExpr->isEvaluated();
166 }
167 
168 #endif
int modified() const
GLenum src
Definition: glew.h:2410
#define SYS_DEPRECATED(__V__)
CH_Expression & operator=(const CH_Expression &from)
CH_ExprLanguage
void setFlagsUnsafe(unsigned int flags)
Definition: EXPR.h:438
GLenum GLsizei GLsizei GLsizei GLsizei GLbitfield flags
Definition: glew.h:2864
GLsizei GLsizei GLchar * source
Definition: glew.h:1832
long long int64
Definition: SYS_Types.h:111
const GLuint GLenum const void * binary
Definition: glew.h:3502
unsigned getExpressionFlag() const
void
Definition: png.h:1083
*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
GLsizei const GLchar *const * path
Definition: glew.h:6461
CH_ExprLanguage getLanguage() const
double fpreal
Definition: SYS_Types.h:276
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.
#define CH_API
Definition: CH_API.h:10
GLuint64EXT * result
Definition: glew.h:14007
void setExpressionFlag(int flag)
#define const
Definition: zconf.h:214
const char * getExpression() const
unsigned int getFlags() const
Definition: EXPR.h:399
bool isEvaluated() const
Definition: EXPR.h:410