libyui-ncurses-pkg
Loading...
Searching...
No Matches
NCZypp.h
1/*
2 Copyright (c) [2002-2011] 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 File: NCZypp.h
19 Author: Stefan Hundhammer <shundhammer@suse.de>
20
21*/
22
23
24#ifndef NCZypp_h
25#define NCZypp_h
26
27#include <set>
28#include <zypp/ui/Status.h>
29#include <zypp/ui/Selectable.h>
30#include <zypp/ResObject.h>
31#include <zypp/Package.h>
32#include <zypp/Pattern.h>
33#include <zypp/Product.h>
34#include <zypp/Patch.h>
35#include <zypp/ZYppFactory.h>
36#include <zypp/ResPoolProxy.h>
37#include <zypp/PoolQuery.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::Repository ZyppRepo;
64
65typedef zypp::ResPoolProxy ZyppPool;
66typedef zypp::ResPoolProxy::const_iterator ZyppPoolIterator;
67typedef zypp::ResPoolProxy::repository_iterator ZyppRepositoryIterator;
68
69
70inline ZyppPool zyppPool() { return zypp::getZYpp()->poolProxy(); }
71
72template<class T> ZyppPoolIterator zyppBegin() { return zyppPool().byKindBegin<T>(); }
73template<class T> ZyppPoolIterator zyppEnd() { return zyppPool().byKindEnd<T>(); }
74
75inline ZyppPoolIterator zyppPkgBegin() { return zyppBegin<zypp::Package>(); }
76inline ZyppPoolIterator zyppPkgEnd() { return zyppEnd<zypp::Package>(); }
77
78inline ZyppPoolIterator zyppPatternsBegin() { return zyppBegin<zypp::Pattern>(); }
79inline ZyppPoolIterator zyppPatternsEnd() { return zyppEnd<zypp::Pattern>(); }
80
81inline ZyppPoolIterator zyppPatchesBegin() { return zyppBegin<zypp::Patch>(); }
82inline ZyppPoolIterator zyppPatchesEnd() { return zyppEnd<zypp::Patch>(); }
83
84inline ZyppPoolIterator zyppProductsBegin() { return zyppBegin<zypp::Product>(); }
85inline ZyppPoolIterator zyppProductsEnd() { return zyppEnd<zypp::Product>(); }
86
87inline ZyppRepositoryIterator ZyppRepositoriesBegin() { return zyppPool().knownRepositoriesBegin(); }
88inline ZyppRepositoryIterator ZyppRepositoriesEnd() { return zyppPool().knownRepositoriesEnd(); }
89
90
91inline ZyppPkg tryCastToZyppPkg( ZyppObj zyppObj )
92{
93 return zypp::dynamic_pointer_cast<const zypp::Package>( zyppObj );
94}
95
96inline ZyppPattern tryCastToZyppPattern( ZyppObj zyppObj )
97{
98 return zypp::dynamic_pointer_cast<const zypp::Pattern>( zyppObj );
99}
100
101inline ZyppPatch tryCastToZyppPatch( ZyppObj zyppObj )
102{
103 return zypp::dynamic_pointer_cast<const zypp::Patch>( zyppObj );
104}
105
106inline ZyppProduct tryCastToZyppProduct( ZyppObj zyppObj )
107{
108 return zypp::dynamic_pointer_cast<const zypp::Product>( zyppObj );
109}
110
111template<typename T> bool inContainer( const std::set<T> & container, T search )
112{
113 return container.find( search ) != container.end();
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
121inline bool sortByName( ZyppSel ptr1, ZyppSel ptr2 )
122{
123 return( ptr1->name() < ptr2->name() );
124}
125#endif // NCZypp_h