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>
31
33
34
45template <typename T>
47{
48public:
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;
78private:
79 std::string m_key;
80};
81
82
83template <typename T>
85 m_key(key)
86{
87}
88
89
90template <typename T>
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
101template <typename T>
103{
104 return CDatapool::instance().has_key(m_key);
105}
106
107
108template <typename T>
110{
111 return !m_key.empty();
112}
113
114template <typename T>
115const std::string& TDelayedParameter<T>::get_key() const
116{
117 return m_key;
118}
119
121
122#endif
bool has_key(const std::string &key) const
static CDatapool & instance()
A parameter proxy object with a key to identify it.
const T get() const
bool key_is_valid() const
const std::string & get_key() const
bool pool_has_key() const
TDelayedParameter()=default
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition defines.hh:33
#define NS_MIA_END
conveniance define to end the mia namespace
Definition defines.hh:36