HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UN_Handle.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: UN_Handle.h ( UN Library, C++)
7  *
8  * COMMENTS:
9  *
10  */
11 
12 #ifndef __UN_Handle_h__
13 #define __UN_Handle_h__
14 
15 
16 #include "UN_API.h"
17 #include "UN_Types.h"
18 
19 class UN_GraphData;
20 
21 
22 // ============================================================================
23 /// Data class that is basis for many data classes.
24 /// It factors out the behavious of a data object inside a data container.
25 
26 // Note, no UN_API because all methods are defined in the header.
27 class UN_Handle
28 {
29 public:
30  /// Convenience constructor.
31  UN_Handle( UN_GraphData *graph_data,
32  UN_DataIndex data_index,
33  UN_DataID data_id )
34  : myGraphData( graph_data )
35  , myDataIndex( data_index )
36  , myDataID( data_id )
37  {}
38 
39  /// Default constructor.
41  : UN_Handle( nullptr, UN_DataIndex(), UN_DataID() )
42  {}
43 
44  /// @{ Default destructor, constructors and assignment operators.
45  ~UN_Handle() = default;
46  UN_Handle( const UN_Handle & ) = default;
47  UN_Handle( UN_Handle && ) = default;
48  UN_Handle& operator=( const UN_Handle & ) = default;
49  UN_Handle& operator=( UN_Handle && ) = default;
50  /// @}
51 
52  /// @{ Comparison operators
53  bool operator==( const UN_Handle &other ) const
54  {
55  return myGraphData == other.myGraphData
56  && myDataIndex == other.myDataIndex
57  && myDataID == other.myDataID;
58  }
59 
60  bool operator!=( const UN_Handle &other ) const
61  {
62  return !( *this == other );
63  }
64 
65  /// @}
66 
67  /// Index identifying the data object within the owner graph.
68  /// Note, a data object may reuse space from previously deleted data object,
69  /// and thus share the same data index into the data container.
71  { return myDataIndex; }
72 
73  /// The unique ID of a data object during the lifespan of the owner graph.
74  UN_DataID dataID() const
75  { return myDataID; }
76 
77 protected:
78  /// The graph data struct that owns, manages, and operates on data object.
79  /// Returning a non-const pointer from const method, since the
80  /// derived classes have const methods that operate on non-const graph.
81  UN_GraphData * graphData() const
82  { return myGraphData; }
83 
84 private:
85  /// The graph that owns, manages, and operates on data object.
86  UN_GraphData * myGraphData;
87 
88  /// Index identifying the data object within the graph above.
89  /// Note, a data object may reuse space from previously deleted data object,
90  /// and thus share the same data index into the data container.
91  UN_DataIndex myDataIndex;
92 
93  /// The unique identification number of a data object during the lifespan
94  /// of the graph above, used for detecting and verifying that
95  /// the data object has not been deleted.
96  UN_DataID myDataID;
97 };
98 
99 
100 #endif
101 
UN_DataID dataID() const
The unique ID of a data object during the lifespan of the owner graph.
Definition: UN_Handle.h:74
UN_Handle(UN_GraphData *graph_data, UN_DataIndex data_index, UN_DataID data_id)
Convenience constructor.
Definition: UN_Handle.h:31
bool operator==(const UN_Handle &other) const
Comparison operators.
Definition: UN_Handle.h:53
UN_DataIndex dataIndex() const
Definition: UN_Handle.h:70
bool operator!=(const UN_Handle &other) const
Comparison operators.
Definition: UN_Handle.h:60
UN_Handle & operator=(const UN_Handle &)=default
Default destructor, constructors and assignment operators.
~UN_Handle()=default
Default destructor, constructors and assignment operators.
UN_GraphData * graphData() const
Definition: UN_Handle.h:81
UN_Handle()
Default constructor.
Definition: UN_Handle.h:40