-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathGet_Input.cpp
More file actions
71 lines (70 loc) · 2.37 KB
/
Get_Input.cpp
File metadata and controls
71 lines (70 loc) · 2.37 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
/**
* @author Ashwin K J
* @file
* Implementing Get_Input.hpp
*/
#include "Get_Input.hpp"
#include "Diff_Mapping.hpp"
#include "Module.hpp"
namespace hydrogen_framework {
bool Hydrogen::validateInputs(int c, char *files[]) {
for (int index = 1; index < c; index++) {
std::string file = files[index];
struct stat buffer;
int status = stat(file.c_str(), &buffer);
if (status == -1) {
if (file == hydrogenDemarcation) {
continue;
} // End check for hydrogenDemarcation
std::cerr << file << " not accessible\n"
<< "Please recheck the input\n";
return false;
} // End check for status
} // End loop for inputs
return true;
} // End validateInputs
bool Hydrogen::processInputs(int c, char *files[]) {
int countModules = 0;
/* Getting all the modules first */
int index = 1;
for (; index < c; ++index) {
std::string file = files[index];
if (file == hydrogenDemarcation) {
break;
} // End check for hydrogenDemarcation
countModules++;
Module *module = new Module();
if (!module->setModule(countModules, file)) {
return false;
} // End check for module
hydrogenModules.push_back(module);
} // End module loop
/* Getting the files associated with it */
bool filesForAllVersions = false;
for (int i = 1; i <= countModules; ++i) {
std::list<std::string> versionFiles;
for (++index; index < c; ++index) {
std::string file = files[index];
/* Checking for proper loop exit */
if (file == hydrogenDemarcation) {
if (i == (countModules - 1)) {
filesForAllVersions = true;
} // End check for countModules
break;
} // End check for hydrogenDemarcation
versionFiles.push_back(file);
} // End loop for versionFiles
auto moduleIter = std::find_if(std::begin(hydrogenModules), std::end(hydrogenModules),
[=](Module *mod) { return (mod->getVersion() == i); });
if (moduleIter != hydrogenModules.end()) {
(*moduleIter)->setFiles(versionFiles);
} // End check for hydrogenDemarcation
} // End file loop
if (!filesForAllVersions) {
std::cerr << "Insufficient no of file versions provided\n"
<< "Please recheck your input\n";
return false;
} // End check for filesForAllVersions
return true;
} // End processInputs
} // namespace hydrogen_framework