-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCommandLine.h
More file actions
77 lines (64 loc) · 1.47 KB
/
CommandLine.h
File metadata and controls
77 lines (64 loc) · 1.47 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
#ifndef COMMAND_LINE_H
#define COMMAND_LINE_H
/*
* Simpatico - Simulation Package for Polymeric and Molecular Liquids
*
* Copyright 2010 - 2017, The Regents of the University of Minnesota
* Distributed under the terms of the GNU General Public License.
*/
#include "TestException.h"
#include <string>
#include <vector>
/**
* Abstraction of a C array of command line arguments.
*
* \ingroup Test_Module
*/
class CommandLine
{
public:
/**
* Constructor.
*/
CommandLine()
{ clear(); }
/**
* Add a command line argument string.
*/
void append(const char* arg)
{ strings_.push_back(std::string(arg)); }
/**
* Clear all arguments.
*/
void clear()
{
argv_.clear();
strings_.clear();
append("");
// Empty string is a substitute for the executable name.
// The C standard says that the first argument argv[0] should
// be the executable name, or an empty string if unknown.
}
/**
* Return number of command line arguments.
*/
int argc()
{ return strings_.size(); }
/**
* Return array of C-string command line argument strings.
*
* \return pointer to C array of null terminated C strings.
*/
char** argv()
{
argv_.clear();
for (unsigned int i = 0; i < strings_.size(); ++i) {
argv_.push_back(const_cast<char*>(strings_[i].c_str()));
}
return &(argv_[0]);
}
private:
std::vector<std::string> strings_;
std::vector<char*> argv_;
};
#endif