File: antsCommandLineOption.h

package info (click to toggle)
ants 2.1.0-5
  • links: PTS, VCS
  • area: main
  • in suites: sid, stretch
  • size: 10,656 kB
  • sloc: cpp: 84,137; sh: 11,419; perl: 694; xml: 115; makefile: 74; python: 48
file content (213 lines) | stat: -rw-r--r-- 5,171 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/*=========================================================================

  Program:   Advanced Normalization Tools
  Module:    $RCSfile: antsCommandLineOption.h,v $
  Language:  C++
  Date:      $Date: 2009/01/22 22:48:30 $
  Version:   $Revision: 1.1 $

  Copyright (c) ConsortiumOfANTS. All rights reserved.
  See accompanying COPYING.txt or
 http://sourceforge.net/projects/advants/files/ANTS/ANTSCopyright.txt for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#ifndef __antsCommandLineOption_h
#define __antsCommandLineOption_h

#include "itkDataObject.h"
#include "itkObjectFactory.h"
#include "itkMacro.h"
#include "itkNumericTraits.h"

#include <list>
#include <string>
#include <deque>

namespace itk
{
namespace ants
{
/** \class CommandLineOption
    \brief Simple data structure for holding command line options.
    An option can have multiple values with each value holding 0 or more
    parameters.  E.g. suppose we were creating an image registration program
    which has several transformation model options such as 'rigid', 'affine',
    and 'deformable'.  A instance of the command line option could have a
    long name of "transformation", short name 't', and description
    "Transformation model---rigid, affine, or deformable".  The values for
    this option would be "rigid", "affine", and "deformable".  Each value
    would then hold parameters that relate to that value.  For example, a
    possible subsection of the command line would be

    " --transformation rigid[parameter1,parameter2,etc.]
      -m mutualinformation[parameter1] --optimization gradientdescent"
*/

class OptionFunction
  : public       DataObject
{
public:
  OptionFunction() :
    m_Name( "" ),
    m_ArgOrder( 0 ),
    m_StageID( 0 )
  {
  };
  ~OptionFunction()
  {
  };

  typedef OptionFunction     Self;
  typedef DataObject         Superclass;
  typedef SmartPointer<Self> Pointer;

  itkNewMacro( Self );

  itkTypeMacro( Option, DataObject );

  typedef std::deque<std::string> ParameterStackType;

  itkSetMacro( Name, std::string );
  itkGetConstMacro( Name, std::string );

  itkSetMacro( ArgOrder, unsigned int );
  itkGetConstMacro( ArgOrder, unsigned int );

  itkSetMacro( StageID, unsigned int );
  itkGetConstMacro( StageID, unsigned int );

  ParameterStackType GetParameters()
  {
    return this->m_Parameters;
  }

  void SetParameters( ParameterStackType parameters )
  {
    this->m_Parameters = parameters;
    this->Modified();
  }

  std::string GetParameter( unsigned int i = 0 )
  {
    if( i < this->m_Parameters.size() )
      {
      return this->m_Parameters[i];
      }
    else
      {
      std::string empty( "" );
      return empty;
      }
  }

  unsigned int GetNumberOfParameters()
  {
    return this->m_Parameters.size();
  }

private:
  std::string        m_Name;
  unsigned int       m_ArgOrder;
  unsigned int       m_StageID;
  ParameterStackType m_Parameters;
};

class CommandLineOption
  : public       DataObject
{
public:
  typedef CommandLineOption  Self;
  typedef DataObject         Superclass;
  typedef SmartPointer<Self> Pointer;

  itkNewMacro( Self );

  itkTypeMacro( Option, DataObject );

  typedef OptionFunction OptionFunctionType;

  typedef std::deque<OptionFunctionType::Pointer> FunctionStackType;
  typedef std::deque<std::string>                 UsageOptionStackType;

  FunctionStackType GetFunctions()
  {
    return this->m_OptionFunctions;
  }

  unsigned int GetNumberOfFunctions()
  {
    return this->m_OptionFunctions.size();
  }

  OptionFunction::Pointer GetFunction( unsigned int i = 0 )
  {
    if( i < this->m_OptionFunctions.size() )
      {
      return this->m_OptionFunctions[i];
      }
    else
      {
      return ITK_NULLPTR;
      }
  }

  UsageOptionStackType GetUsageOptions()
  {
    return this->m_UsageOptions;
  }

  unsigned int GetNumberOfUsageOptions()
  {
    return this->m_UsageOptions.size();
  }

  std::string GetUsageOption( unsigned int i = 0 )
  {
    if( i < this->m_UsageOptions.size() )
      {
      return this->m_UsageOptions[i];
      }
    else
      {
      return std::string( "" );
      }
  }

  itkSetMacro( ShortName, char );
  itkGetConstMacro( ShortName, char );

  itkSetMacro( LongName, std::string );
  itkGetConstMacro( LongName, std::string );

  itkSetMacro( Description, std::string );
  itkGetConstMacro( Description, std::string );

  void AddFunction( std::string, char, char, unsigned int order = 0 );

  void AddFunction( std::string s )
  {
    this->AddFunction( s, '[', ']' );
  }

  void SetUsageOption( unsigned int, std::string );

protected:
  CommandLineOption();
  virtual ~CommandLineOption()
  {
  };
private:
  char                 m_ShortName;
  std::string          m_LongName;
  std::string          m_Description;
  UsageOptionStackType m_UsageOptions;
  FunctionStackType    m_OptionFunctions;
};
} // end namespace ants
} // end namespace itk

#endif