]> git.tdb.fi Git - builder.git/commitdiff
Implement PackageManager::get_package
authorMikko Rasa <tdb@tdb.fi>
Sun, 14 Apr 2013 12:10:13 +0000 (15:10 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 14 Apr 2013 12:10:13 +0000 (15:10 +0300)
source/packagemanager.cpp
source/packagemanager.h

index 93fbbc9c0ed204b56b11fea1dde7a9f33dae9099..f840ea22d4edb929624097f3c47fad0a896bf1ae 100644 (file)
@@ -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
index 48c3c16fd4fcbdb486368fa2dfed5147af7f7b8b..9b4f3476d7a2ae821650bdd5118434d1a0546d10 100644 (file)
@@ -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. */