libzypp  10.5.0
ServiceType.cc
Go to the documentation of this file.
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   const ServiceType ServiceType::PLUGIN(ServiceType::PLUGIN_e);
00026 
00027   ServiceType::ServiceType(const std::string & strval_r)
00028     : _type(parse(strval_r))
00029   {}
00030 
00031   ServiceType::Type ServiceType::parse(const std::string & strval_r)
00032   {
00033     if (_table.empty())
00034     {
00035       // initialize it
00036       _table["ris"] = ServiceType::RIS_e;
00037       _table["RIS"] = ServiceType::RIS_e;
00038       _table["nu"] = ServiceType::RIS_e;
00039       _table["NU"] = ServiceType::RIS_e;
00040       _table["plugin"] = ServiceType::PLUGIN_e;
00041       _table["PLUGIN"] = ServiceType::PLUGIN_e;
00042       _table["NONE"] = _table["none"] = ServiceType::NONE_e;
00043     }
00044 
00045     std::map<std::string,ServiceType::Type>::const_iterator it
00046       = _table.find(strval_r);
00047     if (it == _table.end())
00048     {
00049       ZYPP_THROW(RepoUnknownTypeException(
00050         "Unknown service type '" + strval_r + "'"));
00051     }
00052     return it->second;
00053   }
00054 
00055 
00056   const std::string & ServiceType::asString() const
00057   {
00058     static std::map<Type, std::string> _table;
00059     if ( _table.empty() )
00060     {
00061       // initialize it
00062       _table[RIS_e]  = "ris";
00063       _table[PLUGIN_e]  = "plugin";
00064       _table[NONE_e] = "NONE";
00065     }
00066     return _table[_type];
00067   }
00068 
00069 
00070   } // ns repo
00071 } // ns zypp
00072 
00073 // vim: set ts=2 sts=2 sw=2 et ai: