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_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  bool isPureCompiled() const;
57 
58  /// Evaluate as a fpreal
59  fpreal evaluate(int thread);
60  /// Evaluate as a string
61  void evaluateString(UT_String &result, int thread);
62 
63  void dirtyExprCache();
64 
65  int modified() const;
66  int usesInValue();
67  int usesOutValue();
68  int usesValues();
69  int usesSlopes();
70  int usesAccels();
71  int usesKnots();
72 
73  void buildOpDependencies(void *ref_id, int thread);
74  int changeOpRef(const char *new_fullpath,
75  const char *old_fullpath,
76  const char *old_cwd,
77  const char *chan_name,
78  const char *old_chan_name,
79  int thread);
80 
81  void *getSingleFunctionInstanceData(
82  EV_FUNCTION *func, int thread, UT_String &argument);
83 
84  int findString(const char *str, bool fullword,
85  bool usewildcards) const;
86  int changeString(const char *from, const char *to,
87  bool fullword, int thread);
88 
89  const char *getReferencePath() const;
90  void setReferencePath(const char *path);
91 
92  void forceStringType();
93 
95  {
96  const char *src;
97  if ((src = from.getExpression()))
98  setExpression(src, from.getLanguage());
99  return *this;
100  }
101 
102  operator const char *() const { return getExpression(); }
103 
104  // This static method is called to add time dependency flags to the
105  // currently evaluating expression, flag it as using input slopes, etc.
106  // The flags use thread-local storage, so python code making HOM calls
107  // from different threads won't accidentally set each others' flags.
108  static void addExprFlags(int flags, int thread);
109 
110  // This method lets you get at the flags directly. The Python sop,
111  // for example, needs to know if the code set the time-dependent flag
112  // when it evaluated, so it needs to clear the flags beforehand, check
113  // them after the cook, and restore them.
114  static int &exprFlags();
115 
116  // THIS FUNCTION IS DEPRECATED!! Only left here for backwards
117  // compatibility. The proper way to mark expression evaluation as time
118  // dependent is to turn on the CH_EXPRTIME flag in the expression callback
119  // using the new func_flags parameter like so: func_flags |= CH_EXPRTIME.
120  //
121  // Old Note: HDK users may rely on setTimeDependency(), even if we don't
122  // call it directly. It's a shortcut for addExprFlags(CH_EXPRTIME);
123  static SYS_DEPRECATED(10.0) void setTimeDependency();
124 
125 private:
126  void changeExpr(const char *source, int thread);
127 
128  CH_ExprLanguage myLanguage;
129  EV_EXPRESSION *myExpr;
130  PY_CompiledCode *myPyExpr;
131  UT_String myReferencePath;
132 
133  friend std::ostream &operator<<(std::ostream &os, const CH_Expression &d)
134  {
135  d.save(os, 0, false);
136  return os;
137  }
138 };
139 
140 inline unsigned
142 {
143  return myExpr->getFlags();
144 }
145 
146 inline void
148 {
149  myExpr->setFlags(flag);
150 }
151 
152 inline int
154 {
155  return !myExpr->isEvaluated();
156 }
157 
158 #endif
int modified() const
#define SYS_DEPRECATED(__V__)
CH_Expression & operator=(const CH_Expression &from)
Definition: CH_Expression.h:94
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:107
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:270
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