]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/pkgcache.cc
Working cache generator
[apt.git] / apt-pkg / pkgcache.cc
index fa0c363f7cc236a7d0b8ac199944bbcc7ab353cc..20590e971db62803cc139a8e7c7fc85640cc34f8 100644 (file)
@@ -1,11 +1,11 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: pkgcache.cc,v 1.2 1998/07/04 05:57:35 jgg Exp $
+// $Id: pkgcache.cc,v 1.7 1998/07/12 23:58:32 jgg Exp $
 /* ######################################################################
    
    Package Cache - Accessor code for the cache
    
-   Please see doc/pkglib/cache.sgml for a more detailed description of 
+   Please see doc/apt-pkg/cache.sgml for a more detailed description of 
    this format. Also be sure to keep that file up-to-date!!
    
    This is the general utility functions for cache managment. They provide
    ##################################################################### */
                                                                        /*}}}*/
 // Include Files                                                       /*{{{*/
-#include <pkglib/pkgcache.h>
-#include <pkglib/version.h>
-#include <pkglib/error.h>
+#ifdef __GNUG__
+#pragma implementation "apt-pkg/pkgcache.h"
+#pragma implementation "apt-pkg/cacheiterators.h"
+#endif 
+#include <apt-pkg/pkgcache.h>
+#include <apt-pkg/version.h>
+#include <apt-pkg/error.h>
 #include <system.h>
 
 #include <string>
@@ -49,7 +53,8 @@ pkgCache::Header::Header()
    VersionSz = sizeof(pkgCache::Version);
    DependencySz = sizeof(pkgCache::Dependency);
    ProvidesSz = sizeof(pkgCache::Provides);
-
+   VerFileSz = sizeof(pkgCache::VerFile);
+   
    PackageCount = 0;
    VersionCount = 0;
    DependsCount = 0;
@@ -70,7 +75,8 @@ bool pkgCache::Header::CheckSizes(Header &Against) const
        PackageSz == Against.PackageSz &&
        PackageFileSz == Against.PackageFileSz &&
        VersionSz == Against.VersionSz &&
-       DependencySz == Against.DependencySz && 
+       DependencySz == Against.DependencySz &&
+       VerFileSz == Against.VerFileSz &&
        ProvidesSz == Against.ProvidesSz)
       return true;
    return false;
@@ -93,6 +99,7 @@ bool pkgCache::ReMap()
    // Apply the typecasts.
    HeaderP = (Header *)Map.Data();
    PkgP = (Package *)Map.Data();
+   VerFileP = (VerFile *)Map.Data();
    PkgFileP = (PackageFile *)Map.Data();
    VerP = (Version *)Map.Data();
    ProvideP = (Provides *)Map.Data();
@@ -100,7 +107,6 @@ bool pkgCache::ReMap()
    StringItemP = (StringItem *)Map.Data();
    StrP = (char *)Map.Data();
 
-   cout << "Size is " << Map.Size() << endl;
    if (Map.Size() == 0)
       return false;
    
@@ -158,6 +164,17 @@ pkgCache::PkgIterator pkgCache::FindPkg(string Name)
    return PkgIterator(*this,0);
 }
                                                                        /*}}}*/
+// Cache::Priority - Convert a priority value to a string              /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+const char *pkgCache::Priority(unsigned char Prio)
+{
+   const char *Mapping[] = {0,"important","required","standard","optional","extra"};
+   if (Prio < _count(Mapping))
+      return Mapping[Prio];
+   return 0;
+}
+                                                                       /*}}}*/
 
 // Bases for iterator classes                                          /*{{{*/
 void pkgCache::VerIterator::_dummy() {}
@@ -186,13 +203,13 @@ void pkgCache::PkgIterator::operator ++(int)
 /* By this we mean if it is either cleanly installed or cleanly removed. */
 pkgCache::PkgIterator::OkState pkgCache::PkgIterator::State() const
 {
-   if (Pkg->CurrentState == UnPacked ||
-       Pkg->CurrentState == HalfConfigured)
+   if (Pkg->CurrentState == State::UnPacked ||
+       Pkg->CurrentState == State::HalfConfigured)
       return NeedsConfigure;
    
-   if (Pkg->CurrentState == UnInstalled ||
-       Pkg->CurrentState == HalfInstalled ||
-       Pkg->InstState != Ok)
+   if (Pkg->CurrentState == State::UnInstalled ||
+       Pkg->CurrentState == State::HalfInstalled ||
+       Pkg->InstState != State::Ok)
       return NeedsUnpack;
       
    return NeedsNothing;
@@ -204,8 +221,8 @@ pkgCache::PkgIterator::OkState pkgCache::PkgIterator::State() const
    conflicts. */
 bool pkgCache::DepIterator::IsCritical()
 {
-   if (Dep->Type == Conflicts || Dep->Type == Depends ||
-       Dep->Type == PreDepends)
+   if (Dep->Type == Dep::Conflicts || Dep->Type == Dep::Depends ||
+       Dep->Type == Dep::PreDepends)
       return true;
    return false;
 }
@@ -280,7 +297,7 @@ pkgCache::Version **pkgCache::DepIterator::AllTargets()
         if (pkgCheckDep(TargetVer(),I.VerStr(),Dep->CompareOp) == false)
            continue;
 
-        if (Dep->Type == Conflicts && ParentPkg() == I.ParentPkg())
+        if (Dep->Type == Dep::Conflicts && ParentPkg() == I.ParentPkg())
            continue;
         
         Size++;
@@ -294,7 +311,7 @@ pkgCache::Version **pkgCache::DepIterator::AllTargets()
         if (pkgCheckDep(TargetVer(),I.ProvideVersion(),Dep->CompareOp) == false)
            continue;
         
-        if (Dep->Type == Conflicts && ParentPkg() == I.OwnerPkg())
+        if (Dep->Type == Dep::Conflicts && ParentPkg() == I.OwnerPkg())
            continue;
         
         Size++;
@@ -341,6 +358,18 @@ int pkgCache::VerIterator::CompareVer(const VerIterator &B) const
    return -1;
 }
                                                                        /*}}}*/
+// VerIterator::Downloadable - Checks if the version is downloadable   /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+bool pkgCache::VerIterator::Downloadable() const
+{
+   VerFileIterator Files = FileList();
+   for (; Files.end() == false; Files++)
+      if ((Files.File()->Flags & Flag::NotSource) != Flag::NotSource)
+        return true;
+   return false;
+}
+                                                                       /*}}}*/
 // PkgFileIterator::IsOk - Checks if the cache is in sync with the file        /*{{{*/
 // ---------------------------------------------------------------------
 /* This stats the file and compares its stats with the ones that were