libyui-ncurses-pkg  2.48.2
NCZypp.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: NCZypp.h
37 
38  Author: Stefan Hundhammer <sh@suse.de>
39 
40 /-*/
41 
42 #ifndef NCZypp_h
43 #define NCZypp_h
44 
45 #include <set>
46 #include <zypp/ui/Status.h>
47 #include <zypp/ui/Selectable.h>
48 #include <zypp/ResObject.h>
49 #include <zypp/Package.h>
50 #include <zypp/Pattern.h>
51 #include <zypp/Product.h>
52 //#include <zypp/Language.h>
53 #include <zypp/Patch.h>
54 #include <zypp/ZYppFactory.h>
55 #include <zypp/ResPoolProxy.h>
56 #include <zypp/PoolQuery.h>
57 
58 
59 using zypp::ui::S_Protected;
60 using zypp::ui::S_Taboo;
61 using zypp::ui::S_Del;
62 using zypp::ui::S_Update;
63 using zypp::ui::S_Install;
64 using zypp::ui::S_AutoDel;
65 using zypp::ui::S_AutoUpdate;
66 using zypp::ui::S_AutoInstall;
67 using zypp::ui::S_KeepInstalled;
68 using zypp::ui::S_NoInst;
69 
70 
71 //
72 // Typedefs to make those nested namespaces human-readable
73 //
74 
75 typedef zypp::ui::Status ZyppStatus;
76 typedef zypp::ui::Selectable::Ptr ZyppSel;
77 typedef zypp::ResObject::constPtr ZyppObj;
78 typedef zypp::Package::constPtr ZyppPkg;
79 typedef zypp::Pattern::constPtr ZyppPattern;
80 //typedef zypp::Language::constPtr ZyppLang;
81 typedef zypp::Patch::constPtr ZyppPatch;
82 typedef zypp::Product::constPtr ZyppProduct;
83 typedef zypp::Repository ZyppRepo;
84 
85 typedef zypp::ResPoolProxy ZyppPool;
86 typedef zypp::ResPoolProxy::const_iterator ZyppPoolIterator;
87 typedef zypp::ResPoolProxy::repository_iterator ZyppRepositoryIterator;
88 
89 
90 inline ZyppPool zyppPool() { return zypp::getZYpp()->poolProxy(); }
91 
92 template<class T> ZyppPoolIterator zyppBegin() { return zyppPool().byKindBegin<T>(); }
93 template<class T> ZyppPoolIterator zyppEnd() { return zyppPool().byKindEnd<T>(); }
94 
95 inline ZyppPoolIterator zyppPkgBegin() { return zyppBegin<zypp::Package>(); }
96 inline ZyppPoolIterator zyppPkgEnd() { return zyppEnd<zypp::Package>(); }
97 
98 inline ZyppPoolIterator zyppPatternsBegin() { return zyppBegin<zypp::Pattern>(); }
99 inline ZyppPoolIterator zyppPatternsEnd() { return zyppEnd<zypp::Pattern>(); }
100 
101 //inline ZyppPoolIterator zyppLangBegin() { return zyppBegin<zypp::Language>(); }
102 //inline ZyppPoolIterator zyppLangEnd() { return zyppEnd<zypp::Language>(); }
103 
104 inline ZyppPoolIterator zyppPatchesBegin() { return zyppBegin<zypp::Patch>(); }
105 inline ZyppPoolIterator zyppPatchesEnd() { return zyppEnd<zypp::Patch>(); }
106 
107 inline ZyppPoolIterator zyppProductsBegin() { return zyppBegin<zypp::Product>(); }
108 inline ZyppPoolIterator zyppProductsEnd() { return zyppEnd<zypp::Product>(); }
109 
110 inline ZyppRepositoryIterator ZyppRepositoriesBegin() { return zyppPool().knownRepositoriesBegin(); }
111 inline ZyppRepositoryIterator ZyppRepositoriesEnd() { return zyppPool().knownRepositoriesEnd(); }
112 
113 
114 inline ZyppPkg tryCastToZyppPkg( ZyppObj zyppObj )
115 {
116  return zypp::dynamic_pointer_cast<const zypp::Package>( zyppObj );
117 }
118 
119 inline ZyppPattern tryCastToZyppPattern( ZyppObj zyppObj )
120 {
121  return zypp::dynamic_pointer_cast<const zypp::Pattern>( zyppObj );
122 }
123 
124 #if 0
125 inline ZyppLang tryCastToZyppLang( ZyppObj zyppObj )
126 {
127  return zypp::dynamic_pointer_cast<const zypp::Language>( zyppObj );
128 }
129 #endif
130 inline ZyppPatch tryCastToZyppPatch( ZyppObj zyppObj )
131 {
132  return zypp::dynamic_pointer_cast<const zypp::Patch>( zyppObj );
133 }
134 
135 inline ZyppProduct tryCastToZyppProduct( ZyppObj zyppObj )
136 {
137  return zypp::dynamic_pointer_cast<const zypp::Product>( zyppObj );
138 }
139 
140 template<typename T> bool inContainer( const std::set<T> & container, T search )
141 {
142  return container.find( search ) != container.end();
143 }
144 
145 
146 template<typename T> bool bsearch( const std::vector<T> & sorted_vector, T search )
147 {
148  return binary_search( sorted_vector.begin(), sorted_vector.end(), search);
149 }
150 
151 inline bool sortByName( ZyppSel ptr1, ZyppSel ptr2 )
152 {
153  return( ptr1->name() < ptr2->name() );
154 }
155 #endif // NCZypp_h