libzypp
10.5.0
|
00001 /*---------------------------------------------------------------------\ 00002 | ____ _ __ __ ___ | 00003 | |__ / \ / / . \ . \ | 00004 | / / \ V /| _/ _/ | 00005 | / /__ | | | | | | | 00006 | /_____||_| |_| |_| | 00007 | | 00008 \---------------------------------------------------------------------*/ 00009 00010 #include <iostream> 00011 #include <map> 00012 #include "zypp/repo/RepoException.h" 00013 #include "RepoType.h" 00014 00015 namespace zypp 00016 { 00017 namespace repo 00018 { 00019 00020 static std::map<std::string,RepoType::Type> _table; 00021 00022 const RepoType RepoType::RPMMD(RepoType::RPMMD_e); 00023 const RepoType RepoType::YAST2(RepoType::YAST2_e); 00024 const RepoType RepoType::RPMPLAINDIR(RepoType::RPMPLAINDIR_e); 00025 const RepoType RepoType::NONE(RepoType::NONE_e); 00026 00027 RepoType::RepoType(const std::string & strval_r) 00028 : _type(parse(strval_r)) 00029 {} 00030 00031 RepoType::Type RepoType::parse(const std::string & strval_r) 00032 { 00033 if (_table.empty()) 00034 { 00035 // initialize it 00036 _table["repomd"] 00037 = _table["rpmmd"] 00038 = _table["rpm-md"] 00039 = _table["yum"] 00040 = _table["YUM"] 00041 = _table["up2date"] 00042 = RepoType::RPMMD_e; 00043 00044 _table["susetags"] 00045 = _table["yast"] 00046 = _table["YaST"] 00047 = _table["YaST2"] 00048 = _table["YAST"] 00049 = _table["YAST2"] 00050 = _table["yast2"] 00051 = RepoType::YAST2_e; 00052 00053 _table["plaindir"] 00054 = _table["Plaindir"] 00055 = RepoType::RPMPLAINDIR_e; 00056 00057 _table["NONE"] 00058 = _table["none"] 00059 = RepoType::NONE_e; 00060 } 00061 00062 std::map<std::string,RepoType::Type>::const_iterator it 00063 = _table.find(strval_r); 00064 if (it == _table.end()) 00065 { 00066 ZYPP_THROW(RepoUnknownTypeException( 00067 "Unknown repository type '" + strval_r + "'")); 00068 } 00069 return it->second; 00070 } 00071 00072 00073 const std::string & RepoType::asString() const 00074 { 00075 static std::map<Type, std::string> _table; 00076 if ( _table.empty() ) 00077 { 00078 // initialize it 00079 _table[RPMMD_e] = "rpm-md"; 00080 _table[YAST2_e] = "yast2"; 00081 _table[RPMPLAINDIR_e] = "plaindir"; 00082 _table[NONE_e] = "NONE"; 00083 } 00084 return _table[_type]; 00085 } 00086 00087 00088 } // ns repo 00089 } // ns zypp 00090 00091 // vim: set ts=2 sts=2 sw=2 et ai: