Imported Upstream version 15.21.0
[platform/upstream/libzypp.git] / zypp / ResKind.cc
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/ResKind.cc
10  *
11 */
12 #include <iostream>
13
14 #include "zypp/base/String.h"
15
16 #include "zypp/ResKind.h"
17 #include "zypp/ResTraits.h"
18
19 using std::endl;
20
21 ///////////////////////////////////////////////////////////////////
22 namespace zypp
23 { /////////////////////////////////////////////////////////////////
24
25   const ResKind ResKind::nokind;
26   const ResKind ResKind::package        ( "package" );
27   const ResKind ResKind::patch          ( "patch" );
28   const ResKind ResKind::pattern        ( "pattern" );
29   const ResKind ResKind::product        ( "product" );
30   const ResKind ResKind::srcpackage     ( "srcpackage" );
31   const ResKind ResKind::application    ( "application" );
32
33   template<>
34     const ResKind ResTraits<Package>    ::kind( ResKind::package );
35   template<>
36     const ResKind ResTraits<Patch>      ::kind( ResKind::patch );
37   template<>
38     const ResKind ResTraits<Pattern>    ::kind( ResKind::pattern );
39   template<>
40     const ResKind ResTraits<Product>    ::kind( ResKind::product );
41   template<>
42     const ResKind ResTraits<SrcPackage> ::kind( ResKind::srcpackage );
43   template<>
44     const ResKind ResTraits<Application>::kind( ResKind::application );
45
46   ResKind ResKind::explicitBuiltin( const char * str_r )
47   {
48     if ( str_r && str_r[0] && str_r[1] && str_r[2] )
49     {
50       switch ( str_r[3] )
51       {
52         // NOTE: it needs to be assertd that the separating ':' is present
53         // if a known kind is retuirned. Dependent code relies on this!
54         #define OUTS(K,S) if ( !::strncmp( str_r, ResKind::K.c_str(), S ) && str_r[S] == ':' ) return ResKind::K
55         //             ----v
56         case 'c': OUTS( patch, 5 );       break;
57         case 'd': OUTS( product, 7 );     break;
58         case 'k': OUTS( package, 7 );     break;
59         case 'l': OUTS( application, 11 );break;
60         case 'p': OUTS( srcpackage, 10 ); break;
61         case 't': OUTS( pattern, 7 );     break;
62         #undef OUTS
63       }
64     }
65     return nokind;
66   }
67
68   std::string ResKind::satIdent( const ResKind & refers_r, const std::string & name_r )
69   {
70     if ( ! refers_r || refers_r == package || refers_r == srcpackage )
71       return name_r;
72     return str::form( "%s:%s", refers_r.c_str(), name_r.c_str() );
73   }
74
75   /////////////////////////////////////////////////////////////////
76 } // namespace zypp
77 ///////////////////////////////////////////////////////////////////