libzypp 17.25.7
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
18
19using std::endl;
20
22namespace zypp
23{
25 namespace sat
26 {
32 {
33 public:
34 void addIdent( IdString ident_r )
35 {
36 if ( ! ident_r.empty() )
37 _idents.insert( ident_r );
38 }
39
40 void addProvides( Capability provides_r )
41 {
42 if ( ! provides_r.empty() && _provides.insert( provides_r ).second )
43 setDirty();
44 }
45
46
47 void parse( const C_Str & spec_r )
48 {
49 if ( str::hasPrefix( spec_r, "provides:" ) )
50 addProvides( Capability(spec_r.c_str()+9) );
51 else
52 addIdent( IdString(spec_r) );
53 }
54
55
56 bool needed() const
57 { return !_provides.empty(); }
58
59 bool dirty() const
60 { return needed() && !_cache; }
61
62 void setDirty() const
63 { _cache.reset(); }
64
65 const WhatProvides & cache() const
66 {
67 if ( !_cache )
68 {
69 _cache.reset( new WhatProvides( _provides ) );
70 }
71 return *_cache;
72 }
73
74 bool contains( const sat::Solvable & solv_r ) const
75 { return( _idents.count( solv_r.ident() ) || ( needed() && cache().contains( solv_r ) ) ); }
76
77
78 const IdStringSet & idents() const
79 { return _idents; }
80
81 const CapabilitySet & provides() const
82 { return _provides; }
83
84 private:
87
88 mutable shared_ptr<WhatProvides> _cache;
89
90 private:
91 friend Impl * rwcowClone<Impl>( const Impl * rhs );
93 Impl * clone() const
94 { return new Impl( *this ); }
95 };
96
98 inline std::ostream & operator<<( std::ostream & str, const SolvableSpec::Impl & obj )
99 {
100 str << "SolvableSpec {" << endl
101 << " Idents " << obj.idents() << endl
102 << " Provides " << obj.provides() << endl
103 << "}";
104 return str;
105 }
106
108 //
109 // CLASS NAME : SolvableSpec
110 //
112
114 : _pimpl( new Impl )
115 {}
116
118 {}
119
121 { _pimpl->addIdent( ident_r ); }
122
124 { _pimpl->addProvides( provides_r ); }
125
126 void SolvableSpec::parse( const C_Str & spec_r )
127 { _pimpl->parse( spec_r ); }
128
130 {
132 [this]( int num_r, const std::string & line_r )->bool
133 {
134 this->parse( line_r );
135 return true;
136 });
137 }
138
139 void SolvableSpec::splitParseFrom( const C_Str & multispec_r )
140 {
141 std::vector<std::string> v;
142 str::splitEscaped( multispec_r, std::back_inserter( v ), ", \t" );
143 parseFrom( v.begin(), v.end() );
144 }
145
146 bool SolvableSpec::contains( const sat::Solvable & solv_r ) const
147 { return _pimpl->contains( solv_r ) && !solv_r.isKind( ResKind::srcpackage ); }
148
150 { return _pimpl->dirty(); }
151
153 { _pimpl->setDirty(); }
154
155 bool SolvableSpec::containsIdent( const IdString & ident_r ) const
156 { return _pimpl->idents().count( ident_r ); }
157
158 bool SolvableSpec::containsProvides( const Capability & provides_r ) const
159 { return _pimpl->provides().count( provides_r ); }
160
161 std::ostream & operator<<( std::ostream & str, const SolvableSpec & obj )
162 { return str << *obj._pimpl; }
163
164 } // namespace sat
166} // namespace zypp
Convenience char* constructible from std::string and char*, it maps (char*)0 to an empty string.
Definition: String.h:91
const char * c_str() const
Definition: String.h:113
A sat capability.
Definition: Capability.h:60
bool empty() const
Whether the Capability is empty.
Definition: Capability.h:150
Access to the sat-pools string space.
Definition: IdString.h:43
constexpr bool empty() const
Whether the string is empty.
Definition: IdString.h:87
Helper to create and pass std::istream.
Definition: InputStream.h:57
static const ResKind srcpackage
Definition: ResKind.h:44
SolvableSpec implementation.
Definition: SolvableSpec.cc:32
void parse(const C_Str &spec_r)
Definition: SolvableSpec.cc:47
const WhatProvides & cache() const
Definition: SolvableSpec.cc:65
const CapabilitySet & provides() const
Definition: SolvableSpec.cc:81
bool contains(const sat::Solvable &solv_r) const
Definition: SolvableSpec.cc:74
Impl * clone() const
clone for RWCOW_pointer
Definition: SolvableSpec.cc:93
shared_ptr< WhatProvides > _cache
Definition: SolvableSpec.cc:88
void addIdent(IdString ident_r)
Definition: SolvableSpec.cc:34
void addProvides(Capability provides_r)
Definition: SolvableSpec.cc:40
std::ostream & operator<<(std::ostream &str, const SolvableSpec::Impl &obj)
Stream output.
Definition: SolvableSpec.cc:98
const IdStringSet & idents() const
Definition: SolvableSpec.cc:78
Define a set of Solvables by ident and provides.
Definition: SolvableSpec.h:45
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.
Definition: SolvableSpec.h:107
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).
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 it's specs (one per line, #-comments).
A Solvable object within the sat Pool.
Definition: Solvable.h:54
bool isKind(const ResKind &kind_r) const
Test whether a Solvable is of a certain ResKind.
Definition: Solvable.cc:301
IdString ident() const
The identifier.
Definition: Solvable.cc:268
Container of Solvable providing a Capability (read only).
Definition: WhatProvides.h:89
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:1023
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:591
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
std::unordered_set< Capability > CapabilitySet
Definition: Capability.h:35
std::unordered_set< IdString > IdStringSet
Definition: IdString.h:28