librpmDb.h

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00012 #ifndef librpmDb_h
00013 #define librpmDb_h
00014 
00015 #include <iosfwd>
00016 
00017 #include "zypp/base/ReferenceCounted.h"
00018 #include "zypp/base/NonCopyable.h"
00019 #include "zypp/base/PtrTypes.h"
00020 #include "zypp/PathInfo.h"
00021 #include "zypp/Package.h"
00022 #include "zypp/target/rpm/RpmHeader.h"
00023 #include "zypp/target/rpm/RpmException.h"
00024 
00025 namespace zypp {
00026   namespace target {
00027     namespace rpm {
00028 
00030       //
00031       //        CLASS NAME : librpmDb
00035       class librpmDb : public base::ReferenceCounted, private base::NonCopyable
00036       {
00037         public:
00038           typedef intrusive_ptr<librpmDb> Ptr;
00039           typedef intrusive_ptr<const librpmDb> constPtr;
00040         private:
00050         static void dbAccess( librpmDb::Ptr & ptr_r );
00051 
00052         public:
00053 
00055           //
00056           //    static interface
00057           //
00059         private:
00060 
00065           static Pathname _defaultRoot;
00066 
00071           static Pathname _defaultDbPath;
00072 
00076           static librpmDb::constPtr _defaultDb;
00077 
00081           static bool _dbBlocked;
00082 
00090           static librpmDb * newLibrpmDb( Pathname root_r, Pathname dbPath_r, bool readonly_r );
00091 
00104           static void dbAccess();
00105 
00106         public:
00107 
00114           static bool globalInit();
00115 
00119           static std::string expand( const std::string & macro_r );
00120 
00124           static std::string stringPath( const Pathname & root_r, const Pathname & sub_r ) {
00125             return std::string( "'(" ) + root_r.asString() + ")" + sub_r.asString() + "'";
00126           }
00127 
00128         public:
00129 
00133           static const Pathname & defaultRoot() { return _defaultRoot; }
00134 
00138           static const Pathname & defaultDbPath() { return _defaultDbPath; }
00139 
00154           static void dbAccess( const Pathname & root_r, const Pathname & dbPath_r );
00155 
00165           static void dbAccess( librpmDb::constPtr & ptr_r );
00166 
00179           static unsigned dbRelease( bool force_r = false );
00180 
00188           static unsigned blockAccess();
00189 
00200           static void unblockAccess();
00201 
00205           static bool isBlocked() { return _dbBlocked; }
00206 
00210           static std::ostream & dumpState( std::ostream & str );
00211 
00212         public:
00213 
00218           class DbDirInfo;
00219 
00223           class db_const_iterator;
00224 
00225         private:
00227           //
00228           //    internal database handle interface (nonstatic)
00229           //
00231 
00235           class D;
00236           D & _d;
00237 
00238         protected:
00239 
00244           librpmDb( const Pathname & root_r, const Pathname & dbPath_r, bool readonly_r );
00245 
00249           virtual void unref_to( unsigned refCount_r ) const;
00250 
00251         public:
00252 
00256           virtual ~librpmDb();
00257 
00261           const Pathname & root() const;
00262 
00266           const Pathname & dbPath() const;
00267 
00272           shared_ptr<RpmException> error() const;
00273 
00277           bool valid() const { return( ! error() ); }
00278 
00282           bool empty() const;
00283 
00287           unsigned size() const;
00288 
00289         public:
00290 
00294           void * dont_call_it() const;
00295 
00299           virtual std::ostream & dumpOn( std::ostream & str ) const;
00300       };
00301 
00303 
00305       //
00306       //        CLASS NAME : librpmDb::DbDirInfo
00311       class librpmDb::DbDirInfo {
00312         friend std::ostream & operator<<( std::ostream & str, const DbDirInfo & obj );
00313 
00314         private:
00315 
00319           Pathname _root;
00320 
00324           Pathname _dbPath;
00325 
00329           PathInfo _dbDir;
00330 
00334           PathInfo _dbV4;
00335 
00339           PathInfo _dbV3;
00340 
00344           PathInfo _dbV3ToV4;
00345 
00346         public:
00347 
00352           DbDirInfo( const Pathname & root_r, const Pathname & dbPath_r );
00353 
00354         public:
00355 
00359           const Pathname & root() const { return _root; }
00360 
00364           const Pathname & dbPath() const { return _dbPath; }
00365 
00369           const PathInfo & dbDir() const { return _dbDir; }
00370 
00374           const PathInfo & dbV4() const { return _dbV4; }
00375 
00379           const PathInfo & dbV3() const { return _dbV3; }
00380 
00384           const PathInfo & dbV3ToV4() const { return _dbV3ToV4; }
00385 
00386         public:
00387 
00391           void restat();
00392 
00393         public:
00394 
00398           bool illegalArgs() const { return _dbDir.path().empty(); }
00399 
00404           bool usableArgs() const { return _dbDir.isDir() || ! ( _dbDir.path().empty() || _dbDir.isExist() ); }
00405 
00409           bool hasDbDir() const { return _dbDir.isDir(); }
00410 
00414           bool hasDbV4() const { return _dbV4.isFile(); }
00415 
00419           bool hasDbV3() const { return _dbV3.isFile(); }
00420 
00424           bool hasDbV3ToV4() const { return _dbV3ToV4.isFile(); }
00425       };
00426 
00428 
00430       //
00431       //        CLASS NAME : librpmDb::db_const_iterator
00437       class librpmDb::db_const_iterator {
00438         db_const_iterator & operator=( const db_const_iterator & ); // NO ASSIGNMENT!
00439         db_const_iterator ( const db_const_iterator & );            // NO COPY!
00440         friend std::ostream & operator<<( std::ostream & str, const db_const_iterator & obj );
00441         friend class librpmDb;
00442 
00443         private:
00444 
00448           class D;
00449           D & _d;
00450 
00451         public:
00452 
00459           db_const_iterator( librpmDb::constPtr dbptr_r = 0 );
00460 
00464           ~db_const_iterator();
00465 
00473           shared_ptr<RpmException> dbError() const;
00474 
00478           void operator++();
00479 
00484           unsigned dbHdrNum() const;
00485 
00490           const RpmHeader::constPtr & operator*() const;
00491 
00495           const RpmHeader::constPtr & operator->() const {
00496             return operator*();
00497           }
00498 
00499         public:
00500 
00509           bool findAll();
00510 
00514           bool findByFile( const std::string & file_r );
00515 
00519           bool findByProvides( const std::string & tag_r );
00520 
00524           bool findByRequiredBy( const std::string & tag_r );
00525 
00529           bool findByConflicts( const std::string & tag_r );
00530 
00541           bool findByName( const std::string & name_r );
00542 
00543         public:
00544 
00552           bool findPackage( const std::string & name_r );
00553 
00558           bool findPackage( const std::string & name_r, const Edition & ed_r );
00559 
00563           bool findPackage( const Package::constPtr & which_r );
00564       };
00565 
00567     } //namespace rpm
00568   } //namespace target
00569 } // namespace zypp
00570 
00571 #endif // librpmDb_h
00572 

Generated on Tue Nov 28 16:49:33 2006 for zypp by  doxygen 1.5.0