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 /// A handle class that is the basis for many concrete handle 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, UN_DataID data_id )
32  : myGraphData( graph_data )
33  , myDataID( data_id )
34  {}
35 
36  /// Default constructor.
38  : UN_Handle( nullptr, UN_DataID() )
39  {}
40 
41  /// @{ Default destructor, constructors and assignment operators.
42  ~UN_Handle() = default;
43  UN_Handle( const UN_Handle & ) = default;
44  UN_Handle( UN_Handle && ) = default;
45  UN_Handle& operator=( const UN_Handle & ) = default;
46  UN_Handle& operator=( UN_Handle && ) = default;
47  /// @}
48 
49  /// @{ Comparison operators
50  bool operator==( const UN_Handle &other ) const
51  {
52  return myGraphData == other.myGraphData
53  && myDataID == other.myDataID;
54  }
55 
56  bool operator!=( const UN_Handle &other ) const
57  {
58  return !( *this == other );
59  }
60 
61  /// @}
62 
63 
64  /// The unique number identifying this data object during the lifespan
65  /// of the owner graph. Used for referring to this object in the graph.
66  UN_DataID dataID() const
67  { return myDataID; }
68 
69 protected:
70  /// The graph that owns, manages, and operates on data object.
71  /// Returning a non-const pointer from const method, since the
72  /// derived classes have const methods that operate on non-const graph,
73  /// but are always constructed with a non-const graph.
74  UN_GraphData * graphData() const
75  { return myGraphData; }
76 
77 private:
78  /// The graph that owns, manages, and operates on data object.
79  UN_GraphData * myGraphData;
80 
81  /// The unique identification number of a data object during the lifespan
82  /// of the graph above. Used for referring to the data object in a graph.
83  UN_DataID myDataID;
84 };
85 
86 
87 #endif
88 
UN_DataID dataID() const
Definition: UN_Handle.h:66
bool operator==(const UN_Handle &other) const
Comparison operators.
Definition: UN_Handle.h:50
bool operator!=(const UN_Handle &other) const
Comparison operators.
Definition: UN_Handle.h:56
UN_Handle & operator=(const UN_Handle &)=default
Default destructor, constructors and assignment operators.
~UN_Handle()=default
Default destructor, constructors and assignment operators.
UN_Handle(UN_GraphData *graph_data, UN_DataID data_id)
Convenience constructor.
Definition: UN_Handle.h:31
UN_GraphData * graphData() const
Definition: UN_Handle.h:74
UN_Handle()
Default constructor.
Definition: UN_Handle.h:37