~thopiekar/zypper/libzypp-manual-import

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*---------------------------------------------------------------------\
|                          ____ _   __ __ ___                          |
|                         |__  / \ / / . \ . \                         |
|                           / / \ V /|  _/  _/                         |
|                          / /__ | | | | | |                           |
|                         /_____||_| |_| |_|                           |
|                                                                      |
\---------------------------------------------------------------------*/
/** \file	zypp/ResKind.h
 *
*/
#ifndef ZYPP_RESKIND_H
#define ZYPP_RESKIND_H

#include <iosfwd>
#include <string>

#include "zypp/APIConfig.h"
#include "zypp/base/String.h"
#include "zypp/IdStringType.h"

///////////////////////////////////////////////////////////////////
namespace zypp
{ /////////////////////////////////////////////////////////////////

  ///////////////////////////////////////////////////////////////////
  /// \class ResKind
  /// \brief Resolvable kinds.
  /// A \b lowercased string and used as identification. Comparison
  /// against string values is always case insensitive.
  ///////////////////////////////////////////////////////////////////
  class ResKind : public IdStringType<ResKind>
  {
    public:
      /** \name Some builtin ResKind constants. */
      //@{
      /** Value representing \c nokind (<tt>""</tt>)*/
      static const ResKind nokind;

      static const ResKind package;
      static const ResKind patch;
      static const ResKind pattern;
      static const ResKind product;
      static const ResKind srcpackage;
      static const ResKind application;
      //@}

      /** Return the builtin kind if \a str_r explicitly prefixed.
       * \a str_r must start with a builtin kind followed by a \c ':'.
       * If no builtin kind is detected, \ref nokind is returned,
       * which usually indicates a \ref package or \ref srcpackage.
       */
      static ResKind explicitBuiltin( const char * str_r );
      /** \overload */
      static ResKind explicitBuiltin( const std::string & str_r )
      { return explicitBuiltin( str_r.c_str() ); }
      /** \overload */
      static ResKind explicitBuiltin( const IdString & str_r )
      { return explicitBuiltin( str_r.c_str() ); }

    public:
      /** Default ctor: \ref nokind */
      ResKind() {}

      /** Ctor taking kind as string. */
      explicit ResKind( sat::detail::IdType id_r )  : _str( str::toLower(IdString(id_r).c_str()) ) {}
      explicit ResKind( const IdString & idstr_r )  : _str( str::toLower(idstr_r.c_str()) ) {}
      explicit ResKind( const std::string & str_r ) : _str( str::toLower(str_r) ) {}
      explicit ResKind( const char * cstr_r )       : _str( str::toLower(cstr_r) ) {}

    public:
      /** Return libsolv identifier for name.
       * Libsolv combines the objects kind and name in a single
       * identifier \c "pattern:kde_multimedia", \b except for packages
       * and source packes. They are not prefixed by any kind string.
      */
      static std::string satIdent( const ResKind & refers_r, const std::string & name_r );
      /** \overload */
      std::string satIdent( const std::string & name_r ) const
      { return satIdent( *this, name_r ); }

    private:
      static int _doCompare( const char * lhs,  const char * rhs )
      {
        if ( lhs == rhs ) return 0;
        if ( lhs && rhs ) return ::strcasecmp( lhs, rhs );
        return( lhs ? 1 : -1 );
      }

    private:
      friend class IdStringType<ResKind>;
      IdString _str;
  };

  /** \relates ResKind XML output. */
  inline std::ostream & dumpAsXmlOn( std::ostream & str, const ResKind & obj )
  { return str << "<kind>" << obj <<  "</kind>"; }

  /////////////////////////////////////////////////////////////////
} // namespace zypp
///////////////////////////////////////////////////////////////////
#endif // ZYPP_RESKIND_H