libzypp: zypp/pool/ByIdent.h Source File

libzypp 17.38.14

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:
31 ByIdent()
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:
65 sat::detail::IdType makeIdent( sat::Solvable slv_r )
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:
96 sat::detail::IdType _id;
97 };
98
100 } // namespace pool
101
103} // namespace zypp
105#endif // ZYPP_POOL_BYIDENT_H
PoolItem.h
zypp::C_Str
Convenience char* constructible from std::string and char*, it maps (char*)0 to an empty string.
Definition String.h:92
zypp::C_Str::c_str
const char * c_str() const
Definition String.h:117
zypp::IdString
Access to the sat-pools string space.
Definition IdString.h:55
zypp::IdString::c_str
const char * c_str() const
Conversion to const char *.
Definition IdString.cc:51
zypp::IdString::id
IdType id() const
Expert backdoor.
Definition IdString.h:144
zypp::IdString::IdString
constexpr IdString()
Default ctor, empty string.
Definition IdString.h:61
zypp::PoolItem
Combining sat::Solvable and ResStatus.
Definition PoolItem.h:51
zypp::ResKind
Resolvable kinds.
Definition ResKind.h:33
zypp::ResKind::srcpackage
static const ResKind srcpackage
Definition ResKind.h:44
zypp::ResKind::package
static const ResKind package
Definition ResKind.h:40
zypp::ResObject::constPtr
TraitsType::constPtrType constPtr
Definition ResObject.h:43
zypp::pool::ByIdent::operator()
bool operator()(sat::Solvable slv_r) const
Definition ByIdent.h:52
zypp::pool::ByIdent::makeIdent
sat::detail::IdType makeIdent(const ResKind &kind_r, IdString name_r)
Definition ByIdent.h:71
zypp::pool::ByIdent::operator()
bool operator()(const PoolItem &pi_r) const
Definition ByIdent.h:58
zypp::pool::ByIdent::_id
sat::detail::IdType _id
negative _id for srcpackage, as they use the same ident as package.
Definition ByIdent.h:96
zypp::pool::ByIdent::ByIdent
ByIdent()
Definition ByIdent.h:31
zypp::pool::ByIdent::ByIdent
ByIdent(ResKind kind_r, const C_Str &name_r)
Definition ByIdent.h:47
zypp::pool::ByIdent::get
sat::detail::IdType get() const
Definition ByIdent.h:90
zypp::pool::ByIdent::makeIdent
sat::detail::IdType makeIdent(const ResKind &kind_r, const C_Str &name_r)
Definition ByIdent.h:80
zypp::pool::ByIdent::ByIdent
ByIdent(sat::Solvable slv_r)
Definition ByIdent.h:35
zypp::pool::ByIdent::ByIdent
ByIdent(ResKind kind_r, IdString name_r)
Definition ByIdent.h:43
zypp::pool::ByIdent::ByIdent
ByIdent(IdString ident_r)
Definition ByIdent.h:39
zypp::pool::ByIdent::operator()
bool operator()(const ResObject::constPtr &p_r) const
Definition ByIdent.h:61
zypp::pool::ByIdent::makeIdent
sat::detail::IdType makeIdent(sat::Solvable slv_r)
Definition ByIdent.h:65
zypp::sat::Solvable
A Solvable object within the sat Pool.
Definition Solvable.h:54
zypp::sat::Solvable::isKind
bool isKind(const ResKind &kind_r) const
Test whether a Solvable is of a certain ResKind.
Definition Solvable.cc:306
zypp::sat::Solvable::ident
IdString ident() const
The identifier.
Definition Solvable.cc:273
zyppng::IdStringType::c_str
const char * c_str() const
Definition IdStringType.h:115
std
Definition ansi.h:855
zypp::pool
Definition ByIdent.h:24
zypp::sat::detail::IdType
int IdType
Generic Id type.
Definition PoolDefines.h:42
zypp::str::form
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
Definition String.cc:39
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2
zypp::sat::SolvableType::satSolvable
Solvable satSolvable() const
Return the corresponding sat::Solvable.
Definition SolvableType.h:57