libzypp
10.5.0
|
00001 /*---------------------------------------------------------------------\ 00002 | ____ _ __ __ ___ | 00003 | |__ / \ / / . \ . \ | 00004 | / / \ V /| _/ _/ | 00005 | / /__ | | | | | | | 00006 | /_____||_| |_| |_| | 00007 | | 00008 \---------------------------------------------------------------------*/ 00012 #include <iostream> 00013 #include "zypp/base/LogTools.h" 00014 00015 #include "zypp/ResPool.h" 00016 #include "zypp/Pattern.h" 00017 #include "zypp/Filter.h" 00018 00019 using std::endl; 00020 00022 namespace zypp 00023 { 00024 00026 namespace 00027 { 00028 00029 // 00030 // CLASS NAME : PatternExpander 00031 // 00038 class PatternExpander 00039 { 00040 public: 00041 typedef std::map<Pattern::constPtr, DefaultIntegral<bool, false> > PatternMap; 00042 typedef PatternMap::size_type size_type; 00043 typedef PatternMap::key_type value_type; 00044 typedef MapKVIteratorTraits<PatternMap>::Key_const_iterator const_iterator; 00045 00046 public: 00047 PatternExpander() 00048 {} 00049 00051 size_type doExpand( Pattern::constPtr pat_r ) 00052 { 00053 // INT << "+++ " << pat_r << " ++++++++++++++++++++++++++++++++++" << endl; 00054 _patternMap.clear(); 00055 if ( pat_r ) 00056 { 00057 _patternMap[pat_r]; 00058 Pattern::constPtr unprocessed( pat_r ); 00059 // MIL << _patternMap << endl; 00060 do { 00061 expandIncludes( unprocessed ); 00062 expandExtending( unprocessed ); 00063 _patternMap[unprocessed] = true; 00064 // MIL << _patternMap << endl; 00065 } while( (unprocessed = nextUnprocessed()) ); 00066 } 00067 // SEC << "--- " << _patternMap.size() << " ----------------------------------" << endl; 00068 return _patternMap.size(); 00069 } 00070 00071 const_iterator begin() const 00072 { return make_map_key_begin( _patternMap ); } 00073 00074 const_iterator end() const 00075 { return make_map_key_end( _patternMap ); } 00076 00077 private: 00079 Pattern::constPtr nextUnprocessed() const 00080 { 00081 for_( it, _patternMap.begin(), _patternMap.end() ) 00082 { 00083 if ( ! it->second ) 00084 return it->first; 00085 } 00086 return NULL; 00087 } 00088 00089 private: 00091 void expandIncludes( const Pattern::constPtr & pat_r ) 00092 { 00093 Pattern::NameList c( pat_r->includes() ); 00094 for_( it, c.begin(), c.end() ) 00095 { 00096 expandInclude( Capability( it->c_str()/*, *ResKind::pattern*/ ) ); 00097 } 00098 } 00099 00101 void expandInclude( const Capability & include_r ) 00102 { 00103 sat::WhatProvides w( include_r ); 00104 for_( it, w.begin(), w.end() ) 00105 { 00106 _patternMap[asKind<Pattern>(PoolItem(*it))]; 00107 } 00108 } 00109 00110 private: 00112 void expandExtending( const Pattern::constPtr & pat_r ) 00113 { 00114 ResPool pool( ResPool::instance() ); 00115 for_( it, pool.byKindBegin<Pattern>(), pool.byKindEnd<Pattern>() ) 00116 { 00117 expandIfExtends( pat_r, *it ); 00118 } 00119 } 00120 00122 void expandIfExtends( const Pattern::constPtr & pat_r, const PoolItem & extending_r ) 00123 { 00124 Pattern::constPtr extending( asKind<Pattern>(extending_r) ); 00125 Pattern::NameList c( extending->extends() ); 00126 for_( it, c.begin(), c.end() ) 00127 { 00128 if ( providedBy( pat_r, Capability( it->c_str()/*, *ResKind::pattern*/ ) ) ) 00129 { 00130 // an extends matches the Pattern 00131 _patternMap[extending]; 00132 break; 00133 } 00134 } 00135 } 00136 00138 bool providedBy( const Pattern::constPtr & pat_r, const Capability & extends_r ) 00139 { 00140 if ( !pat_r ) 00141 return false; 00142 00143 sat::Solvable pat( pat_r->satSolvable() ); 00144 sat::WhatProvides w( extends_r ); 00145 for_( it, w.begin(), w.end() ) 00146 { 00147 if ( pat == *it ) 00148 return true; 00149 } 00150 return false; 00151 } 00152 00153 private: 00154 PatternMap _patternMap; 00155 }; 00157 } // namespace 00159 IMPL_PTR_TYPE(Pattern); 00160 00162 // 00163 // METHOD NAME : Pattern::Pattern 00164 // METHOD TYPE : Ctor 00165 // 00166 Pattern::Pattern( const sat::Solvable & solvable_r ) 00167 : ResObject( solvable_r ) 00168 {} 00169 00171 // 00172 // METHOD NAME : Pattern::~Pattern 00173 // METHOD TYPE : Dtor 00174 // 00175 Pattern::~Pattern() 00176 {} 00177 00179 // 00180 // Pattern interface forwarded to implementation 00181 // 00183 00184 bool Pattern::isDefault() const 00185 { return lookupBoolAttribute( sat::SolvAttr::isdefault ); } 00187 bool Pattern::userVisible() const 00188 { return lookupBoolAttribute( sat::SolvAttr::isvisible ); } 00190 std::string Pattern::category( const Locale & lang_r ) const 00191 { return lookupStrAttribute( sat::SolvAttr::category, lang_r ); } 00193 Pathname Pattern::icon() const 00194 { return lookupStrAttribute( sat::SolvAttr::icon ); } 00196 Pathname Pattern::script() const 00197 { return lookupStrAttribute( sat::SolvAttr::script ); } 00198 00199 std::string Pattern::order() const 00200 { return lookupStrAttribute( sat::SolvAttr::order ); } 00201 00202 Pattern::NameList Pattern::includes() const 00203 { return NameList( sat::SolvAttr::includes, satSolvable() ); } 00204 00205 Pattern::NameList Pattern::extends() const 00206 { return NameList( sat::SolvAttr::extends, satSolvable() ); } 00207 00208 Pattern::Contents Pattern::core() const 00209 { 00210 // get items providing the requirements 00211 sat::WhatProvides prv( requires() ); 00212 // return packages only. 00213 return Pattern::Contents( make_filter_begin( filter::byKind<Package>(), prv ), 00214 make_filter_end( filter::byKind<Package>(), prv ) ); 00215 } 00216 00217 Pattern::Contents Pattern::depends() const 00218 { 00219 // load requires, recommends, suggests 00220 CapabilitySet caps; 00221 { 00222 Capabilities c( requires() ); 00223 caps.insert( c.begin(),c.end() ); 00224 c = recommends(); 00225 caps.insert( c.begin(),c.end() ); 00226 c = suggests(); 00227 caps.insert( c.begin(),c.end() ); 00228 } 00229 // get items providing the above 00230 sat::WhatProvides prv( caps ); 00231 // return packages only. 00232 return Pattern::Contents( make_filter_begin( filter::byKind<Package>(), prv ), 00233 make_filter_end( filter::byKind<Package>(), prv ) ); 00234 } 00235 00236 Pattern::Contents Pattern::contents() const 00237 { 00238 PatternExpander expander; 00239 if ( ! expander.doExpand( this ) ) 00240 return Contents(); // empty pattern set 00241 00242 Contents result; 00243 for_( it, expander.begin(), expander.end() ) 00244 { 00245 Contents c( (*it)->depends() ); 00246 result.get().insert( c.begin(), c.end() ); 00247 } 00248 return result; 00249 } 00250 00252 } // namespace zypp