-
Notifications
You must be signed in to change notification settings - Fork 24
/
utils.cpp
52 lines (45 loc) · 1.03 KB
/
utils.cpp
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
#include "utils.h"
#include <fstream>
#include <vector>
#include <string>
#include <cstring>
using namespace std;
InitSys::InitSys(const std::string inifile)
{
ifstream instr(inifile.c_str());
if(!instr)
throw("unable to open file");
// save to a vector
string instrument;
vector<string> instrv;
while (instr >> instrument) {
instrv.push_back(instrument);
}
instr.close();
// construct the char**
iInstrumentID = instrv.size();
ppInstrumentID = new char*[iInstrumentID ];
for (int i=0; i != iInstrumentID ; ++i)
{
char* temp = strcpy(new char[instrv[i].length() + 1], instrv[i].c_str());
ppInstrumentID[i] = temp;
}
}
char** InitSys::getInstrument(void)
{
return ppInstrumentID;
}
int InitSys::getInstrCount(void)
{
return iInstrumentID;
}
InitSys::~InitSys()
{
// delete all memory newed;
for (int i=0; i != iInstrumentID; ++i)
{
delete[] ppInstrumentID[i];
}
delete ppInstrumentID;
ppInstrumentID = NULL;
}