paramarray.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_paramarray_hh
22 #define mia_core_paramarray_hh
23 
25 
26 #include <cassert>
27 
28 namespace mia {
29 
30 template <typename T>
32 public:
33  TPerLevelScalarParam(T default_value);
34 
35  PCmdOption create_level_params_option(const char* long_name,
36  char short_name,
37  EParameterBounds flags,
38  const std::vector<T>& boundaries,
39  const char* help);
40 
41  PCmdOption create_level_params_option(const char* long_name,
42  char short_name,
43  const char* help);
44 
45 
46  T operator [](unsigned l)const;
47 private:
48  std::vector<T> m_params;
49  T m_default_value;
50 };
51 
52 template <typename T>
54  m_default_value(default_value)
55 {
56 }
57 
58 template <typename T>
60  char short_opt,
61  EParameterBounds bflags,
62  const std::vector<T>& boundaries,
63  const char* help)
64 {
65  return PCmdOption(new CParamOption( short_opt, long_opt,
66  new TBoundedParameter<std::vector<T> >(m_params, bflags,
67  boundaries, false, help)));
68 }
69 
70 template <typename T>
72  char short_opt,
73  const char* help)
74 {
75  return PCmdOption(new CParamOption( short_opt, long_opt,
76  new CTParameter<std::vector<T> >(m_params, false, help)));
77 }
78 
79 template <typename T>
81 {
82  if (m_params.empty())
83  return m_default_value;
84  return l < m_params.size() ? m_params[l] : m_params[m_params.size() - 1];
85 }
86 
87 
88 } // namespace mia
89 
90 #endif
T operator[](unsigned l) const
Definition: paramarray.hh:80
TPerLevelScalarParam(T default_value)
Definition: paramarray.hh:53
Generic type of a complex paramter.
Definition: parameter.hh:169
EParameterBounds
Scalar parameter with an expected value range.
Definition: parameter.hh:214
command line option that handles a parameter
Definition: paramoption.hh:36
std::shared_ptr< CCmdOption > PCmdOption
a shared pointer definition of the Option
Definition: cmdoption.hh:180
PCmdOption create_level_params_option(const char *long_name, char short_name, EParameterBounds flags, const std::vector< T > &boundaries, const char *help)
Definition: paramarray.hh:59