Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitkCommandLineParser.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef mitkCommandLineParser_h
14 #define mitkCommandLineParser_h
15 
16 #include <map>
17 #include <usAny.h>
18 
19 #include <MitkCommandLineExports.h>
20 #include <mitkVersion.h>
21 
46 {
47 public:
50  enum Type
51  {
52  String = 0,
53  Bool = 1,
55  Int = 3,
56  Float = 4,
57  Directory = 5,
58  File = 6,
59  Image = 7
60  };
61 
66  enum Channel
67  {
68  None = 0,
69  Input = 1,
70  Output = 2
71  };
72 
75  typedef std::vector<std::string> StringContainerType;
76 
82 
88 
109  std::map<std::string, us::Any> parseArguments(const StringContainerType &arguments, bool *ok = nullptr);
110 
123  std::map<std::string, us::Any> parseArguments(int argc, char **argv, bool *ok = nullptr);
124 
131  std::string errorString() const;
132 
143 
151  bool argumentAdded(const std::string &argument) const;
152 
161  bool argumentParsed(const std::string &argument) const;
162 
203  void addArgument(const std::string &longarg,
204  const std::string &shortarg,
205  Type type,
206  const std::string &argLabel,
207  const std::string &argHelp = std::string(),
208  const us::Any &defaultValue = us::Any(),
209  bool optional = true,
210  bool ignoreRest = false,
211  bool deprecated = false,
212  mitkCommandLineParser::Channel channel = mitkCommandLineParser::Channel::None);
213 
227  void addDeprecatedArgument(const std::string &longarg,
228  const std::string &shortarg,
229  const std::string &argLabel,
230  const std::string &argHelp);
231 
232 
237  std::vector < std::map<std::string, us::Any> > getArgumentList();
238 
253  bool setExactMatchRegularExpression(const std::string &argument,
254  const std::string &expression,
255  const std::string &exactMatchFailedMessage);
256 
262  std::string::size_type fieldWidth() const;
263 
271  std::string helpText() const;
272 
297  void setArgumentPrefix(const std::string &longPrefix, const std::string &shortPrefix);
298 
309  void beginGroup(const std::string &description);
310 
316  void endGroup();
317 
324  void setStrictModeEnabled(bool strictMode);
325 
330 
336  void setTitle(std::string title);
342  void setContributor(std::string contributor);
348  void setCategory(std::string category);
354  void setDescription(std::string description);
364  void changeParameterGroup(std::string name, std::string tooltip);
365 
366 protected:
367  class ctkInternal;
368  ctkInternal *Internal;
369 
370  std::string Title;
371  std::string Contributor;
372  std::string Category;
373  std::string Description;
374  std::string ParameterGroupName;
376 };
377 
378 
379 
380 #endif
#define MITKCOMMANDLINE_EXPORT
Command line argument parser for MITK applications, based on the CTK command line parser.
bool argumentParsed(const std::string &argument) const
Check if a given argument has been parsed successfully.
void addArgument(const std::string &longarg, const std::string &shortarg, Type type, const std::string &argLabel, const std::string &argHelp=std::string(), const us::Any &defaultValue=us::Any(), bool optional=true, bool ignoreRest=false, bool deprecated=false, mitkCommandLineParser::Channel channel=mitkCommandLineParser::Channel::None)
Add a command line argument.
std::string helpText() const
std::vector< std::map< std::string, us::Any > > getArgumentList()
void setDescription(std::string description)
~mitkCommandLineParser()
Destructor.
void setArgumentPrefix(const std::string &longPrefix, const std::string &shortPrefix)
Channel
I/O channel classification for arguments.
const StringContainerType & unparsedArguments() const
Get all unparsed arguments.
void setContributor(std::string contributor)
std::string errorString() const
Get a detailed error description if a call to parseArguments() failed.
bool setExactMatchRegularExpression(const std::string &argument, const std::string &expression, const std::string &exactMatchFailedMessage)
void setCategory(std::string category)
mitkCommandLineParser()
Construct a parser with default settings.
Type
Supported argument value types.
std::string::size_type fieldWidth() const
void changeParameterGroup(std::string name, std::string tooltip)
void setTitle(std::string title)
bool argumentAdded(const std::string &argument) const
Check if a given argument has been registered.
void addDeprecatedArgument(const std::string &longarg, const std::string &shortarg, const std::string &argLabel, const std::string &argHelp)
void beginGroup(const std::string &description)
std::vector< std::string > StringContainerType
Container type for string lists, used for argument values and unparsed arguments.
std::map< std::string, us::Any > parseArguments(int argc, char **argv, bool *ok=nullptr)
Convenient overload to parse arguments from argc/argv.
void setStrictModeEnabled(bool strictMode)
std::map< std::string, us::Any > parseArguments(const StringContainerType &arguments, bool *ok=nullptr)
Parse a given list of command line arguments.
An Any class represents a general type and is capable of storing any type, supporting type-safe extra...
Definition: usAny.h:145
class ITK_EXPORT Image
std::vector< std::string > StringList
A list of strings, used throughout the DICOM module to hold file paths and similar data.