My Project
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 <stdexcept>
32
#include <type_traits>
33
#include <utility>
34
35
namespace
Opm
{
45
template
<
bool
cond,
class
T>
46
class
ConditionalStorage
47
{
48
public
:
49
typedef
T type;
50
static
constexpr
bool
condition = cond;
51
52
ConditionalStorage
()
53
{}
54
55
explicit
ConditionalStorage
(
const
T& v)
56
: data_(v)
57
{}
58
59
explicit
ConditionalStorage
(T&& v)
60
: data_(std::move(v))
61
{}
62
63
template
<
class
...Args>
64
ConditionalStorage
(Args... args)
65
: data_(args...)
66
{}
67
68
ConditionalStorage
(
const
ConditionalStorage
& t)
69
: data_(t.data_)
70
{};
71
72
ConditionalStorage
(
ConditionalStorage
&& t)
73
: data_(std::move(t.data_))
74
{};
75
76
ConditionalStorage
& operator=(
const
ConditionalStorage
& v)
77
{
78
data_ = v.data_;
79
return
*
this
;
80
}
81
82
ConditionalStorage
& operator=(
ConditionalStorage
&& v)
83
{
84
data_ = std::move(v.data_);
85
return
*
this
;
86
}
87
88
const
T& operator*()
const
89
{
return
data_; }
90
T& operator*()
91
{
return
data_; }
92
93
const
T* operator->()
const
94
{
return
&data_; }
95
T* operator->()
96
{
return
&data_; }
97
98
private
:
99
T data_{};
100
};
101
102
template
<
class
T>
103
class
ConditionalStorage
<false, T>
104
{
105
public
:
106
typedef
T type;
107
static
constexpr
bool
condition =
false
;
108
109
ConditionalStorage
()
110
{
111
static_assert
(std::is_default_constructible_v<T>);
112
}
113
114
explicit
ConditionalStorage
(
const
T&)
115
{
116
static_assert
(std::is_copy_constructible_v<T>);
117
}
118
119
ConditionalStorage
(
const
ConditionalStorage
&)
120
{
121
// copying an empty conditional storage object does not do anything.
122
};
123
124
template
<
class
...Args>
125
ConditionalStorage
(Args...)
126
{
127
static_assert
(std::is_constructible_v<T, Args...>);
128
}
129
130
ConditionalStorage
& operator=(
const
ConditionalStorage
&)
131
{
132
static_assert
(std::is_copy_assignable_v<T>);
133
return
*
this
;
134
}
135
136
const
T& operator*()
const
137
{
throw
std::logic_error(
"data member deactivated"
); }
138
T& operator*()
139
{
throw
std::logic_error(
"data member deactivated"
); }
140
141
const
T* operator->()
const
142
{
throw
std::logic_error(
"data member deactivated"
); }
143
T* operator->()
144
{
throw
std::logic_error(
"data member deactivated"
); }
145
};
146
147
}
// namespace Opm
148
149
#endif
Opm::ConditionalStorage
A simple class which only stores a given member attribute if a boolean condition is true.
Definition
ConditionalStorage.hpp:47
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