orderlist.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: orderlist.h,v 1.7 1999/08/12 05:59:54 jgg Exp $
  4. /* ######################################################################
  5. Order List - Represents and Manipulates an ordered list of packages.
  6. A list of packages can be ordered by a number of conflicting criteria
  7. each given a specific priority. Each package also has a set of flags
  8. indicating some usefull things about it that are derived in the
  9. course of sorting. The pkgPackageManager class uses this class for
  10. all of it's installation ordering needs.
  11. ##################################################################### */
  12. /*}}}*/
  13. // Header section: pkglib
  14. #ifndef PKGLIB_ORDERLIST_H
  15. #define PKGLIB_ORDERLIST_H
  16. #ifdef __GNUG__
  17. #pragma interface "apt-pkg/orderlist.h"
  18. #endif
  19. #include <apt-pkg/pkgcache.h>
  20. class pkgDepCache;
  21. class pkgOrderList
  22. {
  23. protected:
  24. pkgDepCache &Cache;
  25. // Bring some usefull types into the local scope
  26. typedef pkgCache::PkgIterator PkgIterator;
  27. typedef pkgCache::VerIterator VerIterator;
  28. typedef pkgCache::DepIterator DepIterator;
  29. typedef pkgCache::PrvIterator PrvIterator;
  30. typedef pkgCache::Package Package;
  31. typedef pkgCache::Version Version;
  32. typedef bool (pkgOrderList::*DepFunc)(DepIterator D);
  33. // These are the currently selected ordering functions
  34. DepFunc Primary;
  35. DepFunc Secondary;
  36. DepFunc RevDepends;
  37. DepFunc Remove;
  38. // State
  39. Package **End;
  40. Package **List;
  41. string *FileList;
  42. DepIterator Loops[20];
  43. int LoopCount;
  44. int Depth;
  45. unsigned char *Flags;
  46. // Main visit function
  47. bool VisitNode(PkgIterator Pkg);
  48. bool VisitDeps(DepFunc F,PkgIterator Pkg);
  49. bool VisitRDeps(DepFunc F,PkgIterator Pkg);
  50. bool VisitRProvides(DepFunc F,VerIterator Ver);
  51. bool VisitProvides(DepIterator Pkg,bool Critical);
  52. // Dependency checking functions.
  53. bool DepUnPackCrit(DepIterator D);
  54. bool DepUnPackPreD(DepIterator D);
  55. bool DepUnPackPre(DepIterator D);
  56. bool DepUnPackDep(DepIterator D);
  57. bool DepConfigure(DepIterator D);
  58. bool DepRemove(DepIterator D);
  59. // Analysis helpers
  60. bool AddLoop(DepIterator D);
  61. bool CheckDep(DepIterator D);
  62. bool DoRun();
  63. // For pre sorting
  64. static pkgOrderList *Me;
  65. static int OrderCompareA(const void *a, const void *b);
  66. static int OrderCompareB(const void *a, const void *b);
  67. int FileCmp(PkgIterator A,PkgIterator B);
  68. public:
  69. typedef Package **iterator;
  70. // State flags
  71. enum Flags {Added = (1 << 0), AddPending = (1 << 1),
  72. Immediate = (1 << 2), Loop = (1 << 3),
  73. UnPacked = (1 << 4), Configured = (1 << 5),
  74. Removed = (1 << 6), // Early Remove
  75. InList = (1 << 7),
  76. States = (UnPacked | Configured | Removed)};
  77. // Flag manipulators
  78. inline bool IsFlag(PkgIterator Pkg,unsigned long F) {return (Flags[Pkg->ID] & F) == F;};
  79. inline bool IsFlag(Package *Pkg,unsigned long F) {return (Flags[Pkg->ID] & F) == F;};
  80. void Flag(PkgIterator Pkg,unsigned long State, unsigned long F) {Flags[Pkg->ID] = (Flags[Pkg->ID] & (~F)) | State;};
  81. inline void Flag(PkgIterator Pkg,unsigned long F) {Flags[Pkg->ID] |= F;};
  82. inline void Flag(Package *Pkg,unsigned long F) {Flags[Pkg->ID] |= F;};
  83. inline bool IsNow(PkgIterator Pkg) {return (Flags[Pkg->ID] & (States & (~Removed))) == 0;};
  84. bool IsMissing(PkgIterator Pkg);
  85. void WipeFlags(unsigned long F);
  86. void SetFileList(string *FileList) {this->FileList = FileList;};
  87. // Accessors
  88. inline iterator begin() {return List;};
  89. inline iterator end() {return End;};
  90. inline void push_back(Package *Pkg) {*(End++) = Pkg;};
  91. inline void push_back(PkgIterator Pkg) {*(End++) = Pkg;};
  92. inline void pop_back() {End--;};
  93. inline bool empty() {return End == List;};
  94. inline unsigned int size() {return End - List;};
  95. // Ordering modes
  96. bool OrderCritical();
  97. bool OrderUnpack(string *FileList = 0);
  98. bool OrderConfigure();
  99. int Score(PkgIterator Pkg);
  100. pkgOrderList(pkgDepCache &Cache);
  101. ~pkgOrderList();
  102. };
  103. #endif