~ubuntu-branches/ubuntu/trusty/apt/trusty

« back to all changes in this revision

Viewing changes to apt-pkg/cacheset.h

  • Committer: Package Import Robot
  • Author(s): Michael Vogt
  • Date: 2014-04-01 17:48:58 UTC
  • mfrom: (1.4.87 sid)
  • Revision ID: package-import@ubuntu.com-20140401174858-4mv29mm29zu22fn1
Tags: 1.0.1ubuntu1
merge with the debian/sid 1.0.1 version
(LP: #1302033)

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
#ifndef APT_CACHESET_H
10
10
#define APT_CACHESET_H
11
11
// Include Files                                                        /*{{{*/
12
 
#include <iostream>
13
12
#include <fstream>
14
13
#include <map>
15
14
#include <set>
17
16
#include <string>
18
17
#include <iterator>
19
18
 
 
19
#include <stddef.h>
 
20
 
20
21
#include <apt-pkg/error.h>
21
22
#include <apt-pkg/pkgcache.h>
 
23
#include <apt-pkg/cacheiterators.h>
22
24
 
23
25
#ifndef APT_8_CLEANER_HEADERS
24
26
#include <apt-pkg/cachefile.h>
25
27
#endif
 
28
#ifndef APT_10_CLEANER_HEADERS
 
29
#include <iostream>
 
30
#endif
26
31
                                                                        /*}}}*/
27
32
 
28
33
class pkgCacheFile;
43
48
public:                                                                 /*{{{*/
44
49
        CacheSetHelper(bool const ShowError = true,
45
50
                GlobalError::MsgType ErrorType = GlobalError::ERROR) :
46
 
                        ShowError(ShowError), ErrorType(ErrorType) {};
47
 
        virtual ~CacheSetHelper() {};
 
51
                        ShowError(ShowError), ErrorType(ErrorType) {}
 
52
        virtual ~CacheSetHelper() {}
48
53
 
49
54
        virtual void showTaskSelection(pkgCache::PkgIterator const &pkg, std::string const &pattern);
50
55
        virtual void showRegExSelection(pkgCache::PkgIterator const &pkg, std::string const &pattern);
76
81
        virtual pkgCache::VerIterator canNotFindInstalledVer(pkgCacheFile &Cache,
77
82
                                pkgCache::PkgIterator const &Pkg);
78
83
 
79
 
        bool showErrors() const { return ShowError; };
80
 
        bool showErrors(bool const newValue) { if (ShowError == newValue) return ShowError; else return ((ShowError = newValue) == false); };
81
 
        GlobalError::MsgType errorType() const { return ErrorType; };
 
84
        bool showErrors() const { return ShowError; }
 
85
        bool showErrors(bool const newValue) { if (ShowError == newValue) return ShowError; else return ((ShowError = newValue) == false); }
 
86
        GlobalError::MsgType errorType() const { return ErrorType; }
82
87
        GlobalError::MsgType errorType(GlobalError::MsgType const &newValue)
83
88
        {
84
89
                if (ErrorType == newValue) return ErrorType;
87
92
                        ErrorType = newValue;
88
93
                        return oldValue;
89
94
                }
90
 
        };
 
95
        }
91
96
 
92
97
                                                                        /*}}}*/
93
98
protected:
124
129
                inline pkgCache::PkgIterator::OkState State() const { return getPkg().State(); }
125
130
                inline const char *CandVersion() const { return getPkg().CandVersion(); }
126
131
                inline const char *CurVersion() const { return getPkg().CurVersion(); }
127
 
                inline pkgCache *Cache() const { return getPkg().Cache(); };
128
 
                inline unsigned long Index() const {return getPkg().Index();};
 
132
                inline pkgCache *Cache() const { return getPkg().Cache(); }
 
133
                inline unsigned long Index() const {return getPkg().Index();}
129
134
                // we have only valid iterators here
130
 
                inline bool end() const { return false; };
 
135
                inline bool end() const { return false; }
131
136
 
132
 
                inline pkgCache::Package const * operator->() const {return &*getPkg();};
 
137
                inline pkgCache::Package const * operator->() const {return &*getPkg();}
133
138
        };
134
139
                                                                        /*}}}*/
135
140
 
154
159
                unsigned short ID;
155
160
                const char * const Alias;
156
161
                Position Pos;
157
 
                Modifier (unsigned short const &id, const char * const alias, Position const &pos) : ID(id), Alias(alias), Pos(pos) {};
 
162
                Modifier (unsigned short const &id, const char * const alias, Position const &pos) : ID(id), Alias(alias), Pos(pos) {}
158
163
        };
159
164
 
160
165
        static bool FromModifierCommandLine(unsigned short &modID, PackageContainerInterface * const pci,
177
182
        public:
178
183
                const_iterator(typename Container::const_iterator i) : _iter(i) {}
179
184
                pkgCache::PkgIterator getPkg(void) const { return *_iter; }
180
 
                inline pkgCache::PkgIterator operator*(void) const { return *_iter; };
 
185
                inline pkgCache::PkgIterator operator*(void) const { return *_iter; }
181
186
                operator typename Container::const_iterator(void) const { return _iter; }
182
187
                inline const_iterator& operator++() { ++_iter; return *this; }
183
188
                inline const_iterator operator++(int) { const_iterator tmp(*this); operator++(); return tmp; }
184
 
                inline bool operator!=(const_iterator const &i) const { return _iter != i._iter; };
185
 
                inline bool operator==(const_iterator const &i) const { return _iter == i._iter; };
 
189
                inline bool operator!=(const_iterator const &i) const { return _iter != i._iter; }
 
190
                inline bool operator==(const_iterator const &i) const { return _iter == i._iter; }
186
191
                friend std::ostream& operator<<(std::ostream& out, const_iterator i) { return operator<<(out, *i); }
187
192
        };
188
193
        class iterator : public PackageContainerInterface::const_iterator,
191
196
        public:
192
197
                iterator(typename Container::iterator i) : _iter(i) {}
193
198
                pkgCache::PkgIterator getPkg(void) const { return *_iter; }
194
 
                inline pkgCache::PkgIterator operator*(void) const { return *_iter; };
 
199
                inline pkgCache::PkgIterator operator*(void) const { return *_iter; }
195
200
                operator typename Container::iterator(void) const { return _iter; }
196
201
                operator typename PackageContainer<Container>::const_iterator() { return typename PackageContainer<Container>::const_iterator(_iter); }
197
202
                inline iterator& operator++() { ++_iter; return *this; }
198
203
                inline iterator operator++(int) { iterator tmp(*this); operator++(); return tmp; }
199
 
                inline bool operator!=(iterator const &i) const { return _iter != i._iter; };
200
 
                inline bool operator==(iterator const &i) const { return _iter == i._iter; };
201
 
                inline iterator& operator=(iterator const &i) { _iter = i._iter; return *this; };
202
 
                inline iterator& operator=(typename Container::iterator const &i) { _iter = i; return *this; };
 
204
                inline bool operator!=(iterator const &i) const { return _iter != i._iter; }
 
205
                inline bool operator==(iterator const &i) const { return _iter == i._iter; }
 
206
                inline iterator& operator=(iterator const &i) { _iter = i._iter; return *this; }
 
207
                inline iterator& operator=(typename Container::iterator const &i) { _iter = i; return *this; }
203
208
                friend std::ostream& operator<<(std::ostream& out, iterator i) { return operator<<(out, *i); }
204
209
        };
205
210
                                                                        /*}}}*/
206
211
 
207
 
        bool insert(pkgCache::PkgIterator const &P) { if (P.end() == true) return false; _cont.insert(P); return true; };
208
 
        template<class Cont> void insert(PackageContainer<Cont> const &pkgcont) { _cont.insert((typename Cont::const_iterator)pkgcont.begin(), (typename Cont::const_iterator)pkgcont.end()); };
209
 
        void insert(const_iterator begin, const_iterator end) { _cont.insert(begin, end); };
 
212
        bool insert(pkgCache::PkgIterator const &P) { if (P.end() == true) return false; _cont.insert(P); return true; }
 
213
        template<class Cont> void insert(PackageContainer<Cont> const &pkgcont) { _cont.insert((typename Cont::const_iterator)pkgcont.begin(), (typename Cont::const_iterator)pkgcont.end()); }
 
214
        void insert(const_iterator begin, const_iterator end) { _cont.insert(begin, end); }
210
215
 
211
 
        bool empty() const { return _cont.empty(); };
212
 
        void clear() { return _cont.clear(); };
 
216
        bool empty() const { return _cont.empty(); }
 
217
        void clear() { return _cont.clear(); }
213
218
        //FIXME: on ABI break, replace the first with the second without bool
214
 
        void erase(iterator position) { _cont.erase((typename Container::iterator)position); };
215
 
        iterator& erase(iterator &position, bool) { return position = _cont.erase((typename Container::iterator)position); };
216
 
        size_t erase(const pkgCache::PkgIterator x) { return _cont.erase(x); };
217
 
        void erase(iterator first, iterator last) { _cont.erase(first, last); };
218
 
        size_t size() const { return _cont.size(); };
219
 
 
220
 
        const_iterator begin() const { return const_iterator(_cont.begin()); };
221
 
        const_iterator end() const { return const_iterator(_cont.end()); };
222
 
        iterator begin() { return iterator(_cont.begin()); };
223
 
        iterator end() { return iterator(_cont.end()); };
224
 
        const_iterator find(pkgCache::PkgIterator const &P) const { return const_iterator(_cont.find(P)); };
225
 
 
226
 
        void setConstructor(Constructor const &by) { ConstructedBy = by; };
227
 
        Constructor getConstructor() const { return ConstructedBy; };
228
 
 
229
 
        PackageContainer() : ConstructedBy(UNKNOWN) {};
230
 
        PackageContainer(Constructor const &by) : ConstructedBy(by) {};
 
219
        void erase(iterator position) { _cont.erase((typename Container::iterator)position); }
 
220
        iterator& erase(iterator &position, bool) { return position = _cont.erase((typename Container::iterator)position); }
 
221
        size_t erase(const pkgCache::PkgIterator x) { return _cont.erase(x); }
 
222
        void erase(iterator first, iterator last) { _cont.erase(first, last); }
 
223
        size_t size() const { return _cont.size(); }
 
224
 
 
225
        const_iterator begin() const { return const_iterator(_cont.begin()); }
 
226
        const_iterator end() const { return const_iterator(_cont.end()); }
 
227
        iterator begin() { return iterator(_cont.begin()); }
 
228
        iterator end() { return iterator(_cont.end()); }
 
229
        const_iterator find(pkgCache::PkgIterator const &P) const { return const_iterator(_cont.find(P)); }
 
230
 
 
231
        void setConstructor(Constructor const &by) { ConstructedBy = by; }
 
232
        Constructor getConstructor() const { return ConstructedBy; }
 
233
 
 
234
        PackageContainer() : ConstructedBy(UNKNOWN) {}
 
235
        PackageContainer(Constructor const &by) : ConstructedBy(by) {}
231
236
 
232
237
        /** \brief returns all packages in the cache who belong to the given task
233
238
 
365
370
template<> template<class Cont> void PackageContainer<std::list<pkgCache::PkgIterator> >::insert(PackageContainer<Cont> const &pkgcont) {
366
371
        for (typename PackageContainer<Cont>::const_iterator p = pkgcont.begin(); p != pkgcont.end(); ++p)
367
372
                _cont.push_back(*p);
368
 
};
 
373
}
369
374
// these two are 'inline' as otherwise the linker has problems with seeing these untemplated
370
375
// specializations again and again - but we need to see them, so that library users can use them
371
376
template<> inline bool PackageContainer<std::list<pkgCache::PkgIterator> >::insert(pkgCache::PkgIterator const &P) {
373
378
                return false;
374
379
        _cont.push_back(P);
375
380
        return true;
376
 
};
 
381
}
377
382
template<> inline void PackageContainer<std::list<pkgCache::PkgIterator> >::insert(const_iterator begin, const_iterator end) {
378
383
        for (const_iterator p = begin; p != end; ++p)
379
384
                _cont.push_back(*p);
380
 
};
 
385
}
381
386
typedef PackageContainer<std::set<pkgCache::PkgIterator> > PackageSet;
382
387
typedef PackageContainer<std::list<pkgCache::PkgIterator> > PackageList;
383
388
 
392
397
                virtual pkgCache::VerIterator getVer() const = 0;
393
398
                operator pkgCache::VerIterator(void) { return getVer(); }
394
399
 
395
 
                inline pkgCache *Cache() const { return getVer().Cache(); };
396
 
                inline unsigned long Index() const {return getVer().Index();};
397
 
                inline int CompareVer(const pkgCache::VerIterator &B) const { return getVer().CompareVer(B); };
398
 
                inline const char *VerStr() const { return getVer().VerStr(); };
399
 
                inline const char *Section() const { return getVer().Section(); };
400
 
                inline const char *Arch() const { return getVer().Arch(); };
401
 
                inline pkgCache::PkgIterator ParentPkg() const { return getVer().ParentPkg(); };
402
 
                inline pkgCache::DescIterator DescriptionList() const { return getVer().DescriptionList(); };
403
 
                inline pkgCache::DescIterator TranslatedDescription() const { return getVer().TranslatedDescription(); };
404
 
                inline pkgCache::DepIterator DependsList() const { return getVer().DependsList(); };
405
 
                inline pkgCache::PrvIterator ProvidesList() const { return getVer().ProvidesList(); };
406
 
                inline pkgCache::VerFileIterator FileList() const { return getVer().FileList(); };
407
 
                inline bool Downloadable() const { return getVer().Downloadable(); };
408
 
                inline const char *PriorityType() const { return getVer().PriorityType(); };
409
 
                inline std::string RelStr() const { return getVer().RelStr(); };
410
 
                inline bool Automatic() const { return getVer().Automatic(); };
411
 
                inline pkgCache::VerFileIterator NewestFile() const { return getVer().NewestFile(); };
 
400
                inline pkgCache *Cache() const { return getVer().Cache(); }
 
401
                inline unsigned long Index() const {return getVer().Index();}
 
402
                inline int CompareVer(const pkgCache::VerIterator &B) const { return getVer().CompareVer(B); }
 
403
                inline const char *VerStr() const { return getVer().VerStr(); }
 
404
                inline const char *Section() const { return getVer().Section(); }
 
405
                inline const char *Arch() const { return getVer().Arch(); }
 
406
                inline pkgCache::PkgIterator ParentPkg() const { return getVer().ParentPkg(); }
 
407
                inline pkgCache::DescIterator DescriptionList() const { return getVer().DescriptionList(); }
 
408
                inline pkgCache::DescIterator TranslatedDescription() const { return getVer().TranslatedDescription(); }
 
409
                inline pkgCache::DepIterator DependsList() const { return getVer().DependsList(); }
 
410
                inline pkgCache::PrvIterator ProvidesList() const { return getVer().ProvidesList(); }
 
411
                inline pkgCache::VerFileIterator FileList() const { return getVer().FileList(); }
 
412
                inline bool Downloadable() const { return getVer().Downloadable(); }
 
413
                inline const char *PriorityType() const { return getVer().PriorityType(); }
 
414
                inline std::string RelStr() const { return getVer().RelStr(); }
 
415
                inline bool Automatic() const { return getVer().Automatic(); }
 
416
                inline pkgCache::VerFileIterator NewestFile() const { return getVer().NewestFile(); }
412
417
                // we have only valid iterators here
413
 
                inline bool end() const { return false; };
 
418
                inline bool end() const { return false; }
414
419
 
415
 
                inline pkgCache::Version const * operator->() const { return &*getVer(); };
 
420
                inline pkgCache::Version const * operator->() const { return &*getVer(); }
416
421
        };
417
422
                                                                        /*}}}*/
418
423
 
446
451
                Version SelectVersion;
447
452
                Modifier (unsigned short const &id, const char * const alias, Position const &pos,
448
453
                          Version const &select) : ID(id), Alias(alias), Pos(pos),
449
 
                         SelectVersion(select) {};
 
454
                         SelectVersion(select) {}
450
455
        };
451
456
 
452
457
        static bool FromCommandLine(VersionContainerInterface * const vci, pkgCacheFile &Cache,
479
484
        /** \brief returns the candidate version of the package
480
485
 
481
486
            \param Cache to be used to query for information
482
 
            \param Pkg we want the candidate version from this package */
 
487
            \param Pkg we want the candidate version from this package
 
488
            \param helper used in this container instance */
483
489
        static pkgCache::VerIterator getCandidateVer(pkgCacheFile &Cache,
484
490
                pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper);
485
491
 
486
492
        /** \brief returns the installed version of the package
487
493
 
488
494
            \param Cache to be used to query for information
489
 
            \param Pkg we want the installed version from this package */
 
495
            \param Pkg we want the installed version from this package
 
496
            \param helper used in this container instance */
490
497
        static pkgCache::VerIterator getInstalledVer(pkgCacheFile &Cache,
491
498
                pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper);
492
499
                                                                        /*}}}*/
507
514
        public:
508
515
                const_iterator(typename Container::const_iterator i) : _iter(i) {}
509
516
                pkgCache::VerIterator getVer(void) const { return *_iter; }
510
 
                inline pkgCache::VerIterator operator*(void) const { return *_iter; };
 
517
                inline pkgCache::VerIterator operator*(void) const { return *_iter; }
511
518
                operator typename Container::const_iterator(void) const { return _iter; }
512
519
                inline const_iterator& operator++() { ++_iter; return *this; }
513
520
                inline const_iterator operator++(int) { const_iterator tmp(*this); operator++(); return tmp; }
514
 
                inline bool operator!=(const_iterator const &i) const { return _iter != i._iter; };
515
 
                inline bool operator==(const_iterator const &i) const { return _iter == i._iter; };
 
521
                inline bool operator!=(const_iterator const &i) const { return _iter != i._iter; }
 
522
                inline bool operator==(const_iterator const &i) const { return _iter == i._iter; }
516
523
                friend std::ostream& operator<<(std::ostream& out, const_iterator i) { return operator<<(out, *i); }
517
524
        };
518
525
        class iterator : public VersionContainerInterface::const_iterator,
521
528
        public:
522
529
                iterator(typename Container::iterator i) : _iter(i) {}
523
530
                pkgCache::VerIterator getVer(void) const { return *_iter; }
524
 
                inline pkgCache::VerIterator operator*(void) const { return *_iter; };
 
531
                inline pkgCache::VerIterator operator*(void) const { return *_iter; }
525
532
                operator typename Container::iterator(void) const { return _iter; }
526
533
                operator typename VersionContainer<Container>::const_iterator() { return typename VersionContainer<Container>::const_iterator(_iter); }
527
534
                inline iterator& operator++() { ++_iter; return *this; }
528
535
                inline iterator operator++(int) { iterator tmp(*this); operator++(); return tmp; }
529
 
                inline bool operator!=(iterator const &i) const { return _iter != i._iter; };
530
 
                inline bool operator==(iterator const &i) const { return _iter == i._iter; };
531
 
                inline iterator& operator=(iterator const &i) { _iter = i._iter; return *this; };
532
 
                inline iterator& operator=(typename Container::iterator const &i) { _iter = i; return *this; };
 
536
                inline bool operator!=(iterator const &i) const { return _iter != i._iter; }
 
537
                inline bool operator==(iterator const &i) const { return _iter == i._iter; }
 
538
                inline iterator& operator=(iterator const &i) { _iter = i._iter; return *this; }
 
539
                inline iterator& operator=(typename Container::iterator const &i) { _iter = i; return *this; }
533
540
                friend std::ostream& operator<<(std::ostream& out, iterator i) { return operator<<(out, *i); }
534
541
        };
535
542
                                                                        /*}}}*/
536
543
 
537
 
        bool insert(pkgCache::VerIterator const &V) { if (V.end() == true) return false; _cont.insert(V); return true; };
538
 
        template<class Cont> void insert(VersionContainer<Cont> const &vercont) { _cont.insert((typename Cont::const_iterator)vercont.begin(), (typename Cont::const_iterator)vercont.end()); };
539
 
        void insert(const_iterator begin, const_iterator end) { _cont.insert(begin, end); };
540
 
        bool empty() const { return _cont.empty(); };
541
 
        void clear() { return _cont.clear(); };
 
544
        bool insert(pkgCache::VerIterator const &V) { if (V.end() == true) return false; _cont.insert(V); return true; }
 
545
        template<class Cont> void insert(VersionContainer<Cont> const &vercont) { _cont.insert((typename Cont::const_iterator)vercont.begin(), (typename Cont::const_iterator)vercont.end()); }
 
546
        void insert(const_iterator begin, const_iterator end) { _cont.insert(begin, end); }
 
547
        bool empty() const { return _cont.empty(); }
 
548
        void clear() { return _cont.clear(); }
542
549
        //FIXME: on ABI break, replace the first with the second without bool
543
 
        void erase(iterator position) { _cont.erase((typename Container::iterator)position); };
544
 
        iterator& erase(iterator &position, bool) { return position = _cont.erase((typename Container::iterator)position); };
545
 
        size_t erase(const pkgCache::VerIterator x) { return _cont.erase(x); };
546
 
        void erase(iterator first, iterator last) { _cont.erase(first, last); };
547
 
        size_t size() const { return _cont.size(); };
 
550
        void erase(iterator position) { _cont.erase((typename Container::iterator)position); }
 
551
        iterator& erase(iterator &position, bool) { return position = _cont.erase((typename Container::iterator)position); }
 
552
        size_t erase(const pkgCache::VerIterator x) { return _cont.erase(x); }
 
553
        void erase(iterator first, iterator last) { _cont.erase(first, last); }
 
554
        size_t size() const { return _cont.size(); }
548
555
 
549
 
        const_iterator begin() const { return const_iterator(_cont.begin()); };
550
 
        const_iterator end() const { return const_iterator(_cont.end()); };
551
 
        iterator begin() { return iterator(_cont.begin()); };
552
 
        iterator end() { return iterator(_cont.end()); };
553
 
        const_iterator find(pkgCache::VerIterator const &V) const { return const_iterator(_cont.find(V)); };
 
556
        const_iterator begin() const { return const_iterator(_cont.begin()); }
 
557
        const_iterator end() const { return const_iterator(_cont.end()); }
 
558
        iterator begin() { return iterator(_cont.begin()); }
 
559
        iterator end() { return iterator(_cont.end()); }
 
560
        const_iterator find(pkgCache::VerIterator const &V) const { return const_iterator(_cont.find(V)); }
554
561
 
555
562
        /** \brief returns all versions specified on the commandline
556
563
 
558
565
            non specifically requested  and executes regex's if needed on names.
559
566
            \param Cache the packages and versions are in
560
567
            \param cmdline Command line the versions should be extracted from
 
568
            \param fallback version specification
561
569
            \param helper responsible for error and message handling */
562
570
        static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline,
563
571
                        Version const &fallback, CacheSetHelper &helper) {
656
664
template<> template<class Cont> void VersionContainer<std::list<pkgCache::VerIterator> >::insert(VersionContainer<Cont> const &vercont) {
657
665
        for (typename VersionContainer<Cont>::const_iterator v = vercont.begin(); v != vercont.end(); ++v)
658
666
                _cont.push_back(*v);
659
 
};
 
667
}
660
668
// these two are 'inline' as otherwise the linker has problems with seeing these untemplated
661
669
// specializations again and again - but we need to see them, so that library users can use them
662
670
template<> inline bool VersionContainer<std::list<pkgCache::VerIterator> >::insert(pkgCache::VerIterator const &V) {
664
672
                return false;
665
673
        _cont.push_back(V);
666
674
        return true;
667
 
};
 
675
}
668
676
template<> inline void VersionContainer<std::list<pkgCache::VerIterator> >::insert(const_iterator begin, const_iterator end) {
669
677
        for (const_iterator v = begin; v != end; ++v)
670
678
                _cont.push_back(*v);
671
 
};
 
679
}
672
680
typedef VersionContainer<std::set<pkgCache::VerIterator> > VersionSet;
673
681
typedef VersionContainer<std::list<pkgCache::VerIterator> > VersionList;
674
682
}