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["freshens"] = Dep::FRESHENS_e; 00042 _table["enhances"] = Dep::ENHANCES_e; 00043 _table["supplements"] = Dep::SUPPLEMENTS_e; 00044 } 00045 00046 std::map<std::string,Dep::for_use_in_switch>::const_iterator it 00047 = _table.find( str::toLower( strval_r ) ); 00048 if ( it == _table.end() ) 00049 { 00050 ZYPP_THROW( Exception("Dep parse: illegal string value '"+strval_r+"'") ); 00051 } 00052 return it->second; 00053 } 00054 } 00055 00057 00058 const Dep Dep::PROVIDES ( Dep::PROVIDES_e ); 00059 const Dep Dep::PREREQUIRES( Dep::PREREQUIRES_e ); 00060 const Dep Dep::REQUIRES ( Dep::REQUIRES_e ); 00061 const Dep Dep::CONFLICTS ( Dep::CONFLICTS_e ); 00062 const Dep Dep::OBSOLETES ( Dep::OBSOLETES_e ); 00063 const Dep Dep::RECOMMENDS ( Dep::RECOMMENDS_e ); 00064 const Dep Dep::SUGGESTS ( Dep::SUGGESTS_e ); 00065 const Dep Dep::FRESHENS ( Dep::FRESHENS_e ); 00066 const Dep Dep::ENHANCES ( Dep::ENHANCES_e ); 00067 const Dep Dep::SUPPLEMENTS( Dep::SUPPLEMENTS_e ); 00068 00070 // 00071 // METHOD NAME : Dep::Dep 00072 // METHOD TYPE : Ctor 00073 // 00074 Dep::Dep( const std::string & strval_r ) 00075 : _type( parse( strval_r ) ) 00076 {} 00077 00079 // 00080 // METHOD NAME : Dep::asString 00081 // METHOD TYPE : const std::string & 00082 // 00083 const std::string & Dep::asString() const 00084 { 00085 static std::map<for_use_in_switch,std::string> _table; 00086 if ( _table.empty() ) 00087 { 00088 // initialize it 00089 _table[PROVIDES_e] = "provides"; 00090 _table[PREREQUIRES_e] = "prerequires"; 00091 _table[REQUIRES_e] = "requires"; 00092 _table[CONFLICTS_e] = "conflicts"; 00093 _table[OBSOLETES_e] = "obsoletes"; 00094 _table[RECOMMENDS_e] = "recommends"; 00095 _table[SUGGESTS_e] = "suggests"; 00096 _table[FRESHENS_e] = "freshens"; 00097 _table[ENHANCES_e] = "enhances"; 00098 _table[SUPPLEMENTS_e] = "supplements"; 00099 } 00100 return _table[_type]; 00101 } 00102 00104 } // namespace zypp
1.5.3