#include <zypp/base/Exception.h>
#include <zypp/base/PtrTypes.h>
#include <zypp/base/Iterator.h>
+#include <zypp/base/Algorithm.h>
#include <zypp/PathInfo.h>
#include <zypp/SourceFactory.h>
bool operator()( ResObject::constPtr p ) const
{
- return( make_filter_begin( ByIndex(_index), p->provides() )
- != make_filter_end( ByIndex(_index), p->provides() ) );
+ return( make_filter_begin( ByIndex(_index), p->dep( Dep::PROVIDES ) )
+ != make_filter_end( ByIndex(_index), p->dep( Dep::PROVIDES ) ) );
}
std::string _index;
bool operator()( ResObject::constPtr p ) const
{
- return( make_filter_begin( ByIndex(_index), p->requires() )
- != make_filter_end( ByIndex(_index), p->requires() ) );
+ return( make_filter_begin( ByIndex(_index), p->dep( Dep::REQUIRES ) )
+ != make_filter_end( ByIndex(_index), p->dep( Dep::REQUIRES ) ) );
}
std::string _index;
if ( _table.empty() )
{
// initialize it
- _table["PROVIDES"] = Dep::PROVIDES_e;
- _table["PREREQUIRES"] = Dep::PREREQUIRES_e;
- _table["REQUIRES"] = Dep::REQUIRES_e;
- _table["CONFLICTS"] = Dep::CONFLICTS_e;
- _table["OBSOLETES"] = Dep::OBSOLETES_e;
- _table["RECOMMENDS"] = Dep::RECOMMENDS_e;
- _table["SUGGESTS"] = Dep::SUGGESTS_e;
- _table["FRESHENS"] = Dep::FRESHENS_e;
+ _table["provides"] = Dep::PROVIDES_e;
+ _table["prerequires"] = Dep::PREREQUIRES_e;
+ _table["requires"] = Dep::REQUIRES_e;
+ _table["conflicts"] = Dep::CONFLICTS_e;
+ _table["obsoletes"] = Dep::OBSOLETES_e;
+ _table["recommends"] = Dep::RECOMMENDS_e;
+ _table["suggests"] = Dep::SUGGESTS_e;
+ _table["freshens"] = Dep::FRESHENS_e;
}
std::map<std::string,Dep::for_use_in_switch>::const_iterator it
- = _table.find( str::toUpper( strval_r ) );
+ = _table.find( str::toLower( strval_r ) );
if ( it == _table.end() )
{
ZYPP_THROW( Exception("Dep parse: illegal string value '"+strval_r+"'") );
if ( _table.empty() )
{
// initialize it
- _table[PROVIDES_e] = "PROVIDES";
- _table[PREREQUIRES_e] = "PREREQUIRES";
- _table[REQUIRES_e] = "REQUIRES";
- _table[CONFLICTS_e] = "CONFLICTS";
- _table[OBSOLETES_e] = "OBSOLETES";
- _table[RECOMMENDS_e] = "RECOMMENDS";
- _table[SUGGESTS_e] = "SUGGESTS";
- _table[FRESHENS_e] = "FRESHENS";
+ _table[PROVIDES_e] = "provides";
+ _table[PREREQUIRES_e] = "prerequires";
+ _table[REQUIRES_e] = "requires";
+ _table[CONFLICTS_e] = "conflicts";
+ _table[OBSOLETES_e] = "obsoletes";
+ _table[RECOMMENDS_e] = "recommends";
+ _table[SUGGESTS_e] = "suggests";
+ _table[FRESHENS_e] = "freshens";
}
return _table[_type];
}
{
friend bool operator==( const Dep & lhs, const Dep & rhs );
friend bool operator!=( const Dep & lhs, const Dep & rhs );
+ /** Arbitrary order to allow Dep as key in std::container. */
+ friend bool operator<( const Dep & lhs, const Dep & rhs );
/** \name Dependency types
* These are the \em real dependency type contants to
explicit
Dep( const std::string & strval_r );
- /** String representation of dependency type operator.
- * \return The constants names.
+ /** String representation of dependency type.
+ * \return The constants names lowercased.
*/
const std::string & asString() const;
inline bool operator!=( const Dep & lhs, const Dep & rhs )
{ return lhs._type != rhs._type; }
+ /** \relates Dep */
+ inline bool operator<( const Dep & lhs, const Dep & rhs )
+ { return lhs._type < rhs._type; }
+
/////////////////////////////////////////////////////////////////
} // namespace zypp
///////////////////////////////////////////////////////////////////
std::ostream & operator<<( std::ostream & str, const Dependencies & obj )
{
str << "Dependencies: [" << endl;
- if ( ! obj.provides.empty() )
- str << "PROVIDES:" << endl << obj.provides;
- if ( ! obj.prerequires.empty() )
- str << "PREREQUIRES:" << endl << obj.prerequires;
- if ( ! obj.requires.empty() )
- str << "REQUIRES:" << endl << obj.requires;
- if ( ! obj.conflicts.empty() )
- str << "CONFLICTS:" << endl << obj.conflicts;
- if ( ! obj.obsoletes.empty() )
- str << "OBSOLETES:" << endl << obj.obsoletes;
- if ( ! obj.recommends.empty() )
- str << "RECOMMENDS:" << endl << obj.recommends;
- if ( ! obj.suggests.empty() )
- str << "SUGGESTS:" << endl << obj.suggests;
- if ( ! obj.freshens.empty() )
- str << "FRESHENS:" << endl << obj.freshens;
+ if ( ! obj[Dep::PROVIDES].empty() )
+ str << "PROVIDES:" << endl << obj[Dep::PROVIDES];
+ if ( ! obj[Dep::PREREQUIRES].empty() )
+ str << "PREREQUIRES:" << endl << obj[Dep::PREREQUIRES];
+ if ( ! obj[Dep::REQUIRES].empty() )
+ str << "REQUIRES:" << endl << obj[Dep::REQUIRES];
+ if ( ! obj[Dep::CONFLICTS].empty() )
+ str << "CONFLICTS:" << endl << obj[Dep::CONFLICTS];
+ if ( ! obj[Dep::OBSOLETES].empty() )
+ str << "OBSOLETES:" << endl << obj[Dep::OBSOLETES];
+ if ( ! obj[Dep::RECOMMENDS].empty() )
+ str << "RECOMMENDS:" << endl << obj[Dep::RECOMMENDS];
+ if ( ! obj[Dep::SUGGESTS].empty() )
+ str << "SUGGESTS:" << endl << obj[Dep::SUGGESTS];
+ if ( ! obj[Dep::FRESHENS].empty() )
+ str << "FRESHENS:" << endl << obj[Dep::FRESHENS];
return str << "]";
}
#define ZYPP_DEPENDENCIES_H
#include <iosfwd>
+#include <map>
#include "zypp/Dep.h"
-#include "zypp/CapSetFwd.h"
#include "zypp/CapSet.h"
///////////////////////////////////////////////////////////////////
*/
struct Dependencies
{
- /** */
- CapSet provides;
- /** */
- CapSet prerequires;
- /** */
- CapSet requires;
- /** */
- CapSet conflicts;
- /** */
- CapSet obsoletes;
- /** */
- CapSet recommends;
- /** */
- CapSet suggests;
- /** */
- CapSet freshens;
+ CapSet & operator[]( Dep idx_r )
+ { return _capsets[idx_r]; }
+
+ const CapSet & operator[]( Dep idx_r ) const
+ { return const_cast<std::map<Dep,CapSet>&>(_capsets)[idx_r]; }
+
+ private:
+ std::map<Dep,CapSet> _capsets;
};
///////////////////////////////////////////////////////////////////
const Arch & Resolvable::arch() const
{ return _pimpl->arch(); }
- const CapSet & Resolvable::provides() const
- { return _pimpl->deps().provides; }
-
- const CapSet & Resolvable::prerequires() const
- { return _pimpl->deps().prerequires; }
-
- const CapSet & Resolvable::requires() const
- { return _pimpl->deps().requires; }
-
- const CapSet & Resolvable::conflicts() const
- { return _pimpl->deps().conflicts; }
-
- const CapSet & Resolvable::obsoletes() const
- { return _pimpl->deps().obsoletes; }
-
- const CapSet & Resolvable::recommends() const
- { return _pimpl->deps().recommends; }
-
- const CapSet & Resolvable::suggests() const
- { return _pimpl->deps().suggests; }
-
- const CapSet & Resolvable::freshens() const
- { return _pimpl->deps().freshens; }
+ const CapSet & Resolvable::dep( Dep which_r ) const
+ { return _pimpl->deps()[which_r]; }
const Dependencies & Resolvable::deps() const
{ return _pimpl->deps(); }
#include "zypp/Edition.h"
#include "zypp/Arch.h"
#include "zypp/CapSetFwd.h"
+#include "zypp/Dep.h"
///////////////////////////////////////////////////////////////////
namespace zypp
/** \name Dependencies. */
//@{
- const CapSet & provides() const;
- const CapSet & prerequires() const;
- const CapSet & requires() const;
- const CapSet & conflicts() const;
- const CapSet & obsoletes() const;
- const CapSet & recommends() const;
- const CapSet & suggests() const;
- const CapSet & freshens() const;
+ /** Select by Dep. */
+ const CapSet & dep( Dep which_r ) const;
/** All dependencies. */
const Dependencies & deps() const;
//@}
, _deps( nvrad_r )
{
// assert self provides
- _deps.provides.insert( CapFactory()
+ _deps[Dep::PROVIDES].insert( CapFactory()
.parse( _kind, _name, Rel::EQ, _edition ) );
// assert all prerequires are in requires too
- _deps.requires.insert( _deps.prerequires.begin(),
- _deps.prerequires.end() );
+ _deps[Dep::REQUIRES].insert( _deps[Dep::PREREQUIRES].begin(),
+ _deps[Dep::PREREQUIRES].end() );
}
public:
{
_deps = val_r;
// assert self provides
- _deps.provides.insert( CapFactory()
+ _deps[Dep::PROVIDES].insert( CapFactory()
.parse( _kind, _name, Rel::EQ, _edition ) );
// assert all prerequires are in requires too
- _deps.requires.insert( _deps.prerequires.begin(),
- _deps.prerequires.end() );
+ _deps[Dep::REQUIRES].insert( _deps[Dep::PREREQUIRES].begin(),
+ _deps[Dep::PREREQUIRES].end() );
}
void injectProvides( const Capability & cap_r )
- { _deps.provides.insert( cap_r ); }
+ { _deps[Dep::PROVIDES].insert( cap_r ); }
void injectRequires( const Capability & cap_r )
- { _deps.requires.insert( cap_r ); }
+ { _deps[Dep::REQUIRES].insert( cap_r ); }
//@}
private:
}
Dependencies deps;
- deps.requires = dep_table.requires;
- deps.provides = dep_table.provides;
- deps.conflicts = dep_table.conflicts;
- deps.obsoletes = dep_table.obsoletes;
- deps.suggests = dep_table.suggests;
- deps.recommends = dep_table.recommends;
+ deps[Dep::REQUIRES] = dep_table.requires;
+ deps[Dep::PROVIDES] = dep_table.provides;
+ deps[Dep::CONFLICTS] = dep_table.conflicts;
+ deps[Dep::OBSOLETES] = dep_table.obsoletes;
+ deps[Dep::SUGGESTS] = dep_table.suggests;
+ deps[Dep::RECOMMENDS] = dep_table.recommends;
deprecatedSetDependencies (deps);
if (!_history.empty()) {
for (CapSet::const_iterator iter = provides().begin(); iter != provides().end(); iter++) {
std::string capString = (*iter).asString();
std::string cmpString = name + " == ";
- string::size_type ret = capString.find (cmpString);
+ string::size_type ret = capString.find (cmpString);
if (ret != string::npos)
{
Edition edition = Edition(capString.substr (cmpString.length()));
size_t installedSize() const { return _installed_size; }
void setInstalledSize (size_t installed_size) { _installed_size = installed_size; }
- const CapSet & requires() const { return _resObject->requires(); }
- const CapSet & prerequires() const { return _resObject->prerequires(); }
- const CapSet & provides() const { return _resObject->provides(); }
- const CapSet & conflicts() const { return _resObject->conflicts(); }
- const CapSet & obsoletes() const { return _resObject->obsoletes(); }
- const CapSet & suggests() const { return _resObject->suggests(); }
- const CapSet & recommends() const { return _resObject->recommends(); }
- const CapSet & freshens() const { return _resObject->freshens(); }
+ const CapSet & requires() const { return _resObject->dep( Dep::REQUIRES ); }
+ const CapSet & prerequires() const { return _resObject->dep( Dep::PREREQUIRES ); }
+ const CapSet & provides() const { return _resObject->dep( Dep::PROVIDES ); }
+ const CapSet & conflicts() const { return _resObject->dep( Dep::CONFLICTS ); }
+ const CapSet & obsoletes() const { return _resObject->dep( Dep::OBSOLETES ); }
+ const CapSet & suggests() const { return _resObject->dep( Dep::SUGGESTS ); }
+ const CapSet & recommends() const { return _resObject->dep( Dep::RECOMMENDS ); }
+ const CapSet & freshens() const { return _resObject->dep( Dep::FRESHENS ); }
void deprecatedSetDependencies (const Dependencies & dependencies) { _resObject->deprecatedSetDeps(dependencies); }
else
{
if (update->edition() < (*iter)->edition())
- update = *iter;
+ update = *iter;
}
}
}
_current_resitem_edition = update->edition();
_current_resitem_fileSize = update->packageSize();
_current_resitem_installedSize = update->installedSize();
- _current_resitem_arch = update->arch();
+ _current_resitem_arch = update->arch();
}
else {
for (CapSet::const_iterator iter = _current_provides.begin(); iter != _current_provides.end(); iter++) {
std::string capString = (*iter).asString();
std::string cmpString = _current_resitem_name + " == ";
- string::size_type ret = capString.find (cmpString);
+ string::size_type ret = capString.find (cmpString);
if (ret != string::npos)
{
string editionStr = capString.substr (cmpString.length());
package->setInstalled (true);
Dependencies deps;
- deps.requires = _current_requires;
- deps.provides = _current_provides;
- deps.conflicts = _current_conflicts;
- deps.obsoletes = _current_obsoletes;
- deps.suggests = _current_suggests;
- deps.recommends = _current_recommends;
- deps.freshens = _current_freshens;
+ deps[Dep::REQUIRES] = _current_requires;
+ deps[Dep::PROVIDES] = _current_provides;
+ deps[Dep::CONFLICTS] = _current_conflicts;
+ deps[Dep::OBSOLETES] = _current_obsoletes;
+ deps[Dep::SUGGESTS] = _current_suggests;
+ deps[Dep::RECOMMENDS] = _current_recommends;
+ deps[Dep::FRESHENS] = _current_freshens;
package->deprecatedSetDependencies (deps);
package->setPrettyName (_current_resitem_prettyName);
package->setSummary (_current_resitem_summary);
if ( mtag_r.stag.isPlain( "Prv" ) )
{
- collectDeps( mtag_r.value, nvrad.provides );
+ collectDeps( mtag_r.value, nvrad[Dep::PROVIDES] );
}
else if ( mtag_r.stag.isPlain( "Prq" ) )
{
- collectDeps( mtag_r.value, nvrad.prerequires );
+ collectDeps( mtag_r.value, nvrad[Dep::PREREQUIRES] );
}
else if ( mtag_r.stag.isPlain( "Req" ) )
{
- collectDeps( mtag_r.value, nvrad.requires );
+ collectDeps( mtag_r.value, nvrad[Dep::REQUIRES] );
}
else if ( mtag_r.stag.isPlain( "Con" ) )
{
- collectDeps( mtag_r.value, nvrad.conflicts );
+ collectDeps( mtag_r.value, nvrad[Dep::CONFLICTS] );
}
else if ( mtag_r.stag.isPlain( "Obs" ) )
{
- collectDeps( mtag_r.value, nvrad.obsoletes );
+ collectDeps( mtag_r.value, nvrad[Dep::OBSOLETES] );
}
}
it != parsed.provides.end();
it++)
{
- _deps.provides.insert(createCapability(*it, my_kind));
+ _deps[Dep::PROVIDES].insert(createCapability(*it, my_kind));
}
for (std::list<YUMDependency>::const_iterator it = parsed.conflicts.begin();
it != parsed.conflicts.end();
it++)
{
- _deps.conflicts.insert(createCapability(*it, my_kind));
+ _deps[Dep::CONFLICTS].insert(createCapability(*it, my_kind));
}
for (std::list<YUMDependency>::const_iterator it = parsed.obsoletes.begin();
it != parsed.obsoletes.end();
it++)
{
- _deps.obsoletes.insert(createCapability(*it, my_kind));
+ _deps[Dep::OBSOLETES].insert(createCapability(*it, my_kind));
}
for (std::list<YUMDependency>::const_iterator it = parsed.freshen.begin();
it != parsed.freshen.end();
it++)
{
- _deps.freshens.insert(createCapability(*it, my_kind));
+ _deps[Dep::FRESHENS].insert(createCapability(*it, my_kind));
}
for (std::list<YUMDependency>::const_iterator it = parsed.requires.begin();
it++)
{
if (it->pre == "1")
- _deps.prerequires.insert(createCapability(*it, my_kind));
+ _deps[Dep::PREREQUIRES].insert(createCapability(*it, my_kind));
else
- _deps.requires.insert(createCapability(*it, my_kind));
+ _deps[Dep::REQUIRES].insert(createCapability(*it, my_kind));
}
return _deps;
{
if (it->type == "mandatory" || it->type == "")
{
- _deps.requires.insert(createCapability(YUMDependency(
+ _deps[Dep::REQUIRES].insert(createCapability(YUMDependency(
"",
it->name,
"EQ",
{
if (it->type == "mandatory" || it->type == "")
{
- _deps.requires.insert(createCapability(YUMDependency(
+ _deps[Dep::REQUIRES].insert(createCapability(YUMDependency(
"",
it->name,
"",
{
if (it->type == "mandatory" || it->type == "")
{
- _deps.requires.insert(createCapability(YUMDependency(
+ _deps[Dep::REQUIRES].insert(createCapability(YUMDependency(
"",
it->name,
"EQ",
{
if (it->type == "mandatory" || it->type == "")
{
- _deps.requires.insert(createCapability(YUMDependency(
+ _deps[Dep::REQUIRES].insert(createCapability(YUMDependency(
"",
it->name,
"",
CapFactory _f;
Resolvable::Kind _kind = dep.kind == "" ? my_kind : Resolvable::Kind(dep.kind);
Capability cap;
- if ( ! dep.isEncoded() )
+ if ( ! dep.isEncoded() )
{
cap = _f.parse(
_kind,
arch );
list<string> filenames = impl->filenames();
- dataCollect.provides = iter->tag_provides ( & _filerequires );
+ dataCollect[Dep::PROVIDES] = iter->tag_provides ( & _filerequires );
for (list<string>::const_iterator filename = filenames.begin();
filename != filenames.end();
filename++)
|| filename->find("/opt/gnome/games"))
{
try {
- dataCollect.provides.insert(_f.parse(ResTraits<Package>::kind, *filename));
+ dataCollect[Dep::PROVIDES].insert(_f.parse(ResTraits<Package>::kind, *filename));
}
catch (Exception & excpt_r)
{
}
}
- dataCollect.requires = iter->tag_requires ( &_filerequires );
- dataCollect.prerequires = iter->tag_prerequires ( &_filerequires );
- dataCollect.conflicts = iter->tag_conflicts( &_filerequires );
- dataCollect.obsoletes = iter->tag_obsoletes( &_filerequires );
+ dataCollect[Dep::REQUIRES] = iter->tag_requires ( &_filerequires );
+ dataCollect[Dep::PREREQUIRES] = iter->tag_prerequires ( &_filerequires );
+ dataCollect[Dep::CONFLICTS] = iter->tag_conflicts( &_filerequires );
+ dataCollect[Dep::OBSOLETES] = iter->tag_obsoletes( &_filerequires );
// create package from dataprovider
Package::Ptr nptr = detail::makeResolvableFromImpl( dataCollect, impl );
{
std::string result;
result += "<" + tag + ">";
-
+
if ( escape)
result += xml_escape(text);
else
{
stringstream out;
CapFactory factory;
-
+
out << "<entry kind=\"" << cap.refers() << "\" >" << xml_escape(factory.encode(cap)) << "</entry>";
return out.str();
}
{
out << toXML((*it));
}
- return out.str();
+ return out.str();
}
template<> // or constPtr?
std::string toXML( const Dependencies &dep )
{
stringstream out;
- if ( dep.provides.size() > 0 )
- out << " " << xml_tag_enclose(toXML(dep.provides), "provides") << std::endl;
- if ( dep.prerequires.size() > 0 )
- out << " " << xml_tag_enclose(toXML(dep.prerequires), "prerequires") << std::endl;
- if ( dep.requires.size() > 0 )
- out << " " << xml_tag_enclose(toXML(dep.requires), "requires") << std::endl;
- if ( dep.conflicts.size() > 0 )
- out << " " << xml_tag_enclose(toXML(dep.conflicts), "conflicts") << std::endl;
- if ( dep.obsoletes.size() > 0 )
- out << " " << xml_tag_enclose(toXML(dep.obsoletes), "obsoletes") << std::endl;
+ if ( dep[Dep::PROVIDES].size() > 0 )
+ out << " " << xml_tag_enclose(toXML(dep[Dep::PROVIDES]), "provides") << std::endl;
+ if ( dep[Dep::PREREQUIRES].size() > 0 )
+ out << " " << xml_tag_enclose(toXML(dep[Dep::PREREQUIRES]), "prerequires") << std::endl;
+ if ( dep[Dep::REQUIRES].size() > 0 )
+ out << " " << xml_tag_enclose(toXML(dep[Dep::REQUIRES]), "requires") << std::endl;
+ if ( dep[Dep::CONFLICTS].size() > 0 )
+ out << " " << xml_tag_enclose(toXML(dep[Dep::CONFLICTS]), "conflicts") << std::endl;
+ if ( dep[Dep::OBSOLETES].size() > 0 )
+ out << " " << xml_tag_enclose(toXML(dep[Dep::OBSOLETES]), "obsoletes") << std::endl;
// why the YUM tag is freshen without s????
- if ( dep.freshens.size() > 0 )
- out << " " << xml_tag_enclose(toXML(dep.freshens), "freshen") << std::endl;
- if ( dep.suggests.size() > 0 )
- out << " " << xml_tag_enclose(toXML(dep.suggests), "suggests") << std::endl;
- if ( dep.recommends.size() > 0 )
- out << " " << xml_tag_enclose(toXML(dep.recommends), "recommends") << std::endl;
+ if ( dep[Dep::FRESHENS].size() > 0 )
+ out << " " << xml_tag_enclose(toXML(dep[Dep::FRESHENS]), "freshen") << std::endl;
+ if ( dep[Dep::SUGGESTS].size() > 0 )
+ out << " " << xml_tag_enclose(toXML(dep[Dep::SUGGESTS]), "suggests") << std::endl;
+ if ( dep[Dep::RECOMMENDS].size() > 0 )
+ out << " " << xml_tag_enclose(toXML(dep[Dep::RECOMMENDS]), "recommends") << std::endl;
return out.str();
-
+
}
template<> // or constPtr?
std::string toXML( const Resolvable::constPtr &obj )
{
stringstream out;
-
+
out << " <name>" << obj->name() << "</name>" << std::endl;
// is this shared? uh
out << " " << toXML(obj->edition()) << std::endl;