libyui-qt-pkg
 
Loading...
Searching...
No Matches
YQZypp.h
1/*
2 Copyright (c) 2000 - 2010 Novell, Inc.
3 Copyright (c) 2021 SUSE LLC
4
5 This library is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) version 3.0 of the License. This library
9 is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
12 License for more details. You should have received a copy of the GNU
13 Lesser General Public License along with this library; if not, write
14 to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
15 Floor, Boston, MA 02110-1301 USA
16*/
17
18
19/*
20 File: YQZypp.h
21 Author: Stefan Hundhammer <shundhammer.de>
22*/
23
24
25#ifndef YQZypp_h
26#define YQZypp_h
27
28#include <set>
29#include <zypp/ui/Status.h>
30#include <zypp/ui/Selectable.h>
31#include <zypp/ResObject.h>
32#include <zypp/Package.h>
33#include <zypp/Pattern.h>
34#include <zypp/Patch.h>
35#include <zypp/Product.h>
36#include <zypp/ZYppFactory.h>
37#include <zypp/ResPoolProxy.h>
38
39
40using zypp::ui::S_Protected;
41using zypp::ui::S_Taboo;
42using zypp::ui::S_Del;
43using zypp::ui::S_Update;
44using zypp::ui::S_Install;
45using zypp::ui::S_AutoDel;
46using zypp::ui::S_AutoUpdate;
47using zypp::ui::S_AutoInstall;
48using zypp::ui::S_KeepInstalled;
49using zypp::ui::S_NoInst;
50
51
52//
53// Typedefs to make those nested namespaces human-readable
54//
55
56typedef zypp::ui::Status ZyppStatus;
57typedef zypp::ui::Selectable::Ptr ZyppSel;
58typedef zypp::ResObject::constPtr ZyppObj;
59typedef zypp::Package::constPtr ZyppPkg;
60typedef zypp::Pattern::constPtr ZyppPattern;
61typedef zypp::Patch::constPtr ZyppPatch;
62typedef zypp::Product::constPtr ZyppProduct;
63typedef zypp::PoolItem ZyppPoolItem;
64
65typedef zypp::ResPoolProxy ZyppPool;
66typedef zypp::ResPoolProxy::const_iterator ZyppPoolIterator;
67typedef zypp::ResPoolProxy::repository_iterator ZyppRepositoryIterator;
68
69inline ZyppPool zyppPool() { return zypp::getZYpp()->poolProxy(); }
70
71template<class T> ZyppPoolIterator zyppBegin() { return zyppPool().byKindBegin<T>(); }
72template<class T> ZyppPoolIterator zyppEnd() { return zyppPool().byKindEnd<T>(); }
73
74inline ZyppPoolIterator zyppPkgBegin() { return zyppBegin<zypp::Package>(); }
75inline ZyppPoolIterator zyppPkgEnd() { return zyppEnd<zypp::Package>(); }
76
77inline ZyppPoolIterator zyppPatternsBegin() { return zyppBegin<zypp::Pattern>(); }
78inline ZyppPoolIterator zyppPatternsEnd() { return zyppEnd<zypp::Pattern>(); }
79
80inline ZyppPoolIterator zyppPatchesBegin() { return zyppBegin<zypp::Patch>(); }
81inline ZyppPoolIterator zyppPatchesEnd() { return zyppEnd<zypp::Patch>(); }
82
83inline ZyppPoolIterator zyppProductsBegin() { return zyppBegin<zypp::Product>(); }
84inline ZyppPoolIterator zyppProductsEnd() { return zyppEnd<zypp::Product>(); }
85
86inline ZyppRepositoryIterator ZyppRepositoriesBegin() { return zyppPool().knownRepositoriesBegin(); }
87inline ZyppRepositoryIterator ZyppRepositoriesEnd() { return zyppPool().knownRepositoriesEnd(); }
88
89inline ZyppPkg tryCastToZyppPkg( ZyppObj zyppObj )
90{
91 return zypp::dynamic_pointer_cast<const zypp::Package>( zyppObj );
92}
93
94inline ZyppPattern tryCastToZyppPattern( ZyppObj zyppObj )
95{
96 return zypp::dynamic_pointer_cast<const zypp::Pattern>( zyppObj );
97}
98
99inline ZyppPatch tryCastToZyppPatch( ZyppObj zyppObj )
100{
101 return zypp::dynamic_pointer_cast<const zypp::Patch>( zyppObj );
102}
103
104inline ZyppProduct tryCastToZyppProduct( ZyppObj zyppObj )
105{
106 return zypp::dynamic_pointer_cast<const zypp::Product>( zyppObj );
107}
108
109
110template<typename T> bool contains( const std::set<T> & container, T search )
111{
112 return container.find( search ) != container.end();
113}
114
115
116template<typename T> bool bsearch( const std::vector<T> & sorted_vector, T search )
117{
118 return binary_search( sorted_vector.begin(), sorted_vector.end(), search);
119}
120
121
122#endif // YQZypp_h