Carna  Version 3.3.2
Composition.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 COMPOSITION_H_6014714286
13 #define COMPOSITION_H_6014714286
14 
19 #include <Carna/base/Association.h>
20 
21 namespace Carna
22 {
23 
24 namespace base
25 {
26 
27 
28 
29 // ----------------------------------------------------------------------------------
30 // Composition
31 // ----------------------------------------------------------------------------------
32 
51 template< typename AssociatedObjectType >
52 class Composition : public Association< AssociatedObjectType >
53 {
54 
55 public:
56 
60  explicit Composition( AssociatedObjectType* associatedObject )
61  : Association< AssociatedObjectType >( associatedObject )
62  {
63  }
64 
65 
69  virtual ~Composition()
70  {
71  AssociatedObjectType* const associatedObject = Association< AssociatedObjectType >::get();
72  if( associatedObject )
73  {
74  delete associatedObject;
75  }
76  }
77 
78 }; // Composition
79 
80 
81 
82 } // namespace Carna :: base
83 
84 } // namespace Carna
85 
86 #endif // COMPOSITION_H_6014714286
Defines Carna::base::Association.
virtual ~Composition()
Deletes the associated object, if there is one.
Definition: Composition.h:69
AssociatedObjectType * get() const
Returns raw pointer to the referenced object.
Definition: Association.h:61
Represents a composition, i.e. a strong reference. This basically is a std::unique_ptr that supports ...
Definition: Composition.h:52
Represents an association.
Definition: Association.h:44
Composition(AssociatedObjectType *associatedObject)
Instantiates.
Definition: Composition.h:60