Alexandria
2.31.2
SDC-CH common library for the Euclid project
Loading...
Searching...
No Matches
AlexandriaKernel
AlexandriaKernel
_impl
InstOrRefHolder.icpp
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2012-2022 Euclid Science Ground Segment
3
*
4
* This library is free software; you can redistribute it and/or modify it under
5
* the terms of the GNU Lesser General Public License as published by the Free
6
* Software Foundation; either version 3.0 of the License, or (at your option)
7
* any later version.
8
*
9
* This library is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12
* details.
13
*
14
* You should have received a copy of the GNU Lesser General Public License
15
* along with this library; if not, write to the Free Software Foundation, Inc.,
16
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
*/
18
19
/*
20
* @file InstOrRefHolder.icpp
21
* @author nikoapos
22
*/
23
24
#include "
AlexandriaKernel/memory_tools.h
"
25
#include <type_traits>
26
27
namespace
Euclid
{
28
29
namespace
InstOrRefHolder_Impl {
30
31
template
<
typename
InterfaceType,
typename
InstanceType>
32
struct
InstHolder_Impl
:
public
InstOrRefHolder
<InterfaceType> {
33
template
<
typename
... Args>
34
explicit
InstHolder_Impl
(Args&&... args) :
m_instance
(
std
::forward<Args>(args)...) {}
35
virtual
~InstHolder_Impl
() =
default
;
36
InterfaceType&
ref
()
override
{
37
return
m_instance
;
38
}
39
40
private
:
41
InstanceType
m_instance
;
42
};
43
44
template
<
typename
InterfaceType>
45
struct
RefHolder_Impl
:
public
InstOrRefHolder
<InterfaceType> {
46
explicit
RefHolder_Impl
(InterfaceType& ref_) :
m_reference
(ref_) {}
47
virtual
~RefHolder_Impl
() =
default
;
48
InterfaceType&
ref
()
override
{
49
return
m_reference
.
get
();
50
}
51
52
private
:
53
std::reference_wrapper<InterfaceType>
m_reference
;
54
};
55
56
}
// end of namespace InstOrRefHolder_Impl
57
58
template
<
typename
InterfaceType>
59
template
<
typename
InstanceType,
typename
... Args>
60
std::unique_ptr<InstOrRefHolder<InterfaceType>
>
InstOrRefHolder<InterfaceType>::create
(Args&&... args) {
61
static_assert
(
std::is_same<InterfaceType, InstanceType>::value
||
std::is_base_of<InterfaceType, InstanceType>::value
,
62
"InstanceType must be a subtype of InterfaceType"
);
63
return
Euclid::make_unique<InstOrRefHolder_Impl::InstHolder_Impl<InterfaceType, InstanceType>
>(
64
std::forward<Args>
(args)...);
65
}
66
67
template
<
typename
InterfaceType>
68
std::unique_ptr<InstOrRefHolder<InterfaceType>
>
InstOrRefHolder<InterfaceType>::create
(InterfaceType& ref) {
69
return
Euclid::make_unique<InstOrRefHolder_Impl::RefHolder_Impl<InterfaceType>
>(ref);
70
}
71
72
}
// end of namespace Euclid
Euclid::InstOrRefHolder
Definition
InstOrRefHolder.h:38
Euclid::InstOrRefHolder::create
static std::unique_ptr< InstOrRefHolder< InterfaceType > > create(Args &&... args)
Definition
InstOrRefHolder.icpp:60
std::forward
T forward(T... args)
std::reference_wrapper::get
T get(T... args)
std::is_base_of
std::is_same
memory_tools.h
Euclid
Definition
InstOrRefHolder.icpp:27
Euclid::make_unique
std::unique_ptr< T > make_unique(Args &&... args)
Constructs an object of type T and wraps it in a std::unique_ptr using args as the parameter list for...
Definition
memory_tools.h:42
std
STL namespace.
std::reference_wrapper
Euclid::InstOrRefHolder_Impl::InstHolder_Impl
Definition
InstOrRefHolder.icpp:32
Euclid::InstOrRefHolder_Impl::InstHolder_Impl::ref
InterfaceType & ref() override
Definition
InstOrRefHolder.icpp:36
Euclid::InstOrRefHolder_Impl::InstHolder_Impl::~InstHolder_Impl
virtual ~InstHolder_Impl()=default
Euclid::InstOrRefHolder_Impl::InstHolder_Impl::InstHolder_Impl
InstHolder_Impl(Args &&... args)
Definition
InstOrRefHolder.icpp:34
Euclid::InstOrRefHolder_Impl::InstHolder_Impl::m_instance
InstanceType m_instance
Definition
InstOrRefHolder.icpp:41
Euclid::InstOrRefHolder_Impl::RefHolder_Impl
Definition
InstOrRefHolder.icpp:45
Euclid::InstOrRefHolder_Impl::RefHolder_Impl::RefHolder_Impl
RefHolder_Impl(InterfaceType &ref_)
Definition
InstOrRefHolder.icpp:46
Euclid::InstOrRefHolder_Impl::RefHolder_Impl::ref
InterfaceType & ref() override
Definition
InstOrRefHolder.icpp:48
Euclid::InstOrRefHolder_Impl::RefHolder_Impl::~RefHolder_Impl
virtual ~RefHolder_Impl()=default
Euclid::InstOrRefHolder_Impl::RefHolder_Impl::m_reference
std::reference_wrapper< InterfaceType > m_reference
Definition
InstOrRefHolder.icpp:53
std::unique_ptr
Generated by
1.11.0