apt @VERSION@

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 using std::string;
00021 using std::vector;
00022 
00023 class pkgSourceList;
00024 class pkgIndexFile;
00025 class pkgSrcRecords
00026 {
00027    public:
00028 
00029    // Describes a single file
00030    struct File
00031    {
00032       string MD5Hash;
00033       unsigned long Size;
00034       string Path;
00035       string Type;
00036    };
00037    
00038    // Abstract parser for each source record
00039    class Parser
00040    {
00041       protected:
00042       
00043       const pkgIndexFile *iIndex;
00044       
00045       public:
00046 
00047       enum BuildDep {BuildDepend=0x0,BuildDependIndep=0x1,
00048                      BuildConflict=0x2,BuildConflictIndep=0x3};
00049 
00050       struct BuildDepRec 
00051       {
00052          string Package;
00053          string Version;
00054          unsigned int Op;
00055          unsigned char Type;
00056       };
00057         
00058       inline const pkgIndexFile &Index() const {return *iIndex;};
00059       
00060       virtual bool Restart() = 0;
00061       virtual bool Step() = 0;
00062       virtual bool Jump(unsigned long const &Off) = 0;
00063       virtual unsigned long Offset() = 0;
00064       virtual string AsStr() = 0;
00065       
00066       virtual string Package() const = 0;
00067       virtual string Version() const = 0;
00068       virtual string Maintainer() const = 0;
00069       virtual string Section() const = 0;
00070       virtual const char **Binaries() = 0;   // Ownership does not transfer
00071 
00072       virtual bool BuildDepends(vector<BuildDepRec> &BuildDeps, bool const &ArchOnly, bool const &StripMultiArch = true) = 0;
00073       static const char *BuildDepType(unsigned char const &Type);
00074 
00075       virtual bool Files(vector<pkgSrcRecords::File> &F) = 0;
00076       
00077       Parser(const pkgIndexFile *Index) : iIndex(Index) {};
00078       virtual ~Parser() {};
00079    };
00080    
00081    private:
00082    
00083    // The list of files and the current parser pointer
00084    vector<Parser*> Files;
00085    vector<Parser *>::iterator Current;
00086    
00087    public:
00088 
00089    // Reset the search
00090    bool Restart();
00091 
00092    // Locate a package by name
00093    Parser *Find(const char *Package,bool const &SrcOnly = false);
00094    
00095    pkgSrcRecords(pkgSourceList &List);
00096    ~pkgSrcRecords();
00097 };
00098 
00099 #endif