srcrecords.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 <apt-pkg/macros.h>
  13. #include <apt-pkg/hashes.h>
  14. #include <string>
  15. #include <vector>
  16. #ifndef APT_8_CLEANER_HEADERS
  17. using std::string;
  18. using std::vector;
  19. #endif
  20. class pkgSourceList;
  21. class pkgIndexFile;
  22. class pkgSrcRecords
  23. {
  24. public:
  25. #if __GNUC__ >= 4
  26. // ensure that con- & de-structor don't trigger this warning
  27. #pragma GCC diagnostic push
  28. #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
  29. #endif
  30. // Describes a single file
  31. struct File
  32. {
  33. APT_DEPRECATED std::string MD5Hash;
  34. APT_DEPRECATED unsigned long Size;
  35. std::string Path;
  36. std::string Type;
  37. };
  38. struct File2 : public File
  39. {
  40. unsigned long long FileSize;
  41. HashStringList Hashes;
  42. };
  43. #if __GNUC__ >= 4
  44. #pragma GCC diagnostic pop
  45. #endif
  46. // Abstract parser for each source record
  47. class Parser
  48. {
  49. protected:
  50. const pkgIndexFile *iIndex;
  51. public:
  52. enum BuildDep {BuildDepend=0x0,BuildDependIndep=0x1,
  53. BuildConflict=0x2,BuildConflictIndep=0x3};
  54. struct BuildDepRec
  55. {
  56. std::string Package;
  57. std::string Version;
  58. unsigned int Op;
  59. unsigned char Type;
  60. };
  61. inline const pkgIndexFile &Index() const {return *iIndex;};
  62. virtual bool Restart() = 0;
  63. virtual bool Step() = 0;
  64. virtual bool Jump(unsigned long const &Off) = 0;
  65. virtual unsigned long Offset() = 0;
  66. virtual std::string AsStr() = 0;
  67. virtual std::string Package() const = 0;
  68. virtual std::string Version() const = 0;
  69. virtual std::string Maintainer() const = 0;
  70. virtual std::string Section() const = 0;
  71. virtual const char **Binaries() = 0; // Ownership does not transfer
  72. //FIXME: Add a parameter to specify which architecture to use for [wildcard] matching
  73. virtual bool BuildDepends(std::vector<BuildDepRec> &BuildDeps, bool const &ArchOnly, bool const &StripMultiArch = true) = 0;
  74. static const char *BuildDepType(unsigned char const &Type) APT_PURE;
  75. virtual bool Files(std::vector<pkgSrcRecords::File> &F) = 0;
  76. bool Files2(std::vector<pkgSrcRecords::File2> &F);
  77. Parser(const pkgIndexFile *Index) : iIndex(Index) {};
  78. virtual ~Parser() {};
  79. };
  80. private:
  81. /** \brief dpointer placeholder (for later in case we need it) */
  82. void *d;
  83. // The list of files and the current parser pointer
  84. std::vector<Parser*> Files;
  85. std::vector<Parser *>::iterator Current;
  86. public:
  87. // Reset the search
  88. bool Restart();
  89. // Step to the next SourcePackage and return pointer to the
  90. // next SourceRecord. The pointer is owned by libapt.
  91. const Parser* Step();
  92. // Locate a package by name and return pointer to the Parser.
  93. // The pointer is owned by libapt.
  94. Parser* Find(const char *Package,bool const &SrcOnly = false);
  95. pkgSrcRecords(pkgSourceList &List);
  96. virtual ~pkgSrcRecords();
  97. };
  98. #endif