libzypp  13.10.6
ResourceType.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/Exception.h"
13 #include "ResourceType.h"
14 
15 namespace zypp
16 {
17  namespace repo
18  {
19  namespace yum
20  {
21 
22 
23  static std::map<std::string,ResourceType::Type> _table;
24 
37 
38  ResourceType::ResourceType(const std::string & strval_r)
39  : _type(parse(strval_r))
40  {}
41 
42  ResourceType::Type ResourceType::parse(const std::string & strval_r)
43  {
44  if (_table.empty())
45  {
46  // initialize it
47  _table["repomd"] = ResourceType::REPOMD_e;
48  _table["primary"] = ResourceType::PRIMARY_e;
49  _table["other"] = ResourceType::OTHER_e;
50  _table["filelists"] = ResourceType::FILELISTS_e;
51  _table["group"] = ResourceType::GROUP_e;
52  _table["patches"] = ResourceType::PATCHES_e;
53  _table["patch"] = ResourceType::PATCH_e;
54  _table["product"] = ResourceType::PRODUCT_e;
55  _table["patterns"] = ResourceType::PATTERNS_e;
56  _table["primary_db"] = ResourceType::PRIMARY_DB_e;
57  _table["other_db"] = ResourceType::OTHER_DB_e;
58  _table["NONE"] = _table["none"] = ResourceType::NONE_e;
59  }
60 
61  std::map<std::string,ResourceType::Type>::const_iterator it
62  = _table.find(strval_r);
63  if (it == _table.end())
64  {
65  return ResourceType::NONE_e;
66  }
67  return it->second;
68  }
69 
70 
71  const std::string & ResourceType::asString() const
72  {
73  static std::map<Type, std::string> _table;
74  if ( _table.empty() )
75  {
76  // initialize it
77  _table[REPOMD_e] = "repomd";
78  _table[PRIMARY_e] = "primary";
79  _table[OTHER_e] = "other";
80  _table[FILELISTS_e] = "filelists";
81  _table[GROUP_e] = "group";
82  _table[PATCHES_e] = "patches";
83  _table[PATCH_e] = "patch";
84  _table[PRODUCT_e] = "product";
85  _table[PATTERNS_e] = "patterns";
86  _table[OTHER_DB_e] = "other_db";
87  _table[PRIMARY_DB_e] = "primary_db";
88  _table[NONE_e] = "NONE";
89  }
90  return _table[_type];
91  }
92 
93 
94  } // ns yum
95  } // ns source
96 } // ns zypp
97 
98 // vim: set ts=2 sts=2 sw=2 et ai:
static const ResourceType PATTERNS
Definition: ResourceType.h:38
static const ResourceType PATCHES
Definition: ResourceType.h:35
static std::map< std::string, ResourceType::Type > _table
Definition: ResourceType.cc:23
static const ResourceType OTHER
Definition: ResourceType.h:32
static const ResourceType REPOMD
Definition: ResourceType.h:30
const std::string & asString() const
Definition: ResourceType.cc:71
static const ResourceType PRODUCT
Definition: ResourceType.h:37
static const ResourceType NONE
Definition: ResourceType.h:29
static const ResourceType OTHER_DB
Definition: ResourceType.h:41
ResourceType::Type parse(const std::string &strval_r)
Definition: ResourceType.cc:42
static const ResourceType PRIMARY
Definition: ResourceType.h:31
static const ResourceType PATCH
Definition: ResourceType.h:36
static const ResourceType FILELISTS
Definition: ResourceType.h:33
static const ResourceType GROUP
Definition: ResourceType.h:34
static const ResourceType PRIMARY_DB
Definition: ResourceType.h:40