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
public
:
48
49
TDelayedParameter
() =
default
;
50
56
TDelayedParameter
(
const
std::string& key);
57
62
const
T
get
()
const
;
63
68
bool
pool_has_key
()
const
;
69
74
bool
key_is_valid
()
const
;
75
76
const
std::string&
get_key
()
const
;
77
private
:
78
std::string m_key;
79
};
80
81
82
template
<
typename
T>
83
TDelayedParameter<T>::TDelayedParameter
(
const
std::string& key):
84
m_key(key)
85
{
86
}
87
88
89
template
<
typename
T>
90
const
T
TDelayedParameter<T>::get
()
const
91
{
92
if
(!(
CDatapool::instance
().has_key(m_key))) {
93
throw
create_exception<std::invalid_argument>(
"TDelayedParameter::get(): Key '"
, m_key,
94
"' is not available in the data pool"
);
95
}
96
return
boost::any_cast<T>(
CDatapool::instance
().get(m_key));
97
}
98
99
template
<
typename
T>
100
bool
TDelayedParameter<T>::pool_has_key
()
const
101
{
102
return
CDatapool::instance
().
has_key
(m_key);
103
}
104
105
106
template
<
typename
T>
107
bool
TDelayedParameter<T>::key_is_valid
()
const
108
{
109
return
!m_key.empty();
110
}
111
112
template
<
typename
T>
113
const
std::string&
TDelayedParameter<T>::get_key
()
const
114
{
115
return
m_key;
116
}
117
118
NS_MIA_END
119
120
#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:100
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:107
TDelayedParameter::get_key
const std::string & get_key() const
Definition:
delayedparameter.hh:113
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:90
defines.hh
datapool.hh
mia
core
delayedparameter.hh
Generated by
1.8.17