netxsimdg
Loading...
Searching...
No Matches
ArgV.cpp
Go to the documentation of this file.
1
8#include "ArgV.hpp"
9
10namespace Nextsim {
11
12ArgV::ArgV(std::vector<std::string> vs)
13{
14 nStrings = vs.size();
15 ppc = new char*[nStrings + 1]; // Add 1 for the conventional final \0
16 for (int i = 0; i < nStrings; ++i) {
17 int len = vs[i].size();
18 char* pc = new char[len + 1];
19 for (int j = 0; j < len; ++j) {
20 pc[j] = vs[i][j];
21 }
22 pc[len] = '\0';
23 ppc[i] = pc;
24 }
25 // Ensure argv[argc] = "\0", as required by the standard.
26 char* pnull = new char[1];
27 pnull[0] = '\0';
28 ppc[nStrings] = pnull;
29}
30
31ArgV::~ArgV()
32{
33 for (int i = 0; i < nStrings; ++i) {
34 delete[] ppc[i];
35 }
36 delete[] ppc;
37}
38
39char** ArgV::operator()() { return ppc; }
40
41int ArgV::argc() { return nStrings; }
42}