1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
15 Author: Stefan Hundhammer <sh@suse.de>
24 #include <zypp/ui/Status.h>
25 #include <zypp/ui/Selectable.h>
26 #include <zypp/ResObject.h>
27 #include <zypp/Package.h>
28 #include <zypp/Selection.h>
29 #include <zypp/Pattern.h>
30 #include <zypp/Language.h>
31 #include <zypp/Patch.h>
32 #include <zypp/Product.h>
33 #include <zypp/ZYppFactory.h>
34 #include <zypp/ResPoolProxy.h>
37 using zypp::ui::S_Protected;
38 using zypp::ui::S_Taboo;
39 using zypp::ui::S_Del;
40 using zypp::ui::S_Update;
41 using zypp::ui::S_Install;
42 using zypp::ui::S_AutoDel;
43 using zypp::ui::S_AutoUpdate;
44 using zypp::ui::S_AutoInstall;
45 using zypp::ui::S_KeepInstalled;
46 using zypp::ui::S_NoInst;
50 // Typedefs to make those nested namespaces human-readable
53 typedef zypp::ui::Status ZyppStatus;
54 typedef zypp::ui::Selectable::Ptr ZyppSel;
55 typedef zypp::ResObject::constPtr ZyppObj;
56 typedef zypp::Package::constPtr ZyppPkg;
57 typedef zypp::Selection::constPtr ZyppSelection;
58 typedef zypp::Pattern::constPtr ZyppPattern;
59 typedef zypp::Language::constPtr ZyppLang;
60 typedef zypp::Patch::constPtr ZyppPatch;
61 typedef zypp::Product::constPtr ZyppProduct;
63 typedef zypp::ResPoolProxy ZyppPool;
64 typedef zypp::ResPoolProxy::const_iterator ZyppPoolIterator;
65 typedef zypp::ResPoolProxy::repository_iterator ZyppRepositoryIterator;
67 inline ZyppPool zyppPool() { return zypp::getZYpp()->poolProxy(); }
69 template<class T> ZyppPoolIterator zyppBegin() { return zyppPool().byKindBegin<T>(); }
70 template<class T> ZyppPoolIterator zyppEnd() { return zyppPool().byKindEnd<T>(); }
72 inline ZyppPoolIterator zyppPkgBegin() { return zyppBegin<zypp::Package>(); }
73 inline ZyppPoolIterator zyppPkgEnd() { return zyppEnd<zypp::Package>(); }
75 inline ZyppPoolIterator zyppSelectionsBegin() { return zyppBegin<zypp::Selection>(); }
76 inline ZyppPoolIterator zyppSelectionsEnd() { return zyppEnd<zypp::Selection>(); }
78 inline ZyppPoolIterator zyppPatternsBegin() { return zyppBegin<zypp::Pattern>(); }
79 inline ZyppPoolIterator zyppPatternsEnd() { return zyppEnd<zypp::Pattern>(); }
81 inline ZyppPoolIterator zyppLangBegin() { return zyppBegin<zypp::Language>(); }
82 inline ZyppPoolIterator zyppLangEnd() { return zyppEnd<zypp::Language>(); }
84 inline ZyppPoolIterator zyppPatchesBegin() { return zyppBegin<zypp::Patch>(); }
85 inline ZyppPoolIterator zyppPatchesEnd() { return zyppEnd<zypp::Patch>(); }
87 inline ZyppPoolIterator zyppProductsBegin() { return zyppBegin<zypp::Product>(); }
88 inline ZyppPoolIterator zyppProductsEnd() { return zyppEnd<zypp::Product>(); }
90 inline ZyppRepositoryIterator ZyppRepositoriesBegin() { return zyppPool().knownRepositoriesBegin(); }
91 inline ZyppRepositoryIterator ZyppRepositoriesEnd() { return zyppPool().knownRepositoriesEnd(); }
93 inline ZyppPkg tryCastToZyppPkg( ZyppObj zyppObj )
95 return zypp::dynamic_pointer_cast<const zypp::Package>( zyppObj );
98 inline ZyppSelection tryCastToZyppSelection( ZyppObj zyppObj )
100 return zypp::dynamic_pointer_cast<const zypp::Selection>( zyppObj );
103 inline ZyppPattern tryCastToZyppPattern( ZyppObj zyppObj )
105 return zypp::dynamic_pointer_cast<const zypp::Pattern>( zyppObj );
108 inline ZyppLang tryCastToZyppLang( ZyppObj zyppObj )
110 return zypp::dynamic_pointer_cast<const zypp::Language>( zyppObj );
113 inline ZyppPatch tryCastToZyppPatch( ZyppObj zyppObj )
115 return zypp::dynamic_pointer_cast<const zypp::Patch>( zyppObj );
118 inline ZyppProduct tryCastToZyppProduct( ZyppObj zyppObj )
120 return zypp::dynamic_pointer_cast<const zypp::Product>( zyppObj );
124 template<typename T> bool contains( const std::set<T> & container, T search )
126 return container.find( search ) != container.end();
130 template<typename T> bool bsearch( const std::vector<T> & sorted_vector, T search )
132 return binary_search( sorted_vector.begin(), sorted_vector.end(), search);