-#include <algorithm>
-#include <set>
+#include <msp/core/algorithm.h>
#include <msp/strings/format.h>
#include "buildinfo.h"
namespace {
-/** Removes any duplicate entries from a list, leaving only the first one. The
-order of other elements is preserved. O(nlogn) efficiency. */
+/** Removes any duplicate entries from a vector, leaving only the first one.
+The order of other elements is preserved. */
template<typename T>
-void unique(list<T> &l)
+void unique(vector<T> &v)
{
- set<T> seen;
- for(typename list<T>::iterator i=l.begin(); i!=l.end(); )
+ vector<T> seen;
+ for(auto i=v.begin(); i!=v.end(); )
{
- if(seen.count(*i))
- l.erase(i++);
+ auto j = lower_bound(seen, *i);
+ if(j!=seen.end() && *j==*i)
+ i = v.erase(i);
else
- seen.insert(*i++);
+ seen.insert(j, *i++);
}
}
}
-BuildInfo::BuildInfo():
- libmode(DYNAMIC),
- rpath_mode(NO_RPATH),
- threads(false),
- debug(false),
- optimize(0),
- strip(false),
- warning_level(0),
- fatal_warnings(false)
-{ }
-
BuildInfo::LibraryMode BuildInfo::get_libmode_for(const string &lib) const
{
- LibModeMap::const_iterator i = libmodes.find(lib);
+ auto i = libmodes.find(lib);
if(i!=libmodes.end())
return i->second;
return libmode;
void BuildInfo::update_from(const BuildInfo &bi, UpdateLevel level)
{
- for(DefineMap::const_iterator i=bi.defines.begin(); i!=bi.defines.end(); ++i)
- defines[i->first] = i->second;
+ for(const auto &kvp: bi.defines)
+ defines[kvp.first] = kvp.second;
incpath.insert(incpath.begin(), bi.incpath.begin(), bi.incpath.end());
threads = bi.threads;
- for(StandardMap::const_iterator i=bi.standards.begin(); i!=bi.standards.end(); ++i)
- standards[i->first] = i->second;
+
+ for(const auto &kvp: bi.standards)
+ {
+ auto j = standards.find(kvp.first);
+ if(j==standards.end())
+ standards.insert(kvp);
+ else if(kvp.second.type!=j->second.type || kvp.second.year!=j->second.year)
+ {
+ if(!kvp.second.type.compare(0, 3, "gnu"))
+ j->second.type = kvp.second.type;
+ if(kvp.second.year>j->second.year)
+ j->second.year = kvp.second.year;
+ }
+ }
if(level!=CHAINED)
{
local_incpath.insert(local_incpath.begin(), bi.local_incpath.begin(), bi.local_incpath.end());
libmode = bi.libmode;
rpath_mode = bi.rpath_mode;
- for(LibModeMap::const_iterator i=bi.libmodes.begin(); i!=bi.libmodes.end(); ++i)
- libmodes[i->first] = i->second;
+ for(const auto &kvp: bi.libmodes)
+ libmodes[kvp.first] = kvp.second;
keep_symbols.insert(keep_symbols.end(), bi.keep_symbols.begin(), bi.keep_symbols.end());
debug = bi.debug;
optimize = bi.optimize;
}
+BuildInfo::LanguageStandard::LanguageStandard(const string &std)
+{
+ auto i = find_if(std, [](char c){ return isdigit(static_cast<unsigned char>(c)); });
+ string::size_type num = i-std.begin();
+ type = std.substr(0, num);
+ year = lexical_cast<unsigned>(std.substr(num));
+ year += (year<70 ? 2000 : 1900);
+}
+
+string BuildInfo::LanguageStandard::str() const
+{
+ return format("%s%02d", type, year%100);
+}
+
+
BuildInfo::Loader::Loader(BuildInfo &bi):
DataFile::ObjectLoader<BuildInfo>(bi)
{