My Project
delayedparameter.hh
Go to the documentation of this file.
1
/* -*- mia-c++ -*-
2
*
3
* This file is part of MIA - a toolbox for medical image analysis
4
* Copyright (c) Leipzig, Madrid 1999-2017 Gert Wollny
5
*
6
* MIA 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 3 of the License, or
9
* (at your option) any later version.
10
*
11
* This program 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 MIA; if not, see <http://www.gnu.org/licenses/>.
18
*
19
*/
20
21
#ifndef mia_core_delayedparameter_hh
22
#define mia_core_delayedparameter_hh
23
24
#include <string>
25
#include <stdexcept>
26
27
28
#include <
mia/core/defines.hh
>
29
#include <
mia/core/datapool.hh
>
30
#include <
mia/core/errormacro.hh
>
31
32
NS_MIA_BEGIN
33
34
45
template
<
typename
T>
46
class
TDelayedParameter
47
{
48
public
:
49
50
TDelayedParameter
() =
default
;
51
57
TDelayedParameter
(
const
std::string& key);
58
63
const
T
get
()
const
;
64
69
bool
pool_has_key
()
const
;
70
75
bool
key_is_valid
()
const
;
76
77
const
std::string&
get_key
()
const
;
78
private
:
79
std::string m_key;
80
};
81
82
83
template
<
typename
T>
84
TDelayedParameter<T>::TDelayedParameter
(
const
std::string& key):
85
m_key(key)
86
{
87
}
88
89
90
template
<
typename
T>
91
const
T
TDelayedParameter<T>::get
()
const
92
{
93
if
(!(
CDatapool::instance
().has_key(m_key))) {
94
throw
create_exception<std::invalid_argument>(
"TDelayedParameter::get(): Key '"
, m_key,
95
"' is not available in the data pool"
);
96
}
97
98
return
boost::any_cast<T>(
CDatapool::instance
().get(m_key));
99
}
100
101
template
<
typename
T>
102
bool
TDelayedParameter<T>::pool_has_key
()
const
103
{
104
return
CDatapool::instance
().
has_key
(m_key);
105
}
106
107
108
template
<
typename
T>
109
bool
TDelayedParameter<T>::key_is_valid
()
const
110
{
111
return
!m_key.empty();
112
}
113
114
template
<
typename
T>
115
const
std::string&
TDelayedParameter<T>::get_key
()
const
116
{
117
return
m_key;
118
}
119
120
NS_MIA_END
121
122
#endif
NS_MIA_BEGIN
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition:
defines.hh:33
TDelayedParameter::pool_has_key
bool pool_has_key() const
Definition:
delayedparameter.hh:102
NS_MIA_END
#define NS_MIA_END
conveniance define to end the mia namespace
Definition:
defines.hh:36
TDelayedParameter
A parameter proxy object with a key to identify it.
Definition:
delayedparameter.hh:46
errormacro.hh
TDelayedParameter::key_is_valid
bool key_is_valid() const
Definition:
delayedparameter.hh:109
TDelayedParameter::get_key
const std::string & get_key() const
Definition:
delayedparameter.hh:115
CDatapool::has_key
bool has_key(const std::string &key) const
CDatapool::instance
static CDatapool & instance()
TDelayedParameter::TDelayedParameter
TDelayedParameter()=default
TDelayedParameter::get
const T get() const
Definition:
delayedparameter.hh:91
defines.hh
datapool.hh
mia
core
delayedparameter.hh
Generated by
1.8.17