Rel.cc

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00012 #include <iostream>
00013 #include <map>
00014 
00015 #include "zypp/base/Exception.h"
00016 
00017 #include "zypp/Rel.h"
00018 
00020 namespace zypp
00021 { 
00022 
00023   namespace
00024   {
00025 
00026     std::map<std::string,Rel::for_use_in_switch> _table;
00027 
00028     Rel::for_use_in_switch parse( const std::string & strval_r )
00029     {
00030       if ( _table.empty() )
00031         {
00032           // initialize it
00033           _table["EQ"]   = _table["eq"]  = _table["=="]    = _table["="] = Rel::EQ_e;
00034           _table["NE"]   = _table["ne"]  = _table["!="]                  = Rel::NE_e;
00035           _table["LT"]   = _table["lt"]  = _table["<"]                   = Rel::LT_e;
00036           _table["LE"]   = _table["le"]  = _table["lte"]  = _table["<="] = Rel::LE_e;
00037           _table["GT"]   = _table["gt"]  = _table[">"]                   = Rel::GT_e;
00038           _table["GE"]   = _table["ge"]  = _table["gte"]  = _table[">="] = Rel::GE_e;
00039           _table["ANY"]  = _table["any"] = _table["(any)"] = _table[""]  = Rel::ANY_e;
00040           _table["NONE"] = _table["none"]                                = Rel::NONE_e;
00041         }
00042 
00043       std::map<std::string,Rel::for_use_in_switch>::const_iterator it
00044       = _table.find( strval_r );
00045       if ( it == _table.end() )
00046         {
00047           ZYPP_THROW( Exception("Rel parse: illegal string value '"+strval_r+"'") );
00048         }
00049       return it->second;
00050     }
00051   }
00052 
00054 
00055   const Rel Rel::EQ( Rel::EQ_e );
00056   const Rel Rel::NE( Rel::NE_e );
00057   const Rel Rel::LT( Rel::LT_e );
00058   const Rel Rel::LE( Rel::LE_e );
00059   const Rel Rel::GT( Rel::GT_e );
00060   const Rel Rel::GE( Rel::GE_e );
00061   const Rel Rel::ANY( Rel::ANY_e );
00062   const Rel Rel::NONE( Rel::NONE_e );
00063 
00065   //
00066   //    METHOD NAME : Rel::Rel
00067   //    METHOD TYPE : Constructor
00068   //
00069   Rel::Rel( const std::string & strval_r )
00070   : _op( parse( strval_r ) )
00071   {}
00072 
00074   //
00075   //    METHOD NAME : Rel::asString
00076   //    METHOD TYPE : const std::string &
00077   //
00078   const std::string & Rel::asString() const
00079   {
00080     static std::map<for_use_in_switch,std::string> _table;
00081     if ( _table.empty() )
00082       {
00083         // initialize it
00084         _table[EQ_e]   = "==";
00085         _table[NE_e]   = "!=";
00086         _table[LT_e]   = "<";
00087         _table[LE_e]   = "<=";
00088         _table[GT_e]   = ">";
00089         _table[GE_e]   = ">=";
00090         _table[ANY_e]  = "ANY";
00091         _table[NONE_e] = "NONE";
00092       }
00093     return _table[_op];
00094   }
00095 
00097 } // namespace zypp

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