00001 /*---------------------------------------------------------------------\ 00002 | ____ _ __ __ ___ | 00003 | |__ / \ / / . \ . \ | 00004 | / / \ V /| _/ _/ | 00005 | / /__ | | | | | | | 00006 | /_____||_| |_| |_| | 00007 | | 00008 \---------------------------------------------------------------------*/ 00009 00010 #include <iostream> 00011 #include <map> 00012 #include "zypp/repo/RepoException.h" 00013 #include "ServiceType.h" 00014 00015 namespace zypp 00016 { 00017 namespace repo 00018 { 00019 00020 00021 static std::map<std::string,ServiceType::Type> _table; 00022 00023 const ServiceType ServiceType::RIS(ServiceType::RIS_e); 00024 const ServiceType ServiceType::NONE(ServiceType::NONE_e); 00025 00026 ServiceType::ServiceType(const std::string & strval_r) 00027 : _type(parse(strval_r)) 00028 {} 00029 00030 ServiceType::Type ServiceType::parse(const std::string & strval_r) 00031 { 00032 if (_table.empty()) 00033 { 00034 // initialize it 00035 _table["ris"] = ServiceType::RIS_e; 00036 _table["RIS"] = ServiceType::RIS_e; 00037 _table["nu"] = ServiceType::RIS_e; 00038 _table["NU"] = ServiceType::RIS_e; 00039 _table["NONE"] = _table["none"] = ServiceType::NONE_e; 00040 } 00041 00042 std::map<std::string,ServiceType::Type>::const_iterator it 00043 = _table.find(strval_r); 00044 if (it == _table.end()) 00045 { 00046 ZYPP_THROW(RepoUnknownTypeException( 00047 "Unknown service type '" + strval_r + "'")); 00048 } 00049 return it->second; 00050 } 00051 00052 00053 const std::string & ServiceType::asString() const 00054 { 00055 static std::map<Type, std::string> _table; 00056 if ( _table.empty() ) 00057 { 00058 // initialize it 00059 _table[RIS_e] = "ris"; 00060 _table[NONE_e] = "NONE"; 00061 } 00062 return _table[_type]; 00063 } 00064 00065 00066 } // ns repo 00067 } // ns zypp 00068 00069 // vim: set ts=2 sts=2 sw=2 et ai: