PSCF v1.1
CommandLine.h
1#ifndef COMMAND_LINE_H
2#define COMMAND_LINE_H
3
4/*
5* Simpatico - Simulation Package for Polymeric and Molecular Liquids
6*
7* Copyright 2010 - 2017, The Regents of the University of Minnesota
8* Distributed under the terms of the GNU General Public License.
9*/
10
11#include "TestException.h"
12
13#include <string>
14#include <vector>
15
22{
23
24public:
25
30 { clear(); }
31
35 void append(const char* arg)
36 { strings_.push_back(std::string(arg)); }
37
41 void clear()
42 {
43 argv_.clear();
44 strings_.clear();
45 append("");
46 // Empty string is a substitute for the executable name.
47 // The C standard says that the first argument argv[0] should
48 // be the executable name, or an empty string if unknown.
49 }
50
54 int argc()
55 { return strings_.size(); }
56
62 char** argv()
63 {
64 argv_.clear();
65 for (unsigned int i = 0; i < strings_.size(); ++i) {
66 argv_.push_back(const_cast<char*>(strings_[i].c_str()));
67 }
68 return &(argv_[0]);
69 }
70
71private:
72
73 std::vector<std::string> strings_;
74 std::vector<char*> argv_;
75
76};
77#endif
Abstraction of a C array of command line arguments.
Definition: CommandLine.h:22
void clear()
Clear all arguments.
Definition: CommandLine.h:41
char ** argv()
Return array of C-string command line argument strings.
Definition: CommandLine.h:62
int argc()
Return number of command line arguments.
Definition: CommandLine.h:54
void append(const char *arg)
Add a command line argument string.
Definition: CommandLine.h:35
CommandLine()
Constructor.
Definition: CommandLine.h:29