libzypp: zypp/repo/ServiceType.cc Source File

libzypp 17.38.11

ServiceType.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
9
10#include <iostream>
11#include <map>
12#include <zypp/base/NamedValue.h>
13#include <zypp/repo/RepoException.h>
14#include "ServiceType.h"
15
16namespace zypp
17{
18 namespace repo
19 {
21 namespace
22 {
23 static NamedValue<ServiceType::Type> & table()
24 {
25 static NamedValue<ServiceType::Type> & _t( *new NamedValue<ServiceType::Type> );
26 if ( _t.empty() )
27 {
28 _t( ServiceType::RIS_e ) | "ris" |"RIS"|"nu"|"NU";
29 _t( ServiceType::PLUGIN_e ) | "plugin" |"PLUGIN";
30 _t( ServiceType::NONE_e ) | "N/A" |"n/a"|"NONE"|"none";
31 }
32 return _t;
33 }
34 } // namespace
36
37 const ServiceType ServiceType::RIS(ServiceType::RIS_e);
38 const ServiceType ServiceType::NONE(ServiceType::NONE_e);
39 const ServiceType ServiceType::PLUGIN(ServiceType::PLUGIN_e);
40
41 ServiceType::ServiceType(const std::string & strval_r)
42 : _type(parse(strval_r))
43 {}
44
45 ServiceType::Type ServiceType::parse(const std::string & strval_r)
46 {
47 ServiceType::Type type;
48 if ( ! table().getValue( str::toLower( strval_r ), type ) )
49 {
50 ZYPP_THROW( RepoUnknownTypeException( "Unknown service type '" + strval_r + "'") );
51 }
52 return type;
53 }
54
55 const std::string & ServiceType::asString() const
56 {
57 return table().getName( _type );
58 }
59
60
61 } // ns repo
62} // ns zypp
63
64// vim: set ts=2 sts=2 sw=2 et ai:
ZYPP_THROW
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition Exception.h:459
NamedValue.h
RepoException.h
ServiceType.h
zypp::repo::RepoUnknownTypeException
thrown when it was impossible to determine this repo type.
Definition RepoException.h:143
zypp::repo
Definition DeltaCandidates.cc:30
zypp::str::toLower
std::string toLower(const std::string &s)
Return lowercase version of s.
Definition String.cc:180
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2
zypp::repo::ServiceType
Service type enumeration.
Definition ServiceType.h:27
zypp::repo::ServiceType::parse
ServiceType::Type parse(const std::string &strval_r)
Definition ServiceType.cc:45
zypp::repo::ServiceType::asString
const std::string & asString() const
Definition ServiceType.cc:55
zypp::repo::ServiceType::_type
Type _type
Definition ServiceType.h:64
zypp::repo::ServiceType::ServiceType
ServiceType()
Definition ServiceType.h:52
zypp::repo::ServiceType::Type
Type
Definition ServiceType.h:46
zypp::repo::ServiceType::RIS_e
@ RIS_e
Definition ServiceType.h:48
zypp::repo::ServiceType::NONE_e
@ NONE_e
Definition ServiceType.h:47
zypp::repo::ServiceType::PLUGIN_e
@ PLUGIN_e
Definition ServiceType.h:49