]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/pkg/YQZypp.h
don't create QObjects in ycp thread - make timeouts work
[duncan/yast2-qt4.git] / src / pkg / YQZypp.h
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                               core system                            |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:         YQZypp.h
14
15   Author:       Stefan Hundhammer <sh@suse.de>
16
17 /-*/
18
19
20 #ifndef YQZypp_h
21 #define YQZypp_h
22
23 #include <set>
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>
35
36
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;
47
48
49 //
50 // Typedefs to make those nested namespaces human-readable
51 //
52
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;
62
63 typedef zypp::ResPoolProxy                      ZyppPool;
64 typedef zypp::ResPoolProxy::const_iterator      ZyppPoolIterator;
65 typedef zypp::ResPoolProxy::repository_iterator ZyppRepositoryIterator;
66
67 inline ZyppPool         zyppPool()              { return zypp::getZYpp()->poolProxy();  }
68
69 template<class T> ZyppPoolIterator zyppBegin()  { return zyppPool().byKindBegin<T>();   }
70 template<class T> ZyppPoolIterator zyppEnd()    { return zyppPool().byKindEnd<T>();     }
71
72 inline ZyppPoolIterator zyppPkgBegin()          { return zyppBegin<zypp::Package>();    }
73 inline ZyppPoolIterator zyppPkgEnd()            { return zyppEnd<zypp::Package>();      }
74
75 inline ZyppPoolIterator zyppSelectionsBegin()   { return zyppBegin<zypp::Selection>();  }
76 inline ZyppPoolIterator zyppSelectionsEnd()     { return zyppEnd<zypp::Selection>();    }
77
78 inline ZyppPoolIterator zyppPatternsBegin()     { return zyppBegin<zypp::Pattern>();    }
79 inline ZyppPoolIterator zyppPatternsEnd()       { return zyppEnd<zypp::Pattern>();      }
80
81 inline ZyppPoolIterator zyppLangBegin()         { return zyppBegin<zypp::Language>();   }
82 inline ZyppPoolIterator zyppLangEnd()           { return zyppEnd<zypp::Language>();     }
83
84 inline ZyppPoolIterator zyppPatchesBegin()      { return zyppBegin<zypp::Patch>();      }
85 inline ZyppPoolIterator zyppPatchesEnd()        { return zyppEnd<zypp::Patch>();        }
86
87 inline ZyppPoolIterator zyppProductsBegin()     { return zyppBegin<zypp::Product>();    }
88 inline ZyppPoolIterator zyppProductsEnd()       { return zyppEnd<zypp::Product>();      }
89
90 inline ZyppRepositoryIterator ZyppRepositoriesBegin() { return zyppPool().knownRepositoriesBegin(); }
91 inline ZyppRepositoryIterator ZyppRepositoriesEnd()   { return zyppPool().knownRepositoriesEnd();   }
92
93 inline ZyppPkg          tryCastToZyppPkg( ZyppObj zyppObj )
94 {
95     return zypp::dynamic_pointer_cast<const zypp::Package>( zyppObj );
96 }
97
98 inline ZyppSelection    tryCastToZyppSelection( ZyppObj zyppObj )
99 {
100     return zypp::dynamic_pointer_cast<const zypp::Selection>( zyppObj );
101 }
102
103 inline ZyppPattern      tryCastToZyppPattern( ZyppObj zyppObj )
104 {
105     return zypp::dynamic_pointer_cast<const zypp::Pattern>( zyppObj );
106 }
107
108 inline ZyppLang         tryCastToZyppLang( ZyppObj zyppObj )
109 {
110     return zypp::dynamic_pointer_cast<const zypp::Language>( zyppObj );
111 }
112
113 inline ZyppPatch        tryCastToZyppPatch( ZyppObj zyppObj )
114 {
115     return zypp::dynamic_pointer_cast<const zypp::Patch>( zyppObj );
116 }
117
118 inline ZyppProduct      tryCastToZyppProduct( ZyppObj zyppObj )
119 {
120     return zypp::dynamic_pointer_cast<const zypp::Product>( zyppObj );
121 }
122
123
124 template<typename T> bool contains( const std::set<T> & container, T search )
125 {
126     return container.find( search ) != container.end();
127 }
128
129
130 template<typename T> bool bsearch( const std::vector<T> & sorted_vector, T search )
131 {
132     return binary_search( sorted_vector.begin(), sorted_vector.end(), search);
133 }
134
135
136 #endif // YQZypp_h