Main Page
Related Pages
Modules
Data Structures
Files
File List
Globals
mia
core
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-2013 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
private
:
76
std::string m_key;
77
};
78
79
80
template
<
typename
T>
81
TDelayedParameter<T>::TDelayedParameter
(
const
std::string& key):
82
m_key(key)
83
{
84
}
85
86
87
template
<
typename
T>
88
const
T
TDelayedParameter<T>::get
()
const
89
{
90
if
(!(
CDatapool::instance
().has_key(m_key))) {
91
throw
create_exception<std::invalid_argument>(
"TDelayedParameter::get(): Key '"
, m_key,
92
"' is not availabe in the data pool"
);
93
}
94
return
boost::any_cast<T>(
CDatapool::instance
().
get
(m_key));
95
}
96
97
template
<
typename
T>
98
bool
TDelayedParameter<T>::pool_has_key
()
const
99
{
100
return
CDatapool::instance
().
has_key
(m_key);
101
}
102
103
104
template
<
typename
T>
105
bool
TDelayedParameter<T>::key_is_valid
()
const
106
{
107
return
!m_key.empty();
108
}
109
110
NS_MIA_END
111
112
#endif
Generated on Tue Oct 15 2013 13:56:37 by
1.8.4