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