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