1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/ResKind.h
12 #ifndef ZYPP_RESKIND_H
13 #define ZYPP_RESKIND_H
18 #include "zypp/APIConfig.h"
19 #include "zypp/base/String.h"
20 #include "zypp/IdStringType.h"
22 ///////////////////////////////////////////////////////////////////
24 { /////////////////////////////////////////////////////////////////
26 ///////////////////////////////////////////////////////////////////
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>
35 /** \name Some builtin ResKind constants. */
37 /** Value representing \c nokind (<tt>""</tt>)*/
38 static const ResKind nokind;
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;
48 /** Return the builtin kind if \a str_r explicitly prefixed.
49 * \a str_r must start with a builtin kind followed by a \c ':'.
50 * If no builtin kind is detected, \ref nokind is returned,
51 * which usually indicates a \ref package or \ref srcpackage.
53 static ResKind explicitBuiltin( const char * str_r );
55 static ResKind explicitBuiltin( const std::string & str_r )
56 { return explicitBuiltin( str_r.c_str() ); }
58 static ResKind explicitBuiltin( const IdString & str_r )
59 { return explicitBuiltin( str_r.c_str() ); }
62 /** Default ctor: \ref nokind */
65 /** Ctor taking kind as string. */
66 explicit ResKind( sat::detail::IdType id_r ) : _str( str::toLower(IdString(id_r).c_str()) ) {}
67 explicit ResKind( const IdString & idstr_r ) : _str( str::toLower(idstr_r.c_str()) ) {}
68 explicit ResKind( const std::string & str_r ) : _str( str::toLower(str_r) ) {}
69 explicit ResKind( const char * cstr_r ) : _str( str::toLower(cstr_r) ) {}
72 /** Return libsolv identifier for name.
73 * Libsolv combines the objects kind and name in a single
74 * identifier \c "pattern:kde_multimedia", \b except for packages
75 * and source packes. They are not prefixed by any kind string.
77 static std::string satIdent( const ResKind & refers_r, const std::string & name_r );
79 std::string satIdent( const std::string & name_r ) const
80 { return satIdent( *this, name_r ); }
83 static int _doCompare( const char * lhs, const char * rhs )
85 if ( lhs == rhs ) return 0;
86 if ( lhs && rhs ) return ::strcasecmp( lhs, rhs );
87 return( lhs ? 1 : -1 );
91 friend class IdStringType<ResKind>;
95 /** \relates ResKind XML output. */
96 inline std::ostream & dumpAsXmlOn( std::ostream & str, const ResKind & obj )
97 { return str << "<kind>" << obj << "</kind>"; }
99 /////////////////////////////////////////////////////////////////
101 ///////////////////////////////////////////////////////////////////
102 #endif // ZYPP_RESKIND_H