RepoType.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/repo/RepoException.h"
00013 #include "RepoType.h"
00014 
00015 namespace zypp
00016 {
00017 namespace repo
00018 {
00019 
00020   static std::map<std::string,RepoType::Type> _table;
00021 
00022   const RepoType RepoType::RPMMD(RepoType::RPMMD_e);
00023   const RepoType RepoType::YAST2(RepoType::YAST2_e);
00024   const RepoType RepoType::RPMPLAINDIR(RepoType::RPMPLAINDIR_e);
00025   const RepoType RepoType::NONE(RepoType::NONE_e);
00026 
00027   RepoType::RepoType(const std::string & strval_r)
00028     : _type(parse(strval_r))
00029   {}
00030 
00031   RepoType::Type RepoType::parse(const std::string & strval_r)
00032   {
00033     if (_table.empty())
00034     {
00035       // initialize it
00036       _table["repomd"] = RepoType::RPMMD_e;
00037       _table["rpmmd"] = RepoType::RPMMD_e;
00038       _table["rpm-md"] = RepoType::RPMMD_e;
00039       _table["yum"] = RepoType::RPMMD_e;
00040       _table["YUM"] = RepoType::RPMMD_e;
00041       _table["susetags"] = RepoType::YAST2_e;
00042       _table["yast"] = RepoType::YAST2_e;
00043       _table["YaST"] = RepoType::YAST2_e;
00044       _table["YaST2"] = RepoType::YAST2_e;
00045       _table["YAST"] = RepoType::YAST2_e;
00046       _table["YAST2"] = RepoType::YAST2_e;
00047       _table["yast2"] = RepoType::YAST2_e;
00048       _table["plaindir"] = _table["Plaindir"] = RepoType::RPMPLAINDIR_e;
00049       _table["NONE"] = _table["none"] = RepoType::NONE_e;
00050     }
00051 
00052     std::map<std::string,RepoType::Type>::const_iterator it
00053       = _table.find(strval_r);
00054     if (it == _table.end())
00055     {
00056       ZYPP_THROW(RepoUnknownTypeException(
00057         "Unknown repository type '" + strval_r + "'"));
00058     }
00059     return it->second;
00060   }
00061 
00062 
00063   const std::string & RepoType::asString() const
00064   {
00065     static std::map<Type, std::string> _table;
00066     if ( _table.empty() )
00067     {
00068       // initialize it
00069       _table[RPMMD_e]   = "rpm-md";
00070       _table[YAST2_e]   = "yast2";
00071       _table[RPMPLAINDIR_e]   = "plaindir";
00072       _table[NONE_e] = "NONE";
00073     }
00074     return _table[_type];
00075   }
00076 
00077 
00078   } // ns repo
00079 } // ns zypp
00080 
00081 // vim: set ts=2 sts=2 sw=2 et ai:
Generated on Fri Mar 2 09:45:53 2012 for libzypp by  doxygen 1.6.3