]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/pkgcache.h
It is NOT OK to just munmap memory from malloc :/.
[apt.git] / apt-pkg / pkgcache.h
index fba6929826c1e21897ee1468509fa0be8e3b5304..83bf8961def2b2d4afc835dff27e47f5d705575a 100644 (file)
 #include <time.h>
 #include <stdint.h>
 
+#ifdef APT_PKG_EXPOSE_STRING_VIEW
+#include <apt-pkg/string_view.h>
+#endif
+
 #ifndef APT_8_CLEANER_HEADERS
 using std::string;
 #endif
@@ -119,6 +123,7 @@ class pkgCache                                                              /*{{{*/
    struct StringItem;
    struct VerFile;
    struct DescFile;
+   struct Tag;
    
    // Iterators
    template<typename Str, typename Itr> class Iterator;
@@ -132,6 +137,7 @@ class pkgCache                                                              /*{{{*/
    class PkgFileIterator;
    class VerFileIterator;
    class DescFileIterator;
+   class TagIterator;
    
    class Namespace;
    
@@ -149,8 +155,12 @@ class pkgCache                                                             /*{{{*/
           The lower 4 bits are used to indicate what operator is being specified and
           the upper 4 bits are flags. OR indicates that the next package is
           or'd with the current package. */
-      enum DepCompareOp {Or=0x10,NoOp=0,LessEq=0x1,GreaterEq=0x2,Less=0x3,
-        Greater=0x4,Equals=0x5,NotEquals=0x6};
+      enum DepCompareOp {NoOp=0,LessEq=0x1,GreaterEq=0x2,Less=0x3,
+        Greater=0x4,Equals=0x5,NotEquals=0x6,
+        Or=0x10, /*!< or'ed with the next dependency */
+        MultiArchImplicit=0x20, /*!< generated internally, not spelled out in the index */
+        ArchSpecific=0x40 /*!< was decorated with an explicit architecture in index */
+      };
    };
    
    struct State
@@ -178,6 +188,10 @@ class pkgCache                                                             /*{{{*/
         NotAutomatic=(1<<0), /*!< archive has a default pin of 1 */
         ButAutomaticUpgrades=(1<<1), /*!< (together with the previous) archive has a default pin of 100 */
       };
+      enum ProvidesFlags {
+        MultiArchImplicit=pkgCache::Dep::MultiArchImplicit, /*!< generated internally, not spelled out in the index */
+        ArchSpecific=pkgCache::Dep::ArchSpecific /*!< was decorated with an explicit architecture in index */
+      };
    };
    
    protected:
@@ -185,7 +199,9 @@ class pkgCache                                                              /*{{{*/
    // Memory mapped cache file
    std::string CacheFile;
    MMap &Map;
-
+#ifdef APT_PKG_EXPOSE_STRING_VIEW
+   APT_HIDDEN map_id_t sHash(APT::StringView S) const APT_PURE;
+#endif
    map_id_t sHash(const std::string &S) const APT_PURE;
    map_id_t sHash(const char *S) const APT_PURE;
    
@@ -200,11 +216,12 @@ class pkgCache                                                            /*{{{*/
    ReleaseFile *RlsFileP;
    PackageFile *PkgFileP;
    Version *VerP;
+   Tag *TagP;
    Description *DescP;
    Provides *ProvideP;
    Dependency *DepP;
    DependencyData *DepDataP;
-   APT_DEPRECATED StringItem *StringItemP;
+   APT_DEPRECATED_MSG("Not used anymore in cache generation and without a replacement") StringItem *StringItemP;
    char *StrP;
 
    virtual bool ReMap(bool const &Errorchecks = true);
@@ -213,13 +230,34 @@ class pkgCache                                                            /*{{{*/
    inline void *DataEnd() {return ((unsigned char *)Map.Data()) + Map.Size();}
       
    // String hashing function (512 range)
+#ifdef APT_PKG_EXPOSE_STRING_VIEW
+   APT_HIDDEN inline map_id_t Hash(APT::StringView S) const {return sHash(S);}
+#endif
    inline map_id_t Hash(const std::string &S) const {return sHash(S);}
    inline map_id_t Hash(const char *S) const {return sHash(S);}
 
+   APT_HIDDEN uint32_t CacheHash();
+
    // Useful transformation things
-   const char *Priority(unsigned char Priority);
+   static const char *Priority(unsigned char Priority);
    
    // Accessors
+#ifdef APT_PKG_EXPOSE_STRING_VIEW
+   APT_HIDDEN GrpIterator FindGrp(APT::StringView Name);
+   APT_HIDDEN PkgIterator FindPkg(APT::StringView Name);
+   APT_HIDDEN PkgIterator FindPkg(APT::StringView Name, APT::StringView Arch);
+#endif
+
+#ifdef APT_PKG_EXPOSE_STRING_VIEW
+   APT::StringView ViewString(map_stringitem_t idx) const
+   {
+      char *name = StrP + idx;
+      uint16_t len = *reinterpret_cast<const uint16_t*>(name - sizeof(uint16_t));
+      return APT::StringView(name, len);
+   }
+#endif
+
+
    GrpIterator FindGrp(const std::string &Name);
    PkgIterator FindPkg(const std::string &Name);
    PkgIterator FindPkg(const std::string &Name, const std::string &Arch);
@@ -251,7 +289,6 @@ class pkgCache                                                              /*{{{*/
 private:
    void * const d;
    bool MultiArchEnabled;
-   APT_HIDDEN PkgIterator SingleArchFindPkg(const std::string &Name);
 };
                                                                        /*}}}*/
 // Header structure                                                    /*{{{*/
@@ -286,6 +323,7 @@ struct pkgCache::Header
    map_number_t ReleaseFileSz;
    map_number_t PackageFileSz;
    map_number_t VersionSz;
+   map_number_t TagSz;
    map_number_t DescriptionSz;
    map_number_t DependencySz;
    map_number_t DependencyDataSz;
@@ -301,6 +339,7 @@ struct pkgCache::Header
    map_id_t GroupCount;
    map_id_t PackageCount;
    map_id_t VersionCount;
+   map_id_t TagCount;
    map_id_t DescriptionCount;
    map_id_t DependsCount;
    map_id_t DependsDataCount;
@@ -357,7 +396,7 @@ struct pkgCache::Header
    map_pointer_t * PkgHashTableP() const { return (map_pointer_t*) (this + 1); }
    map_pointer_t * GrpHashTableP() const { return PkgHashTableP() + GetHashTableSize(); }
 
-   /** \brief Size of the complete cache file */
+   /** \brief Hash of the file (TODO: Rename) */
    map_filesize_small_t CacheFileSize;
 
    bool CheckSizes(Header &Against) const APT_PURE;
@@ -406,7 +445,7 @@ struct pkgCache::Package
     * Note that the access method Name() will remain. It is just this data member
     * deprecated as this information is already stored and available via the
     * associated Group – so it is wasting precious binary cache space */
-   APT_DEPRECATED map_stringitem_t Name;
+   APT_DEPRECATED_MSG("Use the .Name() method instead of accessing the member directly") map_stringitem_t Name;
    /** \brief Architecture of the package */
    map_stringitem_t Arch;
    /** \brief Base of a singly linked list of versions
@@ -421,12 +460,6 @@ struct pkgCache::Package
    map_pointer_t VersionList;       // Version
    /** \brief index to the installed version */
    map_pointer_t CurrentVer;        // Version
-   /** \brief indicates nothing (consistently)
-       This field used to contain ONE section the package belongs to,
-       if those differs between versions it is a RANDOM one.
-       The Section() method tries to reproduce it, but the only sane
-       thing to do is use the Section field from the version! */
-   APT_DEPRECATED map_ptrloc Section; // StringItem
    /** \brief index of the group this package belongs to */
    map_pointer_t Group;             // Group the Package belongs to
 
@@ -557,6 +590,16 @@ struct pkgCache::VerFile
    map_filesize_t Size;
 };
                                                                        /*}}}*/
+// TagFile structure                                                   /*{{{*/
+/** \brief associates a tag with something */
+struct pkgCache::Tag
+{
+   /** \brief name of this tag */
+   map_stringitem_t Name;
+   /** \brief next step in the linked list */
+   map_pointer_t NextTag;       // Tag
+};
+                                                                       /*}}}*/
 // DescFile structure                                                  /*{{{*/
 /** \brief associates a description with a Translation file */
 struct pkgCache::DescFile
@@ -577,12 +620,15 @@ struct pkgCache::DescFile
     The version list is always sorted from highest version to lowest
     version by the generator. Equal version numbers are either merged
     or handled as separate versions based on the Hash value. */
+APT_IGNORE_DEPRECATED_PUSH
 struct pkgCache::Version
 {
    /** \brief complete version string */
    map_stringitem_t VerStr;
    /** \brief section this version is filled in */
    map_stringitem_t Section;
+   /** \brief high-level name used to display package */
+   map_stringitem_t Display;
    /** \brief source package name this version comes from
       Always contains the name, even if it is the same as the binary name */
    map_stringitem_t SourcePkgName;
@@ -591,13 +637,17 @@ struct pkgCache::Version
    map_stringitem_t SourceVerStr;
 
    /** \brief Multi-Arch capabilities of a package version */
-   enum VerMultiArch { None = 0, /*!< is the default and doesn't trigger special behaviour */
+   enum VerMultiArch { No = 0, /*!< is the default and doesn't trigger special behaviour */
                       All = (1<<0), /*!< will cause that Ver.Arch() will report "all" */
                       Foreign = (1<<1), /*!< can satisfy dependencies in another architecture */
                       Same = (1<<2), /*!< can be co-installed with itself from other architectures */
                       Allowed = (1<<3), /*!< other packages are allowed to depend on thispkg:any */
                       AllForeign = All | Foreign,
                       AllAllowed = All | Allowed };
+
+   /** \brief deprecated variant of No */
+   static const APT_DEPRECATED_MSG("The default value of the Multi-Arch field is no, not none") VerMultiArch None = No;
+
    /** \brief stores the MultiArch capabilities of this version
 
        Flags used are defined in pkgCache::Version::VerMultiArch
@@ -623,6 +673,8 @@ struct pkgCache::Version
    map_pointer_t ParentPkg;         // Package
    /** \brief list of pkgCache::Provides */
    map_pointer_t ProvidesList;      // Provides
+   /** \brief list of pkgCache::Tag */
+   map_pointer_t TagList;           // Tag
 
    /** \brief archive size for this version
 
@@ -640,6 +692,7 @@ struct pkgCache::Version
    /** \brief parsed priority value */
    map_number_t Priority;
 };
+APT_IGNORE_DEPRECATED_POP
                                                                        /*}}}*/
 // Description structure                                               /*{{{*/
 /** \brief datamember of a linked list of available description for a version */
@@ -725,9 +778,9 @@ struct pkgCache::Provides
    /** \brief version in the provides line (if any)
 
        This version allows dependencies to depend on specific versions of a
-       Provides, as well as allowing Provides to override existing packages.
-       This is experimental. Note that Debian doesn't allow versioned provides */
+       Provides, as well as allowing Provides to override existing packages. */
    map_stringitem_t ProvideVersion;
+   map_flags_t Flags;
    /** \brief next provides (based of package) */
    map_pointer_t NextProvides;     // Provides
    /** \brief next provides (based of version) */
@@ -735,7 +788,7 @@ struct pkgCache::Provides
 };
                                                                        /*}}}*/
 // UNUSED StringItem structure                                         /*{{{*/
-struct APT_DEPRECATED  pkgCache::StringItem
+struct APT_DEPRECATED_MSG("No longer used in cache generation without a replacement") pkgCache::StringItem
 {
    /** \brief string this refers to */
    map_ptrloc String;        // StringItem
@@ -774,6 +827,7 @@ class pkgCache::Namespace                                           /*{{{*/
    typedef pkgCache::GrpIterator GrpIterator;
    typedef pkgCache::PkgIterator PkgIterator;
    typedef pkgCache::VerIterator VerIterator;
+   typedef pkgCache::TagIterator TagIterator;
    typedef pkgCache::DescIterator DescIterator;
    typedef pkgCache::DepIterator DepIterator;
    typedef pkgCache::PrvIterator PrvIterator;