PatternFileReader.cc

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00012 #include <iostream>
00013 #include "zypp/base/Logger.h"
00014 
00015 #include "zypp/parser/susetags/PatternFileReader.h"
00016 #include "zypp/parser/susetags/FileReaderBaseImpl.h"
00017 
00018 using std::endl;
00019 #undef  ZYPP_BASE_LOGGER_LOGGROUP
00020 #define ZYPP_BASE_LOGGER_LOGGROUP "parser::susetags"
00021 
00023 namespace zypp
00024 { 
00025 
00026   namespace parser
00027   { 
00028 
00029     namespace susetags
00030     { 
00031 
00033       //
00034       //        CLASS NAME : PatternFileReader::Impl
00035       //
00037       class PatternFileReader::Impl : public BaseImpl
00038       {
00039         public:
00040           Impl( const PatternFileReader & parent_r )
00041           : BaseImpl( parent_r )
00042           {}
00043 
00044           virtual ~Impl()
00045           {}
00046 
00047           bool hasData() const
00048           { return _data; }
00049 
00050           data::Pattern_Ptr handoutData()
00051           {
00052             data::Pattern_Ptr ret;
00053             ret.swap( _data );
00054             return ret;
00055           }
00056 
00057         public: // single tags
00059           void consumeVer( const SingleTagPtr & tag_r )
00060           { /* NOP */; }
00061 
00063           void consumePat( const SingleTagPtr & tag_r )
00064           {
00065             std::vector<std::string> words;
00066             if ( str::split( tag_r->value, std::back_inserter(words) ) != 4 )
00067             {
00068               ZYPP_THROW( error( tag_r, "Expected [name version release arch]") );
00069             }
00070 
00071             _data = new data::Pattern;
00072             _data->name    = words[0];
00073             _data->edition = Edition( words[1],words[2] );
00074             _data->arch    = Arch( words[3] );
00075           }
00076 
00078           void consumeSum( const SingleTagPtr & tag_r )
00079           {
00080             _data->summary.setText( tag_r->value, Locale(tag_r->modifier) );
00081           }
00082 
00084           void consumeVis( const SingleTagPtr & tag_r )
00085           {
00086             _data->userVisible = ( tag_r->value == "true" );
00087           }
00088 
00090           void consumeCat( const SingleTagPtr & tag_r )
00091           {
00092             _data->category.setText( tag_r->value, Locale(tag_r->modifier) );
00093           }
00094 
00096           void consumeIco( const SingleTagPtr & tag_r )
00097           {
00098             _data->icon = tag_r->value;
00099           }
00100 
00102           void consumeOrd( const SingleTagPtr & tag_r )
00103           {
00104             _data->order = tag_r->value;
00105           }
00106 
00107         public: // multi tags
00109           void consumeReq( const MultiTagPtr & tag_r )
00110           {
00111             depParse<Pattern>( tag_r, _data->deps[Dep::REQUIRES] );
00112           }
00113 
00115           void consumePrv( const MultiTagPtr & tag_r )
00116           {
00117             depParse<Pattern>( tag_r, _data->deps[Dep::PROVIDES] );
00118           }
00119 
00121           void consumeCon( const MultiTagPtr & tag_r )
00122           {
00123             depParse<Pattern>( tag_r, _data->deps[Dep::CONFLICTS] );
00124           }
00125 
00127           void consumeObs( const MultiTagPtr & tag_r )
00128           {
00129             depParse<Pattern>( tag_r, _data->deps[Dep::OBSOLETES] );
00130           }
00131 
00133           void consumeRec( const MultiTagPtr & tag_r )
00134           {
00135             depParse<Pattern>( tag_r, _data->deps[Dep::RECOMMENDS] );
00136           }
00137 
00139           void consumeFre( const MultiTagPtr & tag_r )
00140           {
00141             depParse<Pattern>( tag_r, _data->deps[Dep::FRESHENS] );
00142           }
00143 
00145           void consumeEnh( const MultiTagPtr & tag_r )
00146           {
00147             depParse<Pattern>( tag_r, _data->deps[Dep::ENHANCES] );
00148           }
00149 
00151           void consumeSug( const MultiTagPtr & tag_r )
00152           {
00153             depParse<Pattern>( tag_r, _data->deps[Dep::SUGGESTS] );
00154           }
00155 
00157           void consumeSup( const MultiTagPtr & tag_r )
00158           {
00159             depParse<Pattern>( tag_r, _data->deps[Dep::SUPPLEMENTS] );
00160           }
00161 
00162           // package related dependencies:
00163 
00165           void consumePrq( const MultiTagPtr & tag_r )
00166           {
00167             depParse<Package>( tag_r, _data->deps[Dep::REQUIRES] );
00168           }
00169 
00171           void consumePcn( const MultiTagPtr & tag_r )
00172           {
00173             depParse<Package>( tag_r, _data->deps[Dep::CONFLICTS] );
00174           }
00175 
00177           void consumePob( const MultiTagPtr & tag_r )
00178           {
00179             depParse<Package>( tag_r, _data->deps[Dep::OBSOLETES] );
00180           }
00181 
00183           void consumePrc( const MultiTagPtr & tag_r )
00184           {
00185             depParse<Package>( tag_r, _data->deps[Dep::RECOMMENDS] );
00186           }
00187 
00189           void consumePfr( const MultiTagPtr & tag_r )
00190           {
00191             depParse<Package>( tag_r, _data->deps[Dep::FRESHENS] );
00192           }
00193 
00195           void consumePen( const MultiTagPtr & tag_r )
00196           {
00197             depParse<Package>( tag_r, _data->deps[Dep::ENHANCES] );
00198           }
00199 
00201           void consumePsg( const MultiTagPtr & tag_r )
00202           {
00203             depParse<Package>( tag_r, _data->deps[Dep::SUGGESTS] );
00204           }
00205 
00207           void consumePsp( const MultiTagPtr & tag_r )
00208           {
00209             depParse<Package>( tag_r, _data->deps[Dep::SUPPLEMENTS] );
00210           }
00211 
00212           // non dependency tags
00213 
00215           void consumeDes( const MultiTagPtr & tag_r )
00216           {
00217             _data->description.setText( tag_r->value, Locale(tag_r->modifier) );
00218           }
00219 
00221           void consumeInc( const MultiTagPtr & tag_r )
00222           {
00223             depParse<Pattern>( tag_r, _data->includes );
00224           }
00225 
00227           void consumeExt( const MultiTagPtr & tag_r )
00228           {
00229             depParse<Pattern>( tag_r, _data->extends );
00230           }
00231 
00232         private:
00233           data::Pattern_Ptr _data;
00234       };
00236 
00238       //
00239       //        CLASS NAME : PatternFileReader
00240       //
00242 
00244       //
00245       //        METHOD NAME : PatternFileReader::PatternFileReader
00246       //        METHOD TYPE : Ctor
00247       //
00248       PatternFileReader::PatternFileReader()
00249       {}
00250 
00252       //
00253       //        METHOD NAME : PatternFileReader::~PatternFileReader
00254       //        METHOD TYPE : Dtor
00255       //
00256       PatternFileReader::~PatternFileReader()
00257       {}
00258 
00260       //
00261       //        METHOD NAME : PatternFileReader::beginParse
00262       //        METHOD TYPE : void
00263       //
00264       void PatternFileReader::beginParse()
00265       {
00266         _pimpl.reset( new Impl(*this) );
00267       }
00268 
00270       //
00271       //        METHOD NAME : PatternFileReader::consume
00272       //        METHOD TYPE : void
00273       //
00274       void PatternFileReader::consume( const SingleTagPtr & tag_r )
00275       {
00276 #define TAGN(V)   tag_r->name == #V
00277 #define TAGFWD(V) ( TAGN(V) ) _pimpl->consume##V( tag_r )
00278 
00279         if ( TAGN( Pat ) )
00280         {
00281           // consume old data
00282           if ( _pimpl->hasData() )
00283           {
00284             if ( _consumer )
00285               _consumer( _pimpl->handoutData() );
00286           }
00287           // start new data
00288           _pimpl->consumePat( tag_r );
00289         }
00290         else if TAGFWD( Sum );
00291         else if TAGFWD( Vis );
00292         else if TAGFWD( Cat );
00293         else if TAGFWD( Ico );
00294         else if TAGFWD( Ord );
00295         else if TAGFWD( Ver );
00296         else
00297         { WAR << errPrefix( tag_r, "Unknown tag" ) << endl; }
00298       }
00299 
00301       //
00302       //        METHOD NAME : PatternFileReader::consume
00303       //        METHOD TYPE : void
00304       //
00305       void PatternFileReader::consume( const MultiTagPtr & tag_r )
00306       {
00307         if TAGFWD( Req );
00308         else if TAGFWD( Prq );
00309         else if TAGFWD( Prv );
00310         else if TAGFWD( Con );
00311         else if TAGFWD( Obs );
00312         else if TAGFWD( Rec );
00313         else if TAGFWD( Fre );
00314         else if TAGFWD( Enh );
00315         else if TAGFWD( Sug );
00316         else if TAGFWD( Sup );
00317         // package related dependencies
00318         else if TAGFWD( Prq ); // requires
00319         else if TAGFWD( Pcn ); // conflicts
00320         else if TAGFWD( Pob ); // obsoletes
00321         else if TAGFWD( Prc ); // recommends
00322         else if TAGFWD( Pfr ); // freshens
00323         else if TAGFWD( Pen ); // enhances
00324         else if TAGFWD( Psg ); // suggests
00325         else if TAGFWD( Psp ); // supplements
00326         //
00327         else if TAGFWD( Des );
00328         else if TAGFWD( Inc ); // UI hint: includes
00329         else if TAGFWD( Ext ); // UI hint: extends
00330         else
00331         { WAR << errPrefix( tag_r, "Unknown tag" ) << endl; }
00332       }
00333 
00335       //
00336       //        METHOD NAME : PatternFileReader::lastData
00337       //        METHOD TYPE : void
00338       //
00339       void PatternFileReader::endParse()
00340       {
00341         // consume data
00342         if ( _pimpl->hasData() )
00343         {
00344           if ( _consumer )
00345             _consumer( _pimpl->handoutData() );
00346         }
00347         _pimpl.reset();
00348       }
00349 
00351     } // namespace susetags
00354   } // namespace parser
00357 } // namespace zypp

Generated on Tue Sep 25 19:23:03 2007 for libzypp by  doxygen 1.5.3