apt  1.5
srcrecords.h
00001 // -*- mode: cpp; mode: fold -*-
00002 // Description                                                          /*{{{*/
00003 // $Id: srcrecords.h,v 1.8.2.1 2003/12/26 16:27:34 mdz Exp $
00004 /* ######################################################################
00005    
00006    Source Package Records - Allows access to source package records
00007    
00008    Parses and allows access to the list of source records and searching by
00009    source name on that list.
00010    
00011    ##################################################################### */
00012                                                                         /*}}}*/
00013 #ifndef PKGLIB_SRCRECORDS_H
00014 #define PKGLIB_SRCRECORDS_H
00015 
00016 
00017 #include <string>
00018 #include <vector>
00019 
00020 #ifndef APT_8_CLEANER_HEADERS
00021 using std::string;
00022 using std::vector;
00023 #endif
00024 
00025 class pkgSourceList;
00026 class pkgIndexFile;
00027 class pkgSrcRecords
00028 {
00029    public:
00030 
00031    // Describes a single file
00032    struct File
00033    {
00034       std::string MD5Hash;
00035       unsigned long Size;
00036       std::string Path;
00037       std::string Type;
00038    };
00039    
00040    // Abstract parser for each source record
00041    class Parser
00042    {
00043       protected:
00044       
00045       const pkgIndexFile *iIndex;
00046       
00047       public:
00048 
00049       enum BuildDep {BuildDepend=0x0,BuildDependIndep=0x1,
00050                      BuildConflict=0x2,BuildConflictIndep=0x3};
00051 
00052       struct BuildDepRec 
00053       {
00054          std::string Package;
00055          std::string Version;
00056          unsigned int Op;
00057          unsigned char Type;
00058       };
00059         
00060       inline const pkgIndexFile &Index() const {return *iIndex;};
00061       
00062       virtual bool Restart() = 0;
00063       virtual bool Step() = 0;
00064       virtual bool Jump(unsigned long const &Off) = 0;
00065       virtual unsigned long Offset() = 0;
00066       virtual std::string AsStr() = 0;
00067       
00068       virtual std::string Package() const = 0;
00069       virtual std::string Version() const = 0;
00070       virtual std::string Maintainer() const = 0;
00071       virtual std::string Section() const = 0;
00072       virtual const char **Binaries() = 0;   // Ownership does not transfer
00073 
00074       virtual bool BuildDepends(std::vector<BuildDepRec> &BuildDeps, bool const &ArchOnly, bool const &StripMultiArch = true) = 0;
00075       static const char *BuildDepType(unsigned char const &Type);
00076 
00077       virtual bool Files(std::vector<pkgSrcRecords::File> &F) = 0;
00078       
00079       Parser(const pkgIndexFile *Index) : iIndex(Index) {};
00080       virtual ~Parser() {};
00081    };
00082    
00083    private:
00085    void *d;
00086    
00087    // The list of files and the current parser pointer
00088    std::vector<Parser*> Files;
00089    std::vector<Parser *>::iterator Current;
00090    
00091    public:
00092 
00093    // Reset the search
00094    bool Restart();
00095 
00096    // Locate a package by name
00097    Parser *Find(const char *Package,bool const &SrcOnly = false);
00098    
00099    pkgSrcRecords(pkgSourceList &List);
00100    virtual ~pkgSrcRecords();
00101 };
00102 
00103 #endif