libzypp  10.5.0
Dep.cc
Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00012 #include <map>
00013 #include <iostream>
00014 
00015 #include "zypp/base/Exception.h"
00016 #include "zypp/base/String.h"
00017 
00018 #include "zypp/Dep.h"
00019 
00021 namespace zypp
00022 { 
00023 
00024   namespace
00025   {
00026 
00027     std::map<std::string,Dep::for_use_in_switch> _table;
00028 
00029     Dep::for_use_in_switch parse( const std::string & strval_r )
00030     {
00031       if ( _table.empty() )
00032         {
00033           // initialize it
00034           _table["provides"]    = Dep::PROVIDES_e;
00035           _table["prerequires"] = Dep::PREREQUIRES_e;
00036           _table["requires"]    = Dep::REQUIRES_e;
00037           _table["conflicts"]   = Dep::CONFLICTS_e;
00038           _table["obsoletes"]   = Dep::OBSOLETES_e;
00039           _table["recommends"]  = Dep::RECOMMENDS_e;
00040           _table["suggests"]    = Dep::SUGGESTS_e;
00041           _table["enhances"]    = Dep::ENHANCES_e;
00042           _table["supplements"] = Dep::SUPPLEMENTS_e;
00043         }
00044 
00045       std::map<std::string,Dep::for_use_in_switch>::const_iterator it
00046       = _table.find( str::toLower( strval_r ) );
00047       if ( it == _table.end() )
00048         {
00049           ZYPP_THROW( Exception("Dep parse: illegal string value '"+strval_r+"'") );
00050         }
00051       return it->second;
00052     }
00053   }
00054 
00056 
00057   const Dep Dep::PROVIDES   ( Dep::PROVIDES_e );
00058   const Dep Dep::PREREQUIRES( Dep::PREREQUIRES_e );
00059   const Dep Dep::REQUIRES   ( Dep::REQUIRES_e );
00060   const Dep Dep::CONFLICTS  ( Dep::CONFLICTS_e );
00061   const Dep Dep::OBSOLETES  ( Dep::OBSOLETES_e );
00062   const Dep Dep::RECOMMENDS ( Dep::RECOMMENDS_e );
00063   const Dep Dep::SUGGESTS   ( Dep::SUGGESTS_e );
00064   const Dep Dep::ENHANCES   ( Dep::ENHANCES_e );
00065   const Dep Dep::SUPPLEMENTS( Dep::SUPPLEMENTS_e );
00066 
00068   //
00069   //    METHOD NAME : Dep::Dep
00070   //    METHOD TYPE : Ctor
00071   //
00072   Dep::Dep( const std::string & strval_r )
00073   : _type( parse( strval_r ) )
00074   {}
00075 
00077   //
00078   //    METHOD NAME : Dep::asString
00079   //    METHOD TYPE : const std::string &
00080   //
00081   const std::string & Dep::asString() const
00082   {
00083     static std::map<for_use_in_switch,std::string> _table;
00084     if ( _table.empty() )
00085       {
00086         // initialize it
00087         _table[PROVIDES_e]    = "provides";
00088         _table[PREREQUIRES_e] = "prerequires";
00089         _table[REQUIRES_e]    = "requires";
00090         _table[CONFLICTS_e]   = "conflicts";
00091         _table[OBSOLETES_e]   = "obsoletes";
00092         _table[RECOMMENDS_e]  = "recommends";
00093         _table[SUGGESTS_e]    = "suggests";
00094         _table[ENHANCES_e]    = "enhances";
00095         _table[SUPPLEMENTS_e] = "supplements";
00096       }
00097     return _table[_type];
00098   }
00099 
00101 } // namespace zypp