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