HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GA_AttributeProxy.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: GA_AttributeProxy.h ( GA Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GA_AttributeProxy__
12 #define __GA_AttributeProxy__
13 
14 #include "GA_API.h"
15 #include <UT/UT_IntrusivePtr.h>
16 #include <SYS/SYS_AtomicInt.h>
17 #include <SYS/SYS_Types.h>
18 
19 #include <stddef.h>
20 
21 
22 class GA_Attribute;
23 class UT_MemoryCounter;
24 
25 
26 /// @brief This class holds a reference to an attribute.
27 /// Such an indirection level allows an easy way to invalidate attribute
28 /// references when an attribute gets deleted (or when the detail itself is
29 /// deleted).
31 {
32 public:
33  /// Constructor.
34  explicit GA_AttributeProxy(GA_Attribute * atr);
36 
37  /// @{
38  /// Obtains an actual attribute. May be NULL, if the attribute got deleted
39  /// or was never actually found (or sussessfully created).
41  { return myAttribute; }
43  { return myAttribute; }
44  /// @}
45 
46  /// Returns true if the proxy is still pointing to a valid attribute.
48  { return myAttribute != NULL; }
49 
50  /// Checks if there is only one reference to this proxy (held by the caller)
51  bool isLastReference() const;
52 
53  /// Returns the memory footprint of the proxy and the attribute it
54  /// represents.
55  int64 getMemoryUsage(bool inclusive) const;
56 
57  /// Count memory usage using a UT_MemoryCounter in order to count
58  /// shared memory correctly.
59  /// If inclusive is true, the size of this object is counted,
60  /// else only memory owned by this object is counted.
61  /// If this is pointed to by the calling object, inclusive should be true.
62  /// If this is contained in the calling object, inclusive should be false.
63  /// (Its memory was already counted in the size of the calling object.)
64  ///
65  /// NOTE: This treats GA_AttributeProxy as unshared, despite
66  /// myReferenceCount, because the count should always be 1.
67  void countMemory(UT_MemoryCounter &counter, bool inclusive) const;
68 
69  /// @private
70  /// This interface should only be used by the intrusive pointer handles
71  SYS_FORCE_INLINE void intrusive_ptr_add_ref() const { incref(); }
72  SYS_FORCE_INLINE void intrusive_ptr_release() const { decref(); }
73  /// @}
74 
75 private:
76  /// Makes the attribute reference invalid. This is necessary to do when the
77  /// detail or the attribute in the detail gets deleted to prevent the
78  /// proxy from referencing deleted objects.
79  void invalidate(); // only GA_AttributeSet calls it
80  /// Ask the proxy to register a new reference, which essentially
81  /// increments the reference counter.
82  void incref() const;
83  /// Ask the proxy to unregister a reference, which essentially
84  /// decrements the reference counter. When the reference decreases to
85  /// zero the proxy object gets deleted.
86  void decref() const;
87 
88  friend class GA_AttributeSet;
89 
90 private:
91  /// A reference to the actual attribute.
92  GA_Attribute *myAttribute;
93 
94  /// A reference counter.
95  mutable SYS_AtomicInt32 myReferenceCount;
96 };
97 
98 /// @{
99 /// Boost function callbacks for referencing and unreferencing GA_AttributeProxy
100 static inline void
101 intrusive_ptr_add_ref(const GA_AttributeProxy *proxy)
102 {
103  proxy->intrusive_ptr_add_ref();
104 }
105 
106 static inline void
107 intrusive_ptr_release(const GA_AttributeProxy *proxy)
108 {
109  proxy->intrusive_ptr_release();
110 }
111 /// @}
112 
113 /// @{
114 /// Define an intrusive type handle type for GA_AttributeProxy
117 /// @}
118 
119 #endif
Definition of a geometry attribute.
Definition: GA_Attribute.h:198
UT_IntrusivePtr< GA_AttributeProxy > GA_AttributeProxyHandle
SYS_FORCE_INLINE GA_Attribute * getAttribute()
UT_IntrusivePtr< const GA_AttributeProxy > GA_ConstAttributeProxyHandle
#define GA_API
Definition: GA_API.h:14
SYS_FORCE_INLINE const GA_Attribute * getAttribute() const
SYS_FORCE_INLINE void intrusive_ptr_release() const
This class holds a reference to an attribute. Such an indirection level allows an easy way to invalid...
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
long long int64
Definition: SYS_Types.h:116
SYS_FORCE_INLINE bool isValid() const
Returns true if the proxy is still pointing to a valid attribute.