srcrecords.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. class pkgSourceList;
  15. class pkgIndexFile;
  16. class pkgSrcRecords
  17. {
  18. public:
  19. // Describes a single file
  20. struct File
  21. {
  22. std::string MD5Hash;
  23. unsigned long Size;
  24. std::string Path;
  25. std::string Type;
  26. };
  27. // Abstract parser for each source record
  28. class Parser
  29. {
  30. protected:
  31. const pkgIndexFile *iIndex;
  32. public:
  33. enum BuildDep {BuildDepend=0x0,BuildDependIndep=0x1,
  34. BuildConflict=0x2,BuildConflictIndep=0x3};
  35. struct BuildDepRec
  36. {
  37. std::string Package;
  38. std::string Version;
  39. unsigned int Op;
  40. unsigned char Type;
  41. };
  42. inline const pkgIndexFile &Index() const {return *iIndex;};
  43. virtual bool Restart() = 0;
  44. virtual bool Step() = 0;
  45. virtual bool Jump(unsigned long const &Off) = 0;
  46. virtual unsigned long Offset() = 0;
  47. virtual std::string AsStr() = 0;
  48. virtual std::string Package() const = 0;
  49. virtual std::string Version() const = 0;
  50. virtual std::string Maintainer() const = 0;
  51. virtual std::string Section() const = 0;
  52. virtual const char **Binaries() = 0; // Ownership does not transfer
  53. virtual bool BuildDepends(std::vector<BuildDepRec> &BuildDeps, bool const &ArchOnly, bool const &StripMultiArch = true) = 0;
  54. static const char *BuildDepType(unsigned char const &Type);
  55. virtual bool Files(std::vector<pkgSrcRecords::File> &F) = 0;
  56. Parser(const pkgIndexFile *Index) : iIndex(Index) {};
  57. virtual ~Parser() {};
  58. };
  59. private:
  60. /** \brief dpointer placeholder (for later in case we need it) */
  61. void *d;
  62. // The list of files and the current parser pointer
  63. std::vector<Parser*> Files;
  64. std::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 const &SrcOnly = false);
  70. pkgSrcRecords(pkgSourceList &List);
  71. virtual ~pkgSrcRecords();
  72. };
  73. #endif