libzypp  17.23.8
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 
16 #include <zypp/sat/SolvableSpec.h>
17 #include <zypp/sat/WhatProvides.h>
18 
19 using std::endl;
20 
22 namespace 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 
129  void SolvableSpec::parseFrom( const InputStream & istr_r )
130  {
131  iostr::simpleParseFile( istr_r,
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 
149  bool SolvableSpec::dirty() const
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
zypp::sat::SolvableSpec::containsProvides
bool containsProvides(const Capability &provides_r) const
Whether provides_r has been added to the sepcs (mainly for parser tests).
Definition: SolvableSpec.cc:158
zypp::sat::SolvableSpec::Impl::idents
const IdStringSet & idents() const
Definition: SolvableSpec.cc:78
zypp::IdStringSet
std::unordered_set< IdString > IdStringSet
Definition: IdString.h:26
zypp::sat::Solvable
A Solvable object within the sat Pool.
Definition: Solvable.h:53
zypp::sat::WhatProvides
Container of Solvable providing a Capability (read only).
Definition: WhatProvides.h:87
zypp::sat::SolvableSpec::Impl::provides
const CapabilitySet & provides() const
Definition: SolvableSpec.cc:81
zypp::sat::SolvableSpec::dirty
bool dirty() const
Whether the cache is needed and dirty.
Definition: SolvableSpec.cc:149
zypp::sat::SolvableSpec::Impl::dirty
bool dirty() const
Definition: SolvableSpec.cc:59
zypp::sat::Solvable::isKind
bool isKind(const ResKind &kind_r) const
Test whether a Solvable is of a certain ResKind.
Definition: Solvable.cc:301
zypp::sat::SolvableSpec::addProvides
void addProvides(Capability provides_r)
A all sat::Solvable matching this provides_r.
Definition: SolvableSpec.cc:123
zypp::sat::SolvableSpec::Impl::_idents
IdStringSet _idents
Definition: SolvableSpec.cc:85
zypp::sat::SolvableSpec::Impl::_provides
CapabilitySet _provides
Definition: SolvableSpec.cc:86
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:123
zypp::sat::SolvableSpec
Define a set of Solvables by ident and provides.
Definition: SolvableSpec.h:44
IOStream.h
zypp::sat::SolvableSpec::Impl::parse
void parse(const C_Str &spec_r)
Definition: SolvableSpec.cc:47
zypp::sat::SolvableSpec::Impl::addIdent
void addIdent(IdString ident_r)
Definition: SolvableSpec.cc:34
zypp::sat::SolvableSpec::setDirty
void setDirty() const
Explicitly flag the cache as dirty, so it will be rebuilt on the next request.
Definition: SolvableSpec.cc:152
SolvableSpec.h
WhatProvides.h
zypp::IdString
Access to the sat-pools string space.
Definition: IdString.h:41
LogTools.h
zypp::CapabilitySet
std::unordered_set< Capability > CapabilitySet
Definition: Capability.h:33
zypp::sat::SolvableSpec::Impl::cache
const WhatProvides & cache() const
Definition: SolvableSpec.cc:65
zypp::sat::SolvableSpec::parseFrom
void parseFrom(const InputStream &istr_r)
Parse file istr_r and add it's specs (one per line, #-comments).
Definition: SolvableSpec.cc:129
zypp::sat::SolvableSpec::containsIdent
bool containsIdent(const IdString &ident_r) const
Whether ident_r has been added to the specs (mainly for parser tests).
Definition: SolvableSpec.cc:155
zypp::Capability::empty
bool empty() const
Whether the Capability is empty.
Definition: Capability.h:150
zypp::sat::SolvableSpec::_pimpl
RWCOW_pointer< Impl > _pimpl
Implementation class.
Definition: SolvableSpec.h:105
zypp::sat::SolvableSpec::Impl::setDirty
void setDirty() const
Definition: SolvableSpec.cc:62
zypp::sat::operator<<
std::ostream & operator<<(std::ostream &str, const FileConflicts &obj)
Definition: FileConflicts.cc:109
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:591
zypp::InputStream
Helper to create and pass std::istream.
Definition: InputStream.h:56
zypp::sat::SolvableSpec::~SolvableSpec
~SolvableSpec()
Dtor.
Definition: SolvableSpec.cc:117
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
zypp::C_Str
Convenience char* constructible from std::string and char*, it maps (char*)0 to an empty string.
Definition: String.h:90
zypp::sat::SolvIterMixin::contains
bool contains(const TSolv &solv_r) const
Whether collection contains a specific Solvable.
Definition: SolvIterMixin.h:137
zypp::sat::SolvableSpec::Impl::contains
bool contains(const sat::Solvable &solv_r) const
Definition: SolvableSpec.cc:74
zypp::sat::SolvableSpec::contains
bool contains(const sat::Solvable &solv_r) const
Test whether solv_r matches the spec.
Definition: SolvableSpec.cc:146
zypp::sat::SolvableSpec::Impl::_cache
shared_ptr< WhatProvides > _cache
Definition: SolvableSpec.cc:88
zypp::Capability
A sat capability.
Definition: Capability.h:59
zypp::ResKind::srcpackage
static const ResKind srcpackage
Definition: ResKind.h:44
zypp::sat::SolvableSpec::Impl::needed
bool needed() const
Definition: SolvableSpec.cc:56
zypp::sat::SolvableSpec::Impl::clone
Impl * clone() const
clone for RWCOW_pointer
Definition: SolvableSpec.cc:93
zypp::sat::SolvableSpec::Impl::operator<<
std::ostream & operator<<(std::ostream &str, const SolvableSpec::Impl &obj)
Definition: SolvableSpec.cc:98
zypp::sat::SolvableSpec::Impl
SolvableSpec implementation.
Definition: SolvableSpec.cc:31
zypp::sat::SolvableSpec::splitParseFrom
void splitParseFrom(const C_Str &multispec_r)
Convenience using str::splitEscaped(", \t") to parse multiple specs from one line.
Definition: SolvableSpec.cc:139
zypp::sat::SolvableSpec::addIdent
void addIdent(IdString ident_r)
Add all sat::Solvable with this ident_r.
Definition: SolvableSpec.cc:120
zypp::sat::SolvableSpec::parse
void parse(const C_Str &spec_r)
Parse and add spec from a string (IDENT or provides:CAPABILITY`).
Definition: SolvableSpec.cc:126
str
String related utilities and Regular expression matching.
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:1023
zypp::sat::SolvableSpec::Impl::addProvides
void addProvides(Capability provides_r)
Definition: SolvableSpec.cc:40
zypp::IdString::empty
constexpr bool empty() const
Whether the string is empty.
Definition: IdString.h:80
zypp::sat::SolvableSpec::SolvableSpec
SolvableSpec()
Default ctor.
Definition: SolvableSpec.cc:113
zypp::C_Str::c_str
const char * c_str() const
Definition: String.h:113
zypp::sat::Solvable::ident
IdString ident() const
The identifier.
Definition: Solvable.cc:268