orderlist.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: orderlist.h,v 1.9 2001/02/20 07:03:17 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 useful 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. #ifndef PKGLIB_ORDERLIST_H
  14. #define PKGLIB_ORDERLIST_H
  15. #include <apt-pkg/pkgcache.h>
  16. #include <apt-pkg/macros.h>
  17. class pkgDepCache;
  18. class pkgOrderList : protected pkgCache::Namespace
  19. {
  20. protected:
  21. pkgDepCache &Cache;
  22. typedef bool (pkgOrderList::*DepFunc)(DepIterator D);
  23. // These are the currently selected ordering functions
  24. DepFunc Primary;
  25. DepFunc Secondary;
  26. DepFunc RevDepends;
  27. DepFunc Remove;
  28. // State
  29. Package **End;
  30. Package **List;
  31. Package **AfterEnd;
  32. std::string *FileList;
  33. DepIterator Loops[20];
  34. int LoopCount;
  35. int Depth;
  36. unsigned short *Flags;
  37. bool Debug;
  38. // Main visit function
  39. __deprecated bool VisitNode(PkgIterator Pkg) { return VisitNode(Pkg, "UNKNOWN"); };
  40. bool VisitNode(PkgIterator Pkg, char const* from);
  41. bool VisitDeps(DepFunc F,PkgIterator Pkg);
  42. bool VisitRDeps(DepFunc F,PkgIterator Pkg);
  43. bool VisitRProvides(DepFunc F,VerIterator Ver);
  44. bool VisitProvides(DepIterator Pkg,bool Critical);
  45. // Dependency checking functions.
  46. bool DepUnPackCrit(DepIterator D);
  47. bool DepUnPackPreD(DepIterator D);
  48. bool DepUnPackPre(DepIterator D);
  49. bool DepUnPackDep(DepIterator D);
  50. bool DepConfigure(DepIterator D);
  51. bool DepRemove(DepIterator D);
  52. // Analysis helpers
  53. bool AddLoop(DepIterator D);
  54. bool CheckDep(DepIterator D);
  55. bool DoRun();
  56. // For pre sorting
  57. static pkgOrderList *Me;
  58. static int OrderCompareA(const void *a, const void *b);
  59. static int OrderCompareB(const void *a, const void *b);
  60. int FileCmp(PkgIterator A,PkgIterator B);
  61. public:
  62. typedef Package **iterator;
  63. /* State flags
  64. The Loop flag can be set on a package that is currently being processed by either SmartConfigure or
  65. SmartUnPack. This allows the package manager to tell when a loop has been formed as it will try to
  66. SmartUnPack or SmartConfigure a package with the Loop flag set. It will then either stop (as it knows
  67. that the operation is unnecessary as its already in process), or in the case of the conflicts resolution
  68. in SmartUnPack, use EarlyRemove to resolve the situation. */
  69. enum Flags {Added = (1 << 0), AddPending = (1 << 1),
  70. Immediate = (1 << 2), Loop = (1 << 3),
  71. UnPacked = (1 << 4), Configured = (1 << 5),
  72. Removed = (1 << 6), // Early Remove
  73. InList = (1 << 7),
  74. After = (1 << 8),
  75. States = (UnPacked | Configured | Removed)};
  76. // Flag manipulators
  77. inline bool IsFlag(PkgIterator Pkg,unsigned long F) {return (Flags[Pkg->ID] & F) == F;};
  78. inline bool IsFlag(Package *Pkg,unsigned long F) {return (Flags[Pkg->ID] & F) == F;};
  79. void Flag(PkgIterator Pkg,unsigned long State, unsigned long F) {Flags[Pkg->ID] = (Flags[Pkg->ID] & (~F)) | State;};
  80. inline void Flag(PkgIterator Pkg,unsigned long F) {Flags[Pkg->ID] |= F;};
  81. inline void Flag(Package *Pkg,unsigned long F) {Flags[Pkg->ID] |= F;};
  82. // RmFlag removes a flag from a package
  83. inline void RmFlag(Package *Pkg,unsigned long F) {Flags[Pkg->ID] &= ~F;};
  84. // IsNow will return true if the Pkg has been not been either configured or unpacked
  85. inline bool IsNow(PkgIterator Pkg) {return (Flags[Pkg->ID] & (States & (~Removed))) == 0;};
  86. bool IsMissing(PkgIterator Pkg);
  87. void WipeFlags(unsigned long F);
  88. void SetFileList(std::string *FileList) {this->FileList = FileList;};
  89. // Accessors
  90. inline iterator begin() {return List;};
  91. inline iterator end() {return End;};
  92. inline void push_back(Package *Pkg) {*(End++) = Pkg;};
  93. inline void push_back(PkgIterator Pkg) {*(End++) = Pkg;};
  94. inline void pop_back() {End--;};
  95. inline bool empty() {return End == List;};
  96. inline unsigned int size() {return End - List;};
  97. // Ordering modes
  98. bool OrderCritical();
  99. bool OrderUnpack(std::string *FileList = 0);
  100. bool OrderConfigure();
  101. int Score(PkgIterator Pkg);
  102. pkgOrderList(pkgDepCache *Cache);
  103. ~pkgOrderList();
  104. };
  105. #endif