Introduce new solvable kind: Application (as provided by appdata.xml)
[platform/upstream/libzypp.git] / zypp / ResKind.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/ResKind.h
10  *
11 */
12 #ifndef ZYPP_RESKIND_H
13 #define ZYPP_RESKIND_H
14
15 #include <iosfwd>
16 #include <string>
17
18 #include "zypp/APIConfig.h"
19 #include "zypp/base/String.h"
20 #include "zypp/IdStringType.h"
21
22 ///////////////////////////////////////////////////////////////////
23 namespace zypp
24 { /////////////////////////////////////////////////////////////////
25
26   ///////////////////////////////////////////////////////////////////
27   /// \class ResKind
28   /// \brief Resolvable kinds.
29   /// A \b lowercased string and used as identification. Comparison
30   /// against string values is always case insensitive.
31   ///////////////////////////////////////////////////////////////////
32   class ResKind : public IdStringType<ResKind>
33   {
34     public:
35       /** \name Some builtin ResKind constants. */
36       //@{
37       /** Value representing \c nokind (<tt>""</tt>)*/
38       static const ResKind nokind;
39
40       static const ResKind package;
41       static const ResKind patch;
42       static const ResKind pattern;
43       static const ResKind product;
44       static const ResKind srcpackage;
45       static const ResKind application;
46       //@}
47
48     public:
49       /** Default ctor: \ref nokind */
50       ResKind() {}
51
52       /** Ctor taking kind as string. */
53       explicit ResKind( sat::detail::IdType id_r )  : _str( str::toLower(IdString(id_r).c_str()) ) {}
54       explicit ResKind( const IdString & idstr_r )  : _str( str::toLower(idstr_r.c_str()) ) {}
55       explicit ResKind( const std::string & str_r ) : _str( str::toLower(str_r) ) {}
56       explicit ResKind( const char * cstr_r )       : _str( str::toLower(cstr_r) ) {}
57
58     public:
59       /** Return libsolv identifier for name.
60        * Libsolv combines the objects kind and name in a single
61        * identifier \c "pattern:kde_multimedia", \b except for packages
62        * and source packes. They are not prefixed by any kind string.
63       */
64       static std::string satIdent( const ResKind & refers_r, const std::string & name_r );
65       /** \overload */
66       std::string satIdent( const std::string & name_r ) const
67       { return satIdent( *this, name_r ); }
68
69     private:
70       static int _doCompare( const char * lhs,  const char * rhs )
71       {
72         if ( lhs == rhs ) return 0;
73         if ( lhs && rhs ) return ::strcasecmp( lhs, rhs );
74         return( lhs ? 1 : -1 );
75       }
76
77     private:
78       friend class IdStringType<ResKind>;
79       IdString _str;
80   };
81
82   /** \relates ResKind XML output. */
83   inline std::ostream & dumpAsXmlOn( std::ostream & str, const ResKind & obj )
84   { return str << "<kind>" << obj <<  "</kind>"; }
85
86   /////////////////////////////////////////////////////////////////
87 } // namespace zypp
88 ///////////////////////////////////////////////////////////////////
89 #endif // ZYPP_RESKIND_H