ewmscp  ..
optionExample.cpp
Go to the documentation of this file.
1 #include "OptionsChrono.h"
2 #include <list>
4 
5 
6 int main(int argc, const char *argv[]) {
7  options::single<int> number('N', "number", "some number", 0);
8  options::single<int> number2('k', "kumber", "some other number", 0, {0, 3, 3});
9  options::map<int, std::vector<std::pair<std::string, int> > > numbers('m', "numbers", "several numbers");
10  options::map<std::string, std::list<std::pair<std::string, std::string> > > strings('s', "strings", "several strings");
11  options::single<const char *>cs('c', "cstring", "a c string", "", {"bla", "blubb"});
12  options::single<std::string>Cs('C', "Cstring", "a C++ string", "", {"bla", "blubb"});
13  options::container<double> dnums('d', "doubles", "double numbers");
14  // options::container<const char*, std::list<const char*>> stringl('S', "listString", "list of strings");
15  options::container<std::string, std::list<std::string>> stringS('X', "liststring", "list of std::strings");
16  options::single<double> complexDescription('\0', "ComplexDescription", "Pass here the Bremsstrahl-Tagging-Hodoscope-Engineering-Assemply-Rate in Hz", 84.);
17  options::single<double> moreComplexDescription('\0', "MoreComplexDescription", "very complicated example option with very long explanation to illustrate automatic wrapping in help output when the explanations become very long and would break readability otherwise.", 42.);
18  options::single<double> evenMoreComplexDescription('\0', "EvenMoreComplexDescription", "very complicated example option with very long explanation containing averylongwordwhichisunbreakableandthustriggersforcefulwordwrappinginaninconvenientplacetokeepthingssomehowatleastabitreadable.", 21.);
19 
20  options::single<options::postFixedNumber<size_t>> size('\0', "size", "a size");
21  options::single<std::chrono::system_clock::time_point> date('\0', "date", "a date");
22  options::single<std::chrono::duration<long>> dur('\0', "dur", "a duration");
23  options::single<bool> lateOption('\0', "lateOption", "try to book an option late", false);
24  cs.fForbid(&Cs);
25  Cs.fForbid(&cs);
26 
27  options::container<std::chrono::system_clock::time_point> dates('\0', "dates", "list of dates");
28 
29  options::OptionsForTApplication TApplicationOptions(argv[0]);
30 
31  options::positional<options::single<float>>posNumber(10, "posnumber", "positional float number", 0);
32  options::positional<options::container<std::string>>files(20, "files", "positional file list");
33  options::positional<options::single<const char *>>dest(30, "dest", "positional destination file", "");
34 
35  options::parser parser("option parsing example");
36 
37  parser.fRequire(&number);
38 
39  auto unusedOptions = parser.fParse(argc, argv);
40 
41  TApplicationOptions.fFinalize(unusedOptions.begin(), unusedOptions.end());
42 
43  for (auto & unusedOption : unusedOptions) {
44  std::cout << "unused option : '" << unusedOption << "'" << std::endl;
45  }
46  for (auto & num : numbers) {
47  std::cout << " number '" << num.first << "' is '" << num.second << "'\n";
48  }
49  for (auto & str : strings) {
50  std::cout << " string '" << str.first << "' is '" << str.second << "'\n";
51  }
52  for (double & dnum : dnums) {
53  std::cout << " double number '" << dnum << "'\n";
54  }
55  // for (auto & it : stringl) {
56  // std::cout << " list string '" << it << "'\n";
57  //}
58  for (auto & it : stringS) {
59  std::cout << " list std::string '" << it << "'\n";
60  }
61 
62  std::cout << "and the time variable is:";
63  date.fWriteValue(std::cout);
64  auto timebuf = std::chrono::system_clock::to_time_t(date);
65  std::cout << ", that is " << std::ctime(&timebuf);
66 
67  std::cout << "the duration is: ";
68  dur.fWriteValue(std::cout);
69  std::cout << " or " << std::chrono::duration_cast<std::chrono::hours>(dur).count() << " hours \n";
70 
71  if (lateOption) {
72  options::single<bool> optionLate('\0', "lateOptionTest", "option booked late", false);
73  }
74 
75  return number;
76 }
options::parser
class that contains the parser, i.e. does that option handling
Definition: Options.h:363
options::single< int >
options::single< std::chrono::system_clock::time_point >
Definition: OptionsChrono.h:68
options::single< bool >
class specialisation for options of type bool
Definition: Options.h:595
options::parser::fParse
const std::vector< std::string > & fParse(int argc, const char *argv[])
parse the options on the command line
Definition: Options.cpp:168
options::OptionsForTApplication
specific class to give the options for a TApplication as ForeignApplicationOptions to the option pars...
Definition: OptionsForTApplication.h:10
options::ForeignApplicationOptions::fFinalize
void fFinalize()
build the internal argument vector for the call to the external parser
Definition: OptionsWithForeignParser.cpp:22
options::map
template for map-based options.
Definition: Options.h:671
main
int main(int argc, const char *argv[])
Definition: optionExample.cpp:6
options::container
template for container-based options.
Definition: Options.h:789
OptionsChrono.h
OptionsForTApplication.h
options::single::fWriteValue
void fWriteValue(std::ostream &aStream) const override
write textual representation of value to a std::ostream
Definition: Options.h:569
options::positional
Definition: Options.h:876
options::single< std::chrono::system_clock::time_point >::fWriteValue
void fWriteValue(std::ostream &aStream) const override
write textual representation of value to a std::ostream
Definition: OptionsChrono.cpp:449
options::parser::fRequire
virtual void fRequire(const base *aOtherOption)
Definition: Options.cpp:135