-
Notifications
You must be signed in to change notification settings - Fork 1
/
world.cpp
73 lines (60 loc) · 1.69 KB
/
world.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <generator.h>
using namespace generator;
using namespace std;
std::map<std::string *, Module *>::iterator World::modulesIterBegin()
{
return this->Modules->begin();
}
std::map<std::string *, Module *>::iterator World::modulesIterEnd()
{
return this->Modules->end();
}
bool World::moduleAdd(std::string *name, Module *m)
{
this->Modules->insert(std::pair<std::string *, Module *>(name, m));
return true;
}
std::list<std::string *>::iterator World::filesIterBegin()
{
return this->Files->begin();
}
std::list<std::string *>::iterator World::filesIterEnd()
{
return this->Files->end();
}
bool World::print_logic_header(std::ofstream &logic)
{
std::list<std::string *>::iterator fCurr = filesIterBegin();
std::list<std::string *>::iterator fEnd = filesIterEnd();
logic << "/* This file was automatically generated by generator from (one of): *" << std::endl;
for(; fCurr != fEnd; fCurr++)
{
logic << " * " << *fCurr << std::endl;
}
logic << " */" << std::endl;
return true;
}
bool World::generate(const char *output_dir)
{
std::map<std::string *, Module *>::iterator curr = modulesIterBegin();
std::map<std::string *, Module *>::iterator end = modulesIterEnd();
// create the directories we need to make
int res = mkdir(output_dir, 0755);
if(res != 0 && errno != EEXIST)
gen_error(strerror(errno));
char *lb_path = NULL;
asprintf(&lb_path, "%s/lib", output_dir);
res = mkdir(output_dir, 0755);
free(lb_path);
if(res != 0 && errno != EEXIST)
gen_error(strerror(errno));
for( ; curr != end ; ++curr)
{
if(!curr->second->generate(curr->first, output_dir))
{
std::cerr << "Error generating module: " << curr->first << std::endl;
return false;
}
}
return true;
}