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::REPOMD(ResourceType::REPOMD_e);
00026   const ResourceType ResourceType::PRIMARY(ResourceType::PRIMARY_e);
00027   const ResourceType ResourceType::OTHER(ResourceType::OTHER_e);
00028   const ResourceType ResourceType::FILELISTS(ResourceType::FILELISTS_e);
00029   const ResourceType ResourceType::GROUP(ResourceType::GROUP_e);
00030   const ResourceType ResourceType::PATCHES(ResourceType::PATCHES_e);
00031   const ResourceType ResourceType::PATCH(ResourceType::PATCH_e);
00032   const ResourceType ResourceType::PRODUCTS(ResourceType::PRODUCTS_e);
00033   const ResourceType ResourceType::PATTERNS(ResourceType::PATTERNS_e);
00034 
00035 
00036   ResourceType::ResourceType(const std::string & strval_r)
00037     : _type(parse(strval_r))
00038   {}
00039 
00040   ResourceType::Type ResourceType::parse(const std::string & strval_r)
00041   {
00042     if (_table.empty())
00043     {
00044       // initialize it
00045       _table["repomd"] = ResourceType::REPOMD_e;
00046       _table["primary"] = ResourceType::PRIMARY_e;
00047       _table["other"] = ResourceType::OTHER_e;
00048       _table["filelists"] = ResourceType::FILELISTS_e;
00049       _table["group"] = ResourceType::GROUP_e;
00050       _table["patches"] = ResourceType::PATCHES_e;
00051       _table["patch"] = ResourceType::PATCH_e;
00052       _table["products"] = ResourceType::PRODUCTS_e;
00053       _table["patterns"] = ResourceType::PATTERNS_e;
00054       _table["NONE"] = _table["none"] = ResourceType::NONE_e;
00055     }
00056 
00057     std::map<std::string,ResourceType::Type>::const_iterator it
00058       = _table.find(strval_r);
00059     if (it == _table.end())
00060     {
00061       ZYPP_THROW(Exception(
00062         "ResourceType parse: illegal string value '" + strval_r + "'"));
00063     }
00064     return it->second;
00065   }
00066 
00067 
00068   const std::string & ResourceType::asString() const
00069   {
00070     static std::map<Type, std::string> _table;
00071     if ( _table.empty() )
00072     {
00073       // initialize it
00074       _table[REPOMD_e]   = "repomd";
00075       _table[PRIMARY_e]   = "primary";
00076       _table[OTHER_e]   = "other";
00077       _table[FILELISTS_e]   = "filelists";
00078       _table[GROUP_e]   = "group";
00079       _table[PATCHES_e]   = "patches";
00080       _table[PATCH_e]  = "patch";
00081       _table[PRODUCTS_e]  = "products";
00082       _table[PATTERNS_e]  = "patterns";
00083       _table[NONE_e] = "NONE";
00084     }
00085     return _table[_type];
00086   }
00087 
00088 
00089     } // ns yum
00090   } // ns source
00091 } // ns zypp
00092 
00093 // vim: set ts=2 sts=2 sw=2 et ai:

Generated on Tue Sep 25 19:23:05 2007 for libzypp by  doxygen 1.5.3