From: Mikko Rasa Date: Sun, 14 Apr 2013 12:10:13 +0000 (+0300) Subject: Implement PackageManager::get_package X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=c45cc6fd2b13513909d43b5f95370b00c8b4c25e;p=builder.git Implement PackageManager::get_package --- diff --git a/source/packagemanager.cpp b/source/packagemanager.cpp index 93fbbc9..f840ea2 100644 --- a/source/packagemanager.cpp +++ b/source/packagemanager.cpp @@ -61,6 +61,15 @@ void PackageManager::add_package(Package *pkg) packages.insert(PackageMap::value_type(pkg->get_name(), pkg)); } +Package *PackageManager::get_package(const string &name) const +{ + PackageMap::const_iterator i = packages.find(name); + if(i!=packages.end()) + return i->second; + + return 0; +} + Package &PackageManager::get_main_package() const { if(!main_pkg) @@ -73,9 +82,8 @@ Package *PackageManager::find_package(const string &name) if(not_found.count(name)) return 0; - PackageMap::iterator i = packages.find(name); - if(i!=packages.end()) - return i->second; + if(Package *pkg = get_package(name)) + return pkg; if(!no_externals) { @@ -83,7 +91,7 @@ Package *PackageManager::find_package(const string &name) if(!path.empty()) { builder.load_build_file(path/"Build"); - i = packages.find(name); + PackageMap::iterator i = packages.find(name); if(i!=packages.end()) return i->second; } @@ -93,9 +101,8 @@ Package *PackageManager::find_package(const string &name) if(!path.empty()) { builder.load_build_file(path); - i = packages.find(name); - if(i!=packages.end()) - return i->second; + if(Package *pkg = get_package(name)) + return pkg; } try diff --git a/source/packagemanager.h b/source/packagemanager.h index 48c3c16..9b4f347 100644 --- a/source/packagemanager.h +++ b/source/packagemanager.h @@ -49,7 +49,7 @@ public: void add_package(Package *); /** Returns a package from the cache. */ - Package *get_package(const std::string &); + Package *get_package(const std::string &) const; /** Returns the package that was added first. This should be considered the primary build target. */