HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PY_EvaluationCache.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  * COMMENTS:
7  * An instance of this class is stored with each instance of
8  * PY_CompiledCode. Each time the code is evaluated, the cache is
9  * made active, and subsequent evaluations can use information that
10  * was cached during previous evaluations.
11  *
12  * The cache has nothing to do with python, and is used to cache
13  * the results of expensive computations done in Houdini's code.
14  *
15  * This class only exists at the PY level so PY_CompiledCode can store
16  * an instance of it and so it can deleted it. HOMF_Module will set
17  * a callback to create new instances of HOMF_EvaluationCache objects.
18  * These objects store things like OP_ExprFindOp caches that speed up
19  * channel references, etc.
20  */
21 
22 #ifndef __PY_EvaluationCache_h__
23 #define __PY_EvaluationCache_h__
24 
25 #include "PY_API.h"
26 #include <UT/UT_NonCopyable.h>
27 #include <UT/UT_Array.h>
28 
30 {
31 public:
32  PY_EvaluationCache() = default;
34  {}
35 
37 
38  // Count all memory owned by the PY_EvaluationCache. Remember to
39  // include sizeof(*this) if inclusive, else don't.
40  virtual int64 getMemoryUsage(bool inclusive) const
41  { return inclusive ? sizeof(*this) : 0; }
42 
43  // Use this static function to set a callback that creates instances of a
44  // subclass of PY_EvaluationCache. This callback is invoked from
45  // PY_CompiledCode when evaluating Python code. This static function is
46  // called when the hou Python module is imported and the HOMF_Module
47  // instance is created.
48  static void setConstructionCallback(
49  PY_EvaluationCache *(*callback)());
50 
51  static bool isConstructionCallbackSet();
52 
53  // This static function uses the creation callback to create a new instance
54  // of the evaluation cache subclass. Don't call this function unless
55  // the callback has been set.
56  static PY_EvaluationCache *createNew();
57 
58  // Each thread has a stack of evaluation caches, and this static function
59  // returns that stack. Note that you must use the evaluation stack from
60  // the same thread that you call evaluationCacheStack() from.
61  static UT_Array<PY_EvaluationCache *> &getThreadSpecificStack();
62 
63 private:
64  static PY_EvaluationCache *(*theConstructionCallback)();
65 };
66 
67 #endif
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
#define PY_API
Definition: PY_API.h:10
long long int64
Definition: SYS_Types.h:116