1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/sat/SolvableSpec.cc
13 #include "zypp/base/LogTools.h"
14 #include "zypp/base/IOStream.h"
16 #include "zypp/sat/SolvableSpec.h"
17 #include "zypp/sat/WhatProvides.h"
21 ///////////////////////////////////////////////////////////////////
24 ///////////////////////////////////////////////////////////////////
27 ///////////////////////////////////////////////////////////////////
28 /// \class SolvableSpec::Impl
29 /// \brief SolvableSpec implementation.
30 ///////////////////////////////////////////////////////////////////
31 class SolvableSpec::Impl
34 void addIdent( IdString ident_r )
36 if ( ! ident_r.empty() )
37 _idents.insert( ident_r );
40 void addProvides( Capability provides_r )
42 if ( ! provides_r.empty() && _provides.insert( provides_r ).second )
47 void parse( const C_Str & spec_r )
49 if ( str::hasPrefix( spec_r, "provides:" ) )
50 addProvides( Capability(spec_r.c_str()+9) );
52 addIdent( IdString(spec_r) );
57 { return !_provides.empty(); }
60 { return needed() && !_cache; }
65 const WhatProvides & cache() const
69 _cache.reset( new WhatProvides( _provides ) );
74 bool contains( const sat::Solvable & solv_r ) const
75 { return( _idents.count( solv_r.ident() ) || ( needed() && cache().contains( solv_r ) ) ); }
78 const IdStringSet & idents() const
81 const CapabilitySet & provides() const
86 CapabilitySet _provides;
88 mutable shared_ptr<WhatProvides> _cache;
91 friend Impl * rwcowClone<Impl>( const Impl * rhs );
92 /** clone for RWCOW_pointer */
94 { return new Impl( *this ); }
97 /** \relates SolvableSpec::Impl Stream output */
98 inline std::ostream & operator<<( std::ostream & str, const SolvableSpec::Impl & obj )
100 str << "SolvableSpec {" << endl
101 << " Idents " << obj.idents() << endl
102 << " Provides " << obj.provides() << endl
107 ///////////////////////////////////////////////////////////////////
109 // CLASS NAME : SolvableSpec
111 ///////////////////////////////////////////////////////////////////
113 SolvableSpec::SolvableSpec()
117 SolvableSpec::~SolvableSpec()
120 void SolvableSpec::addIdent( IdString ident_r )
121 { _pimpl->addIdent( ident_r ); }
123 void SolvableSpec::addProvides( Capability provides_r )
124 { _pimpl->addProvides( provides_r ); }
126 void SolvableSpec::parse( const C_Str & spec_r )
127 { _pimpl->parse( spec_r ); }
129 void SolvableSpec::parseFrom( const InputStream & istr_r )
131 iostr::simpleParseFile( istr_r,
132 [this]( int num_r, const std::string & line_r )->bool
134 this->parse( line_r );
139 void SolvableSpec::splitParseFrom( const C_Str & multispec_r )
141 std::vector<std::string> v;
142 str::splitEscaped( multispec_r, std::back_inserter( v ), ", \t" );
143 parseFrom( v.begin(), v.end() );
146 bool SolvableSpec::contains( const sat::Solvable & solv_r ) const
147 { return _pimpl->contains( solv_r ) && !solv_r.isKind( ResKind::srcpackage ); }
149 bool SolvableSpec::dirty() const
150 { return _pimpl->dirty(); }
152 void SolvableSpec::setDirty() const
153 { _pimpl->setDirty(); }
155 bool SolvableSpec::containsIdent( const IdString & ident_r ) const
156 { return _pimpl->idents().count( ident_r ); }
158 bool SolvableSpec::containsProvides( const Capability & provides_r ) const
159 { return _pimpl->provides().count( provides_r ); }
161 std::ostream & operator<<( std::ostream & str, const SolvableSpec & obj )
162 { return str << *obj._pimpl; }
165 ///////////////////////////////////////////////////////////////////
167 ///////////////////////////////////////////////////////////////////