HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OP_BundleReferences.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_BundleReferences.h ( OP Library, C++)
7  *
8  * COMMENTS: For parameters which reference bundles, we have to keep track
9  * of the bundle so that we get notifications to rebuild
10  * data (e.g., the shader string) properly.
11  *
12  * This class manages such bundle references by the operator's
13  * parameters. It attempts to keep track of the bundle names
14  * for the referencing/dereferencing purposes
15  * and to register and unregister the interest with the bundles.
16  */
17 
18 #ifndef __OP_BundleReferences__
19 #define __OP_BundleReferences__
20 
21 #include "OP_API.h"
22 #include <UT/UT_Defines.h>
23 #include <UT/UT_SmallObject.h>
24 #include <UT/UT_String.h>
25 #include <UT/UT_StringMap.h>
26 
27 class OP_BundleRefList;
28 class OP_Bundle;
29 class OP_Network;
30 class OP_Node;
31 template<typename> class UT_Array;
32 
33 
34 /// Implementation of a reference to a single bundle by a single parameter.
35 /// The parameter is identified by its name (token) and the vector
36 /// index into the parameter (for vector parms)
37 class OP_API OP_BundleRef : public UT_SmallObject<OP_BundleRef>
38 {
39 public:
40  OP_BundleRef( const char *name, int v_index )
41  : myParmName( name ), myVecIndex( v_index ), myUsedFlag( true ) {}
42 
43  // some accessors
44  const UT_String& getParmName() const { return myParmName; }
45  int getVectorIndex() const { return myVecIndex; }
46  bool isUsed() const { return myUsedFlag; }
47 
48 private:
49  UT_String myParmName; // parameter name (token)
50  int myVecIndex; // sub-parm index into a vector parm
51  bool myUsedFlag; // flags if a parm actually references
52  // a bundle: used to "mark and clear"
53 
54  // only OP_BundleRefList knows how to modify this class properly
55  friend class OP_BundleRefList;
56 };
57 
58 
59 /// Implementation of a manager that overlooks all the references to
60 /// the bundles by a all parameters of an operator.
62 {
63 public:
66 
67  /// Obtains a bundle defined by an operator pattern and filter using
68  /// the creator and myOwner as relative_to nodes (much like OP_BundleList),
69  /// and then associates this bundle with a parameter defined by a name
70  /// and index.
71  ///
72  /// The bundle references by this parameter are updated (ie, bundle
73  /// previously referenced by this parm is dereferenced, and a reference
74  /// count of the new bundle (which is returned) is bumped up.
75  ///
76  /// The also and interest is registered with the bundle for myOwner
77  /// node (much like OP_BundleList::getPattern() does.
78  ///
79  /// The bundle reference used flag is set to true for that parm/index pair.
80  OP_Bundle * getParmBundle(const char* parm_name, int vector_index,
81  UT_String &pattern, OP_Network *creator,
82  const char *filter);
83 
84  /// Marks all the references as unused. Usually followed by cleanUnused()
85  /// to delete the references that no longer exist.
86  void markAllUnused();
87 
88  /// Deletes all references whose used flag is false. Usually preceeded
89  /// by markAllUnused, and a series of getParmBundle to identify and delete
90  /// obsolete references.
91  void cleanUnused();
92 
93  /// Deletes all references.
94  void cleanAll();
95 
96  /// Obtains a list of bundle references. Given a bundle name,
97  /// this method returns all parameters that reference that bundle.
99  *getListOfRefs( const char* bundle_name ) const;
100 
101  /// Estimates memory usage of the this object
102  int64 getMemoryUsage(bool inclusive) const;
103 
104  /// Obtains a bundle defined by an operator pattern with or without
105  /// subnet_inclusion
106  OP_Bundle * getParmBundle(const char* parm_name, int vector_index,
107  UT_String &pattern, OP_Network *creator,
108  const char *filter, bool subnet_inclusion);
109 
110 private:
111  /// map: bundle name -> list of referencing parameters
112  // Given a bundle name, finds all parameters that refer to this bundle.
113  // On a bundle changed event, this map is used to find all referencing
114  // parameters (and possibly invoke parm dirty on them).
115  UT_StringMap<OP_BundleRefList *> myBundleToParmsMap;
116 
117  /// map: parameter -> name of a bundle
118  /// NB: this is a "one-to-one" mapping, where tag = name + vector index
119  // Given a parameter tag, finds a (single) bundle this parameter references.
120  UT_StringMap<UT_StringHolder> myTagToBundleMap;
121 
122  // the owner of this bundle reference manager
123  OP_Node &myOwner;
124 };
125 #endif
126 
int getVectorIndex() const
const UT_String & getParmName() const
bool isUsed() const
long long int64
Definition: SYS_Types.h:106
GLuint const GLchar * name
Definition: glcorearb.h:785
OP_BundleRef(const char *name, int v_index)
#define OP_API
Definition: OP_API.h:10
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glcorearb.h:1296