Medical Imaging Interaction Toolkit  2016.11.0
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 /*=========================================================================
17 
18  Library: CTK
19 
20  Copyright (c) Kitware Inc.
21 
22  Licensed under the Apache License, Version 2.0 (the "License");
23  you may not use this file except in compliance with the License.
24  You may obtain a copy of the License at
25 
26  http://www.apache.org/licenses/LICENSE-2.0.txt
27 
28  Unless required by applicable law or agreed to in writing, software
29  distributed under the License is distributed on an "AS IS" BASIS,
30  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31  See the License for the specific language governing permissions and
32  limitations under the License.
33 
34 =========================================================================*/
35 
36 #ifndef __mitkCommandLineParser_h
37 #define __mitkCommandLineParser_h
38 
39 #include <map>
40 #include <usAny.h>
41 
42 #include <MitkCommandLineExports.h>
43 
44 #ifdef _MSC_VER
45 #pragma warning(push)
46 #pragma warning(disable : 4251)
47 #endif
48 
78 {
79 public:
80  enum Type
81  {
82  String = 0,
83  Bool = 1,
85  Int = 3,
86  Float = 4,
87  InputDirectory = 5,
88  InputFile = 6,
89  OutputDirectory = 7,
90  OutputFile = 8,
91  InputImage = 9
92  };
93 
94  typedef std::vector<std::string> StringContainerType;
95 
97 
99 
120  std::map<std::string, us::Any> parseArguments(const StringContainerType &arguments, bool *ok = nullptr);
121 
126  std::map<std::string, us::Any> parseArguments(int argc, char **argv, bool *ok = nullptr);
127 
135  std::string errorString() const;
136 
146  const StringContainerType &unparsedArguments() const;
147 
158  bool argumentAdded(const std::string &argument) const;
159 
168  bool argumentParsed(const std::string &argument) const;
169 
215  void addArgument(const std::string &longarg,
216  const std::string &shortarg,
217  Type type,
218  const std::string &argLabel,
219  const std::string &argHelp = std::string(),
220  const us::Any &defaultValue = us::Any(),
221  bool optional = true,
222  bool ignoreRest = false,
223  bool deprecated = false);
224 
237  void addDeprecatedArgument(const std::string &longarg,
238  const std::string &shortarg,
239  const std::string &argLabel,
240  const std::string &argHelp);
241 
256  bool setExactMatchRegularExpression(const std::string &argument,
257  const std::string &expression,
258  const std::string &exactMatchFailedMessage);
259 
265  std::string::size_type fieldWidth() const;
266 
275  std::string helpText() const;
276 
301  void setArgumentPrefix(const std::string &longPrefix, const std::string &shortPrefix);
302 
313  void beginGroup(const std::string &description);
314 
320  void endGroup();
321 
328  void setStrictModeEnabled(bool strictMode);
329 
333  void generateXmlOutput();
334 
340  void setTitle(std::string title);
346  void setContributor(std::string contributor);
352  void setCategory(std::string category);
358  void setDescription(std::string description);
368  void changeParameterGroup(std::string name, std::string tooltip);
369 
370 private:
371  class ctkInternal;
372  ctkInternal *Internal;
373 
374  std::string Title;
375  std::string Contributor;
376  std::string Category;
377  std::string Description;
378  std::string ParameterGroupName;
379  std::string ParameterGroupDescription;
380 };
381 
382 #endif
#define MITKCOMMANDLINE_EXPORT
Definition: usAny.h:163
int Int
Definition: jsoncpp.h:158
std::vector< std::string > StringList
std::vector< std::string > StringContainerType