opm-common
Loading...
Searching...
No Matches
ConditionalStorage.hpp
Go to the documentation of this file.
1
// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2
// vi: set et ts=4 sw=4 sts=4:
3
/*
4
This file is part of the Open Porous Media project (OPM).
5
6
OPM is free software: you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation, either version 2 of the License, or
9
(at your option) any later version.
10
11
OPM is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
15
16
You should have received a copy of the GNU General Public License
17
along with OPM. If not, see <http://www.gnu.org/licenses/>.
18
19
Consult the COPYING file in the top-level source directory of this
20
module for the precise wording of the license and the list of
21
copyright holders.
22
*/
28
#ifndef OPM_CONDITIONAL_STORAGE_HH
29
#define OPM_CONDITIONAL_STORAGE_HH
30
31
#include <opm/common/utility/gpuDecorators.hpp>
32
#include <opm/common/ErrorMacros.hpp>
33
#include <cassert>
34
#include <stdexcept>
35
#include <type_traits>
36
#include <utility>
37
38
namespace
Opm
{
48
template
<
bool
cond,
class
T>
49
class
ConditionalStorage
50
{
51
public
:
52
typedef
T type;
53
static
constexpr
bool
condition = cond;
54
55
OPM_HOST_DEVICE
ConditionalStorage
()
56
{}
57
58
OPM_HOST_DEVICE
explicit
ConditionalStorage
(
const
T& v)
59
: data_(v)
60
{}
61
62
OPM_HOST_DEVICE
explicit
ConditionalStorage
(T&& v)
63
: data_(std::move(v))
64
{}
65
66
template
<
class
...Args>
67
OPM_HOST_DEVICE
ConditionalStorage
(Args... args)
68
: data_(args...)
69
{}
70
71
OPM_HOST_DEVICE
ConditionalStorage
(
const
ConditionalStorage
& t)
72
: data_(t.data_)
73
{};
74
75
OPM_HOST_DEVICE
ConditionalStorage
(
ConditionalStorage
&& t)
76
: data_(std::move(t.data_))
77
{};
78
79
OPM_HOST_DEVICE
ConditionalStorage
& operator=(
const
ConditionalStorage
& v)
80
{
81
data_ = v.data_;
82
return
*
this
;
83
}
84
85
OPM_HOST_DEVICE
ConditionalStorage
& operator=(
ConditionalStorage
&& v)
86
{
87
data_ = std::move(v.data_);
88
return
*
this
;
89
}
90
91
OPM_HOST_DEVICE
const
T& operator*()
const
92
{
return
data_; }
93
OPM_HOST_DEVICE T& operator*()
94
{
return
data_; }
95
96
OPM_HOST_DEVICE
const
T* operator->()
const
97
{
return
&data_; }
98
OPM_HOST_DEVICE T* operator->()
99
{
return
&data_; }
100
101
OPM_HOST_DEVICE
operator
const
T&()
const
102
{
return
data_; }
103
OPM_HOST_DEVICE
operator
T&()
104
{
return
data_; }
105
106
private
:
107
T data_{};
108
};
109
110
template
<
class
T>
111
class
ConditionalStorage
<false, T>
112
{
113
public
:
114
typedef
T type;
115
static
constexpr
bool
condition =
false
;
116
117
OPM_HOST_DEVICE
ConditionalStorage
()
118
{
119
static_assert
(std::is_default_constructible_v<T>);
120
}
121
122
OPM_HOST_DEVICE
explicit
ConditionalStorage
(
const
T&)
123
{
124
static_assert
(std::is_copy_constructible_v<T>);
125
}
126
127
OPM_HOST_DEVICE
ConditionalStorage
(
const
ConditionalStorage
&)
128
{
129
// copying an empty conditional storage object does not do anything.
130
};
131
132
template
<
class
...Args>
133
OPM_HOST_DEVICE
ConditionalStorage
(Args...)
134
{
135
static_assert
(std::is_constructible_v<T, Args...>);
136
}
137
138
OPM_HOST_DEVICE
ConditionalStorage
& operator=(
const
ConditionalStorage
&)
139
{
140
static_assert
(std::is_copy_assignable_v<T>);
141
return
*
this
;
142
}
143
144
};
145
146
}
// namespace Opm
147
148
#endif
Opm::ConditionalStorage
A simple class which only stores a given member attribute if a boolean condition is true.
Definition
ConditionalStorage.hpp:50
Opm
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition
Exceptions.hpp:30
opm
material
common
ConditionalStorage.hpp
Generated by
1.9.8