1 #include <iostream>
2 #include <fstream>
3 #include <BasicFramework.hpp>
4 #include <StringUtils.hpp>
5 #include <CommandOptionWithCommonTimeArg.hpp>
6 #include <TimeString.hpp>
7 
8 using namespace std;
9 using namespace gpstk;
10 
11 // Given that Doxygen removes Doxygen comments when rendering
12 // examples, please do not consider the absence of comments in the
13 // HTML rendering to be representative.  Refer to the file in the
14 // depot instead.
15 
16 // Interesting examples:
17 // CommandOption5
18 // CommandOption5 --scream
19 // CommandOption5 --hush
20 // CommandOption5 -x
21 // CommandOption5 -xxxxyyz
22 // CommandOption5 -xxxxyyz --hush
23 
24 /// Example of using CommandOptionNOf in an application.
25 class CommandOption5Example : public BasicFramework
26 {
27 public:
28       /// Initialize command-line arguments
29    CommandOption5Example(const string& applName);
30       /// Process command-line arguments
31    bool initialize(int argc, char *argv[], bool pretty = true) throw() override;
32       /// Do the processing.
33    void process() override;
34       /// Clean up.
35    void shutDown() override;
36       /// generic option x
37    CommandOptionNoArg xOpt;
38       /// generic option y
39    CommandOptionNoArg yOpt;
40       /// generic option z
41    CommandOptionNoArg zOpt;
42       /// Virtual option that is "set" if x y or z are in use
43    CommandOptionGroupOr xyzOpts;
44 
45       /// Option for demonstrating CommandOptionOneOf
46    CommandOptionNoArg screamOpt;
47       /// Option for demonstrating CommandOptionOneOf
48    CommandOptionNoArg hushOpt;
49       /// Make sure only one of hushOpt or screamOpt are used
50    CommandOptionMutex hushOrScreamOpt;
51       /// Make sure that if xyz options are used, hush is specified
52    CommandOptionDependent hushAndXYZOpt;
53 };
54 
55 
56 CommandOption5Example ::
CommandOption5Example(const string & applName)57 CommandOption5Example(const string& applName)
58       : BasicFramework(applName, "Example application for CommandOption"),
59         xOpt('x', "", "you say you want an x"),
60         yOpt('y', "", "you say you want an y"),
61         zOpt('z', "", "you say you want an z"),
62         screamOpt(0, "scream", "print a message very loudly"),
63         hushOpt(0, "hush", "don't print a message very loudly"),
64         hushAndXYZOpt(&xyzOpts, &hushOpt)
65 {
66       // One of these options must be used if hush is used
67    xyzOpts.addOption(&xOpt);
68    xyzOpts.addOption(&yOpt);
69    xyzOpts.addOption(&zOpt);
70       // Only one of these options may be specified.
71    hushOrScreamOpt.addOption(&screamOpt);
72    hushOrScreamOpt.addOption(&hushOpt);
73 }
74 
75 
76 bool CommandOption5Example ::
initialize(int argc,char * argv[],bool pretty)77 initialize(int argc, char *argv[], bool pretty) throw()
78 {
79    if (!BasicFramework::initialize(argc, argv, pretty))
80       return false;
81    if (screamOpt)
82    {
83       cout << "HELLO WORLD x" << screamOpt.getCount() << endl;
84    }
85    if (hushOpt)
86    {
87       cout << "ok i'll be quiet x" << hushOpt.getCount() << endl;
88    }
89       // whichOne returns the option that was used
90    CommandOption *which = hushOrScreamOpt.whichOne();
91    if (which != nullptr)
92    {
93       cout << "You used " << which->getFullOptionString() << endl;
94    }
95    cout << "You specified x,y, and/or z a total of " << xyzOpts.getCount()
96         << " times" << endl;
97    return true;
98 }
99 
100 
101 void CommandOption5Example ::
process()102 process()
103 {
104    cout << "Nothing to do" << endl;
105 }
106 
107 
108 void CommandOption5Example ::
shutDown()109 shutDown()
110 {
111    cout << "Shutting down" << endl;
112 }
113 
114 
main(int argc,char * argv[])115 int main(int argc, char *argv[])
116 {
117    try
118    {
119       CommandOption5Example app(argv[0]);
120       if (app.initialize(argc, argv))
121       {
122          app.run();
123       }
124       return app.exitCode;
125    }
126    catch (gpstk::Exception& e)
127    {
128       cerr << e << endl;
129    }
130    catch (std::exception& e)
131    {
132       cerr << e.what() << endl;
133    }
134    catch (...)
135    {
136       cerr << "Caught unknown exception" << endl;
137    }
138    return gpstk::BasicFramework::EXCEPTION_ERROR;
139 }
140