srcrecords.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: srcrecords.h,v 1.8.2.1 2003/12/26 16:27:34 mdz Exp $
  4. /* ######################################################################
  5. Source Package Records - Allows access to source package records
  6. Parses and allows access to the list of source records and searching by
  7. source name on that list.
  8. ##################################################################### */
  9. /*}}}*/
  10. #ifndef PKGLIB_SRCRECORDS_H
  11. #define PKGLIB_SRCRECORDS_H
  12. #include <string>
  13. #include <vector>
  14. using std::string;
  15. using std::vector;
  16. class pkgSourceList;
  17. class pkgIndexFile;
  18. class pkgSrcRecords
  19. {
  20. public:
  21. // Describes a single file
  22. struct File
  23. {
  24. string MD5Hash;
  25. unsigned long Size;
  26. string Path;
  27. string Type;
  28. };
  29. // Abstract parser for each source record
  30. class Parser
  31. {
  32. protected:
  33. const pkgIndexFile *iIndex;
  34. public:
  35. enum BuildDep {BuildDepend=0x0,BuildDependIndep=0x1,
  36. BuildConflict=0x2,BuildConflictIndep=0x3};
  37. struct BuildDepRec
  38. {
  39. string Package;
  40. string Version;
  41. unsigned int Op;
  42. unsigned char Type;
  43. };
  44. inline const pkgIndexFile &Index() const {return *iIndex;};
  45. virtual bool Restart() = 0;
  46. virtual bool Step() = 0;
  47. virtual bool Jump(unsigned long Off) = 0;
  48. virtual unsigned long Offset() = 0;
  49. virtual string AsStr() = 0;
  50. virtual string Package() const = 0;
  51. virtual string Version() const = 0;
  52. virtual string Maintainer() const = 0;
  53. virtual string Section() const = 0;
  54. virtual const char **Binaries() = 0; // Ownership does not transfer
  55. virtual bool BuildDepends(vector<BuildDepRec> &BuildDeps, bool ArchOnly) = 0;
  56. static const char *BuildDepType(unsigned char Type);
  57. virtual bool Files(vector<pkgSrcRecords::File> &F) = 0;
  58. Parser(const pkgIndexFile *Index) : iIndex(Index) {};
  59. virtual ~Parser() {};
  60. };
  61. private:
  62. // The list of files and the current parser pointer
  63. vector<Parser*> Files;
  64. vector<Parser *>::iterator Current;
  65. public:
  66. // Reset the search
  67. bool Restart();
  68. // Locate a package by name
  69. Parser *Find(const char *Package,bool SrcOnly = false);
  70. pkgSrcRecords(pkgSourceList &List);
  71. ~pkgSrcRecords();
  72. };
  73. #endif