Imported Upstream version 15.21.0
[platform/upstream/libzypp.git] / zypp / Dep.cc
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/Dep.cc
10  *
11 */
12 #include <map>
13 #include <iostream>
14
15 #include "zypp/base/Exception.h"
16 #include "zypp/base/Gettext.h"
17 #include "zypp/base/String.h"
18
19 #include "zypp/Dep.h"
20
21 ///////////////////////////////////////////////////////////////////
22 namespace zypp
23 { /////////////////////////////////////////////////////////////////
24
25   namespace
26   {
27     inline Dep::for_use_in_switch parse( const std::string & strval_r )
28     {
29       const std::map<std::string,Dep::for_use_in_switch> _table = {
30         { "provides",           Dep::PROVIDES_e         },
31         { "prerequires",        Dep::PREREQUIRES_e      },
32         { "requires",           Dep::REQUIRES_e         },
33         { "conflicts",          Dep::CONFLICTS_e        },
34         { "obsoletes",          Dep::OBSOLETES_e        },
35         { "recommends",         Dep::RECOMMENDS_e       },
36         { "suggests",           Dep::SUGGESTS_e         },
37         { "enhances",           Dep::ENHANCES_e         },
38         { "supplements",        Dep::SUPPLEMENTS_e      }
39       };
40
41       auto it = _table.find( str::toLower( strval_r ) );
42       if ( it == _table.end() )
43       {
44         ZYPP_THROW( Exception("Dep parse: illegal string value '"+strval_r+"'") );
45       }
46       return it->second;
47     }
48   }
49
50   ///////////////////////////////////////////////////////////////////
51
52   const Dep Dep::PROVIDES   ( Dep::PROVIDES_e );
53   const Dep Dep::PREREQUIRES( Dep::PREREQUIRES_e );
54   const Dep Dep::REQUIRES   ( Dep::REQUIRES_e );
55   const Dep Dep::CONFLICTS  ( Dep::CONFLICTS_e );
56   const Dep Dep::OBSOLETES  ( Dep::OBSOLETES_e );
57   const Dep Dep::RECOMMENDS ( Dep::RECOMMENDS_e );
58   const Dep Dep::SUGGESTS   ( Dep::SUGGESTS_e );
59   const Dep Dep::ENHANCES   ( Dep::ENHANCES_e );
60   const Dep Dep::SUPPLEMENTS( Dep::SUPPLEMENTS_e );
61
62   ///////////////////////////////////////////////////////////////////
63   //
64   //    METHOD NAME : Dep::Dep
65   //    METHOD TYPE : Ctor
66   //
67   Dep::Dep( const std::string & strval_r )
68   : _type( parse( strval_r ) )
69   {}
70
71   ///////////////////////////////////////////////////////////////////
72   //
73   //    METHOD NAME : Dep::asString
74   //    METHOD TYPE : const std::string &
75   //
76   const std::string & Dep::asString() const
77   {
78     static const std::map<for_use_in_switch,std::string> _table = {
79       { PROVIDES_e,     "provides"      },
80       { PREREQUIRES_e,  "prerequires"   },
81       { REQUIRES_e,     "requires"      },
82       { CONFLICTS_e,    "conflicts"     },
83       { OBSOLETES_e,    "obsoletes"     },
84       { RECOMMENDS_e,   "recommends"    },
85       { SUGGESTS_e,     "suggests"      },
86       { ENHANCES_e,     "enhances"      },
87       { SUPPLEMENTS_e,  "supplements"   }
88     };
89     return _table.at(_type);
90   }
91
92   std::string Dep::asUserString() const
93   {
94     switch ( inSwitch() )
95     {
96       case PROVIDES_e:          return _("Provides");           break;
97       case PREREQUIRES_e:       return _("Prerequires");        break;
98       case REQUIRES_e:          return _("Requires");           break;
99       case CONFLICTS_e:         return _("Conflicts");          break;
100       case OBSOLETES_e:         return _("Obsoletes");          break;
101       case RECOMMENDS_e:        return _("Recommends");         break;
102       case SUGGESTS_e:          return _("Suggests");           break;
103       case ENHANCES_e:          return _("Enhances");           break;
104       case SUPPLEMENTS_e:       return _("Supplements");        break;
105     }
106     return "<missing translation>";
107   }
108
109   /////////////////////////////////////////////////////////////////
110 } // namespace zypp
111 ///////////////////////////////////////////////////////////////////