libzypp 17.37.17
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
20namespace zypp
21{
23 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
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
101
103} // namespace zypp
105#endif // ZYPP_POOL_BYIDENT_H
Convenience char* constructible from std::string and char*, it maps (char*)0 to an empty string.
Definition String.h:92
const char * c_str() const
Definition String.h:117
const char * c_str() const
Access to the sat-pools string space.
Definition IdString.h:44
const char * c_str() const
Conversion to const char *
Definition IdString.cc:50
IdType id() const
Expert backdoor.
Definition IdString.h:133
Combining sat::Solvable and ResStatus.
Definition PoolItem.h:51
Resolvable kinds.
Definition ResKind.h:33
static const ResKind srcpackage
Definition ResKind.h:44
static const ResKind package
Definition ResKind.h:40
TraitsType::constPtrType constPtr
Definition ResObject.h:43
bool operator()(sat::Solvable slv_r) const
Definition ByIdent.h:52
sat::detail::IdType makeIdent(const ResKind &kind_r, IdString name_r)
Definition ByIdent.h:71
bool operator()(const PoolItem &pi_r) const
Definition ByIdent.h:58
sat::detail::IdType _id
negative _id for srcpackage, as they use the same ident as package.
Definition ByIdent.h:96
ByIdent(ResKind kind_r, const C_Str &name_r)
Definition ByIdent.h:47
sat::detail::IdType get() const
Definition ByIdent.h:90
sat::detail::IdType makeIdent(const ResKind &kind_r, const C_Str &name_r)
Definition ByIdent.h:80
ByIdent(sat::Solvable slv_r)
Definition ByIdent.h:35
ByIdent(ResKind kind_r, IdString name_r)
Definition ByIdent.h:43
ByIdent(IdString ident_r)
Definition ByIdent.h:39
bool operator()(const ResObject::constPtr &p_r) const
Definition ByIdent.h:61
sat::detail::IdType makeIdent(sat::Solvable slv_r)
Definition ByIdent.h:65
A Solvable object within the sat Pool.
Definition Solvable.h:54
bool isKind(const ResKind &kind_r) const
Test whether a Solvable is of a certain ResKind.
Definition Solvable.cc:303
IdString ident() const
The identifier.
Definition Solvable.cc:270
Definition Arch.h:364
int IdType
Generic Id type.
Definition PoolMember.h:104
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
Definition String.cc:39
Easy-to use interface to the ZYPP dependency resolver.
Solvable satSolvable() const
Return the corresponding sat::Solvable.