libzypp: zypp/sat/SolvableSpec.cc Source File

libzypp 17.38.6

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-core/base/LogTools.h>
14#include <zypp-core/base/IOStream.h>
15
16#include <zypp/sat/SolvableSpec.h>
17#include <zypp/sat/SolvableSet.h>
18#include <zypp/sat/WhatProvides.h>
19
20using std::endl;
21
23namespace zypp
24{
26 namespace sat
27 {
32 class SolvableSpec::Impl
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
47 bool addIdenticalInstalledToo() const
48 { return _addIdenticalInstalledToo; }
49
50 void addIdenticalInstalledToo( bool yesno_r )
51 {
52 if ( yesno_r != _addIdenticalInstalledToo ) {
53 _addIdenticalInstalledToo = yesno_r;
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 ) );
82 if ( _addIdenticalInstalledToo ) {
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:
116 IdStringSet _idents;
117 CapabilitySet _provides;
118 bool _addIdenticalInstalledToo = false;
119 mutable SolvableSet _cacheIdenticalInstalled; // follows _cache
120 mutable shared_ptr<WhatProvides> _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 {
168 iostr::simpleParseFile( istr_r,
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
IOStream.h
LogTools.h
SolvableSet.h
SolvableSpec.h
WhatProvides.h
Impl
shared_ptr
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::Capability
A sat capability.
Definition Capability.h:63
zypp::Capability::empty
bool empty() const
Whether the Capability is empty.
Definition Capability.h:185
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
zypp::PoolItem
Combining sat::Solvable and ResStatus.
Definition PoolItem.h:51
zypp::ResKind::srcpackage
static const ResKind srcpackage
Definition ResKind.h:44
zypp::sat::SolvableSet
Solvable set wrapper to allow adding additional convenience iterators.
Definition SolvableSet.h:36
zypp::sat::SolvableSpec::Impl
SolvableSpec implementation.
Definition SolvableSpec.cc:33
zypp::sat::SolvableSpec::Impl::parse
void parse(const C_Str &spec_r)
Definition SolvableSpec.cc:59
zypp::sat::SolvableSpec::Impl::cache
const WhatProvides & cache() const
Definition SolvableSpec.cc:77
zypp::sat::SolvableSpec::Impl::provides
const CapabilitySet & provides() const
Definition SolvableSpec.cc:112
zypp::sat::SolvableSpec::Impl::addIdenticalInstalledToo
bool addIdenticalInstalledToo() const
Definition SolvableSpec.cc:47
zypp::sat::SolvableSpec::Impl::rwcowClone
friend Impl * rwcowClone(const Impl *rhs)
zypp::sat::SolvableSpec::Impl::_idents
IdStringSet _idents
Definition SolvableSpec.cc:116
zypp::sat::SolvableSpec::Impl::setDirty
void setDirty() const
Definition SolvableSpec.cc:74
zypp::sat::SolvableSpec::Impl::_addIdenticalInstalledToo
bool _addIdenticalInstalledToo
Definition SolvableSpec.cc:118
zypp::sat::SolvableSpec::Impl::contains
bool contains(const sat::Solvable &solv_r) const
Definition SolvableSpec.cc:95
zypp::sat::SolvableSpec::Impl::_provides
CapabilitySet _provides
Definition SolvableSpec.cc:117
zypp::sat::SolvableSpec::Impl::clone
Impl * clone() const
clone for RWCOW_pointer
Definition SolvableSpec.cc:125
zypp::sat::SolvableSpec::Impl::_cache
shared_ptr< WhatProvides > _cache
Definition SolvableSpec.cc:120
zypp::sat::SolvableSpec::Impl::dirty
bool dirty() const
Definition SolvableSpec.cc:71
zypp::sat::SolvableSpec::Impl::addIdenticalInstalledToo
void addIdenticalInstalledToo(bool yesno_r)
Definition SolvableSpec.cc:50
zypp::sat::SolvableSpec::Impl::addIdent
void addIdent(IdString ident_r)
Definition SolvableSpec.cc:35
zypp::sat::SolvableSpec::Impl::addProvides
void addProvides(Capability provides_r)
Definition SolvableSpec.cc:41
zypp::sat::SolvableSpec::Impl::needed
bool needed() const
Definition SolvableSpec.cc:68
zypp::sat::SolvableSpec::Impl::idents
const IdStringSet & idents() const
Definition SolvableSpec.cc:109
zypp::sat::SolvableSpec::Impl::_cacheIdenticalInstalled
SolvableSet _cacheIdenticalInstalled
Definition SolvableSpec.cc:119
zypp::sat::Solvable
A Solvable object within the sat Pool.
Definition Solvable.h:54
zypp::sat::Solvable::ident
IdString ident() const
The identifier.
Definition Solvable.cc:273
zypp::sat::WhatProvides
Container of Solvable providing a Capability (read only).
Definition WhatProvides.h:89
zypp::ui::Selectable::get
static Ptr get(const pool::ByIdent &ident_r)
Get the Selctable.
Definition Selectable.cc:29
str
String related utilities and Regular expression matching.
zypp::iostr::simpleParseFile
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
zypp::sat
Libsolv interface
zypp::sat::operator<<
std::ostream & operator<<(std::ostream &str, const FileConflicts &obj)
relates: FileConflicts Stream output
Definition FileConflicts.cc:109
zypp::sat::_pimpl
RWCOW_pointer< Impl > _pimpl
Implementation class.
Definition SolvableSpec.h:122
zypp::sat::parseFrom
void parseFrom(const InputStream &istr_r)
Parse and add spec from a string (IDENT or provides:CAPABILITY`).
zypp::str::hasPrefix
bool hasPrefix(const C_Str &str_r, const C_Str &prefix_r)
Return whether str_r has prefix prefix_r.
Definition String.h:1097
zypp::str::splitEscaped
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
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2
zypp::IdStringSet
std::unordered_set< IdString > IdStringSet
Definition IdString.h:37
zypp::CapabilitySet
std::unordered_set< Capability > CapabilitySet
Definition Capability.h:35
zypp::operator<<
std::ostream & operator<<(std::ostream &str, const Capabilities &obj)
relates: Capabilities Stream output
Definition Capabilities.cc:65