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