orderlist.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. #ifdef __GNUG__
  16. #pragma interface "apt-pkg/orderlist.h"
  17. #endif
  18. #include <apt-pkg/pkgcache.h>
  19. class pkgDepCache;
  20. class pkgOrderList : protected pkgCache::Namespace
  21. {
  22. protected:
  23. pkgDepCache &Cache;
  24. typedef bool (pkgOrderList::*DepFunc)(DepIterator D);
  25. // These are the currently selected ordering functions
  26. DepFunc Primary;
  27. DepFunc Secondary;
  28. DepFunc RevDepends;
  29. DepFunc Remove;
  30. // State
  31. Package **End;
  32. Package **List;
  33. Package **AfterEnd;
  34. string *FileList;
  35. DepIterator Loops[20];
  36. int LoopCount;
  37. int Depth;
  38. unsigned short *Flags;
  39. bool Debug;
  40. // Main visit function
  41. bool VisitNode(PkgIterator Pkg);
  42. bool VisitDeps(DepFunc F,PkgIterator Pkg);
  43. bool VisitRDeps(DepFunc F,PkgIterator Pkg);
  44. bool VisitRProvides(DepFunc F,VerIterator Ver);
  45. bool VisitProvides(DepIterator Pkg,bool Critical);
  46. // Dependency checking functions.
  47. bool DepUnPackCrit(DepIterator D);
  48. bool DepUnPackPreD(DepIterator D);
  49. bool DepUnPackPre(DepIterator D);
  50. bool DepUnPackDep(DepIterator D);
  51. bool DepConfigure(DepIterator D);
  52. bool DepRemove(DepIterator D);
  53. // Analysis helpers
  54. bool AddLoop(DepIterator D);
  55. bool CheckDep(DepIterator D);
  56. bool DoRun();
  57. // For pre sorting
  58. static pkgOrderList *Me;
  59. static int OrderCompareA(const void *a, const void *b);
  60. static int OrderCompareB(const void *a, const void *b);
  61. int FileCmp(PkgIterator A,PkgIterator B);
  62. public:
  63. typedef Package **iterator;
  64. // State flags
  65. enum Flags {Added = (1 << 0), AddPending = (1 << 1),
  66. Immediate = (1 << 2), Loop = (1 << 3),
  67. UnPacked = (1 << 4), Configured = (1 << 5),
  68. Removed = (1 << 6), // Early Remove
  69. InList = (1 << 7),
  70. After = (1 << 8),
  71. States = (UnPacked | Configured | Removed)};
  72. // Flag manipulators
  73. inline bool IsFlag(PkgIterator Pkg,unsigned long F) {return (Flags[Pkg->ID] & F) == F;};
  74. inline bool IsFlag(Package *Pkg,unsigned long F) {return (Flags[Pkg->ID] & F) == F;};
  75. void Flag(PkgIterator Pkg,unsigned long State, unsigned long F) {Flags[Pkg->ID] = (Flags[Pkg->ID] & (~F)) | State;};
  76. inline void Flag(PkgIterator Pkg,unsigned long F) {Flags[Pkg->ID] |= F;};
  77. inline void Flag(Package *Pkg,unsigned long F) {Flags[Pkg->ID] |= F;};
  78. inline bool IsNow(PkgIterator Pkg) {return (Flags[Pkg->ID] & (States & (~Removed))) == 0;};
  79. bool IsMissing(PkgIterator Pkg);
  80. void WipeFlags(unsigned long F);
  81. void SetFileList(string *FileList) {this->FileList = FileList;};
  82. // Accessors
  83. inline iterator begin() {return List;};
  84. inline iterator end() {return End;};
  85. inline void push_back(Package *Pkg) {*(End++) = Pkg;};
  86. inline void push_back(PkgIterator Pkg) {*(End++) = Pkg;};
  87. inline void pop_back() {End--;};
  88. inline bool empty() {return End == List;};
  89. inline unsigned int size() {return End - List;};
  90. // Ordering modes
  91. bool OrderCritical();
  92. bool OrderUnpack(string *FileList = 0);
  93. bool OrderConfigure();
  94. int Score(PkgIterator Pkg);
  95. pkgOrderList(pkgDepCache *Cache);
  96. ~pkgOrderList();
  97. };
  98. #endif