libzypp 17.37.17
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:
35 void addIdent( IdString ident_r )
36 {
37 if ( ! ident_r.empty() )
38 _idents.insert( ident_r );
39 }
40
41 void addProvides( Capability provides_r )
42 {
43 if ( ! provides_r.empty() && _provides.insert( provides_r ).second )
44 setDirty();
45 }
46
49
50 void addIdenticalInstalledToo( bool yesno_r )
51 {
52 if ( yesno_r != _addIdenticalInstalledToo ) {
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
64 addIdent( IdString(spec_r) );
65 }
66
67
68 bool needed() const
69 { return !_provides.empty(); }
70
71 bool dirty() const
72 { return needed() && !_cache; }
73
74 void setDirty() const
75 { _cache.reset(); _cacheIdenticalInstalled.clear(); }
76
77 const WhatProvides & cache() const
78 {
79 if ( !_cache )
80 {
81 _cache.reset( new WhatProvides( _provides ) );
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 )
88 _cacheIdenticalInstalled.insert( 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;
102 if ( _addIdenticalInstalledToo && _cacheIdenticalInstalled.contains( solv_r ) )
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
145 SolvableSpec::SolvableSpec()
146 : _pimpl( new Impl )
147 {}
148
149 SolvableSpec::~SolvableSpec()
150 {}
151
152 void SolvableSpec::addIdent( IdString ident_r )
153 { _pimpl->addIdent( ident_r ); }
154
155 void SolvableSpec::addProvides( Capability provides_r )
156 { _pimpl->addProvides( provides_r ); }
157
158 bool SolvableSpec::addIdenticalInstalledToo() const
159 { return _pimpl->addIdenticalInstalledToo(); }
160 void SolvableSpec::addIdenticalInstalledToo( bool yesno_r )
161 { _pimpl->addIdenticalInstalledToo( yesno_r ); }
162
163 void SolvableSpec::parse( const C_Str & spec_r )
164 { _pimpl->parse( spec_r ); }
165
166 void SolvableSpec::parseFrom( const InputStream & istr_r )
167 {
169 [this]( int num_r, const std::string & line_r )->bool
170 {
171 this->parse( line_r );
172 return true;
173 });
174 }
175
176 void SolvableSpec::splitParseFrom( const C_Str & multispec_r )
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
183 bool SolvableSpec::contains( const sat::Solvable & solv_r ) const
184 { return _pimpl->contains( solv_r ) && !solv_r.isKind( ResKind::srcpackage ); }
185
186 bool SolvableSpec::dirty() const
187 { return _pimpl->dirty(); }
188
189 void SolvableSpec::setDirty() const
190 { _pimpl->setDirty(); }
191
192 bool SolvableSpec::empty() const
193 { return _pimpl->idents().empty() && _pimpl->provides().empty(); }
194
195 bool SolvableSpec::containsIdent( const IdString & ident_r ) const
196 { return _pimpl->idents().count( ident_r ); }
197
198 bool SolvableSpec::containsProvides( const Capability & provides_r ) const
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
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
A sat capability.
Definition Capability.h:63
bool empty() const
Whether the Capability is empty.
Definition Capability.h:160
Access to the sat-pools string space.
Definition IdString.h:44
constexpr bool empty() const
Whether the string is empty.
Definition IdString.h:88
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
SolvableSpec implementation.
void parse(const C_Str &spec_r)
const WhatProvides & cache() const
const CapabilitySet & provides() const
friend Impl * rwcowClone(const Impl *rhs)
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
A Solvable object within the sat Pool.
Definition Solvable.h:54
IdString ident() const
The identifier.
Definition Solvable.cc:270
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
Libsolv interface
std::ostream & operator<<(std::ostream &str, const FileConflicts &obj)
RWCOW_pointer< Impl > _pimpl
Implementation class.
void parse(const C_Str &spec_r)
Parse and add spec from a string (IDENT or provides:CAPABILITY`).
void parseFrom(const InputStream &istr_r)
Parse file istr_r and add its specs (one per line, #-comments).
bool hasPrefix(const C_Str &str_r, const C_Str &prefix_r)
Return whether str_r has prefix prefix_r.
Definition String.h:1097
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:665
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