Main Page | Namespace List | Class Hierarchy | Class List | Directories | 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 
00167     const PkgRelList_type& setProvides(const PkgRelList_type& provides)
00168     {
00169       _provides = provides;
00170       return _provides;
00171     }
00172 
00178     const PkgRelList_type& setRequires(const PkgRelList_type& requires)
00179     {
00180       _requires = requires;
00181       traceFileRel( _requires );
00182       return _requires;
00183     }
00184 
00193     const PkgRelList_type& addPreRequires(PkgRelList_type& prerequires);
00194 
00200     const PkgRelList_type& setObsoletes(const PkgRelList_type& obsoletes)
00201     {
00202       _obsoletes = obsoletes;
00203       return _obsoletes;
00204     }
00205 
00211     const PkgRelList_type& setConflicts(const PkgRelList_type& conflicts)
00212     {
00213       _conflicts = conflicts;
00214       traceFileRel( _conflicts );
00215       return _conflicts;
00216     }
00217 
00218     // Unused? If not check for FileRel.
00222     const PkgRelation& addRequires(const PkgRelation& r) {
00223       _requires.push_front(r);
00224       traceFileRel( r );
00225       return *(_requires.begin());
00226     }
00227 
00232     Provides_iterator all_provides_begin() const {
00233       return Provides_iterator(constPMSolvablePtr(this));
00234     }
00235     Provides_iterator all_provides_end() const {
00236       return Provides_iterator( provides_end() );
00237     }
00238     PkgRelation self_provides() const {
00239       return PkgRelation( _name, EQ, _edition );
00240     }
00241 
00249     bool doesProvide(const PkgRelation& rel) const;
00250 
00254     bool doesObsolete( const constPMSolvablePtr & item_r ) const;
00255 
00259     const PkgName& name() const { return _name; }
00260     const PkgEdition& edition() const { return _edition; }
00261     const PkgArch& arch() const { return _arch; }
00262 
00266     const std::string & version() const { return _edition.version(); }
00267     const std::string & release() const { return _edition.release(); }
00268 
00272     std::string nameEd() const { return (const std::string &)_name + '-' + _edition.asString(); }
00273 
00277     std::string nameEdArch() const { return nameEd() + '.' + (const std::string &)_arch; }
00278 
00283     const PkgRelList_type& requires() const { return _requires; }
00284     PkgRelList_type prerequires() const;
00285     const PkgRelList_type& conflicts() const { return _conflicts; }
00286     const PkgRelList_type& provides() const { return _provides; }
00287     const PkgRelList_type& obsoletes() const { return _obsoletes; }
00288 
00289 
00290     static std::list<std::string> PkgRelList2StringList ( const PkgRelList_type & rellist_r );
00291     static PkgRelList_type StringList2PkgRelList ( const std::list<std::string>& relationlist );
00292 
00293     // for convenience: directly return an iterator for relation lists
00294 #define decl_PkgRelList_iterators(name)                                 \
00295         PkgRelList_iterator name##_begin() {                            \
00296                 return _##name.begin(); }                               \
00297         PkgRelList_const_iterator name##_begin() const {                \
00298                 return _##name.begin(); }                               \
00299         PkgRelList_iterator name##_end() {                              \
00300                 return _##name.end(); }                                 \
00301         PkgRelList_const_iterator name##_end() const {                  \
00302                 return _##name.end(); }
00303 
00304     decl_PkgRelList_iterators(requires)
00305     decl_PkgRelList_iterators(conflicts)
00306     decl_PkgRelList_iterators(provides)
00307     decl_PkgRelList_iterators(obsoletes)
00308 };
00309 
00311 
00312 extern std::ostream & operator<<( std::ostream&, const PMSolvable::PkgRelList_type & );
00313 
00315 
00316 #endif // PMSolvable_h
00317 

Generated on Mon Sep 12 21:52:13 2005 for yast2-packagemanager by  doxygen 1.4.4