Carna  Version 3.3.2
Association.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2010 - 2015 Leonid Kostrykin
3  *
4  * Chair of Medical Engineering (mediTEC)
5  * RWTH Aachen University
6  * Pauwelsstr. 20
7  * 52074 Aachen
8  * Germany
9  *
10  */
11 
12 #ifndef ASSOCIATION_H_6014714286
13 #define ASSOCIATION_H_6014714286
14 
19 #include <Carna/Carna.h>
20 #include <Carna/base/noncopyable.h>
21 
22 namespace Carna
23 {
24 
25 namespace base
26 {
27 
28 
29 
30 // ----------------------------------------------------------------------------------
31 // Association
32 // ----------------------------------------------------------------------------------
33 
43 template< typename AssociatedObjectType >
45 {
46 
48 
49 public:
50 
54  virtual ~Association()
55  {
56  }
57 
61  AssociatedObjectType* get() const
62  {
63  return associatedObject;
64  }
65 
68  AssociatedObjectType* operator->() const
69  {
70  return this->get();
71  }
72 
76  AssociatedObjectType& operator*() const
77  {
78  return *this->get();
79  }
80 
84  operator bool() const
85  {
86  return this->get() != nullptr;
87  }
88 
95  void forget()
96  {
97  associatedObject = 0;
98  }
99 
100 protected:
101 
105  explicit Association( AssociatedObjectType* associatedObject = nullptr )
106  : associatedObject( associatedObject )
107  {
108  }
109 
110 private:
111 
112  AssociatedObjectType* associatedObject;
113 
114 }; // Association
115 
116 
117 
118 } // namespace Carna :: base
119 
120 } // namespace Carna
121 
122 
123 
129 template< typename AssociatedObjectType >
131 {
132  return l.get() == r.get();
133 }
134 
135 
136 
137 #endif // ASSOCIATION_H_6014714286
Association(AssociatedObjectType *associatedObject=nullptr)
Instantiates.
Definition: Association.h:105
void forget()
Makes this association forget it&#39;s referenced object.
Definition: Association.h:95
bool operator==(const Carna::base::Association< AssociatedObjectType > &l, const Carna::base::Association< AssociatedObjectType > &r)
Tells whether l and r do reference the same object, that may be nullptr.
Definition: Association.h:130
AssociatedObjectType * get() const
Returns raw pointer to the referenced object.
Definition: Association.h:61
Represents an association.
Definition: Association.h:44
AssociatedObjectType & operator*() const
Returns raw reference to the referenced object.
Definition: Association.h:76
#define NON_COPYABLE
Features class it is placed in as non-copyable.
Definition: noncopyable.h:109
virtual ~Association()
Does nothing.
Definition: Association.h:54
AssociatedObjectType * operator->() const
Definition: Association.h:68