apt
1.5
|
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 <list> 00018 #include <string> 00019 #include <iterator> 00020 00021 #include <apt-pkg/error.h> 00022 #include <apt-pkg/pkgcache.h> 00023 00024 #ifndef APT_8_CLEANER_HEADERS 00025 #include <apt-pkg/cachefile.h> 00026 #endif 00027 /*}}}*/ 00028 00029 class pkgCacheFile; 00030 00031 namespace APT { 00032 class PackageContainerInterface; 00033 class VersionContainerInterface; 00034 00035 class CacheSetHelper { /*{{{*/ 00044 public: /*{{{*/ 00045 CacheSetHelper(bool const ShowError = true, 00046 GlobalError::MsgType ErrorType = GlobalError::ERROR) : 00047 ShowError(ShowError), ErrorType(ErrorType) {}; 00048 virtual ~CacheSetHelper() {}; 00049 00050 virtual void showTaskSelection(pkgCache::PkgIterator const &pkg, std::string const &pattern); 00051 virtual void showRegExSelection(pkgCache::PkgIterator const &pkg, std::string const &pattern); 00052 virtual void showSelectedVersion(pkgCache::PkgIterator const &Pkg, pkgCache::VerIterator const Ver, 00053 std::string const &ver, bool const verIsRel); 00054 00055 virtual void canNotFindTask(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern); 00056 virtual void canNotFindRegEx(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern); 00057 virtual void canNotFindPackage(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &str); 00058 00059 virtual void canNotFindAllVer(VersionContainerInterface * const vci, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg); 00060 virtual void canNotFindInstCandVer(VersionContainerInterface * const vci, pkgCacheFile &Cache, 00061 pkgCache::PkgIterator const &Pkg); 00062 virtual void canNotFindCandInstVer(VersionContainerInterface * const vci, 00063 pkgCacheFile &Cache, 00064 pkgCache::PkgIterator const &Pkg); 00065 00066 virtual pkgCache::PkgIterator canNotFindPkgName(pkgCacheFile &Cache, std::string const &str); 00067 virtual pkgCache::VerIterator canNotFindNewestVer(pkgCacheFile &Cache, 00068 pkgCache::PkgIterator const &Pkg); 00069 virtual pkgCache::VerIterator canNotFindCandidateVer(pkgCacheFile &Cache, 00070 pkgCache::PkgIterator const &Pkg); 00071 virtual pkgCache::VerIterator canNotFindInstalledVer(pkgCacheFile &Cache, 00072 pkgCache::PkgIterator const &Pkg); 00073 00074 bool showErrors() const { return ShowError; }; 00075 bool showErrors(bool const newValue) { if (ShowError == newValue) return ShowError; else return ((ShowError = newValue) == false); }; 00076 GlobalError::MsgType errorType() const { return ErrorType; }; 00077 GlobalError::MsgType errorType(GlobalError::MsgType const &newValue) 00078 { 00079 if (ErrorType == newValue) return ErrorType; 00080 else { 00081 GlobalError::MsgType const &oldValue = ErrorType; 00082 ErrorType = newValue; 00083 return oldValue; 00084 } 00085 }; 00086 00087 /*}}}*/ 00088 protected: 00089 bool ShowError; 00090 GlobalError::MsgType ErrorType; 00091 }; /*}}}*/ 00092 class PackageContainerInterface { /*{{{*/ 00102 public: 00103 class const_iterator { /*{{{*/ 00104 public: 00105 virtual pkgCache::PkgIterator getPkg() const = 0; 00106 operator pkgCache::PkgIterator(void) const { return getPkg(); } 00107 00108 inline const char *Name() const {return getPkg().Name(); } 00109 inline std::string FullName(bool const Pretty) const { return getPkg().FullName(Pretty); } 00110 inline std::string FullName() const { return getPkg().FullName(); } 00111 inline const char *Section() const {return getPkg().Section(); } 00112 inline bool Purge() const {return getPkg().Purge(); } 00113 inline const char *Arch() const {return getPkg().Arch(); } 00114 inline pkgCache::GrpIterator Group() const { return getPkg().Group(); } 00115 inline pkgCache::VerIterator VersionList() const { return getPkg().VersionList(); } 00116 inline pkgCache::VerIterator CurrentVer() const { return getPkg().CurrentVer(); } 00117 inline pkgCache::DepIterator RevDependsList() const { return getPkg().RevDependsList(); } 00118 inline pkgCache::PrvIterator ProvidesList() const { return getPkg().ProvidesList(); } 00119 inline pkgCache::PkgIterator::OkState State() const { return getPkg().State(); } 00120 inline const char *CandVersion() const { return getPkg().CandVersion(); } 00121 inline const char *CurVersion() const { return getPkg().CurVersion(); } 00122 inline pkgCache *Cache() const { return getPkg().Cache(); }; 00123 inline unsigned long Index() const {return getPkg().Index();}; 00124 // we have only valid iterators here 00125 inline bool end() const { return false; }; 00126 00127 inline pkgCache::Package const * operator->() const {return &*getPkg();}; 00128 }; 00129 /*}}}*/ 00130 00131 virtual bool insert(pkgCache::PkgIterator const &P) = 0; 00132 virtual bool empty() const = 0; 00133 virtual void clear() = 0; 00134 00135 enum Constructor { UNKNOWN, REGEX, TASK }; 00136 virtual void setConstructor(Constructor const &con) = 0; 00137 virtual Constructor getConstructor() const = 0; 00138 00139 static bool FromTask(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper); 00140 static bool FromRegEx(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper); 00141 static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper); 00142 static bool FromString(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper); 00143 static bool FromCommandLine(PackageContainerInterface * const pci, pkgCacheFile &Cache, const char **cmdline, CacheSetHelper &helper); 00144 00145 struct Modifier { 00146 enum Position { NONE, PREFIX, POSTFIX }; 00147 unsigned short ID; 00148 const char * const Alias; 00149 Position Pos; 00150 Modifier (unsigned short const &id, const char * const alias, Position const &pos) : ID(id), Alias(alias), Pos(pos) {}; 00151 }; 00152 00153 static bool FromModifierCommandLine(unsigned short &modID, PackageContainerInterface * const pci, 00154 pkgCacheFile &Cache, const char * cmdline, 00155 std::list<Modifier> const &mods, CacheSetHelper &helper); 00156 }; 00157 /*}}}*/ 00158 template<class Container> class PackageContainer : public PackageContainerInterface {/*{{{*/ 00164 Container _cont; 00165 public: /*{{{*/ 00167 class const_iterator : public PackageContainerInterface::const_iterator,/*{{{*/ 00168 public std::iterator<std::forward_iterator_tag, typename Container::const_iterator> { 00169 typename Container::const_iterator _iter; 00170 public: 00171 const_iterator(typename Container::const_iterator i) : _iter(i) {} 00172 pkgCache::PkgIterator getPkg(void) const { return *_iter; } 00173 inline pkgCache::PkgIterator operator*(void) const { return *_iter; }; 00174 operator typename Container::const_iterator(void) const { return _iter; } 00175 inline const_iterator& operator++() { ++_iter; return *this; } 00176 inline const_iterator operator++(int) { const_iterator tmp(*this); operator++(); return tmp; } 00177 inline bool operator!=(const_iterator const &i) const { return _iter != i._iter; }; 00178 inline bool operator==(const_iterator const &i) const { return _iter == i._iter; }; 00179 friend std::ostream& operator<<(std::ostream& out, const_iterator i) { return operator<<(out, *i); } 00180 }; 00181 class iterator : public PackageContainerInterface::const_iterator, 00182 public std::iterator<std::forward_iterator_tag, typename Container::iterator> { 00183 typename Container::iterator _iter; 00184 public: 00185 iterator(typename Container::iterator i) : _iter(i) {} 00186 pkgCache::PkgIterator getPkg(void) const { return *_iter; } 00187 inline pkgCache::PkgIterator operator*(void) const { return *_iter; }; 00188 operator typename Container::iterator(void) const { return _iter; } 00189 operator typename PackageContainer<Container>::const_iterator() { return typename PackageContainer<Container>::const_iterator(_iter); } 00190 inline iterator& operator++() { ++_iter; return *this; } 00191 inline iterator operator++(int) { iterator tmp(*this); operator++(); return tmp; } 00192 inline bool operator!=(iterator const &i) const { return _iter != i._iter; }; 00193 inline bool operator==(iterator const &i) const { return _iter == i._iter; }; 00194 inline iterator& operator=(iterator const &i) { _iter = i._iter; return *this; }; 00195 inline iterator& operator=(typename Container::iterator const &i) { _iter = i; return *this; }; 00196 friend std::ostream& operator<<(std::ostream& out, iterator i) { return operator<<(out, *i); } 00197 }; 00198 /*}}}*/ 00199 00200 bool insert(pkgCache::PkgIterator const &P) { if (P.end() == true) return false; _cont.insert(P); return true; }; 00201 template<class Cont> void insert(PackageContainer<Cont> const &pkgcont) { _cont.insert((typename Cont::const_iterator)pkgcont.begin(), (typename Cont::const_iterator)pkgcont.end()); }; 00202 void insert(const_iterator begin, const_iterator end) { _cont.insert(begin, end); }; 00203 00204 bool empty() const { return _cont.empty(); }; 00205 void clear() { return _cont.clear(); }; 00206 //FIXME: on ABI break, replace the first with the second without bool 00207 void erase(iterator position) { _cont.erase((typename Container::iterator)position); }; 00208 iterator& erase(iterator &position, bool) { return position = _cont.erase((typename Container::iterator)position); }; 00209 size_t erase(const pkgCache::PkgIterator x) { return _cont.erase(x); }; 00210 void erase(iterator first, iterator last) { _cont.erase(first, last); }; 00211 size_t size() const { return _cont.size(); }; 00212 00213 const_iterator begin() const { return const_iterator(_cont.begin()); }; 00214 const_iterator end() const { return const_iterator(_cont.end()); }; 00215 iterator begin() { return iterator(_cont.begin()); }; 00216 iterator end() { return iterator(_cont.end()); }; 00217 const_iterator find(pkgCache::PkgIterator const &P) const { return const_iterator(_cont.find(P)); }; 00218 00219 void setConstructor(Constructor const &by) { ConstructedBy = by; }; 00220 Constructor getConstructor() const { return ConstructedBy; }; 00221 00222 PackageContainer() : ConstructedBy(UNKNOWN) {}; 00223 PackageContainer(Constructor const &by) : ConstructedBy(by) {}; 00224 00233 static PackageContainer FromTask(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) { 00234 PackageContainer cont(TASK); 00235 PackageContainerInterface::FromTask(&cont, Cache, pattern, helper); 00236 return cont; 00237 } 00238 static PackageContainer FromTask(pkgCacheFile &Cache, std::string const &pattern) { 00239 CacheSetHelper helper; 00240 return FromTask(Cache, pattern, helper); 00241 } 00242 00251 static PackageContainer FromRegEx(pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) { 00252 PackageContainer cont(REGEX); 00253 PackageContainerInterface::FromRegEx(&cont, Cache, pattern, helper); 00254 return cont; 00255 } 00256 00257 static PackageContainer FromRegEx(pkgCacheFile &Cache, std::string const &pattern) { 00258 CacheSetHelper helper; 00259 return FromRegEx(Cache, pattern, helper); 00260 } 00261 00267 static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) { 00268 return PackageContainerInterface::FromName(Cache, pattern, helper); 00269 } 00270 static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &pattern) { 00271 CacheSetHelper helper; 00272 return PackageContainerInterface::FromName(Cache, pattern, helper); 00273 } 00274 00280 static PackageContainer FromString(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) { 00281 PackageContainer cont; 00282 PackageContainerInterface::FromString(&cont, Cache, pattern, helper); 00283 return cont; 00284 } 00285 static PackageContainer FromString(pkgCacheFile &Cache, std::string const &pattern) { 00286 CacheSetHelper helper; 00287 return FromString(Cache, pattern, helper); 00288 } 00289 00297 static PackageContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline, CacheSetHelper &helper) { 00298 PackageContainer cont; 00299 PackageContainerInterface::FromCommandLine(&cont, Cache, cmdline, helper); 00300 return cont; 00301 } 00302 static PackageContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline) { 00303 CacheSetHelper helper; 00304 return FromCommandLine(Cache, cmdline, helper); 00305 } 00306 00318 static std::map<unsigned short, PackageContainer> GroupedFromCommandLine( 00319 pkgCacheFile &Cache, 00320 const char **cmdline, 00321 std::list<Modifier> const &mods, 00322 unsigned short const &fallback, 00323 CacheSetHelper &helper) { 00324 std::map<unsigned short, PackageContainer> pkgsets; 00325 for (const char **I = cmdline; *I != 0; ++I) { 00326 unsigned short modID = fallback; 00327 PackageContainer pkgset; 00328 PackageContainerInterface::FromModifierCommandLine(modID, &pkgset, Cache, *I, mods, helper); 00329 pkgsets[modID].insert(pkgset); 00330 } 00331 return pkgsets; 00332 } 00333 static std::map<unsigned short, PackageContainer> GroupedFromCommandLine( 00334 pkgCacheFile &Cache, 00335 const char **cmdline, 00336 std::list<Modifier> const &mods, 00337 unsigned short const &fallback) { 00338 CacheSetHelper helper; 00339 return GroupedFromCommandLine(Cache, cmdline, 00340 mods, fallback, helper); 00341 } 00342 /*}}}*/ 00343 private: /*{{{*/ 00344 Constructor ConstructedBy; 00345 /*}}}*/ 00346 }; /*}}}*/ 00347 00348 template<> template<class Cont> void PackageContainer<std::list<pkgCache::PkgIterator> >::insert(PackageContainer<Cont> const &pkgcont) { 00349 for (typename PackageContainer<Cont>::const_iterator p = pkgcont.begin(); p != pkgcont.end(); ++p) 00350 _cont.push_back(*p); 00351 }; 00352 // these two are 'inline' as otherwise the linker has problems with seeing these untemplated 00353 // specializations again and again - but we need to see them, so that library users can use them 00354 template<> inline bool PackageContainer<std::list<pkgCache::PkgIterator> >::insert(pkgCache::PkgIterator const &P) { 00355 if (P.end() == true) 00356 return false; 00357 _cont.push_back(P); 00358 return true; 00359 }; 00360 template<> inline void PackageContainer<std::list<pkgCache::PkgIterator> >::insert(const_iterator begin, const_iterator end) { 00361 for (const_iterator p = begin; p != end; ++p) 00362 _cont.push_back(*p); 00363 }; 00364 typedef PackageContainer<std::set<pkgCache::PkgIterator> > PackageSet; 00365 typedef PackageContainer<std::list<pkgCache::PkgIterator> > PackageList; 00366 00367 class VersionContainerInterface { /*{{{*/ 00371 public: 00373 class const_iterator { /*{{{*/ 00374 public: 00375 virtual pkgCache::VerIterator getVer() const = 0; 00376 operator pkgCache::VerIterator(void) { return getVer(); } 00377 00378 inline pkgCache *Cache() const { return getVer().Cache(); }; 00379 inline unsigned long Index() const {return getVer().Index();}; 00380 inline int CompareVer(const pkgCache::VerIterator &B) const { return getVer().CompareVer(B); }; 00381 inline const char *VerStr() const { return getVer().VerStr(); }; 00382 inline const char *Section() const { return getVer().Section(); }; 00383 inline const char *Arch() const { return getVer().Arch(); }; 00384 inline pkgCache::PkgIterator ParentPkg() const { return getVer().ParentPkg(); }; 00385 inline pkgCache::DescIterator DescriptionList() const { return getVer().DescriptionList(); }; 00386 inline pkgCache::DescIterator TranslatedDescription() const { return getVer().TranslatedDescription(); }; 00387 inline pkgCache::DepIterator DependsList() const { return getVer().DependsList(); }; 00388 inline pkgCache::PrvIterator ProvidesList() const { return getVer().ProvidesList(); }; 00389 inline pkgCache::VerFileIterator FileList() const { return getVer().FileList(); }; 00390 inline bool Downloadable() const { return getVer().Downloadable(); }; 00391 inline const char *PriorityType() const { return getVer().PriorityType(); }; 00392 inline std::string RelStr() const { return getVer().RelStr(); }; 00393 inline bool Automatic() const { return getVer().Automatic(); }; 00394 inline pkgCache::VerFileIterator NewestFile() const { return getVer().NewestFile(); }; 00395 // we have only valid iterators here 00396 inline bool end() const { return false; }; 00397 00398 inline pkgCache::Version const * operator->() const { return &*getVer(); }; 00399 }; 00400 /*}}}*/ 00401 00402 virtual bool insert(pkgCache::VerIterator const &V) = 0; 00403 virtual bool empty() const = 0; 00404 virtual void clear() = 0; 00405 00407 enum Version { 00409 ALL, 00411 CANDANDINST, 00413 CANDIDATE, 00415 INSTALLED, 00417 CANDINST, 00419 INSTCAND, 00421 NEWEST 00422 }; 00423 00424 struct Modifier { 00425 enum Position { NONE, PREFIX, POSTFIX }; 00426 unsigned short ID; 00427 const char * const Alias; 00428 Position Pos; 00429 Version SelectVersion; 00430 Modifier (unsigned short const &id, const char * const alias, Position const &pos, 00431 Version const &select) : ID(id), Alias(alias), Pos(pos), 00432 SelectVersion(select) {}; 00433 }; 00434 00435 static bool FromCommandLine(VersionContainerInterface * const vci, pkgCacheFile &Cache, 00436 const char **cmdline, Version const &fallback, 00437 CacheSetHelper &helper); 00438 00439 static bool FromString(VersionContainerInterface * const vci, pkgCacheFile &Cache, 00440 std::string pkg, Version const &fallback, CacheSetHelper &helper, 00441 bool const onlyFromName = false); 00442 00443 static bool FromPackage(VersionContainerInterface * const vci, pkgCacheFile &Cache, 00444 pkgCache::PkgIterator const &P, Version const &fallback, 00445 CacheSetHelper &helper); 00446 00447 static bool FromModifierCommandLine(unsigned short &modID, 00448 VersionContainerInterface * const vci, 00449 pkgCacheFile &Cache, const char * cmdline, 00450 std::list<Modifier> const &mods, 00451 CacheSetHelper &helper); 00452 00453 00454 static bool FromDependency(VersionContainerInterface * const vci, 00455 pkgCacheFile &Cache, 00456 pkgCache::DepIterator const &D, 00457 Version const &selector, 00458 CacheSetHelper &helper); 00459 00460 protected: /*{{{*/ 00461 00466 static pkgCache::VerIterator getCandidateVer(pkgCacheFile &Cache, 00467 pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper); 00468 00473 static pkgCache::VerIterator getInstalledVer(pkgCacheFile &Cache, 00474 pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper); 00475 /*}}}*/ 00476 }; 00477 /*}}}*/ 00478 template<class Container> class VersionContainer : public VersionContainerInterface {/*{{{*/ 00484 Container _cont; 00485 public: /*{{{*/ 00487 class const_iterator : public VersionContainerInterface::const_iterator, 00488 public std::iterator<std::forward_iterator_tag, typename Container::const_iterator> {/*{{{*/ 00489 typename Container::const_iterator _iter; 00490 public: 00491 const_iterator(typename Container::const_iterator i) : _iter(i) {} 00492 pkgCache::VerIterator getVer(void) const { return *_iter; } 00493 inline pkgCache::VerIterator operator*(void) const { return *_iter; }; 00494 operator typename Container::const_iterator(void) const { return _iter; } 00495 inline const_iterator& operator++() { ++_iter; return *this; } 00496 inline const_iterator operator++(int) { const_iterator tmp(*this); operator++(); return tmp; } 00497 inline bool operator!=(const_iterator const &i) const { return _iter != i._iter; }; 00498 inline bool operator==(const_iterator const &i) const { return _iter == i._iter; }; 00499 friend std::ostream& operator<<(std::ostream& out, const_iterator i) { return operator<<(out, *i); } 00500 }; 00501 class iterator : public VersionContainerInterface::const_iterator, 00502 public std::iterator<std::forward_iterator_tag, typename Container::iterator> { 00503 typename Container::iterator _iter; 00504 public: 00505 iterator(typename Container::iterator i) : _iter(i) {} 00506 pkgCache::VerIterator getVer(void) const { return *_iter; } 00507 inline pkgCache::VerIterator operator*(void) const { return *_iter; }; 00508 operator typename Container::iterator(void) const { return _iter; } 00509 operator typename VersionContainer<Container>::const_iterator() { return typename VersionContainer<Container>::const_iterator(_iter); } 00510 inline iterator& operator++() { ++_iter; return *this; } 00511 inline iterator operator++(int) { iterator tmp(*this); operator++(); return tmp; } 00512 inline bool operator!=(iterator const &i) const { return _iter != i._iter; }; 00513 inline bool operator==(iterator const &i) const { return _iter == i._iter; }; 00514 inline iterator& operator=(iterator const &i) { _iter = i._iter; return *this; }; 00515 inline iterator& operator=(typename Container::iterator const &i) { _iter = i; return *this; }; 00516 friend std::ostream& operator<<(std::ostream& out, iterator i) { return operator<<(out, *i); } 00517 }; 00518 /*}}}*/ 00519 00520 bool insert(pkgCache::VerIterator const &V) { if (V.end() == true) return false; _cont.insert(V); return true; }; 00521 template<class Cont> void insert(VersionContainer<Cont> const &vercont) { _cont.insert((typename Cont::const_iterator)vercont.begin(), (typename Cont::const_iterator)vercont.end()); }; 00522 void insert(const_iterator begin, const_iterator end) { _cont.insert(begin, end); }; 00523 bool empty() const { return _cont.empty(); }; 00524 void clear() { return _cont.clear(); }; 00525 //FIXME: on ABI break, replace the first with the second without bool 00526 void erase(iterator position) { _cont.erase((typename Container::iterator)position); }; 00527 iterator& erase(iterator &position, bool) { return position = _cont.erase((typename Container::iterator)position); }; 00528 size_t erase(const pkgCache::VerIterator x) { return _cont.erase(x); }; 00529 void erase(iterator first, iterator last) { _cont.erase(first, last); }; 00530 size_t size() const { return _cont.size(); }; 00531 00532 const_iterator begin() const { return const_iterator(_cont.begin()); }; 00533 const_iterator end() const { return const_iterator(_cont.end()); }; 00534 iterator begin() { return iterator(_cont.begin()); }; 00535 iterator end() { return iterator(_cont.end()); }; 00536 const_iterator find(pkgCache::VerIterator const &V) const { return const_iterator(_cont.find(V)); }; 00537 00545 static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline, 00546 Version const &fallback, CacheSetHelper &helper) { 00547 VersionContainer vercon; 00548 VersionContainerInterface::FromCommandLine(&vercon, Cache, cmdline, fallback, helper); 00549 return vercon; 00550 } 00551 static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline, 00552 Version const &fallback) { 00553 CacheSetHelper helper; 00554 return FromCommandLine(Cache, cmdline, fallback, helper); 00555 } 00556 static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline) { 00557 return FromCommandLine(Cache, cmdline, CANDINST); 00558 } 00559 00560 static VersionContainer FromString(pkgCacheFile &Cache, std::string const &pkg, 00561 Version const &fallback, CacheSetHelper &helper, 00562 bool const onlyFromName = false) { 00563 VersionContainer vercon; 00564 VersionContainerInterface::FromString(&vercon, Cache, pkg, fallback, helper); 00565 return vercon; 00566 } 00567 static VersionContainer FromString(pkgCacheFile &Cache, std::string pkg, 00568 Version const &fallback) { 00569 CacheSetHelper helper; 00570 return FromString(Cache, pkg, fallback, helper); 00571 } 00572 static VersionContainer FromString(pkgCacheFile &Cache, std::string pkg) { 00573 return FromString(Cache, pkg, CANDINST); 00574 } 00575 00582 static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P, 00583 Version const &fallback, CacheSetHelper &helper) { 00584 VersionContainer vercon; 00585 VersionContainerInterface::FromPackage(&vercon, Cache, P, fallback, helper); 00586 return vercon; 00587 } 00588 static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P, 00589 Version const &fallback) { 00590 CacheSetHelper helper; 00591 return FromPackage(Cache, P, fallback, helper); 00592 } 00593 static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P) { 00594 return FromPackage(Cache, P, CANDIDATE); 00595 } 00596 00597 static std::map<unsigned short, VersionContainer> GroupedFromCommandLine( 00598 pkgCacheFile &Cache, 00599 const char **cmdline, 00600 std::list<Modifier> const &mods, 00601 unsigned short const fallback, 00602 CacheSetHelper &helper) { 00603 std::map<unsigned short, VersionContainer> versets; 00604 for (const char **I = cmdline; *I != 0; ++I) { 00605 unsigned short modID = fallback; 00606 VersionContainer verset; 00607 VersionContainerInterface::FromModifierCommandLine(modID, &verset, Cache, *I, mods, helper); 00608 versets[modID].insert(verset); 00609 } 00610 return versets; 00611 00612 } 00613 static std::map<unsigned short, VersionContainer> GroupedFromCommandLine( 00614 pkgCacheFile &Cache, const char **cmdline, 00615 std::list<Modifier> const &mods, 00616 unsigned short const fallback) { 00617 CacheSetHelper helper; 00618 return GroupedFromCommandLine(Cache, cmdline, 00619 mods, fallback, helper); 00620 } 00621 00622 static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D, 00623 Version const &selector, CacheSetHelper &helper) { 00624 VersionContainer vercon; 00625 VersionContainerInterface::FromDependency(&vercon, Cache, D, selector, helper); 00626 return vercon; 00627 } 00628 static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D, 00629 Version const &selector) { 00630 CacheSetHelper helper; 00631 return FromPackage(Cache, D, selector, helper); 00632 } 00633 static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D) { 00634 return FromPackage(Cache, D, CANDIDATE); 00635 } 00636 /*}}}*/ 00637 }; /*}}}*/ 00638 00639 template<> template<class Cont> void VersionContainer<std::list<pkgCache::VerIterator> >::insert(VersionContainer<Cont> const &vercont) { 00640 for (typename VersionContainer<Cont>::const_iterator v = vercont.begin(); v != vercont.end(); ++v) 00641 _cont.push_back(*v); 00642 }; 00643 // these two are 'inline' as otherwise the linker has problems with seeing these untemplated 00644 // specializations again and again - but we need to see them, so that library users can use them 00645 template<> inline bool VersionContainer<std::list<pkgCache::VerIterator> >::insert(pkgCache::VerIterator const &V) { 00646 if (V.end() == true) 00647 return false; 00648 _cont.push_back(V); 00649 return true; 00650 }; 00651 template<> inline void VersionContainer<std::list<pkgCache::VerIterator> >::insert(const_iterator begin, const_iterator end) { 00652 for (const_iterator v = begin; v != end; ++v) 00653 _cont.push_back(*v); 00654 }; 00655 typedef VersionContainer<std::set<pkgCache::VerIterator> > VersionSet; 00656 typedef VersionContainer<std::list<pkgCache::VerIterator> > VersionList; 00657 } 00658 #endif