-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogfileConfig.cpp
More file actions
166 lines (145 loc) · 3.95 KB
/
logfileConfig.cpp
File metadata and controls
166 lines (145 loc) · 3.95 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#include "logfileConfig.h"
LogfileConfig::LogfileConfig(std::string incfgfile) : config_file(incfgfile)
{
std::string line;
std::string buf;
std::ifstream cfg(config_file);
while (std::getline(cfg, line))
{
// ignore empty line
if (line.size() == 0)
{
std::cout << "Ignored empty line " << std::endl;
continue;
}
// ignore the comments
if (line.at(0) == '#')
{
std::cout << "Ignored comments - " << line << std::endl;
continue;
}
// convert the line in to stream:
std::istringstream iss(line);
// declare vector of string (instead of fixed array)
std::vector<std::string> tokens;
// read the line, word by word
while (std::getline(iss, buf, ':'))
{
tokens.push_back(buf);
}
// std::cout << "tokens: " << tokens[0] << tokens[1] << std::endl;
configProps.insert(std::pair<std ::string, std ::string>(tokens[0], tokens[1]));
tokens.clear();
}
// std::map<std::string, std::string>::iterator it = configProps.begin();
// for (; it != configProps.end(); ++it)
// std::cout << it->first << " => " << it->second << '\n';
init();
cfg.close();
}
bool LogfileConfig::init()
{
std::filesystem::path output_dir{""};
std::string result = "";
// initialise output directory
if (configProps.find("Output_Dir") != configProps.end())
{
result = configProps["Output_Dir"];
output_dir.assign(result);
if (std::filesystem::exists(output_dir))
std::cout << " exists\n";
else
{
std::cout << " does not exist\n";
std::filesystem::create_directory(output_dir);
}
}
// initialise other configuration if needed
return true;
}
std::string LogfileConfig::getRootDir()
{
std::string result = "";
if (configProps.find("Root_Dir") != configProps.end())
{
result = configProps["Root_Dir"];
}
std::cout << "Root_Dir: " << result << std::endl;
return result;
}
std::string LogfileConfig::getOutputDir()
{
std::string result = "";
if (configProps.find("Output_Dir") != configProps.end())
{
result = configProps["Output_Dir"];
}
std::cout << "Output_Dir: " << result << std::endl;
return result;
}
std::vector<std::string> LogfileConfig::getLookupFiles(std::string marker)
{
// declare vector of string (instead of fixed array)
std::vector<std::string> logfiles;
std::string buf;
if (configProps.find(marker) != configProps.end())
{
std::string tokens = configProps[marker];
// convert the line in to stream:
std::istringstream iss(tokens);
// read the line, word by word
while (std::getline(iss, buf, ';'))
{
logfiles.push_back(buf);
}
}
return logfiles;
}
std::vector<std::string> LogfileConfig::getRelatedFiles(std::string marker)
{
// declare vector of string (instead of fixed array)
std::vector<std::string> logfiles;
std::string buf;
if (configProps.find(marker) != configProps.end())
{
std::string tokens = configProps[marker];
// convert the line in to stream:
std::istringstream iss(tokens);
// read the line, word by word
while (std::getline(iss, buf, ';'))
{
logfiles.push_back(buf);
}
}
return logfiles;
}
std::string LogfileConfig::getInspectFile()
{
std::string result = "";
if (configProps.find("Inspect_Filename") != configProps.end())
{
result = configProps["Inspect_Filename"];
}
std::cout << "Inspect_Filename: " << result << std::endl;
return result;
}
std::string LogfileConfig::getMarkerString()
{
std::string result = "";
if (configProps.find("Marker_String") != configProps.end())
{
result = configProps["Marker_String"];
}
// std::cout << "Marker_String: " << result << std::endl;
return result;
}
int LogfileConfig::getInspectionDuration()
{
int duration = 0;
if (configProps.find("Inspection_Duration") != configProps.end())
{
duration = stoi(configProps["Inspection_Duration"]);
}
// std::cout << "Inspection_Duration: " << duration << std::endl;
return duration;
}