libyui-ncurses-pkg  2.43.4.1
 All Classes Functions
NCPkgSelMapper.h
1 /****************************************************************************
2 |
3 | Copyright (c) [2002-2011] Novell, Inc.
4 | All Rights Reserved.
5 |
6 | This program is free software; you can redistribute it and/or
7 | modify it under the terms of version 2 of the GNU General Public License as
8 | published by the Free Software Foundation.
9 |
10 | This program is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with this program; if not, contact Novell, Inc.
17 |
18 | To contact Novell about this file by physical or electronic mail,
19 | you may find current contact information at www.novell.com
20 |
21 |***************************************************************************/
22 
23 
24 /*---------------------------------------------------------------------\
25 | |
26 | __ __ ____ _____ ____ |
27 | \ \ / /_ _/ ___|_ _|___ \ |
28 | \ V / _` \___ \ | | __) | |
29 | | | (_| |___) || | / __/ |
30 | |_|\__,_|____/ |_| |_____| |
31 | |
32 | core system |
33 | (C) SuSE GmbH |
34 \----------------------------------------------------------------------/
35 
36  File: NCPkgSelMapper.h
37 
38  Author: Stefan Hundhammer <sh@suse.de>
39 
40 /-*/
41 
42 // -*- c++ -*-
43 
44 #ifndef NCPkgSelMapper_h
45 #define NCPkgSelMapper_h
46 
47 #include "NCZypp.h"
48 #include <map>
49 
50 
51 
52 /**
53  * Mapping from ZyppPkg to the correspoinding ZyppSel.
54  *
55  * All instances of this class share the same cache. The cache remains alive as
56  * long as any instance of this class exists.
57  **/
59 {
60 public:
61 
62  /**
63  * Constructor. Builds a cache, if necessary.
64  **/
66 
67  /**
68  * Destructor. Clears the cache if this was the last NCPkgSelMapper
69  * (i.e. if refCount() reaches 0)
70  **/
71  virtual ~NCPkgSelMapper();
72 
73  /**
74  * Find the corresponding ZyppSel to a ZyppPkg.
75  * Returns 0 if there is no corresponding ZyppSel.
76  **/
77 
78  ZyppSel findZyppSel( ZyppPkg pkg );
79 
80  /**
81  * Reference count - indicates how many instances of this class are alive
82  * right now.
83  **/
84  static int refCount() { return _refCount; }
85 
86  /**
87  * Rebuild the shared cache. This is expensive. Call this only when the
88  * ZyppPool has changed, i.e. after installation sources were added or
89  * removed.
90  *
91  * Since the cache is shared, this affects all instances of this class.
92  **/
93  void rebuildCache();
94 
95 
96 protected:
97 
98  typedef std::map<ZyppPkg, ZyppSel> Cache;
99  typedef std::pair<ZyppPkg, ZyppSel> CachePair;
100  typedef Cache::iterator CacheIterator;
101 
102  static int _refCount;
103  static Cache _cache;
104 };
105 
106 
107 
108 #endif // NCPkgSelMapper_h