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 
33 
34 
45 template <typename T>
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>
84  m_key(key)
85 {
86 }
87 
88 
89 template <typename T>
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>
101 {
102  return CDatapool::instance().has_key(m_key);
103 }
104 
105 
106 template <typename T>
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 
119 
120 #endif
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
boost::any get(const std::string &key) const
bool has_key(const std::string &key) const
bool pool_has_key() const
const std::string & get_key() const
TDelayedParameter()=default
bool key_is_valid() const
const T get() const
static CDatapool & instance()
A parameter proxy object with a key to identify it.
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36