libzypp: zypp/ng/sat/solvablespec.h Source File

libzypp 17.38.14

solvablespec.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
14#ifndef ZYPP_NG_SAT_SOLVABLESPEC_H_INCLUDED
15#define ZYPP_NG_SAT_SOLVABLESPEC_H_INCLUDED
16
17#include <zypp/ng/idstring.h>
18#include <zypp/ng/sat/capability.h>
19#include <zypp/ng/sat/poolconstants.h>
20#include <zypp-core/base/inputstream.h>
21
22#include <unordered_set>
23
24namespace zyppng::sat {
25
26 class Pool;
27 class PreparedPool;
28 class Solvable;
29
54 class SolvableSpec
55 {
56 public:
57 SolvableSpec() = default;
58 ~SolvableSpec() = default;
59
60 SolvableSpec( const SolvableSpec & ) = default;
61 SolvableSpec( SolvableSpec && ) = default;
62 SolvableSpec & operator=( const SolvableSpec & ) = default;
63 SolvableSpec & operator=( SolvableSpec && ) = default;
64
66 bool empty() const
67 { return _idents.empty() && _provides.empty(); }
68
70 void clear()
71 { _idents.clear(); _provides.clear(); }
72
78
79 void addIdent( IdString ident_r )
80 { if ( !ident_r.empty() ) _idents.insert( std::move(ident_r) ); }
81
82 const IdStringSet & idents() const
83 { return _idents; }
84
86 bool containsIdent( const IdString & ident_r ) const
87 { return _idents.count( ident_r ) != 0; }
88
89
97
98 void addProvides( Capability cap_r )
99 { if ( !cap_r.empty() ) _provides.insert( std::move(cap_r) ); }
100
101 const CapabilitySet & provides() const
102 { return _provides; }
103
105 bool containsProvides( const Capability & cap_r ) const
106 { return _provides.count( cap_r ) != 0; }
107
108
118
119 void parse( std::string_view spec_r );
120
123 void parseFrom( const zypp::InputStream & istr_r );
124
126 template <class TIterator>
127 void parseFrom( TIterator begin, TIterator end )
128 { for ( ; begin != end; ++begin ) parse( *begin ); }
129
131 void splitParseFrom( std::string_view multispec_r );
133
144 bool contains( Pool & pool_r, const Solvable & solv_r ) const;
145
146 private:
147 IdStringSet _idents;
148 CapabilitySet _provides;
149 };
150
174 class EvaluatedSolvableSpec
175 {
176 public:
177 using SolvIdSet = std::unordered_set<detail::SolvableIdType>;
178
180 EvaluatedSolvableSpec( PreparedPool & pp_r, const SolvableSpec & spec_r );
181
182 EvaluatedSolvableSpec( const EvaluatedSolvableSpec & ) = default;
183 EvaluatedSolvableSpec( EvaluatedSolvableSpec && ) = default;
184 EvaluatedSolvableSpec & operator=( const EvaluatedSolvableSpec & ) = default;
185 EvaluatedSolvableSpec & operator=( EvaluatedSolvableSpec && ) = default;
186
188 bool empty() const
189 { return _ids.empty(); }
190
192 bool contains( const Solvable & solv_r ) const;
193
195 const SolvIdSet & ids() const
196 { return _ids; }
197
198 private:
199 SolvIdSet _ids;
200 };
201
202} // namespace zyppng::sat
203
204#endif // ZYPP_NG_SAT_SOLVABLESPEC_H_INCLUDED
zypp::IdString
Access to the sat-pools string space.
Definition IdString.h:55
zypp::IdString::empty
constexpr bool empty() const
Whether the string is empty.
Definition IdString.h:99
zypp::InputStream
Helper to create and pass std::istream.
Definition inputstream.h:57
zyppng::sat::Capability
A sat capability.
Definition capability.h:74
zyppng::sat::Capability::empty
bool empty() const
Whether the Capability is empty.
Definition capability.h:195
zyppng::sat::EvaluatedSolvableSpec::contains
bool contains(const Solvable &solv_r) const
O(1) membership test — no pool access required.
Definition solvablespec.cc:116
zyppng::sat::EvaluatedSolvableSpec::EvaluatedSolvableSpec
EvaluatedSolvableSpec(EvaluatedSolvableSpec &&)=default
zyppng::sat::EvaluatedSolvableSpec::_ids
SolvIdSet _ids
Definition solvablespec.h:199
zyppng::sat::EvaluatedSolvableSpec::operator=
EvaluatedSolvableSpec & operator=(const EvaluatedSolvableSpec &)=default
zyppng::sat::EvaluatedSolvableSpec::EvaluatedSolvableSpec
EvaluatedSolvableSpec(const EvaluatedSolvableSpec &)=default
zyppng::sat::EvaluatedSolvableSpec::ids
const SolvIdSet & ids() const
Direct access to the resolved id set (e.g.
Definition solvablespec.h:195
zyppng::sat::EvaluatedSolvableSpec::EvaluatedSolvableSpec
EvaluatedSolvableSpec(PreparedPool &pp_r, const SolvableSpec &spec_r)
Construct by evaluating spec_r against pp_r.
Definition solvablespec.cc:84
zyppng::sat::EvaluatedSolvableSpec::operator=
EvaluatedSolvableSpec & operator=(EvaluatedSolvableSpec &&)=default
zyppng::sat::EvaluatedSolvableSpec::empty
bool empty() const
Whether no solvable matched the spec at construction time.
Definition solvablespec.h:188
zyppng::sat::EvaluatedSolvableSpec::SolvIdSet
std::unordered_set< detail::SolvableIdType > SolvIdSet
Definition solvablespec.h:177
zyppng::sat::Pool
Orchestrator for a libsolv pool instance.
Definition pool.h:37
zyppng::sat::PreparedPool
A move-only, non-owning view of a Pool that guarantees the whatprovides index is valid.
Definition preparedpool.h:51
zyppng::sat::SolvableSpec
A pure data container describing a set of solvables by ident and/or provides.
Definition solvablespec.h:55
zyppng::sat::SolvableSpec::parse
void parse(std::string_view spec_r)
Parse and add a single spec entry.
Definition solvablespec.cc:52
zyppng::sat::SolvableSpec::empty
bool empty() const
Whether the spec has no idents and no provides tokens.
Definition solvablespec.h:66
zyppng::sat::SolvableSpec::~SolvableSpec
~SolvableSpec()=default
zyppng::sat::SolvableSpec::containsIdent
bool containsIdent(const IdString &ident_r) const
Whether ident_r has been added to the spec (for introspection/tests).
Definition solvablespec.h:86
zyppng::sat::SolvableSpec::SolvableSpec
SolvableSpec(const SolvableSpec &)=default
zyppng::sat::SolvableSpec::parseFrom
void parseFrom(const zypp::InputStream &istr_r)
Parse and add specs from istr_r (one per line; #-comments and empty lines are skipped automatically).
Definition solvablespec.cc:63
zyppng::sat::SolvableSpec::provides
const CapabilitySet & provides() const
Definition solvablespec.h:101
zyppng::sat::SolvableSpec::idents
const IdStringSet & idents() const
Definition solvablespec.h:82
zyppng::sat::SolvableSpec::addIdent
void addIdent(IdString ident_r)
Add ident_r to the ident set.
Definition solvablespec.h:79
zyppng::sat::SolvableSpec::parseFrom
void parseFrom(TIterator begin, TIterator end)
Parse and add specs from an iterator range of string-like values.
Definition solvablespec.h:127
zyppng::sat::SolvableSpec::SolvableSpec
SolvableSpec(SolvableSpec &&)=default
zyppng::sat::SolvableSpec::_idents
IdStringSet _idents
Definition solvablespec.h:147
zyppng::sat::SolvableSpec::contains
bool contains(Pool &pool_r, const Solvable &solv_r) const
Test whether a single Solvable matches this spec.
Definition solvablespec.cc:25
zyppng::sat::SolvableSpec::operator=
SolvableSpec & operator=(SolvableSpec &&)=default
zyppng::sat::SolvableSpec::SolvableSpec
SolvableSpec()=default
zyppng::sat::SolvableSpec::_provides
CapabilitySet _provides
Definition solvablespec.h:148
zyppng::sat::SolvableSpec::containsProvides
bool containsProvides(const Capability &cap_r) const
Whether cap_r has been added to the spec (for introspection/tests).
Definition solvablespec.h:105
zyppng::sat::SolvableSpec::addProvides
void addProvides(Capability cap_r)
Add cap_r to the provides set.
Definition solvablespec.h:98
zyppng::sat::SolvableSpec::operator=
SolvableSpec & operator=(const SolvableSpec &)=default
zyppng::sat::SolvableSpec::splitParseFrom
void splitParseFrom(std::string_view multispec_r)
Split multispec_r on ',', ' ', '\t' and parse each token.
Definition solvablespec.cc:72
zyppng::sat::SolvableSpec::clear
void clear()
Reset to empty state.
Definition solvablespec.h:70
zyppng::sat::Solvable
A Solvable object within the sat Pool.
Definition solvable.h:66
inputstream.h
zypp::IdStringSet
std::unordered_set< IdString > IdStringSet
Definition IdString.h:37
zyppng::sat
This file contains private API, this might break at any time between releases.
Definition capabilities.h:22
zyppng::sat::CapabilitySet
std::unordered_set< Capability > CapabilitySet
Definition capability.h:35
poolconstants.h
capability.h
idstring.h