]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/pkg/YQPkgSelMapper.h
don't create QObjects in ycp thread - make timeouts work
[duncan/yast2-qt4.git] / src / pkg / YQPkgSelMapper.h
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                               core system                            |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:         YQPkgSelMapper.h
14
15   Author:       Stefan Hundhammer <sh@suse.de>
16
17 /-*/
18
19
20 #ifndef YQPkgSelMapper_h
21 #define YQPkgSelMapper_h
22
23 #include "YQZypp.h"
24 #include <map>
25
26
27
28 /**
29  * Mapping from ZyppPkg to the correspoinding ZyppSel.
30  *
31  * All instances of this class share the same cache. The cache remains alive as
32  * long as any instance of this class exists.
33  **/
34 class YQPkgSelMapper
35 {
36 public:
37
38     /**
39      * Constructor. Builds a cache, if necessary.
40      **/
41     YQPkgSelMapper();
42
43     /**
44      * Destructor. Clears the cache if this was the last YQPkgSelMapper
45      * (i.e. if refCount() reaches 0)
46      **/
47     virtual ~YQPkgSelMapper();
48
49     /**
50      * Find the corresponding ZyppSel to a ZyppPkg.
51      * Returns 0 if there is no corresponding ZyppSel.
52      **/
53
54     ZyppSel findZyppSel( ZyppPkg pkg );
55
56     /**
57      * Reference count - indicates how many instances of this class are alive
58      * right now.
59      **/
60     static int refCount() { return _refCount; }
61
62     /**
63      * Rebuild the shared cache. This is expensive. Call this only when the
64      * ZyppPool has changed, i.e. after installation sources were added or
65      * removed. 
66      *
67      * Since the cache is shared, this affects all instances of this class.
68      **/
69     void rebuildCache();
70
71
72 protected:
73
74     typedef std::map<ZyppPkg, ZyppSel>          Cache;
75     typedef std::pair<ZyppPkg, ZyppSel>         CachePair;
76     typedef Cache::iterator                     CacheIterator;
77
78     static int          _refCount;
79     static Cache        _cache;
80 };
81
82
83
84 #endif // YQPkgSelMapper_h