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       
00284         public:
00285       
00289           void * dont_call_it() const;
00290       
00294           virtual std::ostream & dumpOn( std::ostream & str ) const;
00295       };
00296       
00298       
00300       //
00301       //        CLASS NAME : librpmDb::DbDirInfo
00306       class librpmDb::DbDirInfo {
00307         friend std::ostream & operator<<( std::ostream & str, const DbDirInfo & obj );
00308       
00309         private:
00310       
00314           Pathname _root;
00315       
00319           Pathname _dbPath;
00320       
00324           PathInfo _dbDir;
00325       
00329           PathInfo _dbV4;
00330       
00334           PathInfo _dbV3;
00335       
00339           PathInfo _dbV3ToV4;
00340       
00341         public:
00342       
00347           DbDirInfo( const Pathname & root_r, const Pathname & dbPath_r );
00348       
00349         public:
00350       
00354           const Pathname & root() const { return _root; }
00355       
00359           const Pathname & dbPath() const { return _dbPath; }
00360       
00364           const PathInfo & dbDir() const { return _dbDir; }
00365       
00369           const PathInfo & dbV4() const { return _dbV4; }
00370       
00374           const PathInfo & dbV3() const { return _dbV3; }
00375       
00379           const PathInfo & dbV3ToV4() const { return _dbV3ToV4; }
00380       
00381         public:
00382       
00386           void restat();
00387       
00388         public:
00389       
00393           bool illegalArgs() const { return _dbDir.path().empty(); }
00394       
00399           bool usableArgs() const { return _dbDir.isDir() || ! ( _dbDir.path().empty() || _dbDir.isExist() ); }
00400       
00404           bool hasDbDir() const { return _dbDir.isDir(); }
00405       
00409           bool hasDbV4() const { return _dbV4.isFile(); }
00410       
00414           bool hasDbV3() const { return _dbV3.isFile(); }
00415       
00419           bool hasDbV3ToV4() const { return _dbV3ToV4.isFile(); }
00420       };
00421       
00423       
00425       //
00426       //        CLASS NAME : librpmDb::db_const_iterator
00432       class librpmDb::db_const_iterator {
00433         db_const_iterator & operator=( const db_const_iterator & ); // NO ASSIGNMENT!
00434         db_const_iterator ( const db_const_iterator & );            // NO COPY!
00435         friend std::ostream & operator<<( std::ostream & str, const db_const_iterator & obj );
00436         friend class librpmDb;
00437       
00438         private:
00439       
00443           class D;
00444           D & _d;
00445       
00446         public:
00447       
00454           db_const_iterator( librpmDb::constPtr dbptr_r = 0 );
00455       
00459           ~db_const_iterator();
00460       
00468           shared_ptr<RpmException> dbError() const;
00469       
00473           void operator++();
00474       
00479           unsigned dbHdrNum() const;
00480       
00485           const RpmHeader::constPtr & operator*() const;
00486       
00490           const RpmHeader::constPtr & operator->() const {
00491             return operator*();
00492           }
00493       
00494         public:
00495       
00504           bool findAll();
00505       
00509           bool findByFile( const std::string & file_r );
00510       
00514           bool findByProvides( const std::string & tag_r );
00515       
00519           bool findByRequiredBy( const std::string & tag_r );
00520       
00524           bool findByConflicts( const std::string & tag_r );
00525       
00536           bool findByName( const std::string & name_r );
00537       
00538         public:
00539       
00547           bool findPackage( const std::string & name_r );
00548       
00553           bool findPackage( const std::string & name_r, const Edition & ed_r );
00554 
00558           bool findPackage( const Package::constPtr & which_r );
00559       };
00560 
00562     } //namespace rpm
00563   } //namespace target
00564 } // namespace zypp
00565 
00566 #endif // librpmDb_h
00567 

Generated on Thu Jul 6 00:07:26 2006 for zypp by  doxygen 1.4.6