00001 /* 00002 * PROPRIETARY INFORMATION. This software is proprietary to 00003 * Side Effects Software Inc., and is not to be reproduced, 00004 * transmitted, or disclosed in any way without written permission. 00005 * 00006 * Produced by: 00007 * Side Effects Software Inc 00008 * 477 Richmond Street West 00009 * Toronto, Ontario 00010 * Canada M5V 3E7 00011 * 416-504-9876 00012 * 00013 * NAME: OP_BundleReferences.h ( OP Library, C++) 00014 * 00015 * COMMENTS: For parameters which reference bundles, we have to keep track 00016 * of the bundle so that we get notifications to rebuild 00017 * data (e.g., the shader string) properly. 00018 * 00019 * This class manages such bundle references by the operator's 00020 * parameters. It attempts to keep track of the bundle names 00021 * for the referencing/dereferencing purposes 00022 * and to register and unregister the interest with the bundles. 00023 */ 00024 00025 #ifndef __OP_BundleReferences__ 00026 #define __OP_BundleReferences__ 00027 00028 #include "OP_API.h" 00029 #include <UT/UT_Defines.h> 00030 #include <UT/UT_SmallObject.h> 00031 #include <UT/UT_String.h> 00032 #include <UT/UT_HashTable.h> 00033 00034 00035 class OP_BundleRefList; 00036 class OP_Bundle; 00037 class OP_Network; 00038 class OP_Node; 00039 template<typename> class UT_PtrArray; 00040 00041 00042 /// Implementation of a reference to a single bundle by a single parameter. 00043 /// The parameter is identified by its name (token) and the vector 00044 /// index into the parameter (for vector parms) 00045 class OP_API OP_BundleRef : public UT_SmallObject<OP_BundleRef> 00046 { 00047 public: 00048 OP_BundleRef( const char *name, int v_index ) 00049 : myParmName( name ), myVecIndex( v_index ), myUsedFlag( true ) {} 00050 00051 // some accessors 00052 const UT_String& getParmName() const { return myParmName; } 00053 int getVectorIndex() const { return myVecIndex; } 00054 bool isUsed() const { return myUsedFlag; } 00055 00056 private: 00057 UT_String myParmName; // parameter name (token) 00058 int myVecIndex; // sub-parm index into a vector parm 00059 bool myUsedFlag; // flags if a parm actually references 00060 // a bundle: used to "mark and clear" 00061 00062 // only OP_BundleRefList knows how to modify this class properly 00063 friend class OP_BundleRefList; 00064 }; 00065 00066 00067 /// Implementation of a manager that overlooks all the references to 00068 /// the bundles by a all parameters of an operator. 00069 class OP_API OP_BundleReferences 00070 { 00071 public: 00072 OP_BundleReferences( OP_Node &owner); 00073 ~OP_BundleReferences(); 00074 00075 /// Obtains a bundle defined by an operator pattern and filter using 00076 /// the creator and myOwner as relative_to nodes (much like OP_BundleList), 00077 /// and then associates this bundle with a parameter defined by a name 00078 /// and index. 00079 /// 00080 /// The bundle references by this parameter are updated (ie, bundle 00081 /// previously referenced by this parm is dereferenced, and a reference 00082 /// count of the new bundle (which is returned) is bumped up. 00083 /// 00084 /// The also and interest is registered with the bundle for myOwner 00085 /// node (much like OP_BundleList::getPattern() does. 00086 /// 00087 /// The bundle reference used flag is set to true for that parm/index pair. 00088 OP_Bundle * getParmBundle(const char* parm_name, int vector_index, 00089 UT_String &pattern, OP_Network *creator, 00090 const char *filter); 00091 00092 /// Marks all the references as unused. Usually followed by cleanUnused() 00093 /// to delete the references that no longer exist. 00094 void markAllUnused(); 00095 00096 /// Deletes all references whose used flag is false. Usually preceeded 00097 /// by markAllUnused, and a series of getParmBundle to identify and delete 00098 /// obsolete references. 00099 void cleanUnused(); 00100 00101 /// Deletes all references. 00102 void cleanAll(); 00103 00104 /// Obtains a list of bundle references. Given a bundle name, 00105 /// this method returns all parameters that reference that bundle. 00106 const UT_PtrArray<OP_BundleRef *> 00107 *getListOfRefs( const char* bundle_name ) const; 00108 00109 /// Estimates memory usage of the this object 00110 int64 getMemUsage(UT_Bool onlythis) const; 00111 00112 private: 00113 /// map: bundle name -> list of referencing parameters 00114 // Given a bundle name, finds all parameters that refer to this bundle. 00115 // On a bundle changed event, this map is used to find all referencing 00116 // parameters (and possibly invoke parm dirty on them). 00117 UT_HashTable myBundleToParmsMap; 00118 00119 /// map: parameter -> name of a bundle 00120 /// NB: this is a "one-to-one" mapping, where tag = name + vector index 00121 // Given a parameter tag, finds a (single) bundle this parameter references. 00122 UT_HashTable myTagToBundleMap; 00123 00124 // the owner of this bundle reference manager 00125 OP_Node &myOwner; 00126 }; 00127 #endif 00128
1.5.9