libyui-qt-pkg  2.42.13
 All Classes Functions Variables Enumerations
YQZypp.h
1 /**************************************************************************
2 Copyright (C) 2000 - 2010 Novell, Inc.
3 All Rights Reserved.
4 
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
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 along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 
19 **************************************************************************/
20 
21 
22 /*---------------------------------------------------------------------\
23 | |
24 | __ __ ____ _____ ____ |
25 | \ \ / /_ _/ ___|_ _|___ \ |
26 | \ V / _` \___ \ | | __) | |
27 | | | (_| |___) || | / __/ |
28 | |_|\__,_|____/ |_| |_____| |
29 | |
30 | core system |
31 | (C) SuSE GmbH |
32 \----------------------------------------------------------------------/
33 
34  File: YQZypp.h
35 
36  Author: Stefan Hundhammer <sh@suse.de>
37 
38 /-*/
39 
40 
41 #ifndef YQZypp_h
42 #define YQZypp_h
43 
44 #include <set>
45 #include <zypp/ui/Status.h>
46 #include <zypp/ui/Selectable.h>
47 #include <zypp/ResObject.h>
48 #include <zypp/Package.h>
49 #include <zypp/Pattern.h>
50 #include <zypp/Patch.h>
51 #include <zypp/Product.h>
52 #include <zypp/ZYppFactory.h>
53 #include <zypp/ResPoolProxy.h>
54 
55 
56 using zypp::ui::S_Protected;
57 using zypp::ui::S_Taboo;
58 using zypp::ui::S_Del;
59 using zypp::ui::S_Update;
60 using zypp::ui::S_Install;
61 using zypp::ui::S_AutoDel;
62 using zypp::ui::S_AutoUpdate;
63 using zypp::ui::S_AutoInstall;
64 using zypp::ui::S_KeepInstalled;
65 using zypp::ui::S_NoInst;
66 
67 
68 //
69 // Typedefs to make those nested namespaces human-readable
70 //
71 
72 typedef zypp::ui::Status ZyppStatus;
73 typedef zypp::ui::Selectable::Ptr ZyppSel;
74 typedef zypp::ResObject::constPtr ZyppObj;
75 typedef zypp::Package::constPtr ZyppPkg;
76 typedef zypp::Pattern::constPtr ZyppPattern;
77 typedef zypp::Patch::constPtr ZyppPatch;
78 typedef zypp::Product::constPtr ZyppProduct;
79 typedef zypp::PoolItem ZyppPoolItem;
80 
81 typedef zypp::ResPoolProxy ZyppPool;
82 typedef zypp::ResPoolProxy::const_iterator ZyppPoolIterator;
83 typedef zypp::ResPoolProxy::repository_iterator ZyppRepositoryIterator;
84 
85 inline ZyppPool zyppPool() { return zypp::getZYpp()->poolProxy(); }
86 
87 template<class T> ZyppPoolIterator zyppBegin() { return zyppPool().byKindBegin<T>(); }
88 template<class T> ZyppPoolIterator zyppEnd() { return zyppPool().byKindEnd<T>(); }
89 
90 inline ZyppPoolIterator zyppPkgBegin() { return zyppBegin<zypp::Package>(); }
91 inline ZyppPoolIterator zyppPkgEnd() { return zyppEnd<zypp::Package>(); }
92 
93 inline ZyppPoolIterator zyppPatternsBegin() { return zyppBegin<zypp::Pattern>(); }
94 inline ZyppPoolIterator zyppPatternsEnd() { return zyppEnd<zypp::Pattern>(); }
95 
96 inline ZyppPoolIterator zyppPatchesBegin() { return zyppBegin<zypp::Patch>(); }
97 inline ZyppPoolIterator zyppPatchesEnd() { return zyppEnd<zypp::Patch>(); }
98 
99 inline ZyppPoolIterator zyppProductsBegin() { return zyppBegin<zypp::Product>(); }
100 inline ZyppPoolIterator zyppProductsEnd() { return zyppEnd<zypp::Product>(); }
101 
102 inline ZyppRepositoryIterator ZyppRepositoriesBegin() { return zyppPool().knownRepositoriesBegin(); }
103 inline ZyppRepositoryIterator ZyppRepositoriesEnd() { return zyppPool().knownRepositoriesEnd(); }
104 
105 inline ZyppPkg tryCastToZyppPkg( ZyppObj zyppObj )
106 {
107  return zypp::dynamic_pointer_cast<const zypp::Package>( zyppObj );
108 }
109 
110 inline ZyppPattern tryCastToZyppPattern( ZyppObj zyppObj )
111 {
112  return zypp::dynamic_pointer_cast<const zypp::Pattern>( zyppObj );
113 }
114 
115 inline ZyppPatch tryCastToZyppPatch( ZyppObj zyppObj )
116 {
117  return zypp::dynamic_pointer_cast<const zypp::Patch>( zyppObj );
118 }
119 
120 inline ZyppProduct tryCastToZyppProduct( ZyppObj zyppObj )
121 {
122  return zypp::dynamic_pointer_cast<const zypp::Product>( zyppObj );
123 }
124 
125 
126 template<typename T> bool contains( const std::set<T> & container, T search )
127 {
128  return container.find( search ) != container.end();
129 }
130 
131 
132 template<typename T> bool bsearch( const std::vector<T> & sorted_vector, T search )
133 {
134  return binary_search( sorted_vector.begin(), sorted_vector.end(), search);
135 }
136 
137 
138 #endif // YQZypp_h