libzypp  17.31.31
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>
14 #include "ServiceType.h"
15 
16 namespace 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:
thrown when it was impossible to determine this repo type.
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition: Exception.h:428
ServiceType::Type parse(const std::string &strval_r)
Definition: ServiceType.cc:45
static const ServiceType RIS
Repository Index Service (RIS) (formerly known as &#39;Novell Update&#39; (NU) service)
Definition: ServiceType.h:32
const std::string & asString() const
Definition: ServiceType.cc:55
static const ServiceType NONE
No service set.
Definition: ServiceType.h:34
static const ServiceType PLUGIN
Plugin services are scripts installed on your system that provide the package manager with repositori...
Definition: ServiceType.h:43
std::string toLower(const std::string &s)
Return lowercase version of s.
Definition: String.cc:177
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1