libzypp  17.38.7
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>
21 
22 #include <unordered_set>
23 
24 namespace zyppng::sat {
25 
26  class Pool;
27  class PreparedPool;
28  class Solvable;
29 
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 
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; }
89 
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; }
108 
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:
149  };
150 
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;
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:
200  };
201 
202 } // namespace zyppng::sat
203 
204 #endif // ZYPP_NG_SAT_SOLVABLESPEC_H_INCLUDED
const CapabilitySet & provides() const
Definition: solvablespec.h:101
A Solvable object within the sat Pool.
Definition: solvable.h:64
void clear()
Reset to empty state.
Definition: solvablespec.h:70
EvaluatedSolvableSpec(PreparedPool &pp_r, const SolvableSpec &spec_r)
Construct by evaluating spec_r against pp_r.
Definition: solvablespec.cc:84
Access to the sat-pools string space.
Definition: IdString.h:51
Orchestrator for a libsolv pool instance.
Definition: pool.h:36
Helper to create and pass std::istream.
Definition: inputstream.h:56
bool containsIdent(const IdString &ident_r) const
Whether ident_r has been added to the spec (for introspection/tests).
Definition: solvablespec.h:86
void parseFrom(TIterator begin, TIterator end)
Parse and add specs from an iterator range of string-like values.
Definition: solvablespec.h:127
bool contains(const Solvable &solv_r) const
O(1) membership test — no pool access required.
A move-only, non-owning view of a Pool that guarantees the whatprovides index is valid.
Definition: preparedpool.h:50
constexpr bool empty() const
Whether the string is empty.
Definition: IdString.h:99
std::unordered_set< IdString > IdStringSet
Definition: IdString.h:37
SolvableSpec & operator=(const SolvableSpec &)=default
A SolvableSpec that has been evaluated against a specific Pool.
Definition: solvablespec.h:174
bool containsProvides(const Capability &cap_r) const
Whether cap_r has been added to the spec (for introspection/tests).
Definition: solvablespec.h:105
This file contains private API, this might break at any time between releases.
Definition: capabilities.h:22
std::unordered_set< detail::SolvableIdType > SolvIdSet
Definition: solvablespec.h:177
A sat capability.
Definition: capability.h:73
bool empty() const
Whether the Capability is empty.
Definition: capability.h:195
std::unordered_set< Capability > CapabilitySet
Definition: capability.h:35
A pure data container describing a set of solvables by ident and/or provides.
Definition: solvablespec.h:54
bool empty() const
Whether no solvable matched the spec at construction time.
Definition: solvablespec.h:188
const SolvIdSet & ids() const
Direct access to the resolved id set (e.g.
Definition: solvablespec.h:195
const IdStringSet & idents() const
Definition: solvablespec.h:82
bool empty() const
Whether the spec has no idents and no provides tokens.
Definition: solvablespec.h:66
void addProvides(Capability cap_r)
Add cap_r to the provides set.
Definition: solvablespec.h:98
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
void splitParseFrom(std::string_view multispec_r)
Split multispec_r on &#39;,&#39;, &#39; &#39;, &#39;\t&#39; and parse each token.
Definition: solvablespec.cc:72
void parse(std::string_view spec_r)
Parse and add a single spec entry.
Definition: solvablespec.cc:52
bool contains(Pool &pool_r, const Solvable &solv_r) const
Test whether a single Solvable matches this spec.
Definition: solvablespec.cc:25
void addIdent(IdString ident_r)
Add ident_r to the ident set.
Definition: solvablespec.h:79
EvaluatedSolvableSpec & operator=(const EvaluatedSolvableSpec &)=default