Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

PMSolvable.h

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                                                                      |
00003 |                      __   __    ____ _____ ____                      |
00004 |                      \ \ / /_ _/ ___|_   _|___ \                     |
00005 |                       \ V / _` \___ \ | |   __) |                    |
00006 |                        | | (_| |___) || |  / __/                     |
00007 |                        |_|\__,_|____/ |_| |_____|                    |
00008 |                                                                      |
00009 |                               core system                            |
00010 |                                                        (C) SuSE GmbH |
00011 \----------------------------------------------------------------------/
00012 
00013    File:       PMSolvable.h
00014 
00015    Author:     Michael Andres <ma@suse.de>
00016    Maintainer: Michael Andres <ma@suse.de>
00017 
00018 /-*/
00019 #ifndef PMSolvable_h
00020 #define PMSolvable_h
00021 
00022 #include <iosfwd>
00023 #include <list>
00024 
00025 #include <y2pm/PMSolvablePtr.h>
00026 
00027 #include <y2pm/PkgName.h>
00028 #include <y2pm/PkgEdition.h>
00029 #include <y2pm/PkgArch.h>
00030 #include <y2pm/PkgRelation.h>
00031 
00033 //
00034 //      CLASS NAME : PMSolvable
00039 class PMSolvable : public CountedRep {
00040   REP_BODY(PMSolvable);
00041 
00042   public:
00043 
00044     typedef std::list<PkgRelation>          PkgRelList_type;
00045     typedef PkgRelList_type::iterator       PkgRelList_iterator;
00046     typedef PkgRelList_type::const_iterator PkgRelList_const_iterator;
00047 
00048   public:
00049 
00051     //
00052     //  CLASS NAME : Provides_iterator
00056     class Provides_iterator {
00057 
00058       private:
00059 
00060         constPMSolvablePtr        pkg;
00061         PkgRelList_const_iterator iter;
00062 
00063       public:
00064 
00065         Provides_iterator( constPMSolvablePtr p )
00066           : pkg( p )
00067         {}
00068 
00069         Provides_iterator( PkgRelList_const_iterator i )
00070           : iter( i )
00071         {}
00072 
00073         PkgRelation operator* () const {
00074               return (pkg!= NULL) ? PkgRelation(pkg->name(), EQ, pkg->edition()) : *iter;
00075         }
00076 
00077         Provides_iterator& operator++ () {
00078           if (pkg) {
00079             iter = pkg->provides_begin();
00080             pkg = NULL;
00081           }
00082           else
00083             ++iter;
00084           return *this;
00085         }
00086 
00087         Provides_iterator  operator++ (int) {
00088           Provides_iterator temp = *this;
00089           operator++();
00090           return temp;
00091         }
00092 
00093         bool operator== ( const Provides_iterator& i2 ) {
00094           return pkg == i2.pkg && iter == i2.iter;
00095         }
00096 
00097         bool operator!= ( const Provides_iterator& i2 ) {
00098           return !operator==(i2);
00099         }
00100     };
00101 
00102     typedef Provides_iterator Provides_const_iterator;
00103 
00104   protected:
00105 
00106     // name, edition, and architecture
00107     PkgName    _name;
00108     PkgEdition _edition;
00109     PkgArch    _arch;
00110 
00111     // relations of the package
00112     PkgRelList_type _requires, _conflicts, _provides, _obsoletes;
00113 
00114   private:
00115 
00119     void traceFileRel( const PkgRelation & rel_r ) const;
00120     void traceFileRel( const PkgRelList_type & rellist_r ) const {
00121       for ( PkgRelList_type::const_iterator it = rellist_r.begin(); it != rellist_r.end(); ++it ) {
00122         traceFileRel( *it );
00123       }
00124     }
00125 
00126   public:
00127 
00134     PMSolvable( const PkgName& name,
00135                 const PkgEdition& edition,
00136                 const PkgArch& arch);
00137 
00138     virtual ~PMSolvable();
00139 
00140   public:
00141 
00145     virtual std::ostream & dumpOn( std::ostream & str ) const;
00146 
00150     const PkgRelation& addProvides(const PkgName name ) {
00151       _provides.push_front( PkgRelation( name, EQ, PkgEdition(PkgEdition::UNSPEC) ));
00152       return *(_provides.begin());
00153     }
00154 
00158     const PkgRelation& addProvides( const char *name ) {
00159       return addProvides( PkgName(name) );
00160     }
00161 
00165     const PkgRelList_type& setProvides(const PkgRelList_type& provides)
00166     {
00167       _provides = provides;
00168       return _provides;
00169     }
00170 
00174     const PkgRelList_type& setRequires(const PkgRelList_type& requires)
00175     {
00176       _requires = requires;
00177       traceFileRel( _requires );
00178       return _requires;
00179     }
00180 
00189     const PkgRelList_type& addPreRequires(PkgRelList_type& prerequires);
00190 
00194     const PkgRelList_type& setObsoletes(const PkgRelList_type& obsoletes)
00195     {
00196       _obsoletes = obsoletes;
00197       return _obsoletes;
00198     }
00199 
00203     const PkgRelList_type& setConflicts(const PkgRelList_type& conflicts)
00204     {
00205       _conflicts = conflicts;
00206       traceFileRel( _conflicts );
00207       return _conflicts;
00208     }
00209 
00210     // Unused? If not check for FileRel.
00214     const PkgRelation& addRequires(const PkgRelation& r) {
00215       _requires.push_front(r);
00216       traceFileRel( r );
00217       return *(_requires.begin());
00218     }
00219 
00224     Provides_iterator all_provides_begin() const {
00225       return Provides_iterator(constPMSolvablePtr(this));
00226     }
00227     Provides_iterator all_provides_end() const {
00228       return Provides_iterator( provides_end() );
00229     }
00230     PkgRelation self_provides() const {
00231       return PkgRelation( _name, EQ, _edition );
00232     }
00233 
00241     bool doesProvide(const PkgRelation& rel) const;
00242 
00246     bool doesObsolete( const constPMSolvablePtr & item_r ) const;
00247 
00251     const PkgName& name() const { return _name; }
00252     const PkgEdition& edition() const { return _edition; }
00253     const PkgArch& arch() const { return _arch; }
00254 
00258     const std::string & version() const { return _edition.version(); }
00259     const std::string & release() const { return _edition.release(); }
00260 
00264     std::string nameEd() const { return (const std::string &)_name + '-' + _edition.asString(); }
00265 
00269     std::string nameEdArch() const { return nameEd() + '.' + (const std::string &)_arch; }
00270 
00275     const PkgRelList_type& requires() const { return _requires; }
00276     PkgRelList_type prerequires() const;
00277     const PkgRelList_type& conflicts() const { return _conflicts; }
00278     const PkgRelList_type& provides() const { return _provides; }
00279     const PkgRelList_type& obsoletes() const { return _obsoletes; }
00280 
00281 
00282     static std::list<std::string> PkgRelList2StringList ( const PkgRelList_type & rellist_r );
00283     static PkgRelList_type StringList2PkgRelList ( const std::list<std::string>& relationlist );
00284 
00285     // for convenience: directly return an iterator for relation lists
00286 #define decl_PkgRelList_iterators(name)                                 \
00287         PkgRelList_iterator name##_begin() {                            \
00288                 return _##name.begin(); }                               \
00289         PkgRelList_const_iterator name##_begin() const {                \
00290                 return _##name.begin(); }                               \
00291         PkgRelList_iterator name##_end() {                              \
00292                 return _##name.end(); }                                 \
00293         PkgRelList_const_iterator name##_end() const {                  \
00294                 return _##name.end(); }
00295 
00296     decl_PkgRelList_iterators(requires)
00297     decl_PkgRelList_iterators(conflicts)
00298     decl_PkgRelList_iterators(provides)
00299     decl_PkgRelList_iterators(obsoletes)
00300 };
00301 
00303 
00304 extern std::ostream & operator<<( std::ostream&, const PMSolvable::PkgRelList_type & );
00305 
00307 
00308 #endif // PMSolvable_h
00309 

Generated on Fri Nov 9 14:30:31 2007 for yast2-packagemanager by doxygen 1.3.6