iRoCS Toolbox  1.1.0
ParamInfo.hh
Go to the documentation of this file.
1 /**************************************************************************
2  *
3  * Copyright (C) 2004-2015 Olaf Ronneberger, Florian Pigorsch, Jörg Mechnich,
4  * Thorsten Falk
5  *
6  * Image Analysis Lab, University of Freiburg, Germany
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software Foundation,
20  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  *
22  **************************************************************************/
23 
24 /**************************************************************************
25 ** Title:
26 ** $RCSfile$
27 ** $Revision: 4820 $$Name$
28 ** $Date: 2011-11-08 10:57:01 +0100 (Tue, 08 Nov 2011) $
29 ** Copyright: GPL $Author: tschmidt $
30 ** Description:
31 **
32 **
33 **
34 **-------------------------------------------------------------------------
35 **
36 ** $Log$
37 ** Revision 1.1 2004/09/08 14:50:37 ronneber
38 ** - initial revision
39 **
40 **
41 **
42 **************************************************************************/
43 
44 
45 #ifndef PARAMINFO_HH
46 #define PARAMINFO_HH
47 
48 #ifdef HAVE_CONFIG_H
49 #include <config.hh>
50 #endif
51 
52 #include <string>
53 #include <vector>
54 #include <algorithm>
55 #include <map>
56 #include "SVMError.hh"
57 
58 namespace svt
59 {
60  /*-----------------------------------------------------------------------
61  * structure for sotring one alternative vor argument values
62  *-----------------------------------------------------------------------*/
64  {
65  AlternativeHelp( const std::string& v, const std::string& h)
66  :value( v),
67  helpText( h)
68  {}
69  std::string value;
70  std::string helpText;
71  };
72 
73  /*======================================================================*/
81  /*======================================================================*/
82  class ParamInfo
83  {
84 
85 
86  public:
87  /*======================================================================*/
97  /*======================================================================*/
98  ParamInfo( std::string longKey, std::string shortKey,
99  std::string value, std::string helpText)
100  :_longKey( longKey),
101  _shortKey( shortKey)
102  {
103  addAlternative( value, helpText);
104  }
105 
106  /*======================================================================*/
119  /*======================================================================*/
120  ParamInfo( std::string longKey, std::string shortKey)
121  :_longKey( longKey),
122  _shortKey( shortKey)
123  {}
124 
125 
126  void addAlternative( const std::string& value, const std::string& helpText)
127  {
128  _alternatives.push_back( AlternativeHelp( value, helpText));
129  }
130 
131  void addGuiHint( const std::string& key, const std::string& value)
132  {
133  _guiHints[key] = value;
134  }
135 
136 
137  const std::string& longKey() const
138  { return _longKey; }
139 
140  const std::string& shortKey() const
141  { return _shortKey; }
142 
143  size_t nAlternatives() const
144  {
145  return _alternatives.size();
146  }
147 
148  const AlternativeHelp& alternatives( size_t index) const
149  {
150  SVM_ASSERT( index < _alternatives.size());
151  return _alternatives[index];
152  }
153 
154  const std::map<std::string, std::string>& guiHints() const
155  {
156  return _guiHints;
157  }
158 
159  bool operator<( const ParamInfo& rhs) const
160  {
161  if( _longKey < rhs._longKey) return true;
162  if( _longKey > rhs._longKey) return false;
163  if( _shortKey < rhs._shortKey) return true;
164  if( _shortKey > rhs._shortKey) return false;
165  size_t nAlter =
166  std::min(_alternatives.size(), rhs._alternatives.size());
167  for( size_t i = 0; i < nAlter; ++i)
168  {
169  if( _alternatives[i].helpText < rhs._alternatives[i].helpText)
170  return true;
171  if( _alternatives[i].helpText > rhs._alternatives[i].helpText)
172  return false;
173  }
174  return false;
175  }
176 
177  bool operator==( const ParamInfo& rhs) const
178  {
179  if( _longKey != rhs._longKey) return false;
180  if( _shortKey != rhs._shortKey) return false;
181  size_t nAlter =
182  std::min( _alternatives.size(), rhs._alternatives.size());
183  for(size_t i = 0; i < nAlter; ++i)
184  {
185  if( _alternatives[i].helpText != rhs._alternatives[i].helpText)
186  return false;
187  }
188  return true;
189  }
190 
191  void debugPrint(std::ostream& os) const
192  {
193  os << "longKey = " << _longKey << "\n"
194  << "shortKey = " << _shortKey << "\n";
195  for( unsigned int i = 0; i < _alternatives.size(); ++i)
196  {
197  os << "alternative[" << i << "].value = "
198  << _alternatives[i].value << "\n"
199  << "alternative[" << i << "].helpText = "
200  << _alternatives[i].helpText << "\n";
201  }
202  for( std::map<std::string, std::string>::const_iterator
203  p = _guiHints.begin(); p != _guiHints.end(); ++p)
204  {
205  os << "guiHint: " << p->first << " --> " << p->second << "\n";
206  }
207  }
208 
209 
210 
211  private:
212  std::string _longKey;
213  std::string _shortKey;
214  std::vector< AlternativeHelp > _alternatives;
215  std::map<std::string, std::string> _guiHints;
216 
217  };
218 
219  /*======================================================================*/
226  /*======================================================================*/
227  inline void sortAndRemoveDuplicates( std::vector<ParamInfo>& params)
228  {
229  std::sort( params.begin(), params.end());
230  params.erase( std::unique( params.begin(), params.end()), params.end());
231  }
232 
233 
234 
235 
236 
237 }
238 #endif
void debugPrint(std::ostream &os) const
Definition: ParamInfo.hh:191
const std::string & longKey() const
Definition: ParamInfo.hh:137
#define SVM_ASSERT(condition)
Definition: SVMError.hh:176
bool operator<(const ParamInfo &rhs) const
Definition: ParamInfo.hh:159
ParamInfo(std::string longKey, std::string shortKey)
Construtor for keys, that need multiple alternative values, e.g.
Definition: ParamInfo.hh:120
std::string helpText
Definition: ParamInfo.hh:70
void addGuiHint(const std::string &key, const std::string &value)
Definition: ParamInfo.hh:131
size_t nAlternatives() const
Definition: ParamInfo.hh:143
bool operator==(const ParamInfo &rhs) const
Definition: ParamInfo.hh:177
void sortAndRemoveDuplicates(std::vector< ParamInfo > &params)
sort list of ParamInfo&#39;s and remove doubles
Definition: ParamInfo.hh:227
void addAlternative(const std::string &value, const std::string &helpText)
Definition: ParamInfo.hh:126
AlternativeHelp(const std::string &v, const std::string &h)
Definition: ParamInfo.hh:65
ParamInfo(std::string longKey, std::string shortKey, std::string value, std::string helpText)
Construtor for keys, that need only one helpText (e.g.
Definition: ParamInfo.hh:98
const std::string & shortKey() const
Definition: ParamInfo.hh:140
const AlternativeHelp & alternatives(size_t index) const
Definition: ParamInfo.hh:148
The ParamInfo class contains informations about one parameter like key, help text, guiHints etc.
Definition: ParamInfo.hh:82
std::string value
Definition: ParamInfo.hh:69
const std::map< std::string, std::string > & guiHints() const
Definition: ParamInfo.hh:154