libzypp 17.34.0
SolvableSpec.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
11#include <iostream>
12
13#include <zypp/base/LogTools.h>
14#include <zypp/base/IOStream.h>
15
19
20using std::endl;
21
23namespace zypp
24{
26 namespace sat
27 {
33 {
34 public:
36 {
37 if ( ! ident_r.empty() )
38 _idents.insert( ident_r );
39 }
40
42 {
43 if ( ! provides_r.empty() && _provides.insert( provides_r ).second )
44 setDirty();
45 }
46
49
51 {
54 if ( not _provides.empty() )
55 setDirty();
56 }
57 }
58
59 void parse( const C_Str & spec_r )
60 {
61 if ( str::hasPrefix( spec_r, "provides:" ) )
62 addProvides( Capability(spec_r.c_str()+9) );
63 else
65 }
66
67
68 bool needed() const
69 { return !_provides.empty(); }
70
71 bool dirty() const
72 { return needed() && !_cache; }
73
76
77 const WhatProvides & cache() const
78 {
79 if ( !_cache )
80 {
83 for ( const auto & solv : *_cache ) {
84 if ( solv.isSystem() )
85 continue;
86 auto pi { ui::Selectable::get(solv)->identicalInstalledObj( PoolItem(solv) ) };
87 if ( pi )
89 }
90 }
91 }
92 return *_cache;
93 }
94
95 bool contains( const sat::Solvable & solv_r ) const
96 {
97 if ( _idents.count( solv_r.ident() ) )
98 return true;
99 if ( needed() ) {
100 if ( cache().contains( solv_r ) )
101 return true;
103 return true;
104 }
105 return false;
106 }
107
108
109 const IdStringSet & idents() const
110 { return _idents; }
111
112 const CapabilitySet & provides() const
113 { return _provides; }
114
115 private:
119 mutable SolvableSet _cacheIdenticalInstalled; // follows _cache
121
122 private:
123 friend Impl * rwcowClone<Impl>( const Impl * rhs );
125 Impl * clone() const
126 { return new Impl( *this ); }
127 };
128
130 inline std::ostream & operator<<( std::ostream & str, const SolvableSpec::Impl & obj )
131 {
132 str << "SolvableSpec {" << endl
133 << " Idents " << obj.idents() << endl
134 << " Provides " << obj.provides() << endl
135 << "}";
136 return str;
137 }
138
140 //
141 // CLASS NAME : SolvableSpec
142 //
144
146 : _pimpl( new Impl )
147 {}
148
151
153 { _pimpl->addIdent( ident_r ); }
154
157
159 { return _pimpl->addIdenticalInstalledToo(); }
161 { _pimpl->addIdenticalInstalledToo( yesno_r ); }
162
164 { _pimpl->parse( spec_r ); }
165
167 {
169 [this]( int num_r, const std::string & line_r )->bool
170 {
171 this->parse( line_r );
172 return true;
173 });
174 }
175
177 {
178 std::vector<std::string> v;
179 str::splitEscaped( multispec_r, std::back_inserter( v ), ", \t" );
180 parseFrom( v.begin(), v.end() );
181 }
182
184 { return _pimpl->contains( solv_r ) && !solv_r.isKind( ResKind::srcpackage ); }
185
187 { return _pimpl->dirty(); }
188
190 { _pimpl->setDirty(); }
191
193 { return _pimpl->idents().empty() && _pimpl->provides().empty(); }
194
196 { return _pimpl->idents().count( ident_r ); }
197
199 { return _pimpl->provides().count( provides_r ); }
200
201 std::ostream & operator<<( std::ostream & str, const SolvableSpec & obj )
202 { return str << *obj._pimpl; }
203
204 } // namespace sat
206} // namespace zypp
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
Definition AutoDispose.h:95
void reset()
Reset to default Ctor values.
shared_ptr< Impl > _pimpl
Convenience char* constructible from std::string and char*, it maps (char*)0 to an empty string.
Definition String.h:91
A sat capability.
Definition Capability.h:63
Access to the sat-pools string space.
Definition IdString.h:44
Helper to create and pass std::istream.
Definition inputstream.h:57
Combining sat::Solvable and ResStatus.
Definition PoolItem.h:51
static const ResKind srcpackage
Definition ResKind.h:44
Solvable set wrapper to allow adding additional convenience iterators.
Definition SolvableSet.h:36
void clear()
Clear the container.
Definition SolvableSet.h:81
bool insert(const TSolv &solv_r)
Insert a Solvable.
Definition SolvableSet.h:88
bool contains(const TSolv &solv_r) const
Definition SolvableSet.h:68
SolvableSpec implementation.
void parse(const C_Str &spec_r)
const WhatProvides & cache() const
const CapabilitySet & provides() const
bool contains(const sat::Solvable &solv_r) const
Impl * clone() const
clone for RWCOW_pointer
shared_ptr< WhatProvides > _cache
void addIdenticalInstalledToo(bool yesno_r)
void addIdent(IdString ident_r)
void addProvides(Capability provides_r)
std::ostream & operator<<(std::ostream &str, const SolvableSpec::Impl &obj)
Stream output.
const IdStringSet & idents() const
Define a set of Solvables by ident and provides.
void parse(const C_Str &spec_r)
Parse and add spec from a string (IDENT or provides:CAPABILITY`).
bool dirty() const
Whether the cache is needed and dirty.
bool containsIdent(const IdString &ident_r) const
Whether ident_r has been added to the specs (mainly for parser tests).
void splitParseFrom(const C_Str &multispec_r)
Convenience using str::splitEscaped(", \t") to parse multiple specs from one line.
RWCOW_pointer< Impl > _pimpl
Implementation class.
bool addIdenticalInstalledToo() const
Extend the provides set to include idential installed items as well.
bool contains(const sat::Solvable &solv_r) const
Test whether solv_r matches the spec.
bool containsProvides(const Capability &provides_r) const
Whether provides_r has been added to the sepcs (mainly for parser tests).
bool empty() const
Whether neither idents nor provides are set.
SolvableSpec()
Default ctor.
void setDirty() const
Explicitly flag the cache as dirty, so it will be rebuilt on the next request.
void addProvides(Capability provides_r)
A all sat::Solvable matching this provides_r.
void addIdent(IdString ident_r)
Add all sat::Solvable with this ident_r.
void parseFrom(const InputStream &istr_r)
Parse file istr_r and add its specs (one per line, #-comments).
A Solvable object within the sat Pool.
Definition Solvable.h:54
Container of Solvable providing a Capability (read only).
static Ptr get(const pool::ByIdent &ident_r)
Get the Selctable.
Definition Selectable.cc:29
String related utilities and Regular expression matching.
int simpleParseFile(std::istream &str_r, ParseFlags flags_r, function< bool(int, std::string)> consume_r)
Simple lineparser optionally trimming and skipping comments.
Definition IOStream.cc:124
std::ostream & operator<<(std::ostream &str, const FileConflicts &obj)
bool hasPrefix(const C_Str &str_r, const C_Str &prefix_r)
Return whether str_r has prefix prefix_r.
Definition String.h:1026
unsigned splitEscaped(const C_Str &line_r, TOutputIterator result_r, const C_Str &sepchars_r=" \t", bool withEmpty=false)
Split line_r into words with respect to escape delimeters.
Definition String.h:594
Easy-to use interface to the ZYPP dependency resolver.
std::unordered_set< IdString > IdStringSet
Definition IdString.h:29
std::unordered_set< Capability > CapabilitySet
Definition Capability.h:35