LibCarna Version 3.4.0
Loading...
Searching...
No Matches
Association.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010 - 2016 Leonid Kostrykin
3 *
4 * Chair of Medical Engineering (mediTEC)
5 * RWTH Aachen University
6 * Pauwelsstr. 20
7 * 52074 Aachen
8 * Germany
9 *
10 *
11 * Copyright (C) 2021 - 2025 Leonid Kostrykin
12 *
13 */
14
15#ifndef ASSOCIATION_H_6014714286
16#define ASSOCIATION_H_6014714286
17
23#include <LibCarna/LibCarna.hpp>
25
26namespace LibCarna
27{
28
29namespace base
30{
31
32
33
34// ----------------------------------------------------------------------------------
35// Association
36// ----------------------------------------------------------------------------------
37
46template< typename AssociatedObjectType >
48{
49
51
52public:
53
57 virtual ~Association()
58 {
59 }
60
65 {
66 return associatedObject;
67 }
68
72 {
73 return this->get();
74 }
75
80 {
81 return *this->get();
82 }
83
87 operator bool() const
88 {
89 return this->get() != nullptr;
90 }
91
98 void forget()
99 {
100 associatedObject = 0;
101 }
102
103protected:
104
108 explicit Association( AssociatedObjectType* associatedObject = nullptr )
109 : associatedObject( associatedObject )
110 {
111 }
112
113private:
114
115 AssociatedObjectType* associatedObject;
116
117}; // Association
118
119
120
121} // namespace LibCarna :: base
122
123} // namespace LibCarna
124
125
126
132template< typename AssociatedObjectType >
137
138
139
140#endif // ASSOCIATION_H_6014714286
Contains forward-declarations.
Represents an association.
AssociatedObjectType * operator->() const
virtual ~Association()
Does nothing.
AssociatedObjectType & operator*() const
Returns raw reference to the referenced object.
Association(AssociatedObjectType *associatedObject=nullptr)
Instantiates.
void forget()
Makes this association forget it's referenced object.
bool operator==(const LibCarna::base::Association< AssociatedObjectType > &l, const LibCarna::base::Association< AssociatedObjectType > &r)
Tells whether l and r do reference the same object, that may be nullptr.
AssociatedObjectType * get() const
Returns raw pointer to the referenced object.
Defines LibCarna::base::noncopyable and NON_COPYABLE.
#define NON_COPYABLE
Marks the class that it is placed in as non-copyable.