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