]> git.saurik.com Git - apt.git/blob - apt-private/private-cachefile.h
implement a more generic ShowList method
[apt.git] / apt-private / private-cachefile.h
1 #ifndef APT_PRIVATE_CACHEFILE_H
2 #define APT_PRIVATE_CACHEFILE_H
3
4 #include <apt-pkg/cachefile.h>
5 #include <apt-pkg/progress.h>
6 #include <apt-pkg/configuration.h>
7 #include <apt-pkg/pkgcache.h>
8 #include <apt-pkg/macros.h>
9 #include <apt-pkg/sourcelist.h>
10 #include <apt-pkg/cacheset.h>
11
12 #include <apti18n.h>
13
14 // FIXME: we need to find a way to export this
15 class APT_PUBLIC SourceList : public pkgSourceList
16 {
17 public:
18 // Add custom metaIndex (e.g. local files)
19 void AddMetaIndex(metaIndex *mi) {
20 SrcList.push_back(mi);
21 }
22
23 };
24
25 // class CacheFile - Cover class for some dependency cache functions /*{{{*/
26 class APT_PUBLIC CacheFile : public pkgCacheFile
27 {
28 public:
29 std::vector<map_pointer_t> UniverseList;
30
31 bool CheckDeps(bool AllowBroken = false);
32 bool BuildCaches(bool WithLock = true)
33 {
34 OpTextProgress Prog(*_config);
35 if (pkgCacheFile::BuildCaches(&Prog,WithLock) == false)
36 return false;
37 return true;
38 }
39 // FIXME: this can go once the "libapt-pkg" pkgSourceList has a way
40 // to add custom metaIndexes (or custom local files or so)
41 bool BuildSourceList(OpProgress */*Progress*/ = NULL) {
42 if (SrcList != NULL)
43 return true;
44 SrcList = new SourceList();
45 if (SrcList->ReadMainList() == false)
46 return _error->Error(_("The list of sources could not be read."));
47 return true;
48 }
49 bool Open(bool WithLock = true)
50 {
51 OpTextProgress Prog(*_config);
52 return pkgCacheFile::Open(&Prog,WithLock);
53 };
54 bool OpenForInstall()
55 {
56 if (_config->FindB("APT::Get::Print-URIs") == true)
57 return Open(false);
58 else
59 return Open(true);
60 }
61 };
62 /*}}}*/
63
64 class APT_PUBLIC SortedPackageUniverse : public APT::PackageUniverse
65 {
66 std::vector<map_pointer_t> &List;
67 void LazyInit() const;
68
69 public:
70 SortedPackageUniverse(CacheFile &Cache);
71
72 class const_iterator : public APT::Container_iterator_base<APT::PackageContainerInterface, SortedPackageUniverse, SortedPackageUniverse::const_iterator, std::vector<map_pointer_t>::const_iterator, pkgCache::PkgIterator>
73 {
74 pkgCache * const Cache;
75 protected:
76 inline virtual pkgCache::PkgIterator getType(void) const APT_OVERRIDE
77 {
78 if (*_iter == 0) return pkgCache::PkgIterator(*Cache);
79 return pkgCache::PkgIterator(*Cache, Cache->PkgP + *_iter);
80 }
81 public:
82 explicit const_iterator(pkgCache * const Owner, std::vector<map_pointer_t>::const_iterator i):
83 Container_iterator_base<APT::PackageContainerInterface, SortedPackageUniverse, SortedPackageUniverse::const_iterator, std::vector<map_pointer_t>::const_iterator, pkgCache::PkgIterator>(i), Cache(Owner) {}
84
85 };
86 typedef const_iterator iterator;
87
88 APT_PUBLIC const_iterator begin() const { LazyInit(); return const_iterator(data(), List.begin()); }
89 APT_PUBLIC const_iterator end() const { LazyInit(); return const_iterator(data(), List.end()); }
90 APT_PUBLIC const_iterator cbegin() const { LazyInit(); return const_iterator(data(), List.begin()); }
91 APT_PUBLIC const_iterator cend() const { LazyInit(); return const_iterator(data(), List.end()); }
92 APT_PUBLIC iterator begin() { LazyInit(); return iterator(data(), List.begin()); }
93 APT_PUBLIC iterator end() { LazyInit(); return iterator(data(), List.end()); }
94 };
95
96 #endif