]> git.tdb.fi Git - builder.git/blobdiff - source/binarypackage.cpp
Replace basic for loops with range-based loops or algorithms
[builder.git] / source / binarypackage.cpp
index e48f17cee0c0d3f5987abb0096bf0154bb37aba5..2c32d87769a76a48f7ce9a2bb2a5414486b42ff3 100644 (file)
@@ -23,9 +23,9 @@ BinaryPackage *BinaryPackage::from_flags(Builder &builder, const string &name, c
        process_flags(flags, pkg->export_binfo);
 
        Flags exclusive_static_flags;
-       for(Flags::const_iterator i=static_flags.begin(); i!=static_flags.end(); ++i)
-               if(find(flags.begin(), flags.end(), *i)==flags.end())
-                       exclusive_static_flags.push_back(*i);
+       for(const string &f: static_flags)
+               if(find(flags.begin(), flags.end(), f)==flags.end())
+                       exclusive_static_flags.push_back(f);
        process_flags(exclusive_static_flags, pkg->static_binfo);
 
        return pkg;
@@ -33,34 +33,32 @@ BinaryPackage *BinaryPackage::from_flags(Builder &builder, const string &name, c
 
 void BinaryPackage::process_flags(const Flags &flags, BuildInfo &binfo)
 {
-       for(Flags::const_iterator i=flags.begin(); i!=flags.end(); ++i)
+       for(const string &f: flags)
        {
-               if(!i->compare(0, 2, "-I"))
-                       binfo.incpath.push_back(i->substr(2));
-               else if(!i->compare(0, 2, "-D"))
+               if(!f.compare(0, 2, "-I"))
+                       binfo.incpath.push_back(f.substr(2));
+               else if(!f.compare(0, 2, "-D"))
                {
-                       string::size_type equals = i->find('=');
+                       string::size_type equals = f.find('=');
                        if(equals!=string::npos)
-                               binfo.defines[i->substr(2, equals-2)] = i->substr(equals+1);
+                               binfo.defines[f.substr(2, equals-2)] = f.substr(equals+1);
                        else
-                               binfo.defines[i->substr(2)] = string();
+                               binfo.defines[f.substr(2)] = string();
                }
-               else if(!i->compare(0, 2, "-L"))
-                       binfo.libpath.push_back(i->substr(2));
-               else if(!i->compare(0, 2, "-l"))
-                       binfo.libs.push_back(i->substr(2));
-               else if(*i=="-pthread")
+               else if(!f.compare(0, 2, "-L"))
+                       binfo.libpath.push_back(f.substr(2));
+               else if(!f.compare(0, 2, "-l"))
+                       binfo.libs.push_back(f.substr(2));
+               else if(f=="-pthread")
                        binfo.threads = true;
        }
 }
 
 void BinaryPackage::do_prepare()
 {
-       bool has_relative_paths = false;
-       for(BuildInfo::PathList::const_iterator i=export_binfo.libpath.begin(); (!has_relative_paths && i!=export_binfo.libpath.end()); ++i)
-               has_relative_paths = !i->is_absolute();
-       for(BuildInfo::PathList::const_iterator i=export_binfo.incpath.begin(); (!has_relative_paths && i!=export_binfo.incpath.end()); ++i)
-               has_relative_paths = !i->is_absolute();
+       auto is_relative = [](const FS::Path &p){ return !p.is_absolute(); };
+       bool has_relative_paths = any_of(export_binfo.libpath.begin(), export_binfo.libpath.end(), is_relative) ||
+               any_of(export_binfo.incpath.begin(), export_binfo.incpath.end(), is_relative);
 
        list<FS::Path> bases;
 
@@ -73,9 +71,9 @@ void BinaryPackage::do_prepare()
        bases.push_back(FS::Path());
 
        bool system = false;
-       for(list<FS::Path>::const_iterator i=bases.begin(); i!=bases.end(); ++i)
+       for(const FS::Path &b: bases)
        {
-               FS::Path prefix = *i;
+               FS::Path prefix = b;
                system = prefix.empty();
                if(system)
                {
@@ -88,21 +86,21 @@ void BinaryPackage::do_prepare()
                BuildInfo::PathList libpath = export_binfo.libpath;
                if(!system && libpath.empty())
                        libpath.push_back("lib");
-               for(BuildInfo::PathList::iterator j=libpath.begin(); j!=libpath.end(); ++j)
-                       *j = prefix/ *j;
+               for(FS::Path &p: libpath)
+                       p = prefix/p;
 
                bool all_found = true;
-               for(BuildInfo::WordList::const_iterator j=export_binfo.libs.begin(); j!=export_binfo.libs.end(); ++j)
-                       all_found &= (builder.get_vfs().find_library(*j, libpath, export_binfo.libmode, system)!=0);
+               for(const string &l: export_binfo.libs)
+                       all_found &= (builder.get_vfs().find_library(l, libpath, export_binfo.libmode, system)!=0);
 
                BuildInfo::PathList incpath = export_binfo.incpath;
                if(!system && incpath.empty())
                        incpath.push_back("include");
-               for(BuildInfo::PathList::iterator j=incpath.begin(); j!=incpath.end(); ++j)
-                       *j = prefix/ *j;
+               for(FS::Path &p: incpath)
+                       p = prefix/p;
 
-               for(HeaderList::const_iterator j=headers.begin(); j!=headers.end(); ++j)
-                       all_found &= (builder.get_vfs().find_header(*j, 0, incpath, system)!=0);
+               for(const string &h: headers)
+                       all_found &= (builder.get_vfs().find_header(h, 0, incpath, system)!=0);
 
                if(all_found)
                {
@@ -129,10 +127,10 @@ void BinaryPackage::do_prepare()
 
        if(has_relative_paths)
        {
-               for(BuildInfo::PathList::iterator i=export_binfo.incpath.begin(); i!=export_binfo.incpath.end(); ++i)
-                       *i = base_path/ *i;
-               for(BuildInfo::PathList::iterator i=export_binfo.libpath.begin(); i!=export_binfo.libpath.end(); ++i)
-                       *i = base_path/ *i;
+               for(FS::Path &p: export_binfo.incpath)
+                       p = base_path/p;
+               for(FS::Path &p: export_binfo.libpath)
+                       p = base_path/p;
        }
 
        if(!static_binfo.libs.empty())
@@ -140,14 +138,14 @@ void BinaryPackage::do_prepare()
                BuildInfo::PathList combined_libpath = static_binfo.libpath;
                combined_libpath.insert(combined_libpath.end(), export_binfo.libpath.begin(), export_binfo.libpath.end());
 
-               for(BuildInfo::WordList::const_iterator i=export_binfo.libs.begin(); i!=export_binfo.libs.end(); ++i)
-                       if(Target *lib = builder.get_vfs().find_library(*i, export_binfo.libpath, BuildInfo::FORCE_STATIC, system))
+               for(const string &l: export_binfo.libs)
+                       if(Target *lib = builder.get_vfs().find_library(l, export_binfo.libpath, BuildInfo::FORCE_STATIC, system))
                                if(StaticLibrary *stlib = dynamic_cast<StaticLibrary *>(lib))
                                {
-                                       for(BuildInfo::WordList::const_iterator j=static_binfo.libs.begin(); j!=static_binfo.libs.end(); ++j)
-                                               stlib->add_required_library(*j);
-                                       for(BuildInfo::PathList::const_iterator j=combined_libpath.begin(); j!=combined_libpath.end(); ++j)
-                                               stlib->add_library_path(*j);
+                                       for(const string &s: static_binfo.libs)
+                                               stlib->add_required_library(s);
+                                       for(const FS::Path &p: combined_libpath)
+                                               stlib->add_library_path(p);
                                }
        }
 }