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