HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UNI_GraphHandle.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: UNI_GraphHandle.h ( UNI Library, C++)
7  *
8  * COMMENTS:
9  *
10  */
11 
12 #ifndef __UNI_GraphHandle_h__
13 #define __UNI_GraphHandle_h__
14 
15 #include "UNI_API.h"
16 #include "UNI_Graph.h"
17 
18 
19 // ============================================================================ /// Handle for holding a reference to a const UNI_Graph.
21 {
22 public:
23  /// @{ Constructor for the graph handle.
24  UNI_ConstGraphHandle() = default;
25  explicit UNI_ConstGraphHandle( UNI_GraphID graph_id );
27  : myGraphPtr( graph_ptr ) {}
29  : myGraphPtr( std::move(graph_ptr) ) {}
30  /// @}
31 
32  /// @{ Returns true if this handle refers to a valid graph; false otherwise.
33  bool isValid() const
34  { return graph(); }
35  explicit operator bool() const
36  { return isValid(); }
37  /// @}
38 
39  /// @{ Comparison operators.
40  bool operator==( const UNI_ConstGraphHandle &other ) const
41  { return graph() == other.graph(); }
42  bool operator!=( const UNI_ConstGraphHandle &other ) const
43  { return graph() != other.graph(); }
44  /// @}
45 
46  /// @{ Returns the UNI graph referenced by this handle.
47  const UNI_Graph * graph() const
48  { return myGraphPtr.get(); }
49  const UNI_Graph * operator->() const
50  { return graph(); }
51  /// @}
52 
53  /// Returns the ID of a UNI graph referenced by this handle.
54  UNI_GraphID graphID() const
55  {
56  return myGraphPtr ? myGraphPtr->graphID() : UNI_GraphID();
57  }
58 
59 private:
60  /// Intrusive pointer to the UNI graph.
61  UNI_ConstGraphPtr myGraphPtr;
62 };
63 
64 // ============================================================================ /// Handle for holding a reference to UNI_Graph.
66 {
67 public:
68  /// @{ Constructor for the graph handle.
69  UNI_GraphHandle() = default;
70  explicit UNI_GraphHandle( UNI_GraphID graph_id );
71  UNI_GraphHandle( const UNI_GraphPtr &graph_ptr )
72  : UNI_ConstGraphHandle( graph_ptr ) {}
74  : UNI_ConstGraphHandle( std::move(graph_ptr) ) {}
75  /// Takes ownership of a freshly created graph. The graph has already
76  /// registered itself in the look-up table in its constructor; this
77  /// handle's reference count becomes the sole owner of the graph.
79  : UNI_GraphHandle( UNI_GraphPtr( graph.release() )) {}
80  /// @}
81 
82  /// @{ Returns the UNI graph referenced by this handle.
83  UNI_Graph * graph() const
84  {
85  // This sub-class constructs the base class always with
86  // a non-const graph, so we can cast away constness here.
87  return const_cast<UNI_Graph*>( UNI_ConstGraphHandle::graph() );
88  }
89 
91  {
92  return graph();
93  }
94  /// @}
95 
96 private:
97 };
98 #endif
bool operator==(const UNI_ConstGraphHandle &other) const
Comparison operators.
UNI_GraphID graphID() const
Returns the ID of a UNI graph referenced by this handle.
bool operator!=(const UNI_ConstGraphHandle &other) const
Comparison operators.
bool isValid() const
Returns true if this handle refers to a valid graph; false otherwise.
UNI_ConstGraphHandle(UNI_ConstGraphPtr &&graph_ptr)
Constructor for the graph handle.
UNI_GraphHandle(const UNI_GraphPtr &graph_ptr)
Constructor for the graph handle.
#define UNI_API
Definition: UNI_API.h:11
OutGridT const XformOp bool bool
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
UNI_Graph * graph() const
Returns the UNI graph referenced by this handle.
UNI_Graph * operator->() const
Returns the UNI graph referenced by this handle.
UNI_GraphHandle(UNI_GraphPtr &&graph_ptr)
Constructor for the graph handle.
UNI_GraphHandle(UT_UniquePtr< UNI_Graph > graph)
UNI_ConstGraphHandle(const UNI_ConstGraphPtr &graph_ptr)
Constructor for the graph handle.
const UNI_Graph * operator->() const
Returns the UNI graph referenced by this handle.
const UNI_Graph * graph() const
Returns the UNI graph referenced by this handle.