~thopiekar/zypper/libzypp-manual-import

« back to all changes in this revision

Viewing changes to zypp/ResKind.h

  • Committer: Thomas-Karl Pietrowski
  • Date: 2014-01-29 22:44:28 UTC
  • Revision ID: thopiekar@googlemail.com-20140129224428-gpcqnsdakby362n8
firstĀ import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
  //
 
28
  //    CLASS NAME : ResKind
 
29
  //
 
30
  /** Resolvable kinds.
 
31
   * A \b lowercased string and used as identification.
 
32
   * Comparison against string values is always case
 
33
   * insensitive.
 
34
   */
 
35
  class ResKind : public IdStringType<ResKind>
 
36
  {
 
37
    public:
 
38
      /** \name Some builtin ResKind constants. */
 
39
      //@{
 
40
      /** Value representing \c nokind (<tt>""</tt>)*/
 
41
      static const ResKind nokind;
 
42
 
 
43
      static const ResKind package;
 
44
      static const ResKind patch;
 
45
      static const ResKind pattern;
 
46
      static const ResKind product;
 
47
      static const ResKind srcpackage;
 
48
      //@}
 
49
 
 
50
    public:
 
51
      /** Default ctor: \ref nokind */
 
52
      ResKind() {}
 
53
 
 
54
      /** Ctor taking kind as string. */
 
55
      explicit ResKind( sat::detail::IdType id_r )  : _str( str::toLower(IdString(id_r).c_str()) ) {}
 
56
      explicit ResKind( const IdString & idstr_r )  : _str( str::toLower(idstr_r.c_str()) ) {}
 
57
      explicit ResKind( const std::string & str_r ) : _str( str::toLower(str_r) ) {}
 
58
      explicit ResKind( const char * cstr_r )       : _str( str::toLower(cstr_r) ) {}
 
59
 
 
60
    public:
 
61
      /** Return libsolv identifier for name.
 
62
       * Libsolv combines the objects kind and name in a single
 
63
       * identifier \c "pattern:kde_multimedia", \b except for packages
 
64
       * and source packes. They are not prefixed by any kind string.
 
65
      */
 
66
      static std::string satIdent( const ResKind & refers_r, const std::string & name_r );
 
67
      /** \overload */
 
68
      std::string satIdent( const std::string & name_r ) const
 
69
      { return satIdent( *this, name_r ); }
 
70
 
 
71
    private:
 
72
      static int _doCompare( const char * lhs,  const char * rhs )
 
73
      {
 
74
        if ( lhs == rhs ) return 0;
 
75
        if ( lhs && rhs ) return ::strcasecmp( lhs, rhs );
 
76
        return( lhs ? 1 : -1 );
 
77
      }
 
78
 
 
79
    private:
 
80
      friend class IdStringType<ResKind>;
 
81
      IdString _str;
 
82
  };
 
83
 
 
84
  /** \relates ResKind XML output. */
 
85
  inline std::ostream & dumpAsXmlOn( std::ostream & str, const ResKind & obj )
 
86
  { return str << "<kind>" << obj <<  "</kind>"; }
 
87
 
 
88
  /////////////////////////////////////////////////////////////////
 
89
} // namespace zypp
 
90
///////////////////////////////////////////////////////////////////
 
91
#endif // ZYPP_RESKIND_H