libzypp  10.5.0
ResourceType.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/base/Exception.h"
00013 #include "ResourceType.h"
00014 
00015 namespace zypp
00016 {
00017   namespace repo
00018   {
00019     namespace yum
00020     {
00021 
00022 
00023   static std::map<std::string,ResourceType::Type> _table;
00024 
00025   const ResourceType ResourceType::NONE(ResourceType::NONE_e);
00026   const ResourceType ResourceType::REPOMD(ResourceType::REPOMD_e);
00027   const ResourceType ResourceType::PRIMARY(ResourceType::PRIMARY_e);
00028   const ResourceType ResourceType::OTHER(ResourceType::OTHER_e);
00029   const ResourceType ResourceType::FILELISTS(ResourceType::FILELISTS_e);
00030   const ResourceType ResourceType::GROUP(ResourceType::GROUP_e);
00031   const ResourceType ResourceType::PATCHES(ResourceType::PATCHES_e);
00032   const ResourceType ResourceType::PATCH(ResourceType::PATCH_e);
00033   const ResourceType ResourceType::PRODUCT(ResourceType::PRODUCT_e);
00034   const ResourceType ResourceType::PATTERNS(ResourceType::PATTERNS_e);
00035   const ResourceType ResourceType::PRIMARY_DB(ResourceType::PRIMARY_DB_e);
00036   const ResourceType ResourceType::OTHER_DB(ResourceType::OTHER_DB_e);
00037 
00038   ResourceType::ResourceType(const std::string & strval_r)
00039     : _type(parse(strval_r))
00040   {}
00041 
00042   ResourceType::Type ResourceType::parse(const std::string & strval_r)
00043   {
00044     if (_table.empty())
00045     {
00046       // initialize it
00047       _table["repomd"] = ResourceType::REPOMD_e;
00048       _table["primary"] = ResourceType::PRIMARY_e;
00049       _table["other"] = ResourceType::OTHER_e;
00050       _table["filelists"] = ResourceType::FILELISTS_e;
00051       _table["group"] = ResourceType::GROUP_e;
00052       _table["patches"] = ResourceType::PATCHES_e;
00053       _table["patch"] = ResourceType::PATCH_e;
00054       _table["product"] = ResourceType::PRODUCT_e;
00055       _table["patterns"] = ResourceType::PATTERNS_e;
00056       _table["primary_db"] = ResourceType::PRIMARY_DB_e;
00057       _table["other_db"] = ResourceType::OTHER_DB_e;
00058       _table["NONE"] = _table["none"] = ResourceType::NONE_e;
00059     }
00060 
00061     std::map<std::string,ResourceType::Type>::const_iterator it
00062       = _table.find(strval_r);
00063     if (it == _table.end())
00064     {
00065       return ResourceType::NONE_e;
00066     }
00067     return it->second;
00068   }
00069 
00070 
00071   const std::string & ResourceType::asString() const
00072   {
00073     static std::map<Type, std::string> _table;
00074     if ( _table.empty() )
00075     {
00076       // initialize it
00077       _table[REPOMD_e]   = "repomd";
00078       _table[PRIMARY_e]   = "primary";
00079       _table[OTHER_e]   = "other";
00080       _table[FILELISTS_e]   = "filelists";
00081       _table[GROUP_e]   = "group";
00082       _table[PATCHES_e]   = "patches";
00083       _table[PATCH_e]  = "patch";
00084       _table[PRODUCT_e]  = "product";
00085       _table[PATTERNS_e]  = "patterns";
00086       _table[OTHER_DB_e]  = "other_db";
00087       _table[PRIMARY_DB_e]  = "primary_db";
00088       _table[NONE_e] = "NONE";
00089     }
00090     return _table[_type];
00091   }
00092 
00093 
00094     } // ns yum
00095   } // ns source
00096 } // ns zypp
00097 
00098 // vim: set ts=2 sts=2 sw=2 et ai: