apt @VERSION@
|
00001 // -*- mode: cpp; mode: fold -*- 00002 // Description /*{{{*/ 00008 /*}}}*/ 00009 #ifndef APT_CACHESET_H 00010 #define APT_CACHESET_H 00011 // Include Files /*{{{*/ 00012 #include <iostream> 00013 #include <fstream> 00014 #include <list> 00015 #include <map> 00016 #include <set> 00017 #include <string> 00018 00019 #include <apt-pkg/cachefile.h> 00020 #include <apt-pkg/pkgcache.h> 00021 /*}}}*/ 00022 namespace APT { 00023 class PackageSet; 00024 class VersionSet; 00025 class CacheSetHelper { /*{{{*/ 00034 public: /*{{{*/ 00035 CacheSetHelper(bool const &ShowError = true, 00036 GlobalError::MsgType ErrorType = GlobalError::ERROR) : 00037 ShowError(ShowError), ErrorType(ErrorType) {}; 00038 virtual ~CacheSetHelper() {}; 00039 00040 virtual void showTaskSelection(PackageSet const &pkgset, string const &pattern) {}; 00041 virtual void showRegExSelection(PackageSet const &pkgset, string const &pattern) {}; 00042 virtual void showSelectedVersion(pkgCache::PkgIterator const &Pkg, pkgCache::VerIterator const Ver, 00043 string const &ver, bool const &verIsRel) {}; 00044 00045 virtual pkgCache::PkgIterator canNotFindPkgName(pkgCacheFile &Cache, std::string const &str); 00046 virtual PackageSet canNotFindTask(pkgCacheFile &Cache, std::string pattern); 00047 virtual PackageSet canNotFindRegEx(pkgCacheFile &Cache, std::string pattern); 00048 virtual PackageSet canNotFindPackage(pkgCacheFile &Cache, std::string const &str); 00049 virtual VersionSet canNotFindAllVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg); 00050 virtual VersionSet canNotFindInstCandVer(pkgCacheFile &Cache, 00051 pkgCache::PkgIterator const &Pkg); 00052 virtual VersionSet canNotFindCandInstVer(pkgCacheFile &Cache, 00053 pkgCache::PkgIterator const &Pkg); 00054 virtual pkgCache::VerIterator canNotFindNewestVer(pkgCacheFile &Cache, 00055 pkgCache::PkgIterator const &Pkg); 00056 virtual pkgCache::VerIterator canNotFindCandidateVer(pkgCacheFile &Cache, 00057 pkgCache::PkgIterator const &Pkg); 00058 virtual pkgCache::VerIterator canNotFindInstalledVer(pkgCacheFile &Cache, 00059 pkgCache::PkgIterator const &Pkg); 00060 00061 bool showErrors() const { return ShowError; }; 00062 bool showErrors(bool const &newValue) { if (ShowError == newValue) return ShowError; else return ((ShowError = newValue) == false); }; 00063 GlobalError::MsgType errorType() const { return ErrorType; }; 00064 GlobalError::MsgType errorType(GlobalError::MsgType const &newValue) 00065 { 00066 if (ErrorType == newValue) return ErrorType; 00067 else { 00068 GlobalError::MsgType const &oldValue = ErrorType; 00069 ErrorType = newValue; 00070 return oldValue; 00071 } 00072 }; 00073 00074 /*}}}*/ 00075 protected: 00076 bool ShowError; 00077 GlobalError::MsgType ErrorType; 00078 }; /*}}}*/ 00079 class PackageSet : public std::set<pkgCache::PkgIterator> { /*{{{*/ 00085 public: /*{{{*/ 00087 class const_iterator : public std::set<pkgCache::PkgIterator>::const_iterator {/*{{{*/ 00088 public: 00089 const_iterator(std::set<pkgCache::PkgIterator>::const_iterator x) : 00090 std::set<pkgCache::PkgIterator>::const_iterator(x) {} 00091 00092 operator pkgCache::PkgIterator(void) { return **this; } 00093 00094 inline const char *Name() const {return (**this).Name(); } 00095 inline std::string FullName(bool const &Pretty) const { return (**this).FullName(Pretty); } 00096 inline std::string FullName() const { return (**this).FullName(); } 00097 inline const char *Section() const {return (**this).Section(); } 00098 inline bool Purge() const {return (**this).Purge(); } 00099 inline const char *Arch() const {return (**this).Arch(); } 00100 inline pkgCache::GrpIterator Group() const { return (**this).Group(); } 00101 inline pkgCache::VerIterator VersionList() const { return (**this).VersionList(); } 00102 inline pkgCache::VerIterator CurrentVer() const { return (**this).CurrentVer(); } 00103 inline pkgCache::DepIterator RevDependsList() const { return (**this).RevDependsList(); } 00104 inline pkgCache::PrvIterator ProvidesList() const { return (**this).ProvidesList(); } 00105 inline pkgCache::PkgIterator::OkState State() const { return (**this).State(); } 00106 inline const char *CandVersion() const { return (**this).CandVersion(); } 00107 inline const char *CurVersion() const { return (**this).CurVersion(); } 00108 inline pkgCache *Cache() const { return (**this).Cache(); }; 00109 inline unsigned long Index() const {return (**this).Index();}; 00110 // we have only valid iterators here 00111 inline bool end() const { return false; }; 00112 00113 friend std::ostream& operator<<(std::ostream& out, const_iterator i) { return operator<<(out, (*i)); } 00114 00115 inline pkgCache::Package const * operator->() const { 00116 return &***this; 00117 }; 00118 }; 00119 // 103. set::iterator is required to be modifiable, but this allows modification of keys 00120 typedef APT::PackageSet::const_iterator iterator; 00121 /*}}}*/ 00122 00123 using std::set<pkgCache::PkgIterator>::insert; 00124 inline void insert(pkgCache::PkgIterator const &P) { if (P.end() == false) std::set<pkgCache::PkgIterator>::insert(P); }; 00125 inline void insert(PackageSet const &pkgset) { insert(pkgset.begin(), pkgset.end()); }; 00126 00135 static APT::PackageSet FromTask(pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper); 00136 static APT::PackageSet FromTask(pkgCacheFile &Cache, std::string const &pattern) { 00137 CacheSetHelper helper; 00138 return APT::PackageSet::FromTask(Cache, pattern, helper); 00139 } 00140 00149 static APT::PackageSet FromRegEx(pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper); 00150 static APT::PackageSet FromRegEx(pkgCacheFile &Cache, std::string const &pattern) { 00151 CacheSetHelper helper; 00152 return APT::PackageSet::FromRegEx(Cache, pattern, helper); 00153 } 00154 00160 static APT::PackageSet FromString(pkgCacheFile &Cache, std::string const &string, CacheSetHelper &helper); 00161 static APT::PackageSet FromString(pkgCacheFile &Cache, std::string const &string) { 00162 CacheSetHelper helper; 00163 return APT::PackageSet::FromString(Cache, string, helper); 00164 } 00165 00171 static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &string, CacheSetHelper &helper); 00172 static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &string) { 00173 CacheSetHelper helper; 00174 return APT::PackageSet::FromName(Cache, string, helper); 00175 } 00176 00184 static APT::PackageSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline, CacheSetHelper &helper); 00185 static APT::PackageSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline) { 00186 CacheSetHelper helper; 00187 return APT::PackageSet::FromCommandLine(Cache, cmdline, helper); 00188 } 00189 00190 struct Modifier { 00191 enum Position { NONE, PREFIX, POSTFIX }; 00192 unsigned short ID; 00193 const char * const Alias; 00194 Position Pos; 00195 Modifier (unsigned short const &id, const char * const alias, Position const &pos) : ID(id), Alias(alias), Pos(pos) {}; 00196 }; 00197 00209 static std::map<unsigned short, PackageSet> GroupedFromCommandLine( 00210 pkgCacheFile &Cache, const char **cmdline, 00211 std::list<PackageSet::Modifier> const &mods, 00212 unsigned short const &fallback, CacheSetHelper &helper); 00213 static std::map<unsigned short, PackageSet> GroupedFromCommandLine( 00214 pkgCacheFile &Cache, const char **cmdline, 00215 std::list<PackageSet::Modifier> const &mods, 00216 unsigned short const &fallback) { 00217 CacheSetHelper helper; 00218 return APT::PackageSet::GroupedFromCommandLine(Cache, cmdline, 00219 mods, fallback, helper); 00220 } 00221 00222 enum Constructor { UNKNOWN, REGEX, TASK }; 00223 Constructor getConstructor() const { return ConstructedBy; }; 00224 00225 PackageSet() : ConstructedBy(UNKNOWN) {}; 00226 PackageSet(Constructor const &by) : ConstructedBy(by) {}; 00227 /*}}}*/ 00228 private: /*{{{*/ 00229 Constructor ConstructedBy; 00230 /*}}}*/ 00231 }; /*}}}*/ 00232 class VersionSet : public std::set<pkgCache::VerIterator> { /*{{{*/ 00238 public: /*{{{*/ 00240 class const_iterator : public std::set<pkgCache::VerIterator>::const_iterator {/*{{{*/ 00241 public: 00242 const_iterator(std::set<pkgCache::VerIterator>::const_iterator x) : 00243 std::set<pkgCache::VerIterator>::const_iterator(x) {} 00244 00245 operator pkgCache::VerIterator(void) { return **this; } 00246 00247 inline pkgCache *Cache() const { return (**this).Cache(); }; 00248 inline unsigned long Index() const {return (**this).Index();}; 00249 // we have only valid iterators here 00250 inline bool end() const { return false; }; 00251 00252 inline pkgCache::Version const * operator->() const { 00253 return &***this; 00254 }; 00255 00256 inline int CompareVer(const pkgCache::VerIterator &B) const { return (**this).CompareVer(B); }; 00257 inline const char *VerStr() const { return (**this).VerStr(); }; 00258 inline const char *Section() const { return (**this).Section(); }; 00259 inline const char *Arch() const { return (**this).Arch(); }; 00260 __deprecated inline const char *Arch(bool const pseudo) const { return (**this).Arch(); }; 00261 inline pkgCache::PkgIterator ParentPkg() const { return (**this).ParentPkg(); }; 00262 inline pkgCache::DescIterator DescriptionList() const { return (**this).DescriptionList(); }; 00263 inline pkgCache::DescIterator TranslatedDescription() const { return (**this).TranslatedDescription(); }; 00264 inline pkgCache::DepIterator DependsList() const { return (**this).DependsList(); }; 00265 inline pkgCache::PrvIterator ProvidesList() const { return (**this).ProvidesList(); }; 00266 inline pkgCache::VerFileIterator FileList() const { return (**this).FileList(); }; 00267 inline bool Downloadable() const { return (**this).Downloadable(); }; 00268 inline const char *PriorityType() const { return (**this).PriorityType(); }; 00269 inline string RelStr() const { return (**this).RelStr(); }; 00270 inline bool Automatic() const { return (**this).Automatic(); }; 00271 __deprecated inline bool Pseudo() const { return false; }; 00272 inline pkgCache::VerFileIterator NewestFile() const { return (**this).NewestFile(); }; 00273 }; 00274 /*}}}*/ 00275 // 103. set::iterator is required to be modifiable, but this allows modification of keys 00276 typedef APT::VersionSet::const_iterator iterator; 00277 00278 using std::set<pkgCache::VerIterator>::insert; 00279 inline void insert(pkgCache::VerIterator const &V) { if (V.end() == false) std::set<pkgCache::VerIterator>::insert(V); }; 00280 inline void insert(VersionSet const &verset) { insert(verset.begin(), verset.end()); }; 00281 00283 enum Version { 00285 ALL, 00287 CANDANDINST, 00289 CANDIDATE, 00291 INSTALLED, 00293 CANDINST, 00295 INSTCAND, 00297 NEWEST 00298 }; 00299 00307 static APT::VersionSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline, 00308 APT::VersionSet::Version const &fallback, CacheSetHelper &helper); 00309 static APT::VersionSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline, 00310 APT::VersionSet::Version const &fallback) { 00311 CacheSetHelper helper; 00312 return APT::VersionSet::FromCommandLine(Cache, cmdline, fallback, helper); 00313 } 00314 static APT::VersionSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline) { 00315 return APT::VersionSet::FromCommandLine(Cache, cmdline, CANDINST); 00316 } 00317 00318 static APT::VersionSet FromString(pkgCacheFile &Cache, std::string pkg, 00319 APT::VersionSet::Version const &fallback, CacheSetHelper &helper, 00320 bool const &onlyFromName = false); 00321 static APT::VersionSet FromString(pkgCacheFile &Cache, std::string pkg, 00322 APT::VersionSet::Version const &fallback) { 00323 CacheSetHelper helper; 00324 return APT::VersionSet::FromString(Cache, pkg, fallback, helper); 00325 } 00326 static APT::VersionSet FromString(pkgCacheFile &Cache, std::string pkg) { 00327 return APT::VersionSet::FromString(Cache, pkg, CANDINST); 00328 } 00329 00336 static APT::VersionSet FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P, 00337 VersionSet::Version const &fallback, CacheSetHelper &helper); 00338 static APT::VersionSet FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P, 00339 APT::VersionSet::Version const &fallback) { 00340 CacheSetHelper helper; 00341 return APT::VersionSet::FromPackage(Cache, P, fallback, helper); 00342 } 00343 static APT::VersionSet FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P) { 00344 return APT::VersionSet::FromPackage(Cache, P, CANDINST); 00345 } 00346 00347 struct Modifier { 00348 enum Position { NONE, PREFIX, POSTFIX }; 00349 unsigned short ID; 00350 const char * const Alias; 00351 Position Pos; 00352 VersionSet::Version SelectVersion; 00353 Modifier (unsigned short const &id, const char * const alias, Position const &pos, 00354 VersionSet::Version const &select) : ID(id), Alias(alias), Pos(pos), 00355 SelectVersion(select) {}; 00356 }; 00357 00358 static std::map<unsigned short, VersionSet> GroupedFromCommandLine( 00359 pkgCacheFile &Cache, const char **cmdline, 00360 std::list<VersionSet::Modifier> const &mods, 00361 unsigned short const &fallback, CacheSetHelper &helper); 00362 static std::map<unsigned short, VersionSet> GroupedFromCommandLine( 00363 pkgCacheFile &Cache, const char **cmdline, 00364 std::list<VersionSet::Modifier> const &mods, 00365 unsigned short const &fallback) { 00366 CacheSetHelper helper; 00367 return APT::VersionSet::GroupedFromCommandLine(Cache, cmdline, 00368 mods, fallback, helper); 00369 } 00370 /*}}}*/ 00371 protected: /*{{{*/ 00372 00377 static pkgCache::VerIterator getCandidateVer(pkgCacheFile &Cache, 00378 pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper); 00379 00384 static pkgCache::VerIterator getInstalledVer(pkgCacheFile &Cache, 00385 pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper); 00386 /*}}}*/ 00387 }; /*}}}*/ 00388 } 00389 #endif