libzypp: zypp/target/rpm/librpmDb.h Source File

libzypp 17.38.6

librpmDb.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#ifndef librpmDb_h
13#define librpmDb_h
14
15#include <iosfwd>
16
17#include <zypp/base/ReferenceCounted.h>
18#include <zypp-core/base/NonCopyable.h>
19#include <zypp-core/base/PtrTypes.h>
20#include <zypp/PathInfo.h>
21#include <zypp/target/rpm/RpmHeader.h>
22#include <zypp/target/rpm/RpmException.h>
23
24namespace zypp
25{
26namespace target
27{
28namespace rpm
29{
30 struct _dumpPath {
31 _dumpPath( const Pathname & root_r, const Pathname & sub_r )
32 : _root {root_r }
33 , _sub { sub_r }
34 {}
35 const Pathname & _root;
36 const Pathname & _sub;
37 };
38 inline std::ostream & operator<<( std::ostream & str, const _dumpPath & obj )
39 { return str << "'(" << obj._root << ")" << obj._sub << "'"; }
40
42 inline _dumpPath dumpPath( const Pathname & root_r, const Pathname & sub_r )
43 { return _dumpPath( root_r, sub_r ); }
44
46//
47// CLASS NAME : librpmDb
51 class librpmDb : public base::ReferenceCounted, private base::NonCopyable
52{
53public:
54 using Ptr = intrusive_ptr<librpmDb>;
55 using constPtr = intrusive_ptr<const librpmDb>;
56
57private:
65 static void dbAccess( librpmDb::Ptr & ptr_r );
66
67public:
69 //
70 // static interface
71 //
73
80 static bool globalInit();
81
85 static std::string expand( const std::string & macro_r );
86
94 static Pathname suggestedDbPath( const Pathname & root_r );
95
103 static bool dbExists( const Pathname & root_r, const Pathname & dbPath_r = Pathname() );
104
112 static librpmDb::constPtr dbOpenIf( const Pathname & root_r, const Pathname & dbPath_r = Pathname() );
113
121 static librpmDb::constPtr dbOpenCreate( const Pathname & root_r, const Pathname & dbPath_r = Pathname() );
122
126 class db_const_iterator;
127
128private:
129
134 static librpmDb::constPtr dbAccess( const Pathname & root_r, const Pathname & dbPath_r, bool create_r = false );
135
136private:
138 //
139 // internal database handle interface (nonstatic)
140 //
142
146 class D;
147 D & _d;
148
153 librpmDb( const Pathname & root_r, const Pathname & dbPath_r, bool readonly_r = true );
154
158 void unref_to( unsigned refCount_r ) const override;
159
160public:
161
165 ~librpmDb() override;
166
170 const Pathname & root() const;
171
175 const Pathname & dbPath() const;
176
177public:
178
182 std::ostream & dumpOn( std::ostream & str ) const override;
183};
184
197 class ZYPP_API librpmDb::db_const_iterator
198{
199 db_const_iterator & operator=( const db_const_iterator & ); // NO ASSIGNMENT!
200 db_const_iterator ( const db_const_iterator & ); // NO COPY!
201 friend std::ostream & operator<<( std::ostream & str, const db_const_iterator & obj );
202 friend class librpmDb;
203
204private:
205
209 class D;
210 D & _d;
211
212#if LEGACY(1735)
213public:
221 db_const_iterator( librpmDb::constPtr dbptr_r ) ZYPP_DEPRECATED;
222#endif
223
224public:
229 db_const_iterator() ZYPP_DEPRECATED;
230
232 explicit db_const_iterator( const Pathname & root_r );
233
235 db_const_iterator( const Pathname & root_r, const Pathname & dbPath_r );
236
240 db_const_iterator( std::nullptr_t );
241
245 ~db_const_iterator();
246
248 bool hasDB() const;
249
253 void operator++();
254
259 unsigned dbHdrNum() const;
260
265 const RpmHeader::constPtr & operator*() const;
266
270 const RpmHeader::constPtr & operator->() const
271 {
272 return operator*();
273 }
274
275public:
276
281 bool findAll();
282
286 bool findByFile( const std::string & file_r );
287
291 bool findByProvides( const std::string & tag_r );
292
296 bool findByRequiredBy( const std::string & tag_r );
297
301 bool findByConflicts( const std::string & tag_r );
302
313 bool findByName( const std::string & name_r );
314
315public:
316
324 bool findPackage( const std::string & name_r );
325
330 bool findPackage( const std::string & name_r, const Edition & ed_r );
331
335 bool findPackage( const Package::constPtr & which_r );
336};
337
339std::ostream & operator<<( std::ostream & str, const librpmDb::db_const_iterator & obj ) ZYPP_API;
340
342} //namespace rpm
343} //namespace target
344} // namespace zypp
345
346#endif // librpmDb_h
347
ZYPP_DEPRECATED
#define ZYPP_DEPRECATED
The ZYPP_DEPRECATED macro can be used to trigger compile-time warnings with gcc >= 3....
Definition Globals.h:112
operator<<
std::ostream & operator<<(std::ostream &str, const zypp::sat::detail::CDataiterator *obj)
relates: zypp::sat::LookupAttr::iterator Stream output of the underlying iterator for debug.
Definition LookupAttr.cc:808
NonCopyable.h
PtrTypes.h
RpmException.h
RpmHeader.h
intrusive_ptr
zypp::Edition
Edition represents [epoch:]version[-release].
Definition Edition.h:60
zypp::Package::constPtr
TraitsType::constPtrType constPtr
Definition Package.h:39
zypp::base::ReferenceCounted
Base class for reference counted objects.
Definition ReferenceCounted.h:35
zypp::filesystem::Pathname
Pathname.
Definition Pathname.h:48
zypp::target::rpm::RpmHeader
Wrapper class for rpm header struct.
Definition RpmHeader.h:62
zypp::target::rpm::librpmDb::D
librpmDb internal database handle
Definition librpmDb.cc:93
zypp::target::rpm::librpmDb::db_const_iterator::D
Definition librpmDb.cc:254
zypp::target::rpm::librpmDb::db_const_iterator
Subclass to retrieve rpm database content.
Definition librpmDb.h:198
zypp::target::rpm::librpmDb::db_const_iterator::dbHdrNum
unsigned dbHdrNum() const
Returns the current headers index in database, 0 if no header.
Definition librpmDb.cc:406
zypp::target::rpm::librpmDb::db_const_iterator::librpmDb
friend class librpmDb
Definition librpmDb.h:202
zypp::target::rpm::librpmDb::db_const_iterator::operator=
db_const_iterator & operator=(const db_const_iterator &)
zypp::target::rpm::librpmDb::db_const_iterator::hasDB
bool hasDB() const
Whether an underlying rpmdb exists.
Definition librpmDb.cc:400
zypp::target::rpm::librpmDb::db_const_iterator::operator*
const RpmHeader::constPtr & operator*() const
Returns the current RpmHeader::constPtr or NULL, if no more entries available.
Definition librpmDb.cc:409
zypp::target::rpm::librpmDb::db_const_iterator::db_const_iterator
db_const_iterator(const db_const_iterator &)
zypp::target::rpm::librpmDb::db_const_iterator::_d
D & _d
Definition librpmDb.h:210
zypp::target::rpm::librpmDb::constPtr
intrusive_ptr< const librpmDb > constPtr
Definition librpmDb.h:55
zypp::target::rpm::librpmDb::dbPath
const Pathname & dbPath() const
Definition librpmDb.cc:243
zypp::target::rpm::librpmDb::root
const Pathname & root() const
Definition librpmDb.cc:240
zypp::target::rpm::librpmDb::globalInit
static bool globalInit()
Initialize lib librpm (read configfiles etc.).
Definition librpmDb.cc:139
zypp::target::rpm::librpmDb::_d
D & _d
Definition librpmDb.h:147
zypp::target::rpm::librpmDb::dumpOn
std::ostream & dumpOn(std::ostream &str) const override
Dump debug info.
Definition librpmDb.cc:246
zypp::target::rpm::librpmDb::dbOpenCreate
static librpmDb::constPtr dbOpenCreate(const Pathname &root_r, const Pathname &dbPath_r=Pathname())
Assert the rpmdb below the system at root_r exists.
Definition librpmDb.cc:198
zypp::target::rpm::librpmDb::expand
static std::string expand(const std::string &macro_r)
Definition librpmDb.cc:159
zypp::target::rpm::librpmDb::librpmDb
librpmDb(const Pathname &root_r, const Pathname &dbPath_r, bool readonly_r=true)
Private constructor!
Definition librpmDb.cc:227
zypp::target::rpm::librpmDb::dbAccess
static void dbAccess(librpmDb::Ptr &ptr_r)
INTENTIONALLY UNDEFINED<\B> because of bug in Ptr classes which allows implicit conversion from librp...
zypp::target::rpm::librpmDb::dbOpenIf
static librpmDb::constPtr dbOpenIf(const Pathname &root_r, const Pathname &dbPath_r=Pathname())
Open the rpmdb below the system at root_r (if it exists).
Definition librpmDb.cc:195
zypp::target::rpm::librpmDb::~librpmDb
~librpmDb() override
Destructor.
Definition librpmDb.cc:231
zypp::target::rpm::librpmDb::Ptr
intrusive_ptr< librpmDb > Ptr
Definition librpmDb.h:54
zypp::target::rpm::librpmDb::suggestedDbPath
static Pathname suggestedDbPath(const Pathname &root_r)
Definition librpmDb.cc:171
zypp::target::rpm::librpmDb::dbExists
static bool dbExists(const Pathname &root_r, const Pathname &dbPath_r=Pathname())
Definition librpmDb.cc:183
zypp::target::rpm::librpmDb::unref_to
void unref_to(unsigned refCount_r) const override
Trigger from Rep, after refCount was decreased.
Definition librpmDb.cc:237
std
Definition ansi.h:855
str
String related utilities and Regular expression matching.
zypp::base::NonCopyable
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Definition NonCopyable.h:26
zypp::target::rpm
Definition KeyRing.h:327
zypp::target::rpm::operator<<
std::ostream & operator<<(std::ostream &str, const librpmDb::db_const_iterator &obj)
relates: librpmDb::db_const_iterator stream output
Definition librpmDb.cc:412
zypp::target::rpm::dumpPath
_dumpPath dumpPath(const Pathname &root_r, const Pathname &sub_r)
dumpPath iomaip to dump '(root_r)sub_r' output,
Definition librpmDb.h:42
zypp::target
Definition KeyRing.h:325
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2
zypp::ZYPP_API
const Arch Arch_empty ZYPP_API
relates: Arch This is an empty Arch represented by an empty string.
Definition Arch.h:173
zypp::target::rpm::_dumpPath
Definition librpmDb.h:30
zypp::target::rpm::_dumpPath::_sub
const Pathname & _sub
Definition librpmDb.h:36
zypp::target::rpm::_dumpPath::_root
const Pathname & _root
Definition librpmDb.h:35
zypp::target::rpm::_dumpPath::_dumpPath
_dumpPath(const Pathname &root_r, const Pathname &sub_r)
Definition librpmDb.h:31
PathInfo.h
ReferenceCounted.h