]> git.tdb.fi Git - builder.git/blob - source/buildinfo.cpp
Derive BuildInfo::Loader from ObjectLoader
[builder.git] / source / buildinfo.cpp
1 #include <algorithm>
2 #include "buildinfo.h"
3
4 using namespace std;
5 using namespace Msp;
6
7 namespace {
8
9 /** Removes any duplicate entries from a list, leaving only the first one.  The
10 order of other elements is preserved.  O(n²) efficiency. */
11 void unique(StringList &l)
12 {
13         for(StringList::iterator i=l.begin(); i!=l.end(); ++i)
14                 for(StringList::iterator j=i; j!=l.end();)
15                 {
16                         if(j!=i && *j==*i)
17                                 j = l.erase(j);
18                         else
19                                 ++j;
20                 }
21 }
22
23 }
24
25
26 void BuildInfo::update_from(const BuildInfo &bi)
27 {
28         cflags.insert(cflags.end(), bi.cflags.begin(), bi.cflags.end());
29         defines.insert(defines.end(), bi.defines.begin(), bi.defines.end());
30         incpath.insert(incpath.end(), bi.incpath.begin(), bi.incpath.end());
31         ldflags.insert(ldflags.end(), bi.ldflags.begin(), bi.ldflags.end());
32         libpath.insert(libpath.end(), bi.libpath.begin(), bi.libpath.end());
33         libs.insert(libs.end(), bi.libs.begin(), bi.libs.end());
34         warnings.insert(warnings.end(), bi.warnings.begin(), bi.warnings.end());
35 }
36
37 void BuildInfo::unique()
38 {
39         ::unique(cflags);
40         ::unique(defines);
41         ::unique(incpath);
42         ::unique(ldflags);
43         ::unique(libpath);
44         ::unique(libs);
45
46         for(StringList::iterator i=warnings.begin(); i!=warnings.end(); ++i)
47         {
48                 bool flag = i->compare(0, 3, "no-");
49
50                 string warn = (flag ? *i : i->substr(3));
51                 string no_warn = "no-"+warn;
52
53                 for(StringList::iterator j=i; j!=warnings.end();)
54                 {
55                         if(j!=i && (*j==warn || *j==no_warn))
56                         {
57                                 flag = (*j==warn);
58                                 j = warnings.erase(j);
59                         }
60                         else
61                                 ++j;
62                 }
63
64                 *i = (flag ? warn : no_warn);
65         }
66 }
67
68
69 BuildInfo::Loader::Loader(BuildInfo &bi):
70         DataFile::ObjectLoader<BuildInfo>(bi)
71 {
72         add("cflag",   &Loader::cflag);
73         add("incpath", &Loader::incpath);
74         add("define",  &Loader::define);
75         add("ldflag",  &Loader::ldflag);
76         add("libpath", &Loader::libpath);
77         add("library", &Loader::library);
78         add("warning", &Loader::warning);
79 }
80
81 void BuildInfo::Loader::cflag(const std::string &s)
82 {
83         obj.cflags.push_back(s);
84 }
85
86 void BuildInfo::Loader::incpath(const std::string &s)
87 {
88         obj.incpath.push_back(s);
89 }
90
91 void BuildInfo::Loader::define(const std::string &s)
92 {
93         obj.defines.push_back(s);
94 }
95
96 void BuildInfo::Loader::ldflag(const std::string &s)
97 {
98         obj.ldflags.push_back(s);
99 }
100
101 void BuildInfo::Loader::libpath(const std::string &s)
102 {
103         obj.libpath.push_back(s);
104 }
105
106 void BuildInfo::Loader::library(const std::string &s)
107 {
108         obj.libs.push_back(s);
109 }
110
111 void BuildInfo::Loader::warning(const std::string &s)
112 {
113         obj.warnings.push_back(s);
114 }