forked from douglascraigschmidt/CPlusPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOptions.cpp
More file actions
105 lines (89 loc) · 1.85 KB
/
Copy pathOptions.cpp
File metadata and controls
105 lines (89 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#ifndef _OPTIONS_CPP_
#define _OPTIONS_CPP_
#include <iostream>
#include <stdio.h>
#include "getopt.h"
#include "Options.h"
#include "LQueue.h"
#include "LStack.h"
#include "Typedefs.h"
// Initialize the singleton.
Options *
Options::instance_ = 0;
Options*
Options::instance ()
{
// Create the options implementation if it hasn't already been done
if (instance_ == 0)
instance_ = new Options;
return instance_;
}
// Ctor
Options::Options (void)
: verbose_ (false)
{
}
// Dtor
Options::~Options (void)
{
// call free_list_release to clean up our preallocated LQueue_Nodes
LQueue_Node<Component_Node *>::free_list_release ();
LQueue_Node<int>::free_list_release ();
LStack_Node<Component_Node *>::free_list_release ();
LStack_Node<int>::free_list_release ();
}
// Return exe name.
std::string
Options::exe (void) const
{
return exe_;
}
// Return path name.
std::string
Options::path (void) const
{
return path_;
}
bool
Options::verbose (void) const
{
return verbose_;
}
// Parse the command line arguments.
bool
Options::parse_args (int argc, char *argv[])
{
// set exe_ to the first arg.
exe_ = parsing::getfilename (argv[0]);
path_ = parsing::getpath (argv[0]);
char opts[] = "h?v";
for (int c;
(c = parsing::getopt (argc, argv, opts)) != EOF;
)
switch (c)
{
// check to see if the user asked for help
case 'v':
verbose_ = true;
break;
case 'h':
case '?':
print_usage ();
return false;
break;
default:
break;
}
return true;
};
// Parse the command line arguments.
void
Options::print_usage (void)
{
std::cout << "\nHelp Invoked on " << path_ + exe_ << "\n\n";
std::cout << "Usage: " << exe_ << " [-h|-v]\n\n" <<
" -h: invoke help\n" <<
" -v: enter verbose mode\n" <<
"\n";
}
#endif /* _OPTIONS_CPP_ */