HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UNI_Item.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_Item.h ( UNI Library, C++)
7  *
8  * COMMENTS:
9  *
10  */
11 
12 #ifndef __UNI_Item_h__
13 #define __UNI_Item_h__
14 
15 #include "UNI_API.h"
16 #include "UNI_GraphHandle.h"
17 
18 // ============================================================================
19 template<class UNI_ID_TYPE>
21 {
22 public:
23  /// Constructor.
24  UNI_ConstItem() = default;
25  UNI_ConstItem( const UNI_ConstGraphHandle &graph_handle, UNI_ID_TYPE id )
26  : myGraphHandle( graph_handle )
27  , myID( id )
28  {}
29 
30  /// Constructor with r-value for the intrusive graph pointer.
31  UNI_ConstItem( UNI_ConstGraphHandle &&graph_handle, UNI_ID_TYPE id )
32  : myGraphHandle( std::move(graph_handle) )
33  , myID( id )
34  {}
35 
36  /// @{ Returns true if the UNI node is valid. Ie, it has a valid API with
37  /// a valid graph, and represents a valid node in that graph.
38  bool isValid() const { return graph() &&
39  graph()->isValid(id()); }
40  explicit operator bool() const { return isValid(); }
41  /// @}
42 
43  /// Returns the graph inside which the node lives.
44  const UNI_Graph * graph() const { return myGraphHandle.graph(); }
45 
46  /// Returns the ID of the node in the graph.
47  UNI_ID_TYPE id() const { return myID; }
48 
49 protected:
50  /// Returns the underlying graph handle.
52  {
53  return myGraphHandle;
54  }
55 
56 private:
57  /// Graph interface that performs operations on nodes.
58  UNI_ConstGraphHandle myGraphHandle;
59 
60  /// The ID of the node in the graph.
61  UNI_ID_TYPE myID;
62 };
63 
64 
65 // ============================================================================
66 template<class UNI_ID_TYPE, class UNI_SESSION_ID_TYPE, class CONST_BASE_TYPE>
67 class UNI_Item : public CONST_BASE_TYPE
68 {
69 public:
70  /// Constructor.
71  UNI_Item() = default;
72  UNI_Item( const UNI_GraphHandle &graph_handle, UNI_ID_TYPE id )
73  : CONST_BASE_TYPE( graph_handle, id ) {}
74 
75  /// Constructor with r-value for the intrusive graph pointer.
76  UNI_Item( UNI_GraphHandle &&graph_handle, UNI_ID_TYPE id )
77  : CONST_BASE_TYPE( std::move(graph_handle), id ) {}
78 
79  /// @{ Other convenience constructors.
80  UNI_Item( UNI_SESSION_ID_TYPE session_id )
81  : UNI_Item( session_id.graphID(), session_id.localID() ) {}
82  UNI_Item( UNI_GraphID graph_id, UNI_ID_TYPE id )
83  : UNI_Item( UNI_GraphHandle(graph_id), id ) {}
84  /// @}
85 
86  /// Returns the graph inside which the node lives.
87  UNI_Graph *graph() const
88  {
89  // This sub-class constructs the base class always with
90  // a non-const graph, so we can cast away constness here.
91  return const_cast<UNI_Graph*>( UNI_ConstItem<UNI_ID_TYPE>::graph() );
92  }
93 
94  /// Alias the change block for use in this class, for brevity.
97 };
98 
99 #endif
virtual bool isValid(UNI_NodeID node_id) const =0
Returns true if the given ID refers to a valid item in this graph.
bool isValid() const
Definition: UNI_Item.h:38
UNI_Item(UNI_GraphHandle &&graph_handle, UNI_ID_TYPE id)
Constructor with r-value for the intrusive graph pointer.
Definition: UNI_Item.h:76
UNI_ID_TYPE id() const
Returns the ID of the node in the graph.
Definition: UNI_Item.h:47
const UNI_ConstGraphHandle & graphHandle() const
Returns the underlying graph handle.
Definition: UNI_Item.h:51
UNI_ConstItem(UNI_ConstGraphHandle &&graph_handle, UNI_ID_TYPE id)
Constructor with r-value for the intrusive graph pointer.
Definition: UNI_Item.h:31
UNI_Item(UNI_SESSION_ID_TYPE session_id)
Other convenience constructors.
Definition: UNI_Item.h:80
OutGridT const XformOp bool bool
UNI_Item(const UNI_GraphHandle &graph_handle, UNI_ID_TYPE id)
Definition: UNI_Item.h:72
UNI_Graph * graph() const
Returns the graph inside which the node lives.
Definition: UNI_Item.h:87
UNI_Item(UNI_GraphID graph_id, UNI_ID_TYPE id)
Other convenience constructors.
Definition: UNI_Item.h:82
UNI_Item()=default
Constructor.
const UNI_Graph * graph() const
Returns the graph inside which the node lives.
Definition: UNI_Item.h:44
const UNI_Graph * graph() const
Returns the UNI graph referenced by this handle.
UNI_ConstItem(const UNI_ConstGraphHandle &graph_handle, UNI_ID_TYPE id)
Definition: UNI_Item.h:25
UNI_ConstItem()=default
Constructor.