MCPcopy Create free account
hub / github.com/MITK/MITK / main

Function main

Examples/FirstSteps/NewModule/cmdapps/ExampleToUpperCaseMiniApp.cpp:37–157  ·  view source on GitHub ↗

[main]

Source from the content-addressed store, hash-verified

35
36//! [main]
37int main(int argc, char *argv[])
38{
39 //! [main]
40
41 //! [create parser]
42 mitkCommandLineParser parser;
43
44 // set general information about your MiniApp
45 parser.setCategory("MITK-Examples");
46 parser.setTitle("To Upper Case");
47 parser.setDescription("An example MiniApp that converts the contents of a test file to upper case.");
48 parser.setContributor("German Cancer Research Center (DKFZ)");
49 //! [create parser]
50
51 //! [add arguments]
52 // how should arguments be prefixed
53 parser.setArgumentPrefix("--", "-");
54 // add each argument, unless specified otherwise each argument is optional
55 // see mitkCommandLineParser::addArgument for more information
56 parser.beginGroup("Required I/O parameters");
57 parser.addArgument(
58 "input", "i", mitkCommandLineParser::File, "Input file", "input file (.txt/.example)", us::Any(), false, false, false, mitkCommandLineParser::Input);
59 parser.addArgument("output",
60 "o",
61 mitkCommandLineParser::File,
62 "Output file",
63 "where to save the output (.txt/.example)",
64 us::Any(),
65 false, false, false, mitkCommandLineParser::Output);
66 parser.endGroup();
67
68 parser.beginGroup("Optional parameters");
69 parser.addArgument(
70 "verbose", "v", mitkCommandLineParser::Bool, "Verbose Output", "Whether to produce verbose output");
71 parser.endGroup();
72 //! [add arguments]
73
74 //! [parse the arguments]
75 // parse arguments, this method returns a mapping of long argument names and their values
76 std::map<std::string, us::Any> parsedArgs = parser.parseArguments(argc, argv);
77
78 if (parsedArgs.size() == 0)
79 return EXIT_FAILURE;
80
81 // parse, cast and set required arguments
82 std::string inFilename = us::any_cast<std::string>(parsedArgs["input"]);
83 std::string outFileName = us::any_cast<std::string>(parsedArgs["output"]);
84
85 // default values for optional arguments
86 bool verbose(false);
87
88 // parse, cast and set optional arguments if given
89 if (parsedArgs.count("verbose"))
90 {
91 verbose = us::any_cast<bool>(parsedArgs["verbose"]);
92 }
93 //! [parse the arguments]
94

Callers

nothing calls this directly

Calls 15

LoadFunction · 0.85
setCategoryMethod · 0.80
setContributorMethod · 0.80
setArgumentPrefixMethod · 0.80
beginGroupMethod · 0.80
addArgumentMethod · 0.80
endGroupMethod · 0.80
parseArgumentsMethod · 0.80
countMethod · 0.80
atMethod · 0.80
GetPointerMethod · 0.80
whatMethod · 0.80

Tested by

no test coverage detected