libzypp  17.35.12
ByIdent.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #ifndef ZYPP_POOL_BYIDENT_H
13 #define ZYPP_POOL_BYIDENT_H
14 
15 #include <zypp/PoolItem.h>
16 
17 #include <utility>
18 
20 namespace zypp
21 {
22  namespace pool
24  {
25 
28  class ByIdent
29  {
30  public:
32  : _id( 0 )
33  {}
34 
35  explicit ByIdent( sat::Solvable slv_r )
36  : _id( makeIdent( slv_r ) )
37  {}
38 
39  explicit ByIdent( IdString ident_r )
40  : _id( ident_r.id() )
41  {}
42 
43  ByIdent( ResKind kind_r, IdString name_r )
44  : _id( makeIdent( std::move(kind_r), name_r ) )
45  {}
46 
47  ByIdent( ResKind kind_r, const C_Str & name_r )
48  : _id( makeIdent( std::move(kind_r), name_r ) )
49  {}
50 
51  public:
52  bool operator()( sat::Solvable slv_r ) const
53  {
54  return _id >= 0 ? ( slv_r.ident().id() == _id && ! slv_r.isKind( ResKind::srcpackage ) )
55  : ( slv_r.ident().id() == -_id && slv_r.isKind( ResKind::srcpackage ) );
56  }
57 
58  bool operator()( const PoolItem & pi_r ) const
59  { return operator()( pi_r.satSolvable() ); }
60 
61  bool operator()( const ResObject::constPtr& p_r ) const
62  { return p_r ? operator()( p_r->satSolvable() ) : !_id; }
63 
64  private:
66  {
67  return slv_r.isKind( ResKind::srcpackage ) ? -slv_r.ident().id()
68  : slv_r.ident().id();
69  }
70 
71  sat::detail::IdType makeIdent( const ResKind& kind_r, IdString name_r )
72  {
73  if ( kind_r == ResKind::package )
74  return name_r.id();
75  else if ( kind_r == ResKind::srcpackage )
76  return -name_r.id();
77  return IdString( str::form( "%s:%s", kind_r.c_str(), name_r.c_str() ) ).id();
78  }
79 
80  sat::detail::IdType makeIdent( const ResKind& kind_r, const C_Str & name_r )
81  {
82  if ( kind_r == ResKind::package )
83  return IdString( name_r ).id();
84  else if ( kind_r == ResKind::srcpackage )
85  return -(IdString( name_r ).id());
86  return IdString( str::form( "%s:%s", kind_r.c_str(), name_r.c_str() ) ).id();
87  }
88 
89  public:
90  sat::detail::IdType get() const { return _id; }
91 
92  private:
97  };
98 
100  } // namespace pool
103 } // namespace zypp
105 #endif // ZYPP_POOL_BYIDENT_H
A Solvable object within the sat Pool.
Definition: Solvable.h:53
sat::detail::IdType _id
negative _id for srcpackage, as they use the same ident as package.
Definition: ByIdent.h:96
static const ResKind package
Definition: ResKind.h:40
sat::detail::IdType makeIdent(sat::Solvable slv_r)
Definition: ByIdent.h:65
IdType id() const
Expert backdoor.
Definition: IdString.h:133
sat::detail::IdType makeIdent(const ResKind &kind_r, IdString name_r)
Definition: ByIdent.h:71
bool isKind(const ResKind &kind_r) const
Test whether a Solvable is of a certain ResKind.
Definition: Solvable.cc:303
Definition: Arch.h:363
int IdType
Generic Id type.
Definition: PoolMember.h:104
static const ResKind srcpackage
Definition: ResKind.h:44
Access to the sat-pools string space.
Definition: IdString.h:43
const char * c_str() const
Definition: String.h:116
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
Definition: String.cc:37
ByIdent(ResKind kind_r, IdString name_r)
Definition: ByIdent.h:43
bool operator()(const PoolItem &pi_r) const
Definition: ByIdent.h:58
bool operator()(const ResObject::constPtr &p_r) const
Definition: ByIdent.h:61
Convenience char* constructible from std::string and char*, it maps (char*)0 to an empty string...
Definition: String.h:90
TraitsType::constPtrType constPtr
Definition: ResObject.h:43
const char * c_str() const
Conversion to const char *
Definition: IdString.cc:50
ByIdent(IdString ident_r)
Definition: ByIdent.h:39
ByIdent(ResKind kind_r, const C_Str &name_r)
Definition: ByIdent.h:47
ByIdent(sat::Solvable slv_r)
Definition: ByIdent.h:35
sat::detail::IdType makeIdent(const ResKind &kind_r, const C_Str &name_r)
Definition: ByIdent.h:80
Combining sat::Solvable and ResStatus.
Definition: PoolItem.h:50
bool operator()(sat::Solvable slv_r) const
Definition: ByIdent.h:52
Resolvable kinds.
Definition: ResKind.h:32
Easy-to use interface to the ZYPP dependency resolver.
Definition: Application.cc:19
Solvable satSolvable() const
Return the corresponding sat::Solvable.
Definition: SolvableType.h:57
zypp::IdString IdString
Definition: idstring.h:16
const char * c_str() const
Definition: IdStringType.h:107
IdString ident() const
The identifier.
Definition: Solvable.cc:270
Main filter selecting PoolItems by name and kind.
Definition: ByIdent.h:28