HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OP_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: OP_Expression.h ( OP Library, C++)
7  *
8  * COMMENTS: This contains a base class for expressions which reference OPs.
9  * This class should be allocated by a function callback (i.e. see
10  * ev_SetFunctionInstanceAllocator in EXPR/EXPR.h) and can be used
11  * to quickly get the correct OP_Node given a path.
12  */
13 
14 #ifndef __OP_Expression__
15 #define __OP_Expression__
16 
17 #include "OP_API.h"
18 #include "OP_Error.h"
19 #include <UT/UT_String.h>
20 #include <SYS/SYS_Types.h>
21 #include <stddef.h>
22 
23 class OP_Node;
24 class PRM_Parm;
25 class PRM_ParmList;
26 class CH_Channel;
27 
29 public:
30  OP_ExprFindOp();
32 
33  // Count all memory owned by the OP_ExprFindOp. Remember to
34  // include sizeof(*this) if inclusive, else don't.
35  int64 getMemoryUsage(bool inclusive) const
36  {
37  int64 mem = inclusive ? sizeof(*this) : 0;
38  mem += myPath.getMemoryUsage(false);
39  return mem;
40  }
41 
42  // Find the node specified by "path" relative to the current location
43  // specified by "cwd". Returns null if there's no such op. If add_warnings
44  // is true, then it will also call UTaddWarning() with something
45  // appropriate when the return value is NULL.
46  OP_Node *getNode(const char *path, OP_Node *cwd,
47  bool add_warnings);
48 
49  // The following functions can be used by the expression lib allocator
50  // However, they may not be used if this class is sub-classed
51  static void *allocFindOp();
52  static void freeFindOp(void *data);
53 
54 private:
55  int myOpId;
56  int myCwdOpId;
57  UT_String myPath;
58 };
59 
60 
62 {
63 public:
64  OP_ExprFindCh();
66 
67  // Count all memory owned by the OP_ExprFindCh. Remember to
68  // include sizeof(*this) if inclusive, else don't.
69  int64 getMemoryUsage(bool inclusive) const
70  {
71  int64 mem = inclusive ? sizeof(*this) : 0;
72  mem += myPath.getMemoryUsage(false);
73  mem += myDestName.getMemoryUsage(false);
74  return mem;
75  }
76 
77  // If is_for_channel_name is false, look up the parm name (e.g. "t")
78  // instead of the channel name (e.g. "tx"). When looking up a parm
79  // name, the subindex result will always be -1.
80  bool findParmRelativeTo(
81  OP_Node &relative_to_node,
82  const char *path,
83  fpreal now, OP_Node *&node,
84  int &parmindex, int &subindex,
85  bool is_for_channel_name);
86 
87  // Returns the node and/or parm that is currently evaluating.
88  // parm_index might be NULL if the node is not currently cooking.
89  void getEvaluatingSource(OP_Node *&node, int &parm_index, int &sub_index,
90  int thread);
91 
92  // If there is no parameter currently being evaluated, node will be null
93  // and parm_index will be -1.
94  void getEvaluatingParm(OP_Node *&node, int &parm_index, int &sub_index,
95  int thread);
96 
97 private:
98  int getDestIndex(
99  OP_Node *node, const char *channel_name, int &sub_index,
100  bool allow_alias);
101 
102  // myOpId is for the node that was found (i.e. the node being referenced).
103  int myOpId;
104  bool myIsForChannelName;
105  int myRelativeToOpId;
106  // myPath is the relative path from myRelativeToOpId's node to myOpId.
107  UT_String myPath;
108 
109  int myParmIndex;
110  int mySubIndex;
111  PRM_ParmList *myParmList;
112  size_t myParmListCounter;
113 
114  // The dest parameter is the one being evaluated. It's the one that will
115  // get node interests.
116  OP_Node * myDestNode;
117  int myDestIndex;
118  int myDestSubIndex;
119  size_t myDestListCounter;
120  UT_String myDestName;
121 };
122 
123 
124 // Get a parameter relative to the currently evaluating node/the pwd.
125 //
126 // This function has the important option of adding parm interests in
127 // the referenced parameter from the currently evaluating parameter. It
128 // basically assumes that that referenced parameter will be evaluated from the
129 // currently evaluating parameter (e.g. like when we do a channel reference).
130 //
131 // This function will use OP_ExprFindCh to cache parameter lookups. Houdini
132 // will allocate OP_ExprFindCh objects when some expression functions
133 // (ch(), chs(), etc.) are compiled into bytecode, so you don't often have
134 // to deal with OP_ExprFindCh manually. Because HOM needs finer-grained
135 // control over when dependencies are added, though, it does deal with them
136 // manually.
137 OP_API extern void OPgetParameter(const char *path, fpreal &time,
138  int *retsubindex, PRM_Parm **retparm,
139  CH_Channel **retchannel, OP_Node **retnode,
140  bool allow_alias,
141  bool add_parm_interests /*= true*/,
142  int thread, bool add_warnings = false);
143 
144 // Possible error code values:
145 // OP_WARN_BAD_CHREF, OP_WARN_BAD_OPREF
146 OP_API extern void OPaddBadRefWarning(OP_ErrorCodes err_code,
147  const char *path, int thread);
148 
149 #endif
OP_ErrorCodes
Definition: OP_Error.h:8
int64 getMemoryUsage(bool inclusive) const
Definition: OP_Expression.h:69
GLsizei const GLchar *const * path
Definition: glcorearb.h:3340
OP_API void OPgetParameter(const char *path, fpreal &time, int *retsubindex, PRM_Parm **retparm, CH_Channel **retchannel, OP_Node **retnode, bool allow_alias, bool add_parm_interests, int thread, bool add_warnings=false)
long long int64
Definition: SYS_Types.h:100
GLboolean * data
Definition: glcorearb.h:130
double fpreal
Definition: SYS_Types.h:263
OP_API void OPaddBadRefWarning(OP_ErrorCodes err_code, const char *path, int thread)
#define OP_API
Definition: OP_API.h:10
int64 getMemoryUsage(bool inclusive) const
Definition: OP_Expression.h:35