From fe8282bb1c8f0c242684957732d6fbb9fec79dc2 Mon Sep 17 00:00:00 2001 From: Michael Andres Date: Wed, 4 Jan 2006 09:17:26 +0000 Subject: [PATCH] Removed references to liby2util. --- zypp/solver/detail/Channel.cc | 200 +++---- zypp/solver/detail/Channel.h | 142 ++--- zypp/solver/detail/ChannelPtr.h | 16 +- zypp/solver/detail/Importance.cc | 39 +- zypp/solver/detail/Importance.h | 44 +- zypp/solver/detail/Makefile.am | 2 +- zypp/solver/detail/Match.cc | 84 ++- zypp/solver/detail/Match.h | 74 +-- zypp/solver/detail/MatchPtr.h | 16 +- zypp/solver/detail/MultiWorld.cc | 392 ++++++------- zypp/solver/detail/MultiWorld.h | 42 +- zypp/solver/detail/MultiWorldPtr.h | 16 +- zypp/solver/detail/Package.cc | 339 +++++------ zypp/solver/detail/Package.h | 28 +- zypp/solver/detail/PackagePtr.h | 16 +- zypp/solver/detail/PackageUpdate.cc | 115 ++-- zypp/solver/detail/PackageUpdate.h | 20 +- zypp/solver/detail/PackageUpdatePtr.h | 19 +- zypp/solver/detail/Packman.cc | 38 +- zypp/solver/detail/Packman.h | 40 +- zypp/solver/detail/PackmanPtr.h | 16 +- zypp/solver/detail/Pending.cc | 2 +- zypp/solver/detail/Pending.h | 94 +-- zypp/solver/detail/PendingPtr.h | 16 +- zypp/solver/detail/QueueItem.cc | 10 +- zypp/solver/detail/QueueItem.h | 94 +-- zypp/solver/detail/QueueItemBranch.cc | 165 +++--- zypp/solver/detail/QueueItemBranch.h | 59 +- zypp/solver/detail/QueueItemBranchPtr.h | 22 +- zypp/solver/detail/QueueItemConflict.cc | 200 +++---- zypp/solver/detail/QueueItemConflict.h | 55 +- zypp/solver/detail/QueueItemConflictPtr.h | 20 +- zypp/solver/detail/QueueItemGroup.cc | 90 +-- zypp/solver/detail/QueueItemGroup.h | 49 +- zypp/solver/detail/QueueItemGroupPtr.h | 22 +- zypp/solver/detail/QueueItemInstall.cc | 52 +- zypp/solver/detail/QueueItemInstall.h | 75 +-- zypp/solver/detail/QueueItemInstallPtr.h | 20 +- zypp/solver/detail/QueueItemPtr.h | 16 +- zypp/solver/detail/QueueItemRequire.cc | 279 +++++---- zypp/solver/detail/QueueItemRequire.h | 69 +-- zypp/solver/detail/QueueItemRequirePtr.h | 20 +- zypp/solver/detail/QueueItemUninstall.cc | 182 +++--- zypp/solver/detail/QueueItemUninstall.h | 59 +- zypp/solver/detail/QueueItemUninstallPtr.h | 20 +- zypp/solver/detail/ResItem.cc | 87 ++- zypp/solver/detail/ResItem.h | 98 ++-- zypp/solver/detail/ResItemAndDependency.cc | 48 +- zypp/solver/detail/ResItemAndDependency.h | 54 +- zypp/solver/detail/ResItemAndDependencyPtr.h | 16 +- zypp/solver/detail/ResItemPtr.h | 16 +- zypp/solver/detail/Resolver.cc | 256 ++++---- zypp/solver/detail/Resolver.h | 98 ++-- zypp/solver/detail/ResolverContext.cc | 680 +++++++++++----------- zypp/solver/detail/ResolverContext.h | 150 ++--- zypp/solver/detail/ResolverContextPtr.h | 16 +- zypp/solver/detail/ResolverInfo.cc | 14 +- zypp/solver/detail/ResolverInfo.h | 81 +-- zypp/solver/detail/ResolverInfoChildOf.cc | 10 +- zypp/solver/detail/ResolverInfoChildOf.h | 6 +- zypp/solver/detail/ResolverInfoChildOfPtr.h | 16 +- zypp/solver/detail/ResolverInfoConflictsWith.cc | 10 +- zypp/solver/detail/ResolverInfoConflictsWith.h | 6 +- zypp/solver/detail/ResolverInfoConflictsWithPtr.h | 16 +- zypp/solver/detail/ResolverInfoContainer.cc | 22 +- zypp/solver/detail/ResolverInfoContainer.h | 16 +- zypp/solver/detail/ResolverInfoContainerPtr.h | 22 +- zypp/solver/detail/ResolverInfoDependsOn.cc | 10 +- zypp/solver/detail/ResolverInfoDependsOn.h | 6 +- zypp/solver/detail/ResolverInfoDependsOnPtr.h | 16 +- zypp/solver/detail/ResolverInfoMisc.cc | 76 +-- zypp/solver/detail/ResolverInfoMisc.h | 8 +- zypp/solver/detail/ResolverInfoMiscPtr.h | 16 +- zypp/solver/detail/ResolverInfoMissingReq.cc | 10 +- zypp/solver/detail/ResolverInfoMissingReq.h | 6 +- zypp/solver/detail/ResolverInfoMissingReqPtr.h | 16 +- zypp/solver/detail/ResolverInfoNeededBy.cc | 10 +- zypp/solver/detail/ResolverInfoNeededBy.h | 6 +- zypp/solver/detail/ResolverInfoNeededByPtr.h | 16 +- zypp/solver/detail/ResolverInfoObsoletes.cc | 10 +- zypp/solver/detail/ResolverInfoObsoletes.h | 6 +- zypp/solver/detail/ResolverInfoObsoletesPtr.h | 16 +- zypp/solver/detail/ResolverInfoPtr.h | 16 +- zypp/solver/detail/ResolverPtr.h | 16 +- zypp/solver/detail/ResolverQueue.cc | 291 +++++---- zypp/solver/detail/ResolverQueue.h | 68 ++- zypp/solver/detail/ResolverQueuePtr.h | 16 +- zypp/solver/detail/Section.cc | 41 +- zypp/solver/detail/Section.h | 44 +- zypp/solver/detail/ServiceWorld.cc | 2 +- zypp/solver/detail/ServiceWorld.h | 6 +- zypp/solver/detail/ServiceWorldPtr.h | 16 +- zypp/solver/detail/Spec.cc | 14 +- zypp/solver/detail/Spec.h | 77 +-- zypp/solver/detail/SpecPtr.h | 16 +- zypp/solver/detail/StoreWorld.cc | 422 +++++++------- zypp/solver/detail/StoreWorld.h | 36 +- zypp/solver/detail/StoreWorldPtr.h | 16 +- zypp/solver/detail/Subscription.cc | 222 ++++--- zypp/solver/detail/Subscription.h | 47 +- zypp/solver/detail/UndumpWorld.cc | 12 +- zypp/solver/detail/UndumpWorld.h | 10 +- zypp/solver/detail/UndumpWorldPtr.h | 16 +- zypp/solver/detail/Ustring.h | 280 +++++++++ zypp/solver/detail/World.cc | 340 +++++------ zypp/solver/detail/World.h | 242 ++++---- zypp/solver/detail/WorldPtr.h | 16 +- zypp/solver/detail/XmlNode.cc | 4 +- zypp/solver/detail/XmlNode.h | 16 +- zypp/solver/detail/XmlNodePtr.h | 16 +- zypp/solver/detail/XmlParser.cc | 14 +- zypp/solver/detail/XmlParser.h | 70 +-- zypp/solver/detail/debug.cc | 1 - zypp/solver/detail/extract.cc | 58 +- zypp/solver/detail/extract.h | 18 +- zypp/solver/detail/utils.cc | 2 +- 116 files changed, 4084 insertions(+), 3751 deletions(-) create mode 100644 zypp/solver/detail/Ustring.h diff --git a/zypp/solver/detail/Channel.cc b/zypp/solver/detail/Channel.cc index 22b99f1..da84338 100644 --- a/zypp/solver/detail/Channel.cc +++ b/zypp/solver/detail/Channel.cc @@ -21,14 +21,16 @@ * 02111-1307, USA. */ -#include +#include + +#include +#include #include #include -#include ///////////////////////////////////////////////////////////////////////// -namespace zypp +namespace zypp { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// namespace solver @@ -36,25 +38,25 @@ namespace zypp ///////////////////////////////////////////////////////////////////// namespace detail { /////////////////////////////////////////////////////////////////// - + using namespace std; - - IMPL_BASE_POINTER(Channel); - + + IMPL_PTR_TYPE(Channel); + //--------------------------------------------------------------------------- - + int Channel::_fake_id = 1; - + //--------------------------------------------------------------------------- - + string Channel::asString ( void ) const { if (this == NULL) fprintf (stderr, "Channel::asString NULL\n"); return toString (*this); } - - + + string Channel::toString ( const Channel & channel ) { @@ -64,7 +66,7 @@ namespace zypp case CHANNEL_TYPE_ANY: res += "any"; break; case CHANNEL_TYPE_SYSTEM: res += "system"; break; case CHANNEL_TYPE_NONSYSTEM: res += "non-system"; break; - + case CHANNEL_TYPE_UNKNOWN: res += "unknown"; break; case CHANNEL_TYPE_HELIX: res += "helix"; break; case CHANNEL_TYPE_DEBIAN: res += "debian"; break; @@ -73,7 +75,7 @@ namespace zypp case CHANNEL_TYPE_YUM: res += "yum"; break; } res += ", "; - + res += "Id: "; res += channel.id(); if (channel.legacyId() != NULL @@ -85,17 +87,17 @@ namespace zypp res += channel.name(); res += ", Alias: "; res += channel.alias(); - + if (channel.description() != NULL) { res += ", Description: "; res += channel.description(); } - + res += ", Priority: "; - res += stringutil::numstring (channel.priority()); + res += str::numstring (channel.priority()); res += ", PriorityUnsubscribed: "; - res += stringutil::numstring (channel.priorityUnsubscribed()); - + res += str::numstring (channel.priorityUnsubscribed()); + if (channel.path() != NULL) { res += ", Path: "; res += channel.path(); @@ -113,34 +115,34 @@ namespace zypp res += channel.pkginfoFile(); } // list *_distro_targets; /* List of targets (char *) for this channel */ - + res += ", LastUpdate: "; - res += stringutil::numstring(channel.lastUpdate()); - + res += str::numstring(channel.lastUpdate()); + if (channel.system()) res += ", System! "; if (channel.hidden()) res += ", Hidden! "; if (channel.immutable()) res += ", Immutable! "; - + return res + "'>"; } - - + + ostream & Channel::dumpOn( ostream & str ) const { str << asString(); return str; } - - + + ostream& operator<<( ostream& os, const Channel& channel) { return os << channel.asString(); } - + //--------------------------------------------------------------------------- - + Channel::Channel(const string & id, const string & name, const string & alias, const string & description) : _world (NULL) , _last_update (0) @@ -149,43 +151,43 @@ namespace zypp , _immutable (false) { if (id.empty()) { - _id = stringutil::form( "fake-id-%d", _fake_id++).c_str(); + _id = str::form( "fake-id-%d", _fake_id++).c_str(); } else { _id = id; } - + if (name.empty()) { _name = "Unnamed Channel"; } else { _name = name; } - + if (alias.empty()) { _alias = name; } else { _alias = alias; } - + if (description.empty()) { _description = "No description available."; } else { _description = description; } - + _type = CHANNEL_TYPE_UNKNOWN; - + _priority = -1; _priority_unsubscribed = -1; - + _DBG("RC_SPEW") << "Channel() [" << this << "] (" << asString() << ")" << endl ; } - - - Channel::Channel (const XmlNodePtr node, int *subscribed, WorldPtr world) + + + Channel::Channel (const XmlNode_Ptr node, int *subscribed, World_Ptr world) : _world (world) , _last_update (0) , _system (false) @@ -196,10 +198,10 @@ namespace zypp const char *subscribed_str; const char *priority_str; const char *priority_unsubscribed_str; - + _name = node->getProp ("name"); _alias = node->getProp ("alias"); - + _id = node->getProp ("id"); if (_id.empty()) { char *temp; @@ -207,61 +209,61 @@ namespace zypp _id = temp; ++dummy_id; } - + subscribed_str = node->getProp ("subscribed"); *subscribed = subscribed_str ? atoi (subscribed_str) : 0; - + priority_str = node->getProp ("priority_base"); priority_unsubscribed_str = node->getProp ("priority_unsubd"); - + _priority = priority_str ? atoi (priority_str) : 0; _priority_unsubscribed = priority_unsubscribed_str ? atoi (priority_unsubscribed_str) : 0; - + free ((void *)subscribed_str); free ((void *)priority_str); free ((void *)priority_unsubscribed_str); - + _DBG("RC_SPEW") << "Channel(xml) [" << this << "] (" << asString() << ")" << endl; } - - + + Channel::~Channel() { } - - + + #if 0 xmlNode * rc_channel_to_xml_node (RCChannel *channel) { xmlNode *node; char tmp[128]; - + g_return_val_if_fail (channel != NULL, NULL); - + node = xmlNewNode (NULL, "channel"); - + xmlNewProp (node, "id", rc_channel_get_id (channel)); - + xmlNewProp (node, "name", rc_channel_get_name (channel)); - + if (rc_channel_get_alias (channel)) xmlNewProp (node, "alias", rc_channel_get_alias (channel)); - + sprintf (tmp, "%d", rc_channel_is_subscribed (channel) ? 1 : 0); xmlNewProp (node, "subscribed", tmp); - + sprintf (tmp, "%d", rc_channel_get_priority (channel, true)); xmlNewProp (node, "priority_base", tmp); - + sprintf (tmp, "%d", rc_channel_get_priority (channel, false)); xmlNewProp (node, "priority_unsubd", tmp); - + return node; } #endif - - + + bool Channel::isSubscribed (void) const { @@ -269,8 +271,8 @@ namespace zypp fprintf (stderr, "Channel::isSubscribed() without world\n"); return _world->isSubscribed (this); } - - + + void Channel::setSubscription (bool subscribed) { @@ -278,18 +280,18 @@ namespace zypp fprintf (stderr, "Channel::setSubscription() without world\n"); _world->setSubscription (this, subscribed); } - - + + int Channel::priorityParse (const char *priority_cptr) const { #define DEFAULT_CHANNEL_PRIORITY 1600 - + typedef struct { const char *str; int priority; } ChannelPriorityPair; - + ChannelPriorityPair channel_priority_table[] = { { "private", 6400 }, { "ximian", 3200 }, @@ -300,11 +302,11 @@ namespace zypp { "snapshot", 100 }, { NULL, 0 } }; - + const char *c; int i; bool is_numeric = true; - + if (priority_cptr && *priority_cptr) { c = priority_cptr; while (*c && is_numeric) { @@ -315,101 +317,101 @@ namespace zypp if (is_numeric) { return atoi (priority_cptr); } - + for (i=0; channel_priority_table[i].str != NULL; ++i) { if (! strcasecmp (channel_priority_table[i].str, priority_cptr)) return channel_priority_table[i].priority; } - + } - + return DEFAULT_CHANNEL_PRIORITY; } - - + + bool Channel::isWildcard (void) const { - return _type == CHANNEL_TYPE_SYSTEM + return _type == CHANNEL_TYPE_SYSTEM || _type == CHANNEL_TYPE_NONSYSTEM || _type == CHANNEL_TYPE_ANY; } - - + + bool Channel::equals (const Channel & channel) const { return equals (&channel); } - + bool - Channel::equals (constChannelPtr channel) const + Channel::equals (Channel_constPtr channel) const { if (_type == CHANNEL_TYPE_ANY || channel->_type == CHANNEL_TYPE_ANY) { return true; } - + if (isWildcard () && channel->isWildcard ()) { return this == channel; } - + /* So at this point we know that between a and b there is at most one wildcard. */ - + if (_type == CHANNEL_TYPE_SYSTEM) { return channel->system(); } else if (_type == CHANNEL_TYPE_NONSYSTEM) { return !channel->system(); } - + if (channel->_type == CHANNEL_TYPE_SYSTEM) { return system(); } else if (channel->_type == CHANNEL_TYPE_NONSYSTEM) { return !system(); } - + return hasEqualId (channel); } - - + + bool Channel::hasEqualId (const Channel & channel) const { return hasEqualId (&channel); } - - + + bool - Channel::hasEqualId (constChannelPtr channel) const + Channel::hasEqualId (Channel_constPtr channel) const { return (channel->id () == _id); } - - + + void Channel::setPriorities (int subscribed_priority, int unsubscribed_priority) { if (immutable()) return; - + _priority = subscribed_priority; _priority_unsubscribed = unsubscribed_priority; } - - + + int Channel::getPriority(bool is_subscribed) const { #define UNSUBSCRIBED_CHANNEL_ADJUSTMENT(x) ((x)/2) - + int priority; - + priority = _priority; if (priority <= 0) priority = DEFAULT_CHANNEL_PRIORITY; - + if (!is_subscribed) { if (_priority_unsubscribed > 0) { priority = _priority_unsubscribed; @@ -417,10 +419,10 @@ namespace zypp priority = UNSUBSCRIBED_CHANNEL_ADJUSTMENT (priority); } } - + return priority; } - + /////////////////////////////////////////////////////////////////// };// namespace detail ///////////////////////////////////////////////////////////////////// diff --git a/zypp/solver/detail/Channel.h b/zypp/solver/detail/Channel.h index 411ca4b..59cc8b7 100644 --- a/zypp/solver/detail/Channel.h +++ b/zypp/solver/detail/Channel.h @@ -27,16 +27,18 @@ #include #include -#include +#include -#include +#include "zypp/base/ReferenceCounted.h" +#include "zypp/base/NonCopyable.h" +#include "zypp/base/PtrTypes.h" #include #include #include ///////////////////////////////////////////////////////////////////////// -namespace zypp +namespace zypp { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// namespace solver @@ -44,170 +46,170 @@ namespace zypp ///////////////////////////////////////////////////////////////////// namespace detail { /////////////////////////////////////////////////////////////////// - - typedef std::list ChannelList; - - typedef bool (*ChannelFn) (constChannelPtr channel, void *data); - typedef bool (*ChannelAndSubscribedFn) (ChannelPtr channel, bool flag, void *data); - + + typedef std::list ChannelList; + + typedef bool (*ChannelFn) (Channel_constPtr channel, void *data); + typedef bool (*ChannelAndSubscribedFn) (Channel_Ptr channel, bool flag, void *data); + typedef enum { - + CHANNEL_TYPE_ANY = 0, CHANNEL_TYPE_SYSTEM, CHANNEL_TYPE_NONSYSTEM, - + CHANNEL_TYPE_UNKNOWN, CHANNEL_TYPE_HELIX, CHANNEL_TYPE_DEBIAN, CHANNEL_TYPE_APTRPM, CHANNEL_TYPE_YAST, CHANNEL_TYPE_YUM - + } ChannelType; - + /////////////////////////////////////////////////////////////////// - + /////////////////////////////////////////////////////////////////// // // CLASS NAME : Channel /** * **/ - - class Channel : public CountedRep { - REP_BODY(Channel); - + + class Channel : public base::ReferenceCounted, private base::NonCopyable { + + private: ChannelType _type; - + static int _fake_id; - - WorldPtr _world; - + + World_Ptr _world; + std::string _id; std::string _legacy_id; // Old ID for RCE servers - + std::string _name; std::string _alias; std::string _description; // priority if channel is... int _priority; // subscribed int _priority_unsubscribed; // unsubscribed - + std::string _path; std::string _file_path; std::string _icon_file; std::string _pkginfo_file; - + // std::list *_distro_targets; /* List of targets (std::string ) for this channel */ - + time_t _last_update; - + bool _system; bool _hidden; bool _immutable; - + public: - + Channel (ChannelType type) : _type (type), _world(NULL) {} - + Channel(const std::string & id = "", const std::string & name = "", const std::string & alias = "", const std::string & description = ""); - Channel(const XmlNodePtr node, int *subscribed, WorldPtr world); //RCChannel *rc_channel_from_xml_node (xmlNode *channel_node); - + Channel(const XmlNode_Ptr node, int *subscribed, World_Ptr world); //RCChannel *rc_channel_from_xml_node (xmlNode *channel_node); + virtual ~Channel(); - + // ---------------------------------- I/O - - const XmlNodePtr asXmlNode (void) const; // rc_channel_to_xml_node - + + const XmlNode_Ptr asXmlNode (void) const; // rc_channel_to_xml_node + static std::string toString ( const Channel & edition ); - + virtual std::ostream & dumpOn( std::ostream & str ) const; - + friend std::ostream& operator<<( std::ostream&, const Channel& ); - + std::string asString ( void ) const; - + // ---------------------------------- accessors - + ChannelType type(void) const { return _type; } void setType (ChannelType type) { _type = type; } - + const char *id (void) const { return _id.c_str(); } void setId (const char *id) { _id = std::string (id); } - - WorldPtr world (void) const { return _world; } - void setWorld (WorldPtr world) { _world = world; } - + + World_Ptr world (void) const { return _world; } + void setWorld (World_Ptr world) { _world = world; } + const char *legacyId (void) const { return _legacy_id.c_str(); } // Old ID for RCE servers void setLegacyId (const char *legacy_id) { _legacy_id = std::string (legacy_id); } - + const char * name (void) const { return _name.c_str(); } void setName (const char *name) { _name = std::string (name); } - + const char *alias (void) const { return _alias.c_str(); } void setAlias (const char *alias) { _alias = std::string (alias); } - + const char *description (void) const { return _description.c_str(); } void setDescription (const char *description) { _description = std::string (description); } - + int priority (void) const { return _priority; } void setPriority (int priority) { _priority = priority; } - + int priorityUnsubscribed (void) const { return _priority_unsubscribed; } void setPriorityUnsubscribed (int priority_unsubscribed) { _priority_unsubscribed = priority_unsubscribed; } - + const char *path (void) const { return _path.c_str(); } void setPath (const char *path) { _path = std::string (path); } - + const char *filePath (void) const { return _file_path.c_str(); } void setFilePath (const char *file_path) { _file_path = std::string (file_path); } - + const char *iconFile (void) const { return _icon_file.c_str(); } void setIconFile (const char *icon_file) { _icon_file = std::string (icon_file); } - + const char *pkginfoFile (void) const { return _pkginfo_file.c_str(); } void setPkginfoFile (const char *pkginfo_file) { _pkginfo_file = std::string (pkginfo_file); } - + // const std::list *distroTargets (void) const { return _distro_targets; } // void setDistroTargets (const std::list *distro_targets) { _distro_targets = distro_targets; } - + time_t lastUpdate (void) const { return _last_update; } void setLastUpdate (time_t last_update) { _last_update = last_update; } - + bool system (void) const { return _system; } void setSystem (bool system) { _system = system; } bool hidden (void) const { return _hidden; } void setHidden (bool hidden) { _hidden = hidden; } bool immutable (void) const { return _immutable; } void setImmutable (bool immutable) { _immutable = immutable; } - + //----------------------------------------------------------------------- - + bool isWildcard (void) const; - + virtual bool equals (const Channel & channel) const; - virtual bool equals (constChannelPtr channel) const; + virtual bool equals (Channel_constPtr channel) const; bool hasEqualId (const Channel & channel) const; - bool hasEqualId (constChannelPtr channel) const; - + bool hasEqualId (Channel_constPtr channel) const; + //RCResItemSList *rc_channel_get_resItems (RCChannel *channel); - + // Distro target functions - + void addDistroTarget (const char *target); bool hasDistroTarget (const char *target) const; - + // Subscription management - + bool isSubscribed (void) const; void setSubscription (bool subscribed); - + int priorityParse (const char *priority_cptr) const; void setPriorities (int subd_priority, int unsubd_priority); int getPriority (bool is_subscribed) const; }; - + /////////////////////////////////////////////////////////////////// };// namespace detail ///////////////////////////////////////////////////////////////////// diff --git a/zypp/solver/detail/ChannelPtr.h b/zypp/solver/detail/ChannelPtr.h index 2e0c4c0..2167991 100644 --- a/zypp/solver/detail/ChannelPtr.h +++ b/zypp/solver/detail/ChannelPtr.h @@ -1,5 +1,5 @@ /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* ChannelPtr.h +/* Channel_Ptr.h * * Copyright (C) 2005 SUSE Linux Products GmbH * @@ -18,10 +18,10 @@ * 02111-1307, USA. */ -#ifndef _ChannelPtr_h -#define _ChannelPtr_h +#ifndef _Channel_Ptr_h +#define _Channel_Ptr_h -#include +#include "zypp/base/PtrTypes.h" ///////////////////////////////////////////////////////////////////////// namespace zypp @@ -34,10 +34,10 @@ namespace zypp { /////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// - // CLASS NAME : ChannelPtr - // CLASS NAME : constChannelPtr + // CLASS NAME : Channel_Ptr + // CLASS NAME : Channel_constPtr /////////////////////////////////////////////////////////////////// - DEFINE_BASE_POINTER(Channel); + DEFINE_PTR_TYPE(Channel); /////////////////////////////////////////////////////////////////// };// namespace detail @@ -48,4 +48,4 @@ namespace zypp /////////////////////////////////////////////////////////////////////// };// namespace zypp //////////////////////////////////////////////////////////////////////// -#endif // _ChannelPtr_h +#endif // _Channel_Ptr_h diff --git a/zypp/solver/detail/Importance.cc b/zypp/solver/detail/Importance.cc index 285adb1..a356505 100644 --- a/zypp/solver/detail/Importance.cc +++ b/zypp/solver/detail/Importance.cc @@ -19,14 +19,11 @@ * 02111-1307, USA. */ -#include - #include - #include ///////////////////////////////////////////////////////////////////////// -namespace zypp +namespace zypp { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// namespace solver @@ -34,24 +31,24 @@ namespace zypp ///////////////////////////////////////////////////////////////////// namespace detail { /////////////////////////////////////////////////////////////////// - + using namespace std; - + const Importance & Importance::Undefined= Importance("undefined"); - + //--------------------------------------------------------------------------- string Importance::asString ( void ) const { return toString (*this); } - - + + string Importance::toString ( const Importance & importance ) { string res; - + switch (importance.importance()) { case IMPORTANCE_UNDEFINED: res = "undefined"; break; case IMPORTANCE_INVALID: res = "invalid"; break; @@ -66,24 +63,24 @@ namespace zypp } return res; } - - + + ostream & Importance::dumpOn( ostream & str ) const { str << asString(); return str; } - - + + ostream& operator<<( ostream& os, const Importance& importance) { return os << importance.asString(); } - + //--------------------------------------------------------------------------- - + Importance::Importance(const char *importance_str) { _importance = IMPORTANCE_INVALID; @@ -122,14 +119,14 @@ namespace zypp } if (_importance == IMPORTANCE_INVALID) rc_debug (RC_DEBUG_LEVEL_WARNING, "invalid importance '%s'\n", importance_str ? importance_str : ""); - + } - - + + Importance::~Importance() { } - + /////////////////////////////////////////////////////////////////// };// namespace detail ///////////////////////////////////////////////////////////////////// @@ -139,5 +136,5 @@ namespace zypp /////////////////////////////////////////////////////////////////////// };// namespace zypp ///////////////////////////////////////////////////////////////////////// - + diff --git a/zypp/solver/detail/Importance.h b/zypp/solver/detail/Importance.h index efcb38b..9eb22d0 100644 --- a/zypp/solver/detail/Importance.h +++ b/zypp/solver/detail/Importance.h @@ -23,12 +23,10 @@ #define _Importance_h #include -#include - -#include +#include ///////////////////////////////////////////////////////////////////////// -namespace zypp +namespace zypp { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// namespace solver @@ -44,59 +42,59 @@ namespace zypp * **/ class Importance { - + private: - + typedef enum { IMPORTANCE_INVALID = -1, - + IMPORTANCE_NECESSARY, IMPORTANCE_URGENT, IMPORTANCE_SUGGESTED, IMPORTANCE_FEATURE, IMPORTANCE_MINOR, IMPORTANCE_UNDEFINED, - + // Not a real importance IMPORTANCE_LAST } importance_t; - + importance_t _importance; - + private: importance_t importance () const { return _importance; } - + public: - + Importance(const char *importance_str); virtual ~Importance(); - + static const Importance & Undefined; - + // ---------------------------------- I/O - + static std::string toString ( const Importance & importance); - + virtual std::ostream & dumpOn( std::ostream & str ) const; - + friend std::ostream& operator<<( std::ostream&, const Importance & importance); - + std::string asString ( void ) const; - + // ---------------------------------- accessors - + // equality bool operator==( const Importance & importance) const { return _importance == importance.importance(); } - + // inequality bool operator!=( const Importance & importance) const { return !(*this == importance); } - + }; - + /////////////////////////////////////////////////////////////////// };// namespace detail ///////////////////////////////////////////////////////////////////// diff --git a/zypp/solver/detail/Makefile.am b/zypp/solver/detail/Makefile.am index 128ec47..a984320 100644 --- a/zypp/solver/detail/Makefile.am +++ b/zypp/solver/detail/Makefile.am @@ -6,7 +6,6 @@ SUBDIRS = INCLUDES = \ -I$(top_srcdir) -Wall -fno-strict-aliasing \ - -I/usr/include/YaST2 \ -I/usr/include/libxml2 -I/usr/include/rpm \ -DG_LOG_DOMAIN=\"solver_detail\" @@ -14,6 +13,7 @@ include_HEADERS = \ debug.h \ utils.h \ extract.h \ + Ustring.h \ Hash.h \ Spec.h \ SpecPtr.h \ diff --git a/zypp/solver/detail/Match.cc b/zypp/solver/detail/Match.cc index 4fb03be..3fdf245 100644 --- a/zypp/solver/detail/Match.cc +++ b/zypp/solver/detail/Match.cc @@ -19,8 +19,6 @@ * 02111-1307, USA. */ -#include - #include #include #include @@ -30,7 +28,7 @@ ///////////////////////////////////////////////////////////////////////// -namespace zypp +namespace zypp { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// namespace solver @@ -38,114 +36,114 @@ namespace zypp ///////////////////////////////////////////////////////////////////// namespace detail { /////////////////////////////////////////////////////////////////// - + using namespace std; - - IMPL_BASE_POINTER(Match); - + + IMPL_PTR_TYPE(Match); + //--------------------------------------------------------------------------- - + string Match::asString ( void ) const { return toString (*this); } - - + + string Match::toString ( const Match & lock ) { return ""; } - - + + ostream & Match::dumpOn( ostream & str ) const { str << asString(); return str; } - - + + ostream& operator<<( ostream& os, const Match& edition) { return os << edition.asString(); } - + //--------------------------------------------------------------------------- - + Match::Match() : _importance (Importance::Undefined) { } - - Match::Match (XmlNodePtr node) + + Match::Match (XmlNode_Ptr node) : _importance (Importance::Undefined) { } - + Match::~Match() { } - + //--------------------------------------------------------------------------- - - XmlNodePtr + + XmlNode_Ptr Match::asXmlNode (void) const { return new XmlNode("match"); } - - + + // equality bool Match::equals ( const Match & lock ) const { - + // Check the name glob - + if ((_name_glob.empty()) ^ (lock._name_glob.empty())) return false; if (_name_glob != lock._name_glob) return false; - + // Check the channel - + if ((_channel_id.empty()) ^ (lock._channel_id.empty())) return false; if (_channel_id != lock._channel_id) return false; - + // Check the importance - + if (_importance != lock._importance || _importance_gteq != lock._importance_gteq) { return false; } - + // Check the dep if ( _dependency != lock._dependency) return false; - + return true; } - - + + bool - Match::test (constResItemPtr resItem, WorldPtr world) const + Match::test (ResItem_constPtr resItem, World_Ptr world) const { string name; - constChannelPtr channel = resItem->channel (); - + Channel_constPtr channel = resItem->channel (); + if (channel != NULL && !_channel_id.empty()) { if (! channel->hasEqualId (_channel_id)) { return false; } } - + name = resItem->name (); - + // FIXME, implement regexp #if 0 if (match->_pattern_spec @@ -153,7 +151,7 @@ namespace zypp return false; } #endif - + /* FIXME: ResItems don't have ResItemUpdate right now */ /* if (match->importance != RC_IMPORTANCE_INVALID && */ /* !rc_resItem_is_installed (resItem)) { */ @@ -164,10 +162,10 @@ namespace zypp /* return FALSE; */ /* } */ /* } */ - CapFactory factory; + CapFactory factory; Capability dependency; bool check = false; - + dependency = factory.parse ( resItem->kind(), resItem->name(), Rel::EQ, @@ -184,5 +182,5 @@ namespace zypp /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// };// namespace zypp -///////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////// diff --git a/zypp/solver/detail/Match.h b/zypp/solver/detail/Match.h index e5d6c41..470e35d 100644 --- a/zypp/solver/detail/Match.h +++ b/zypp/solver/detail/Match.h @@ -23,9 +23,11 @@ #define _Match_h #include -#include +#include -#include +#include "zypp/base/ReferenceCounted.h" +#include "zypp/base/NonCopyable.h" +#include "zypp/base/PtrTypes.h" #include #include @@ -35,7 +37,7 @@ #include ///////////////////////////////////////////////////////////////////////// -namespace zypp +namespace zypp { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// namespace solver @@ -45,74 +47,74 @@ namespace zypp { /////////////////////////////////////////////////////////////////// class Match; - typedef std::list MatchList; - + typedef std::list MatchList; + class World; - typedef bool (*MatchFn) (constMatchPtr match, void *data); - + typedef bool (*MatchFn) (Match_constPtr match, void *data); + /////////////////////////////////////////////////////////////////// // // CLASS NAME : Match /** * **/ - class Match : public CountedRep { - REP_BODY(Match); - + class Match : public base::ReferenceCounted, private base::NonCopyable { + + private: std::string _channel_id; - + Capability _dependency; - + std::string _name_glob; // GPatternSpec *_pattern_spec; - + Importance _importance; bool _importance_gteq; - + public: - + Match(); - Match(XmlNodePtr node); + Match(XmlNode_Ptr node); virtual ~Match(); - + // ---------------------------------- I/O - + static std::string toString ( const Match & lock ); - + virtual std::ostream & dumpOn( std::ostream & str ) const; - + friend std::ostream& operator<<( std::ostream&, const Match & lock ); - + std::string asString ( void ) const; - - XmlNodePtr asXmlNode (void) const; - + + XmlNode_Ptr asXmlNode (void) const; + // ---------------------------------- accessors - + const std::string & channelId () const { return _channel_id; } - void setChannel (constChannelPtr channel) { _channel_id = channel->id(); } + void setChannel (Channel_constPtr channel) { _channel_id = channel->id(); } void setChannelId (const std::string & channel_id) { _channel_id = channel_id; } - + const Capability & dependency () const { return _dependency; } void setDependency (const Capability & dependency) { _dependency = dependency; } - + const std::string & glob () const { return _name_glob; } void setGlob (const std::string & glob_str) { _name_glob = glob_str; } - + const Importance & importance (bool *match_gteq) const { *match_gteq = _importance_gteq; return _importance; } void setImportance (const Importance & importance, bool match_gteq) { _importance = importance; _importance_gteq = match_gteq; } - + // ---------------------------------- methods - - typedef bool (*MatchFn) (constMatchPtr, void *data); - + + typedef bool (*MatchFn) (Match_constPtr, void *data); + // equality bool equals (const Match & match) const; - - bool test (constResItemPtr resItem, WorldPtr world) const; + + bool test (ResItem_constPtr resItem, World_Ptr world) const; }; - + /////////////////////////////////////////////////////////////////// };// namespace detail ///////////////////////////////////////////////////////////////////// diff --git a/zypp/solver/detail/MatchPtr.h b/zypp/solver/detail/MatchPtr.h index 9bae824..ca59e2e 100644 --- a/zypp/solver/detail/MatchPtr.h +++ b/zypp/solver/detail/MatchPtr.h @@ -1,5 +1,5 @@ /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* MatchPtr.h +/* Match_Ptr.h * * Copyright (C) 2005 SUSE Linux Products GmbH * @@ -18,10 +18,10 @@ * 02111-1307, USA. */ -#ifndef _MatchPtr_h -#define _MatchPtr_h +#ifndef _Match_Ptr_h +#define _Match_Ptr_h -#include +#include "zypp/base/PtrTypes.h" ///////////////////////////////////////////////////////////////////////// namespace zypp @@ -34,10 +34,10 @@ namespace zypp { /////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// - // CLASS NAME : MatchPtr - // CLASS NAME : constMatchPtr + // CLASS NAME : Match_Ptr + // CLASS NAME : Match_constPtr /////////////////////////////////////////////////////////////////// - DEFINE_BASE_POINTER(Match); + DEFINE_PTR_TYPE(Match); /////////////////////////////////////////////////////////////////// };// namespace detail @@ -49,4 +49,4 @@ namespace zypp };// namespace zypp ///////////////////////////////////////////////////////////////////////// -#endif // _MatchPtr_h +#endif // _Match_Ptr_h diff --git a/zypp/solver/detail/MultiWorld.cc b/zypp/solver/detail/MultiWorld.cc index 50e3528..47e84f7 100644 --- a/zypp/solver/detail/MultiWorld.cc +++ b/zypp/solver/detail/MultiWorld.cc @@ -19,12 +19,12 @@ * 02111-1307, USA. */ -#include +#include #include #include ///////////////////////////////////////////////////////////////////////// -namespace zypp +namespace zypp { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// namespace solver @@ -32,90 +32,90 @@ namespace zypp ///////////////////////////////////////////////////////////////////// namespace detail { /////////////////////////////////////////////////////////////////// - + using namespace std; - + //=========================================================================== - + /////////////////////////////////////////////////////////////////// // // CLASS NAME : SubWorldInfo - + class SubWorldInfo { - + private: - WorldPtr _subworld; - WorldPtr _refreshed_subworld; - + World_Ptr _subworld; + World_Ptr _refreshed_subworld; + bool _refreshed_ready; - + unsigned int _changed_resItems_id; unsigned int _changed_channels_id; unsigned int _changed_subscriptions_id; unsigned int _changed_locks_id; - + public: - - SubWorldInfo (WorldPtr subworld, MultiWorldPtr multiworld); + + SubWorldInfo (World_Ptr subworld, MultiWorld_Ptr multiworld); virtual ~SubWorldInfo(); - + // ---------------------------------- I/O - + static std::string toString (const SubWorldInfo & subworldinfo); - + virtual std::ostream & dumpOn(std::ostream & str ) const; - + friend std::ostream& operator<<(std::ostream&, const SubWorldInfo & subworldinfo); - + std::string asString (void ) const; - + // ---------------------------------- accessors - - WorldPtr subworld () const { return _subworld; } - + + World_Ptr subworld () const { return _subworld; } + // ---------------------------------- methods - + }; - + //--------------------------------------------------------------------------- - + string SubWorldInfo::asString ( void ) const { return toString (*this); } - - + + string SubWorldInfo::toString ( const SubWorldInfo & subworldinfo ) { return ""; } - - + + ostream & SubWorldInfo::dumpOn( ostream & str ) const { str << asString(); return str; } - - + + ostream& operator<<( ostream& os, const SubWorldInfo & subworldinfo) { return os << subworldinfo.asString(); } - + //--------------------------------------------------------------------------- - - SubWorldInfo::SubWorldInfo (WorldPtr subworld, MultiWorldPtr multiworld) + + SubWorldInfo::SubWorldInfo (World_Ptr subworld, MultiWorld_Ptr multiworld) : _subworld (subworld) , _changed_resItems_id (0) , _changed_channels_id (0) , _changed_subscriptions_id (0) , _changed_locks_id (0) - + { #if 0 _changed_resItems_id = @@ -123,194 +123,194 @@ namespace zypp "changed_resItems", (GCallback) changed_resItems_cb, world); - + _changed_channels_id = g_signal_connect (G_OBJECT (subworld), "changed_channels", (GCallback) changed_channels_cb, world); - + _changed_subscriptions_id = g_signal_connect (G_OBJECT (subworld), "changed_subscriptions", (GCallback) changed_subscriptions_cb, world); - - _changed_locks_id = + + _changed_locks_id = g_signal_connect (G_OBJECT (subworld), "changed_locks", (GCallback) changed_locks_cb, world); #endif } - - + + SubWorldInfo::~SubWorldInfo() { } - - + + //=========================================================================== - + /////////////////////////////////////////////////////////////////// // // CLASS NAME : NameConflictInfo - + class NameConflictInfo { - + private: int _depth; - MultiWorldPtr _multiworld; - WorldPtr _subworld; + MultiWorld_Ptr _multiworld; + World_Ptr _subworld; const char *_name; - + public: - NameConflictInfo(int depth, MultiWorldPtr multiworld, WorldPtr subworld, const char *name); + NameConflictInfo(int depth, MultiWorld_Ptr multiworld, World_Ptr subworld, const char *name); virtual ~NameConflictInfo(); - + // ---------------------------------- I/O - + static std::string toString (const NameConflictInfo & nameconflictinfo); - + virtual std::ostream & dumpOn(std::ostream & str ) const; - + friend std::ostream& operator<<(std::ostream&, const NameConflictInfo & nameconflictinfo); - + std::string asString (void ) const; - + // ---------------------------------- accessors - + int depth () const { return _depth; } - MultiWorldPtr multiworld () const { return _multiworld; } - WorldPtr subworld () const { return _subworld; } + MultiWorld_Ptr multiworld () const { return _multiworld; } + World_Ptr subworld () const { return _subworld; } const char *name () const { return _name; } void setName (const char *name) { free((void *)_name); _name = strdup (name); } - + // ---------------------------------- methods - + void incDepth (void) { _depth++; } }; - - + + //--------------------------------------------------------------------------- - + string NameConflictInfo::asString ( void ) const { return toString (*this); } - - + + string NameConflictInfo::toString ( const NameConflictInfo & subworldinfo ) { return ""; } - - + + ostream & NameConflictInfo::dumpOn( ostream & str ) const { str << asString(); return str; } - - + + ostream& operator<<( ostream& os, const NameConflictInfo & subworldinfo) { return os << subworldinfo.asString(); } - + //--------------------------------------------------------------------------- - - NameConflictInfo::NameConflictInfo (int depth, MultiWorldPtr multiworld, WorldPtr subworld, const char *name) + + NameConflictInfo::NameConflictInfo (int depth, MultiWorld_Ptr multiworld, World_Ptr subworld, const char *name) : _depth (depth) , _multiworld (multiworld) , _subworld (subworld) , _name (strdup (name)) { } - - + + NameConflictInfo::~NameConflictInfo() { free ((void *)_name); } - - + + //=========================================================================== - - IMPL_DERIVED_POINTER(MultiWorld, World); - + + IMPL_PTR_TYPE(MultiWorld); + string MultiWorld::asString ( void ) const { return toString (*this); } - - + + string MultiWorld::toString ( const MultiWorld & world ) { return ""; } - - + + ostream & MultiWorld::dumpOn( ostream & str ) const { str << asString(); return str; } - - + + ostream& operator<<( ostream& os, const MultiWorld & world) { return os << world.asString(); } - + //--------------------------------------------------------------------------- - + MultiWorld::MultiWorld () : World (MULTI_WORLD) { } - - + + MultiWorld::~MultiWorld() { } - + //--------------------------------------------------------------------------- - + class ForeachByTypeInfo { public: WorldType type; WorldFn callback; NameConflictInfo *name_conflict_info; - + int count; }; - - + + int MultiWorld::foreachSubworld (WorldFn callback, void *user_data) { if (callback == NULL) return -1; - + /* Make a copy of subworlds for case where user callback is running main loop and a refresh starts at that time. */ - + WorldList copied_subworlds; - + for (SubWorldInfoList::iterator iter = _subworlds.begin(); iter != _subworlds.end(); iter++) { copied_subworlds.push_front ((*iter)->subworld()); } - + int count = 0; - + for (WorldList::const_iterator iter = copied_subworlds.begin(); iter != copied_subworlds.end(); iter++) { if (! callback (*iter, user_data)) { count = -1; @@ -318,22 +318,22 @@ namespace zypp } else ++count; } - + return count; } - - + + static bool - foreach_by_type_cb (constWorldPtr subworld, void *user_data) + foreach_by_type_cb (World_constPtr subworld, void *user_data) { ForeachByTypeInfo *info = (ForeachByTypeInfo *)user_data; - + if ((subworld->type() != info->type) || info->callback == NULL) { return true; } - + if (! info->callback (subworld, info->name_conflict_info)) { info->count = -1; return false; @@ -342,86 +342,86 @@ namespace zypp return true; } } - - + + int MultiWorld::foreachSubworldByType (WorldType type, WorldFn callback, NameConflictInfo *name_conflict_info) { ForeachByTypeInfo info; - + info.type = type; info.callback = callback; info.name_conflict_info = name_conflict_info; info.count = 0; - + foreachSubworld (foreach_by_type_cb, (void *)(&info)); - + return info.count; } - + //--------------------------------------------------------------------------- // subworld - + static bool - service_name_conflict_cb (constWorldPtr world, void *user_data) + service_name_conflict_cb (World_constPtr world, void *user_data) { - constServiceWorldPtr service = world; + ServiceWorld_constPtr service = dynamic_pointer_cast(world); if (service == NULL) { fprintf (stderr, "OOPS: service_name_conflict_cb: world is no service\n"); abort(); } - + NameConflictInfo *info = (NameConflictInfo *)user_data; if (!strcasecmp (service->name(), info->name())) { info->incDepth(); - ServiceWorldPtr infoservice = info->subworld(); + ServiceWorld_Ptr infoservice = dynamic_pointer_cast(info->subworld()); if (infoservice == NULL) { fprintf (stderr, "OOPS: service_name_conflict_cb: info->subworld is no service\n"); abort(); } - info->setName (stringutil::form ("%s (%d)", infoservice->name(), info->depth()).c_str()); + info->setName (str::form ("%s (%d)", infoservice->name(), info->depth()).c_str()); info->multiworld()->foreachSubworldByType (SERVICE_WORLD, service_name_conflict_cb, info); return false; } - + return true; } - - + + void - MultiWorld::addSubworld (WorldPtr subworld) + MultiWorld::addSubworld (World_Ptr subworld) { if (subworld == NULL) return; - - /* + + /* * If we're adding a service, make sure that the name of the service * doesn't conflict with any other. */ - ServiceWorldPtr service = subworld; // service will be NULL if subworld is not a ServiceWorld - + ServiceWorld_Ptr service = dynamic_pointer_cast(subworld); // service will be NULL if subworld is not a ServiceWorld + if (service != NULL) { NameConflictInfo conflict_info (0, this, subworld, service->name()); - + foreachSubworldByType (SERVICE_WORLD, service_name_conflict_cb, &conflict_info); - + service->setName (conflict_info.name()); } - + SubWorldInfo *subworld_info = new SubWorldInfo (subworld, this); - + _subworlds.push_back (subworld_info); - + // g_signal_emit (multi, signals[SUBWORLD_ADDED], 0, subworld); - + return; } - - + + void - MultiWorld::removeSubworld (WorldPtr subworld) + MultiWorld::removeSubworld (World_Ptr subworld) { if (subworld == NULL) return; - + for (SubWorldInfoList::iterator iter = _subworlds.begin(); iter != _subworlds.end(); iter++) { if ((*iter)->subworld() == subworld) { _subworlds.erase (iter); @@ -431,11 +431,11 @@ namespace zypp } return; } - - + + //--------------------------------------------------------------------------- // channels - + ChannelList MultiWorld::channels () const { @@ -446,10 +446,10 @@ namespace zypp } return cl; } - - + + bool - MultiWorld::containsChannel (constChannelPtr channel) const + MultiWorld::containsChannel (Channel_constPtr channel) const { for (SubWorldInfoList::const_iterator iter = _subworlds.begin(); iter != _subworlds.end(); iter++) { if ((*iter)->subworld()->containsChannel(channel)) @@ -457,12 +457,12 @@ namespace zypp } return false; } - - - ChannelPtr + + + Channel_Ptr MultiWorld::getChannelByName (const char *channel_name) const { - ChannelPtr channel; + Channel_Ptr channel; for (SubWorldInfoList::const_iterator iter = _subworlds.begin(); iter != _subworlds.end(); iter++) { channel = (*iter)->subworld()->getChannelByName(channel_name); if (channel != NULL) @@ -470,12 +470,12 @@ namespace zypp } return NULL; } - - - ChannelPtr + + + Channel_Ptr MultiWorld::getChannelByAlias (const char *alias) const { - ChannelPtr channel; + Channel_Ptr channel; for (SubWorldInfoList::const_iterator iter = _subworlds.begin(); iter != _subworlds.end(); iter++) { channel = (*iter)->subworld()->getChannelByAlias(alias); if (channel != NULL) @@ -483,12 +483,12 @@ namespace zypp } return NULL; } - - - ChannelPtr + + + Channel_Ptr MultiWorld::getChannelById (const char *channel_id) const { - ChannelPtr channel; + Channel_Ptr channel; for (SubWorldInfoList::const_iterator iter = _subworlds.begin(); iter != _subworlds.end(); iter++) { channel = (*iter)->subworld()->getChannelById(channel_id); if (channel != NULL) @@ -496,8 +496,8 @@ namespace zypp } return NULL; } - - + + int MultiWorld::foreachChannel (ChannelFn fn, void *data) const { @@ -511,15 +511,15 @@ namespace zypp } return count; } - - + + //--------------------------------------------------------------------------- // Single resItem queries - - constResItemPtr - MultiWorld::findInstalledResItem (constResItemPtr resItem) + + ResItem_constPtr + MultiWorld::findInstalledResItem (ResItem_constPtr resItem) { - constResItemPtr installed; + ResItem_constPtr installed; for (SubWorldInfoList::const_iterator iter = _subworlds.begin(); iter != _subworlds.end(); iter++) { installed = (*iter)->subworld()->findInstalledResItem(resItem); if (installed != NULL) @@ -527,12 +527,12 @@ namespace zypp } return NULL; } - - - constResItemPtr - MultiWorld::findResItem (constChannelPtr channel, const char *name) const + + + ResItem_constPtr + MultiWorld::findResItem (Channel_constPtr channel, const char *name) const { - constResItemPtr resItem; + ResItem_constPtr resItem; for (SubWorldInfoList::const_iterator iter = _subworlds.begin(); iter != _subworlds.end(); iter++) { resItem = (*iter)->subworld()->findResItem(channel, name); if (resItem != NULL) @@ -540,12 +540,12 @@ namespace zypp } return NULL; } - - - constResItemPtr - MultiWorld::findResItemWithConstraint (constChannelPtr channel, const char *name, const Capability & constraint, bool is_and) const + + + ResItem_constPtr + MultiWorld::findResItemWithConstraint (Channel_constPtr channel, const char *name, const Capability & constraint, bool is_and) const { - constResItemPtr resItem; + ResItem_constPtr resItem; for (SubWorldInfoList::const_iterator iter = _subworlds.begin(); iter != _subworlds.end(); iter++) { resItem = (*iter)->subworld()->findResItemWithConstraint(channel, name, constraint, is_and); if (resItem != NULL) @@ -553,12 +553,12 @@ namespace zypp } return NULL; } - - - ChannelPtr - MultiWorld::guessResItemChannel (constResItemPtr resItem) const + + + Channel_Ptr + MultiWorld::guessResItemChannel (ResItem_constPtr resItem) const { - ChannelPtr channel; + Channel_Ptr channel; for (SubWorldInfoList::const_iterator iter = _subworlds.begin(); iter != _subworlds.end(); iter++) { channel = (*iter)->subworld()->guessResItemChannel(resItem); if (channel != NULL) @@ -566,19 +566,19 @@ namespace zypp } return NULL; } - + //--------------------------------------------------------------------------- // iterate over resItems - + int - MultiWorld::foreachResItem (ChannelPtr channel, CResItemFn fn, void *data) + MultiWorld::foreachResItem (Channel_Ptr channel, CResItemFn fn, void *data) { return foreachResItemByName ("", channel, fn, data); } - - + + int - MultiWorld::foreachResItemByName (const std::string & name, ChannelPtr channel, CResItemFn fn, void *data) + MultiWorld::foreachResItemByName (const std::string & name, Channel_Ptr channel, CResItemFn fn, void *data) { int count = 0; for (SubWorldInfoList::const_iterator iter = _subworlds.begin(); iter != _subworlds.end(); iter++) { @@ -590,19 +590,19 @@ namespace zypp } return count; } - - + + int - MultiWorld::foreachResItemByMatch (constMatchPtr match, CResItemFn fn, void *data) + MultiWorld::foreachResItemByMatch (Match_constPtr match, CResItemFn fn, void *data) { fprintf (stderr, "MultiWorld::foreachResItemByMatch not implemented\n"); return 0; } - - + + //----------------------------------------------------------------------------- // iterater over resItems with dependency - + int MultiWorld::foreachProvidingResItem (const Capability & dep, ResItemAndDepFn fn, void *data) { @@ -616,7 +616,7 @@ namespace zypp } return count; } - + int MultiWorld::foreachRequiringResItem (const Capability & dep, ResItemAndDepFn fn, void *data) { @@ -630,7 +630,7 @@ namespace zypp } return count; } - + int MultiWorld::foreachConflictingResItem (const Capability & dep, ResItemAndDepFn fn, void *data) { @@ -644,11 +644,11 @@ namespace zypp } return count; } - - + + //----------------------------------------------------------------------------- // iterater over resItems with locks - + int MultiWorld::foreachLock (MatchFn fn, void *data) const { @@ -662,7 +662,7 @@ namespace zypp } return count; } - + /////////////////////////////////////////////////////////////////// };// namespace detail ///////////////////////////////////////////////////////////////////// diff --git a/zypp/solver/detail/MultiWorld.h b/zypp/solver/detail/MultiWorld.h index 3fcff8a..185d511 100644 --- a/zypp/solver/detail/MultiWorld.h +++ b/zypp/solver/detail/MultiWorld.h @@ -23,7 +23,7 @@ #define _MultiWorld_h #include -#include +#include #include #include @@ -52,22 +52,22 @@ typedef std::list SubWorldInfoList; // CLASS NAME : MultiWorld class MultiWorld : public World { - REP_BODY(MultiWorld); + private: SubWorldInfoList _subworlds; - PendingPtr _multi_pending; + Pending_Ptr _multi_pending; PendingList _subworld_pendings; - void (*_subworld_added) (WorldPtr subworld); - void (*_subworld_removed) (WorldPtr subworld); + void (*_subworld_added) (World_Ptr subworld); + void (*_subworld_removed) (World_Ptr subworld); public: MultiWorld (); - MultiWorld (XmlNodePtr node); + MultiWorld (XmlNode_Ptr node); MultiWorld (const char *filename); virtual ~MultiWorld(); @@ -83,37 +83,37 @@ class MultiWorld : public World { // ---------------------------------- accessors - void addSubworld (WorldPtr subworld); - void removeSubworld (WorldPtr subworld); + void addSubworld (World_Ptr subworld); + void removeSubworld (World_Ptr subworld); // ---------------------------------- methods virtual ChannelList channels () const; - virtual bool containsChannel (constChannelPtr channel) const; - virtual ChannelPtr getChannelByName (const char *channel_name) const; - virtual ChannelPtr getChannelByAlias (const char *alias) const; - virtual ChannelPtr getChannelById (const char *channel_id) const; - virtual ChannelPtr guessResItemChannel (constResItemPtr resItem) const; + virtual bool containsChannel (Channel_constPtr channel) const; + virtual Channel_Ptr getChannelByName (const char *channel_name) const; + virtual Channel_Ptr getChannelByAlias (const char *alias) const; + virtual Channel_Ptr getChannelById (const char *channel_id) const; + virtual Channel_Ptr guessResItemChannel (ResItem_constPtr resItem) const; virtual int foreachChannel (ChannelFn fn, void *data) const; int foreachSubworld (WorldFn callback, void *user_data); int foreachSubworldByType (WorldType type, WorldFn callback, NameConflictInfo *info); WorldList getSubworlds (); - ServiceWorldPtr lookupService (const char *url); - ServiceWorldPtr lookupServiceById (const char *id); + ServiceWorld_Ptr lookupService (const char *url); + ServiceWorld_Ptr lookupServiceById (const char *id); bool mountService (const char *url, void *error); // GError **error); // Single resItem queries - virtual constResItemPtr findInstalledResItem (constResItemPtr resItem); - virtual constResItemPtr findResItem (constChannelPtr channel, const char *name) const; - virtual constResItemPtr findResItemWithConstraint (constChannelPtr channel, const char *name, const Capability & constraint, bool is_and) const; + virtual ResItem_constPtr findInstalledResItem (ResItem_constPtr resItem); + virtual ResItem_constPtr findResItem (Channel_constPtr channel, const char *name) const; + virtual ResItem_constPtr findResItemWithConstraint (Channel_constPtr channel, const char *name, const Capability & constraint, bool is_and) const; // Iterate over resItems - virtual int foreachResItem (ChannelPtr channel, CResItemFn fn, void *data); - virtual int foreachResItemByName (const std::string & name, ChannelPtr channel, CResItemFn fn, void *data); - virtual int foreachResItemByMatch (constMatchPtr match, CResItemFn fn, void *data); + virtual int foreachResItem (Channel_Ptr channel, CResItemFn fn, void *data); + virtual int foreachResItemByName (const std::string & name, Channel_Ptr channel, CResItemFn fn, void *data); + virtual int foreachResItemByMatch (Match_constPtr match, CResItemFn fn, void *data); // Iterate across provides or requirement diff --git a/zypp/solver/detail/MultiWorldPtr.h b/zypp/solver/detail/MultiWorldPtr.h index 813772c..39b0368 100644 --- a/zypp/solver/detail/MultiWorldPtr.h +++ b/zypp/solver/detail/MultiWorldPtr.h @@ -1,5 +1,5 @@ /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* MultiWorldPtr.h +/* MultiWorld_Ptr.h * * Copyright (C) 2005 SUSE Linux Products GmbH * @@ -18,10 +18,10 @@ * 02111-1307, USA. */ -#ifndef _MultiWorldPtr_h -#define _MultiWorldPtr_h +#ifndef _MultiWorld_Ptr_h +#define _MultiWorld_Ptr_h -#include +#include "zypp/base/PtrTypes.h" #include ///////////////////////////////////////////////////////////////////////// @@ -35,10 +35,10 @@ namespace zypp { /////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// - // CLASS NAME : MultiWorldPtr - // CLASS NAME : constMultiWorldPtr + // CLASS NAME : MultiWorld_Ptr + // CLASS NAME : MultiWorld_constPtr /////////////////////////////////////////////////////////////////// - DEFINE_DERIVED_POINTER(MultiWorld, World); + DEFINE_PTR_TYPE(MultiWorld); /////////////////////////////////////////////////////////////////// };// namespace detail @@ -50,4 +50,4 @@ namespace zypp };// namespace zypp ///////////////////////////////////////////////////////////////////////// -#endif // _MultiWorldPtr_h +#endif // _MultiWorld_Ptr_h diff --git a/zypp/solver/detail/Package.cc b/zypp/solver/detail/Package.cc index 046c0d8..88784f7 100644 --- a/zypp/solver/detail/Package.cc +++ b/zypp/solver/detail/Package.cc @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include #include @@ -32,7 +32,7 @@ ///////////////////////////////////////////////////////////////////////// -namespace zypp +namespace zypp { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// namespace solver @@ -40,11 +40,11 @@ namespace zypp ///////////////////////////////////////////////////////////////////// namespace detail { /////////////////////////////////////////////////////////////////// - + using namespace std; - - IMPL_DERIVED_POINTER(Package,ResItem); - + + IMPL_PTR_TYPE(Package); + struct DepTable { CapSet requires; CapSet provides; @@ -54,22 +54,22 @@ namespace zypp CapSet suggests; CapSet recommends; }; - + //--------------------------------------------------------------------------- - static Capability - parseXmlDep (constXmlNodePtr node) { + static Capability + parseXmlDep (XmlNode_constPtr node) { const char *tmp; string epoch,version,release,name = ""; Arch arch = Arch_noarch; Rel relation; - CapFactory factory; - + CapFactory factory; + if (!node->equals("dep")) { fprintf (stderr, "parseXmlDep bad node\n"); abort(); } - + name = node->getProp ("name"); tmp = node->getProp ("op", NULL); if (tmp) { @@ -78,90 +78,90 @@ namespace zypp version = node->getProp ("version"); release = node->getProp ("release"); } - + tmp = node->getProp ("arch", NULL); if (tmp) { arch = Arch(node->getProp ("arch")); } else { arch = Arch(); } - + return factory.parse ( ResTraits::kind, name, relation, Edition (version, release, epoch)); } - + static void - extract_dep_info (constXmlNodePtr iter, struct DepTable & dep_table) + extract_dep_info (XmlNode_constPtr iter, struct DepTable & dep_table) { if (iter->equals("requires")) { - constXmlNodePtr iter2; - + XmlNode_constPtr iter2; + iter2 = iter->children(); - + while (iter2) { if (!iter2->isElement()) { iter2 = iter2->next(); continue; } - + dep_table.requires.insert(parseXmlDep (iter2)); iter2 = iter2->next(); } - + } else if (iter->equals("recommends")) { - constXmlNodePtr iter2; - + XmlNode_constPtr iter2; + iter2 = iter->children(); - + while (iter2) { if (!iter2->isElement()) { iter2 = iter2->next(); continue; } - + dep_table.recommends.insert (parseXmlDep (iter2)); iter2 = iter2->next(); } - + } else if (iter->equals("suggests")) { - constXmlNodePtr iter2; - + XmlNode_constPtr iter2; + iter2 = iter->children(); - + while (iter2) { if (!iter2->isElement()) { iter2 = iter2->next(); continue; } - + dep_table.suggests.insert (parseXmlDep (iter2)); iter2 = iter2->next(); } - + } else if (iter->equals("conflicts")) { - XmlNodePtr iter2; + XmlNode_Ptr iter2; bool all_are_obs = false, this_is_obs = false; const char *obs; - + iter2 = iter->children(); - + obs = iter->getProp ("obsoletes", NULL); if (obs) { all_are_obs = true; free ((void *)obs); } - + while (iter2) { - + if (!iter2->isElement()) { iter2 = iter2->next(); continue; } - + Capability dep = parseXmlDep(iter2); - + if (! all_are_obs) { this_is_obs = false; obs = iter2->getProp ("obsoletes", NULL); @@ -170,73 +170,73 @@ namespace zypp free ((void *)obs); } } - + if (all_are_obs || this_is_obs) { dep_table.obsoletes.insert (dep); } else { dep_table.conflicts.insert (dep); } - + iter2 = iter2->next(); } - + } else if (iter->equals("obsoletes")) { - constXmlNodePtr iter2; - + XmlNode_constPtr iter2; + iter2 = iter->children(); - + while (iter2) { if (!iter2->isElement()) { iter2 = iter2->next(); continue; } - + dep_table.obsoletes.insert (parseXmlDep (iter2)); iter2 = iter2->next(); } - + } else if (iter->equals("provides")) { - constXmlNodePtr iter2; - + XmlNode_constPtr iter2; + iter2 = iter->children(); - + while (iter2) { if (!iter2->isElement()) { iter2 = iter2->next(); continue; } - + dep_table.provides.insert (parseXmlDep (iter2)); iter2 = iter2->next(); } - + } else if (iter->equals("children")) { - constXmlNodePtr iter2; - + XmlNode_constPtr iter2; + iter2 = iter->children(); - + while (iter2) { if (!iter2->isElement()) { iter2 = iter2->next(); continue; } - + dep_table.children.insert (parseXmlDep (iter2)); iter2 = iter2->next(); } } } - + //--------------------------------------------------------------------------- - - + + string Package::asString ( bool full ) const { return toString (*this, full); } - - + + string Package::toString ( const PackageUpdateList & l, bool full ) { @@ -247,7 +247,7 @@ namespace zypp } return ret + "]"; } - + string Package::toString ( const Package & package, bool full ) { @@ -262,25 +262,25 @@ namespace zypp } return ret; } - - + + ostream & Package::dumpOn( ostream & str ) const { str << asString(); return str; } - - + + ostream& operator<<( ostream& os, const Package& package) { return os << package.asString(); } - + //--------------------------------------------------------------------------- - - Package::Package (constChannelPtr channel) + + Package::Package (Channel_constPtr channel) : ResItem (ResTraits::kind, "") , _section (NULL) , _pretty_name ("") @@ -296,7 +296,7 @@ namespace zypp } - Package::Package (constChannelPtr channel, + Package::Package (Channel_constPtr channel, const string & name, const Edition & edition, const Arch arch) @@ -320,9 +320,9 @@ namespace zypp pkgImpl ) ); _resObject = pkg; } - - - Package::Package (constXmlNodePtr node, constChannelPtr channel) + + + Package::Package (XmlNode_constPtr node, Channel_constPtr channel) : ResItem (ResTraits::kind, "") , _section (NULL) , _pretty_name ("") @@ -339,21 +339,21 @@ namespace zypp string version = ""; string release = ""; Arch arch = Arch_noarch; - + if (!node->equals("package")) { fprintf (stderr, "Package::Package() not a package node\n"); exit (1); } - + struct DepTable dep_table; - + setChannel (channel); - - constXmlNodePtr iter = node->children(); - + + XmlNode_constPtr iter = node->children(); + while (iter) { bool extracted_deps = false; - + if (iter->equals("name")) { name = iter->getContent(); } else if (iter->equals("epoch")) { epoch = atoi (iter->getContent()); } else if (iter->equals("version")) { version = iter->getContent(); @@ -362,7 +362,7 @@ namespace zypp } else if (iter->equals("description")) { _description = strdup (iter->getContent()); } else if (iter->equals("section")) { _section = new Section (iter->getContent()); } else if (iter->equals("arch")) { arch = Arch(iter->getContent()); - } else if (iter->equals("filesize")) { + } else if (iter->equals("filesize")) { const char *tmp = iter->getContent(); setFileSize (tmp && *tmp ? atoi (tmp) : 0); free ((void *)tmp); @@ -373,31 +373,31 @@ namespace zypp } else if (iter->equals("install_only")) { _install_only = true; } else if (iter->equals("package_set")) { _package_set = true; } else if (iter->equals("history")) { - constXmlNodePtr iter2; - + XmlNode_constPtr iter2; + iter2 = iter->children(); - + while (iter2) { if (!iter2->isElement()) { iter2 = iter2->next(); continue; } - - PackageUpdatePtr update = new PackageUpdate (iter2, this); + + PackageUpdate_Ptr update = new PackageUpdate (iter2, this); addUpdate (update); - + iter2 = iter2->next(); } } else if (iter->equals("deps")) { - constXmlNodePtr iter2; - + XmlNode_constPtr iter2; + for (iter2 = iter->children(); iter2; iter2 = iter2->next()) { if (!iter2->isElement()) continue; - + extract_dep_info (iter2, dep_table); } - + extracted_deps = true; } else { @@ -407,10 +407,10 @@ namespace zypp /* FIXME: Bitch to the user here? */ } } - + iter = iter->next(); } - + if (!dep_table.children.empty()) { // children are used in package sets // treat them as normal requires @@ -422,17 +422,17 @@ namespace zypp dep_table.requires.insert (*iter); } } - - + + // check if we're already listed in the provides // if not, provide ourself - CapFactory factory; + CapFactory factory; Capability selfdep = factory.parse ( ResTraits::kind, name, Rel::EQ, Edition( version, release, zypp::str::numstring(epoch))); - + CapSet::const_iterator piter; for (piter = dep_table.provides.begin(); piter != dep_table.provides.end(); piter++) { if ((*piter) == selfdep) @@ -444,7 +444,7 @@ namespace zypp _DBG("RC_SPEW") << "Adding self-provide [" << selfdep.asString() << "]" << endl; dep_table.provides.insert (selfdep); } - + Dependencies deps; deps.setRequires (dep_table.requires); deps.setProvides (dep_table.provides); @@ -453,27 +453,27 @@ namespace zypp deps.setSuggests (dep_table.suggests); deps.setRecommends (dep_table.recommends); setDependencies (deps); - + if (!_history.empty()) { - + /* If possible, we grab the version info from the most recent update. */ - - PackageUpdatePtr update = _history.front(); - + + PackageUpdate_Ptr update = _history.front(); + epoch = update->package()->epoch(); version = update->package()->version(); release = update->package()->release(); - + } -#if 0 //Is this really needed ? +#if 0 //Is this really needed ? else { - + /* Otherwise, try to find where the package provides itself, and use that version info. */ - + if (!provides().empty()) - for (CapSet::const_iterator iter = provides().begin(); iter != provides().end(); iter++) { + for (CapSet::const_iterator iter = provides().begin(); iter != provides().end(); iter++) { if ((*iter)->relation() == Rel::EQ && ((*iter)->name() == name)) { @@ -485,38 +485,39 @@ namespace zypp } } #endif - + Edition _edition( version, release, zypp::str::numstring(epoch) ); shared_ptr pkgImpl; zypp::Package::Ptr pkg( zypp::detail::makeResolvableAndImpl( name, _edition, arch, pkgImpl ) ); _resObject = pkg; } - + Package::~Package() { } - + //--------------------------------------------------------------------------- - - + + void - Package::addUpdate (PackageUpdatePtr update) + Package::addUpdate (PackageUpdate_Ptr update) { if (update == NULL) return; - - assert (update->package() == NULL || update->package() == this); - + + assert (update->package() == NULL + || update->package() == const_cast(this)); + update->setPackage(this); - + if (_history.empty()) { _history.push_back (update); } else { #warning addUpdate incomplete #if 1 for (PackageUpdateList::iterator iter = _history.begin(); iter != _history.end(); iter++) { - int result = Spec::compare ((SpecPtr)update, (SpecPtr)(*iter)); - + int result = Spec::compare ((Spec_Ptr)update, (Spec_Ptr)(*iter)); + if (result > 0 || (result == 0 && update->parent() != NULL)) { _history.insert (iter, update); // = g_slist_insert_before (package->history, l, update); break; @@ -529,52 +530,52 @@ namespace zypp #endif } } - - - PackageUpdatePtr + + + PackageUpdate_Ptr Package::getLatestUpdate (void) const { - WorldPtr world; - + World_Ptr world; + if (_history.empty()) { return NULL; } - - PackageUpdatePtr latest = _history.back(); + + PackageUpdate_Ptr latest = _history.back(); /* if the absolute latest is not a patch, just return that */ if (latest->parent() == NULL) { return latest; } - + world = World::globalWorld(); - + for (PackageUpdateList::const_iterator l = _history.begin(); l != _history.end(); l++) { - PackageUpdatePtr update = *l; - constResItemPtr installed; - + PackageUpdate_Ptr update = *l; + ResItem_constPtr installed; + if (!update->equals (latest)) { return NULL; } - + /* found a non-patch package equal to the latest, so use that */ if (update->parent() == NULL) { return update; } - + /* see if the required parent for this patch is installed */ - + installed = world->findInstalledResItem (update->parent()); - + if (installed != NULL && installed->equals(update->parent())) return update; } - + /* no suitable update found */ return NULL; } - - + + #if 0 xmlNode * rc_package_to_xml_node (RCPackage *package) @@ -588,53 +589,53 @@ namespace zypp int i; char buffer[128]; char *tmp_str; - + r = RC_RESOLVABLE (package); spec = rc_resItem_get_spec (r); - + package_node = xmlNewNode (NULL, "package"); - + xmlNewTextChild (package_node, NULL, "name", rc_resItem_get_name (r)); - + if (spec->has_epoch) { g_snprintf (buffer, 128, "%d", spec->epoch); xmlNewTextChild (package_node, NULL, "epoch", buffer); } - + xmlNewTextChild (package_node, NULL, "version", spec->version); - + if (spec->release) { xmlNewTextChild (package_node, NULL, "release", spec->release); } - + tmp_str = sanitize_string (package->summary); xmlNewTextChild (package_node, NULL, "summary", tmp_str); g_free (tmp_str); - + tmp_str = sanitize_string (package->description); xmlNewTextChild (package_node, NULL, "description", tmp_str); g_free (tmp_str); - + xmlNewTextChild (package_node, NULL, "arch", rc_arch_to_string (spec->arch)); - + xmlNewTextChild (package_node, NULL, "section", rc_package_section_to_string (package->section)); - + g_snprintf (buffer, 128, "%u", rc_resItem_get_file_size (r)); xmlNewTextChild (package_node, NULL, "filesize", buffer); - + g_snprintf (buffer, 128, "%u", rc_resItem_get_installed_size (r)); xmlNewTextChild (package_node, NULL, "installedsize", buffer); - + if (package->install_only) { xmlNewTextChild (package_node, NULL, "install_only", "1"); } - + if (package->package_set) { xmlNewTextChild (package_node, NULL, "package_set", "1"); } - + if (package->history) { tmp_node = xmlNewChild (package_node, NULL, "history", NULL); for (history_iter = package->history; history_iter; @@ -644,68 +645,68 @@ namespace zypp xmlAddChild (tmp_node, rc_package_update_to_xml_node (update)); } } - + deps_node = xmlNewChild (package_node, NULL, "deps", NULL); - + if (r->requires_a) { tmp_node = xmlNewChild (deps_node, NULL, "requires", NULL); for (i = 0; i < r->requires_a->len; i++) { RCResItemDep *dep = r->requires_a->data[i]; - + xmlAddChild (tmp_node, rc_resItem_dep_to_xml_node (dep)); } } - + if (r->recommends_a) { tmp_node = xmlNewChild (deps_node, NULL, "recommends", NULL); for (i = 0; i < r->recommends_a->len; i++) { RCResItemDep *dep = r->recommends_a->data[i]; - + xmlAddChild (tmp_node, rc_resItem_dep_to_xml_node (dep)); } } - + if (r->suggests_a) { tmp_node = xmlNewChild (deps_node, NULL, "suggests", NULL); for (i = 0; i < r->suggests_a->len; i++) { RCResItemDep *dep = r->suggests_a->data[i]; - + xmlAddChild (tmp_node, rc_resItem_dep_to_xml_node (dep)); } } - + if (r->conflicts_a) { tmp_node = xmlNewChild (deps_node, NULL, "conflicts", NULL); for (i = 0; i < r->conflicts_a->len; i++) { RCResItemDep *dep = r->conflicts_a->data[i]; - + xmlAddChild (tmp_node, rc_resItem_dep_to_xml_node (dep)); } } - + if (r->obsoletes_a) { tmp_node = xmlNewChild (deps_node, NULL, "obsoletes", NULL); for (i = 0; i < r->obsoletes_a->len; i++) { RCResItemDep *dep = r->obsoletes_a->data[i]; - + xmlAddChild (tmp_node, rc_resItem_dep_to_xml_node (dep)); } } - + if (r->provides_a) { tmp_node = xmlNewChild (deps_node, NULL, "provides", NULL); for (i = 0; i < r->provides_a->len; i++) { RCResItemDep *dep = r->provides_a->data[i]; - + xmlAddChild (tmp_node, rc_resItem_dep_to_xml_node (dep)); } } - + return (package_node); } /* rc_package_to_xml_node */ - + #endif - + /////////////////////////////////////////////////////////////////// };// namespace detail ///////////////////////////////////////////////////////////////////// diff --git a/zypp/solver/detail/Package.h b/zypp/solver/detail/Package.h index cd4f570..41e026d 100644 --- a/zypp/solver/detail/Package.h +++ b/zypp/solver/detail/Package.h @@ -24,7 +24,7 @@ #include #include -#include +#include #include #include @@ -43,11 +43,11 @@ namespace zypp namespace detail { /////////////////////////////////////////////////////////////////// -typedef std::list PackageList; -typedef PackageList * PackageListPtr; +typedef std::list PackageList; +typedef PackageList * PackageList_Ptr; -typedef std::list PackageUpdateList; -typedef PackageUpdateList * PackageUpdateListPtr; +typedef std::list PackageUpdateList; +typedef PackageUpdateList * PackageUpdateList_Ptr; /////////////////////////////////////////////////////////////////// @@ -58,10 +58,10 @@ typedef PackageUpdateList * PackageUpdateListPtr; **/ class Package : public ResItem { - REP_BODY(Package); + private: - SectionPtr _section; + Section_Ptr _section; // Filled in by package info XML std::string _pretty_name; @@ -82,12 +82,12 @@ class Package : public ResItem { public: - Package(constChannelPtr channel); - Package(constChannelPtr channel, + Package(Channel_constPtr channel); + Package(Channel_constPtr channel, const std::string & name = "", const Edition & edition = Edition::noedition, const Arch arch = Arch_noarch); - Package(constXmlNodePtr node, constChannelPtr channel); //RCPackage *rc_xml_node_to_package (const xmlNode *node, const RCChannel *channel); + Package(XmlNode_constPtr node, Channel_constPtr channel); //RCPackage *rc_xml_node_to_package (const xmlNode *node, const RCChannel *channel); virtual ~Package(); // ---------------------------------- I/O @@ -107,8 +107,8 @@ class Package : public ResItem { // ---------------------------------- accessors // accessor for _section - const SectionPtr section() const { return _section; } - void setSection (const SectionPtr section) { _section = section; } + const Section_Ptr section() const { return _section; } + void setSection (const Section_Ptr section) { _section = section; } // accessor for _pretty_name const std::string prettyName() const { return _pretty_name; } @@ -148,9 +148,9 @@ class Package : public ResItem { // ---------------------------------- methods - void addUpdate (PackageUpdatePtr update); + void addUpdate (PackageUpdate_Ptr update); - PackageUpdatePtr getLatestUpdate (void) const; + PackageUpdate_Ptr getLatestUpdate (void) const; }; /////////////////////////////////////////////////////////////////// diff --git a/zypp/solver/detail/PackagePtr.h b/zypp/solver/detail/PackagePtr.h index 8f350ee..b555dc1 100644 --- a/zypp/solver/detail/PackagePtr.h +++ b/zypp/solver/detail/PackagePtr.h @@ -1,5 +1,5 @@ /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* PackagePtr.h +/* Package_Ptr.h * * Copyright (C) 2005 SUSE Linux Products GmbH * @@ -18,10 +18,10 @@ * 02111-1307, USA. */ -#ifndef _PackagePtr_h -#define _PackagePtr_h +#ifndef _Package_Ptr_h +#define _Package_Ptr_h -#include +#include "zypp/base/PtrTypes.h" #include ///////////////////////////////////////////////////////////////////////// @@ -35,10 +35,10 @@ namespace zypp { /////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// - // CLASS NAME : PackagePtr - // CLASS NAME : constPackagePtr + // CLASS NAME : Package_Ptr + // CLASS NAME : Package_constPtr /////////////////////////////////////////////////////////////////// - DEFINE_DERIVED_POINTER(Package,ResItem); + DEFINE_PTR_TYPE(Package); /////////////////////////////////////////////////////////////////// };// namespace detail ///////////////////////////////////////////////////////////////////// @@ -50,4 +50,4 @@ namespace zypp ///////////////////////////////////////////////////////////////////////// -#endif // _PackagePtr_h +#endif // _Package_Ptr_h diff --git a/zypp/solver/detail/PackageUpdate.cc b/zypp/solver/detail/PackageUpdate.cc index 0fff512..17e4a61 100644 --- a/zypp/solver/detail/PackageUpdate.cc +++ b/zypp/solver/detail/PackageUpdate.cc @@ -19,18 +19,17 @@ * 02111-1307, USA. */ -#include - #include -#include +#include #include +#include #include #include #include ///////////////////////////////////////////////////////////////////////// -namespace zypp +namespace zypp { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// namespace solver @@ -38,101 +37,101 @@ namespace zypp ///////////////////////////////////////////////////////////////////// namespace detail { /////////////////////////////////////////////////////////////////// - + using namespace std; - - IMPL_DERIVED_POINTER(PackageUpdate, Spec); - + + IMPL_PTR_TYPE(PackageUpdate); + //--------------------------------------------------------------------------- - + string PackageUpdate::asString ( bool full ) const { return toString (*this); } - - + + string PackageUpdate::toString ( const PackageUpdate & package_update, bool full ) { string ret; ret += ((const Spec &)package_update).asString(full); - + return ret; } - - + + ostream & PackageUpdate::dumpOn( ostream & str ) const { str << asString(); return str; } - - + + ostream& operator<<( ostream& os, const PackageUpdate& package_update) { return os << package_update.asString(); } - - - const XmlNodePtr + + + const XmlNode_Ptr PackageUpdate::asXmlNode (void) const { - XmlNodePtr update_node = new XmlNode("update"); + XmlNode_Ptr update_node = new XmlNode("update"); string tmp; - + if (hasEpoch()) { - tmp = stringutil::form("%d", epoch()); + tmp = str::form("%d", epoch()); update_node->addTextChild ("epoch", tmp.c_str()); } - + update_node->addTextChild ("version", version().c_str()); - + if (!release().empty()) { update_node->addTextChild ("release", release().c_str()); } - + if (_package_url && *_package_url) { update_node->addTextChild ("filename", basename (strdup (_package_url))); } - - tmp = stringutil::form ("%ld", (unsigned long)_package_size); + + tmp = str::form ("%ld", (unsigned long)_package_size); update_node->addTextChild ("filesize", tmp.c_str()); - - tmp = stringutil::form ("%ld", (unsigned long)_installed_size); + + tmp = str::form ("%ld", (unsigned long)_installed_size); update_node->addTextChild ("installedsize", tmp.c_str()); - + if (_signature_url) { update_node->addTextChild ("signaturename", _signature_url); - - tmp = stringutil::form ("%ld", (unsigned long)_signature_size); + + tmp = str::form ("%ld", (unsigned long)_signature_size); update_node->addTextChild ("signaturesize", tmp.c_str()); } - + if (_md5sum) { update_node->addTextChild ("md5sum", _md5sum); } - + update_node->addTextChild ("importance", _importance->asString().c_str()); - + update_node->addTextChild ("description", _description); - + if (_hid) { - tmp = stringutil::form ("%d", _hid); + tmp = str::form ("%d", _hid); update_node->addTextChild ("hid", tmp.c_str()); } - + if (_license) { update_node->addTextChild ("license", _license); } - + return update_node; } - + //--------------------------------------------------------------------------- - + PackageUpdate::PackageUpdate (const string & name) : Spec (ResTraits::kind, name) , _package (NULL) @@ -149,9 +148,9 @@ namespace zypp , _parent (NULL) { } - - - PackageUpdate::PackageUpdate (constXmlNodePtr node, PackagePtr package) + + + PackageUpdate::PackageUpdate (XmlNode_constPtr node, Package_Ptr package) : Spec (ResTraits::kind, package->name()) , _package (NULL) , _package_url (NULL) @@ -166,31 +165,31 @@ namespace zypp , _license (NULL) , _parent (NULL) { - constChannelPtr channel; + Channel_constPtr channel; const char *url_prefix = NULL; - + if (node == NULL) { fprintf (stderr, "PackageUpdate::PackageUpdate(NULL)\n"); exit (1); } - + /* Make sure this is an update node */ if (strcasecmp (node->name(), "update")) { fprintf (stderr, "PackageUpdate::PackageUpdate() wrong node (%s)\n", node->name()); exit (1); } - + channel = package->channel(); - + _package = package; - + if (channel) { url_prefix = channel->filePath(); } - - XmlNodePtr iter = node->children(); - - while (iter) { + + XmlNode_Ptr iter = node->children(); + + while (iter) { if (iter->equals ("epoch")) { setEpoch (iter->getUnsignedIntContentDefault (0)); } else if (iter->equals ("version")) { setVersion (iter->getContent()); } else if (iter->equals ("release")) { setRelease (iter->getContent()); @@ -218,12 +217,12 @@ namespace zypp } else if (iter->equals ("hid")) { _hid = iter->getUnsignedIntContentDefault (0); } else if (iter->equals ("license")) { _license = iter->getContent(); } - + iter = iter->next(); } } - - + + PackageUpdate::~PackageUpdate() { if (_package != NULL) _package = NULL; @@ -234,7 +233,7 @@ namespace zypp if (_license != NULL) free ((void *)_license); if (_parent != NULL) _parent = NULL; } - + /////////////////////////////////////////////////////////////////// };// namespace detail ///////////////////////////////////////////////////////////////////// diff --git a/zypp/solver/detail/PackageUpdate.h b/zypp/solver/detail/PackageUpdate.h index b99d129..7b99e3f 100644 --- a/zypp/solver/detail/PackageUpdate.h +++ b/zypp/solver/detail/PackageUpdate.h @@ -24,7 +24,7 @@ #include #include -#include +#include #include #include @@ -51,10 +51,10 @@ namespace zypp **/ class PackageUpdate : public Spec { - REP_BODY(PackageUpdate); + private: - PackagePtr _package; + Package_Ptr _package; const char *_package_url; size_t _package_size; @@ -74,18 +74,18 @@ class PackageUpdate : public Spec { const char *_license; // refers to the parent package for SuSE patch RPMs - constPackagePtr _parent; + Package_constPtr _parent; public: PackageUpdate(const std::string & name); - PackageUpdate(constXmlNodePtr node, PackagePtr package); + PackageUpdate(XmlNode_constPtr node, Package_Ptr package); virtual ~PackageUpdate(); // ---------------------------------- I/O - const XmlNodePtr asXmlNode (void) const; + const XmlNode_Ptr asXmlNode (void) const; static std::string toString ( const PackageUpdate & packageupdate, bool full = false ); @@ -97,8 +97,8 @@ class PackageUpdate : public Spec { // ---------------------------------- accessors - constPackagePtr package() const { return _package; } - void setPackage (PackagePtr package) { _package = package; } + Package_constPtr package() const { return _package; } + void setPackage (Package_Ptr package) { _package = package; } const char *packageUrl() const { return _package_url; } void setPackageUrl (const char *package_url) { _package_url = package_url; } @@ -131,8 +131,8 @@ class PackageUpdate : public Spec { void setLicense (const char *license) { _license = license; } // refers to the parent package for SuSE patch RPMs - constPackagePtr parent() const { return _parent; } - void setParent (constPackagePtr parent) { _parent = parent; } + Package_constPtr parent() const { return _parent; } + void setParent (Package_constPtr parent) { _parent = parent; } // ---------------------------------- methods diff --git a/zypp/solver/detail/PackageUpdatePtr.h b/zypp/solver/detail/PackageUpdatePtr.h index efc6aff..629c361 100644 --- a/zypp/solver/detail/PackageUpdatePtr.h +++ b/zypp/solver/detail/PackageUpdatePtr.h @@ -1,5 +1,5 @@ /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* PackageUpdatePtr.h +/* PackageUpdate_Ptr.h * * Copyright (C) 2005 SUSE Linux Products GmbH * @@ -18,14 +18,13 @@ * 02111-1307, USA. */ -#ifndef _PackageUpdatePtr_h -#define _PackageUpdatePtr_h +#ifndef _PackageUpdate_Ptr_h +#define _PackageUpdate_Ptr_h -#include -#include +#include "zypp/base/PtrTypes.h" ///////////////////////////////////////////////////////////////////////// -namespace zypp +namespace zypp { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// namespace solver @@ -35,10 +34,10 @@ namespace zypp { /////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// - // CLASS NAME : PackageUpdatePtr - // CLASS NAME : constPackageUpdatePtr + // CLASS NAME : PackageUpdate_Ptr + // CLASS NAME : PackageUpdate_constPtr /////////////////////////////////////////////////////////////////// - DEFINE_DERIVED_POINTER(PackageUpdate,Spec); + DEFINE_PTR_TYPE(PackageUpdate); /////////////////////////////////////////////////////////////////// };// namespace detail @@ -49,4 +48,4 @@ namespace zypp /////////////////////////////////////////////////////////////////////// };// namespace zypp ///////////////////////////////////////////////////////////////////////// -#endif // _PackageUpdatePtr_h +#endif // _PackageUpdate_Ptr_h diff --git a/zypp/solver/detail/Packman.cc b/zypp/solver/detail/Packman.cc index 767858f..2f8781a 100644 --- a/zypp/solver/detail/Packman.cc +++ b/zypp/solver/detail/Packman.cc @@ -19,13 +19,11 @@ * 02111-1307, USA. */ -#include - #include #include ///////////////////////////////////////////////////////////////////////// -namespace zypp +namespace zypp { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// namespace solver @@ -33,54 +31,54 @@ namespace zypp ///////////////////////////////////////////////////////////////////// namespace detail { /////////////////////////////////////////////////////////////////// - + using namespace std; - - IMPL_BASE_POINTER(Packman); - + + IMPL_PTR_TYPE(Packman); + //--------------------------------------------------------------------------- - + string Packman::asString ( void ) const { return toString (*this); } - - + + string Packman::toString ( const Packman & store ) { string res (""); - + return res; } - - + + ostream & Packman::dumpOn (ostream & str) const { str << asString(); return str; } - - + + ostream & operator<< (ostream & os, const Packman & store) { return os << store.asString(); } - + //--------------------------------------------------------------------------- - + Packman::Packman () { } - - + + Packman::~Packman() { } - + /////////////////////////////////////////////////////////////////// };// namespace detail ///////////////////////////////////////////////////////////////////// diff --git a/zypp/solver/detail/Packman.h b/zypp/solver/detail/Packman.h index d0db177..1246741 100644 --- a/zypp/solver/detail/Packman.h +++ b/zypp/solver/detail/Packman.h @@ -26,10 +26,14 @@ #include #include +#include "zypp/base/ReferenceCounted.h" +#include "zypp/base/NonCopyable.h" +#include "zypp/base/PtrTypes.h" + #include ///////////////////////////////////////////////////////////////////////// -namespace zypp +namespace zypp { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// namespace solver @@ -41,34 +45,34 @@ namespace zypp /////////////////////////////////////////////////////////////////// // // CLASS NAME : Packman - - class Packman : public CountedRep { - REP_BODY(Packman); - + + class Packman : public base::ReferenceCounted, private base::NonCopyable { + + private: - - + + public: - + Packman (); virtual ~Packman(); - + // ---------------------------------- I/O - + static std::string toString (const Packman & section); - + virtual std::ostream & dumpOn(std::ostream & str ) const; - + friend std::ostream& operator<<(std::ostream&, const Packman & section); - + std::string asString (void) const; - + // ---------------------------------- accessors - - + + // ---------------------------------- methods - - + + }; /////////////////////////////////////////////////////////////////// diff --git a/zypp/solver/detail/PackmanPtr.h b/zypp/solver/detail/PackmanPtr.h index 152e174..80e9b80 100644 --- a/zypp/solver/detail/PackmanPtr.h +++ b/zypp/solver/detail/PackmanPtr.h @@ -1,5 +1,5 @@ /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* PackmanPtr.h +/* Packman_Ptr.h * * Copyright (C) 2005 SUSE Linux Products GmbH * @@ -18,10 +18,10 @@ * 02111-1307, USA. */ -#ifndef _PackmanPtr_h -#define _PackmanPtr_h +#ifndef _Packman_Ptr_h +#define _Packman_Ptr_h -#include +#include "zypp/base/PtrTypes.h" ///////////////////////////////////////////////////////////////////////// namespace zypp @@ -34,10 +34,10 @@ namespace zypp { /////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// - // CLASS NAME : PackmanPtr - // CLASS NAME : constPackmanPtr + // CLASS NAME : Packman_Ptr + // CLASS NAME : Packman_constPtr /////////////////////////////////////////////////////////////////// - DEFINE_BASE_POINTER(Packman); + DEFINE_PTR_TYPE(Packman); /////////////////////////////////////////////////////////////////// };// namespace detail @@ -48,4 +48,4 @@ namespace zypp /////////////////////////////////////////////////////////////////////// };// namespace zypp ///////////////////////////////////////////////////////////////////////// -#endif // _PackmanPtr_h +#endif // _Packman_Ptr_h diff --git a/zypp/solver/detail/Pending.cc b/zypp/solver/detail/Pending.cc index 9f62b94..48f93a4 100644 --- a/zypp/solver/detail/Pending.cc +++ b/zypp/solver/detail/Pending.cc @@ -36,7 +36,7 @@ namespace zypp using namespace std; - IMPL_BASE_POINTER(Pending); + IMPL_PTR_TYPE(Pending); //--------------------------------------------------------------------------- diff --git a/zypp/solver/detail/Pending.h b/zypp/solver/detail/Pending.h index 0e72c76..f431b7c 100644 --- a/zypp/solver/detail/Pending.h +++ b/zypp/solver/detail/Pending.h @@ -26,10 +26,14 @@ #include #include +#include "zypp/base/ReferenceCounted.h" +#include "zypp/base/NonCopyable.h" +#include "zypp/base/PtrTypes.h" + #include ///////////////////////////////////////////////////////////////////////// -namespace zypp +namespace zypp { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// namespace solver @@ -39,16 +43,16 @@ namespace zypp { /////////////////////////////////////////////////////////////////// class Pending; - typedef std::list PendingList; - typedef PendingList * PendingListPtr; - + typedef std::list PendingList; + typedef PendingList * PendingList_Ptr; + /////////////////////////////////////////////////////////////////// // // CLASS NAME : Pending - - class Pending : public CountedRep { - REP_BODY(Pending); - + + class Pending : public base::ReferenceCounted, private base::NonCopyable { + + typedef enum { PENDING_STATUS_INVALID = 0, PENDING_STATUS_PRE_BEGIN, @@ -58,54 +62,54 @@ namespace zypp PENDING_STATUS_FAILED, PENDING_STATUS_FINISHED } PendingStatus; - + const char *pendingStatusToString (PendingStatus status); - + #define INVALID_PENDING_ID 0 - - + + private: - + char *_description; int _id; - + PendingStatus _status; - + double _percent_complete; - + size_t _completed_size; size_t _total_size; - + time_t _start_time; time_t _last_time; time_t _poll_time; - + int _retval; char *_error_msg; - + std::list _messages; - - void (*_update) (PendingPtr); - void (*_complete) (PendingPtr); - void (*_message) (PendingPtr); - + + void (*_update) (Pending_Ptr); + void (*_complete) (Pending_Ptr); + void (*_message) (Pending_Ptr); + public: - + Pending (const char *description); virtual ~Pending(); - + // ---------------------------------- I/O - + static std::string toString (const Pending & section); - + virtual std::ostream & dumpOn(std::ostream & str ) const; - + friend std::ostream& operator<<(std::ostream&, const Pending & section); - + std::string asString (void) const; - + // ---------------------------------- accessors - + const char *description (void) const { return _description; } void setDescription (const char *description) { _description = strdup (description); } int id (void) const { return _id; } @@ -116,35 +120,35 @@ namespace zypp time_t startTime (void) const { return _start_time; } time_t lastTime (void) const { return _last_time; } time_t pollTime (void) const { return _poll_time; } - + int elapsedSecs (void) const { return 0; } int expectedSecs (void) const { return 0; } int remainingSecs (void) const { return 0; } - + std::list messages (void) const { return _messages; } const char *latestMessage (void) const { return _error_msg; } - + // ---------------------------------- methods - - PendingPtr lookupById (int id); - std::list getAllActiveIds (void); - + + Pending_Ptr lookupById (int id); + std::list getAllActiveIds (void); + void begin (void); void update (double percent_complete); void updateBySize (size_t size, size_t total_size); - + void finished (int retval); void abort (int retval); void fail (int retval, const char *error_msg); - + bool isActive (void); - + const char *errorMsg (void); - + void addMessage (const char *message); - + }; - + /////////////////////////////////////////////////////////////////// };// namespace detail ///////////////////////////////////////////////////////////////////// diff --git a/zypp/solver/detail/PendingPtr.h b/zypp/solver/detail/PendingPtr.h index e88083a..98d96d8 100644 --- a/zypp/solver/detail/PendingPtr.h +++ b/zypp/solver/detail/PendingPtr.h @@ -1,5 +1,5 @@ /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* PendingPtr.h +/* Pending_Ptr.h * * Copyright (C) 2005 SUSE Linux Products GmbH * @@ -18,10 +18,10 @@ * 02111-1307, USA. */ -#ifndef _PendingPtr_h -#define _PendingPtr_h +#ifndef _Pending_Ptr_h +#define _Pending_Ptr_h -#include +#include "zypp/base/PtrTypes.h" ///////////////////////////////////////////////////////////////////////// namespace zypp { /////////////////////////////////////////////////////////////////////// @@ -33,10 +33,10 @@ namespace zypp { /////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// - // CLASS NAME : PendingPtr - // CLASS NAME : constPendingPtr + // CLASS NAME : Pending_Ptr + // CLASS NAME : Pending_constPtr /////////////////////////////////////////////////////////////////// - DEFINE_BASE_POINTER(Pending); + DEFINE_PTR_TYPE(Pending); /////////////////////////////////////////////////////////////////// };// namespace detail @@ -48,4 +48,4 @@ namespace zypp };// namespace zypp ///////////////////////////////////////////////////////////////////////// -#endif // _PendingPtr_h +#endif // _Pending_Ptr_h diff --git a/zypp/solver/detail/QueueItem.cc b/zypp/solver/detail/QueueItem.cc index 8176fc4..dff31f4 100644 --- a/zypp/solver/detail/QueueItem.cc +++ b/zypp/solver/detail/QueueItem.cc @@ -36,7 +36,7 @@ namespace zypp using namespace std; - IMPL_BASE_POINTER(QueueItem); + IMPL_PTR_TYPE(QueueItem); //--------------------------------------------------------------------------- @@ -83,7 +83,7 @@ namespace zypp //--------------------------------------------------------------------------- - QueueItem::QueueItem (QueueItemType type, WorldPtr world) + QueueItem::QueueItem (QueueItemType type, World_Ptr world) : _type (type) , _world (world) , _priority (0) @@ -99,7 +99,7 @@ namespace zypp //--------------------------------------------------------------------------- void - QueueItem::copy (constQueueItemPtr from) + QueueItem::copy (QueueItem_constPtr from) { _priority = from->_priority; _size = from->_size; @@ -110,14 +110,14 @@ namespace zypp //--------------------------------------------------------------------------- void - QueueItem::addInfo (ResolverInfoPtr info) + QueueItem::addInfo (ResolverInfo_Ptr info) { _pending_info.push_back (info); } void - QueueItem::logInfo (ResolverContextPtr context) + QueueItem::logInfo (ResolverContext_Ptr context) { for (ResolverInfoList::const_iterator iter = _pending_info.begin(); iter != _pending_info.end(); iter++) { context->addInfo (*iter); diff --git a/zypp/solver/detail/QueueItem.h b/zypp/solver/detail/QueueItem.h index 28b89f4..f3dd659 100644 --- a/zypp/solver/detail/QueueItem.h +++ b/zypp/solver/detail/QueueItem.h @@ -24,7 +24,11 @@ #include #include -#include +#include + +#include "zypp/base/ReferenceCounted.h" +#include "zypp/base/NonCopyable.h" +#include "zypp/base/PtrTypes.h" #include #include @@ -33,7 +37,7 @@ #include ///////////////////////////////////////////////////////////////////////// -namespace zypp +namespace zypp { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// namespace solver @@ -52,82 +56,82 @@ namespace zypp QUEUE_ITEM_TYPE_UNINSTALL, QUEUE_ITEM_TYPE_LAST } QueueItemType; - - - typedef std::list QueueItemList; - + + + typedef std::list QueueItemList; + #define CMP(a,b) (((a) < (b)) - ((b) < (a))) - + /////////////////////////////////////////////////////////////////// // // CLASS NAME : QueueItem - - class QueueItem : public CountedRep { - REP_BODY(QueueItem); - + + class QueueItem : public base::ReferenceCounted, private base::NonCopyable { + + private: - + QueueItemType _type; - WorldPtr _world; - + World_Ptr _world; + int _priority; size_t _size; ResolverInfoList _pending_info; - + protected: - - QueueItem (QueueItemType type, WorldPtr world); - + + QueueItem (QueueItemType type, World_Ptr world); + public: - + virtual ~QueueItem(); - + // ---------------------------------- I/O - + static std::string toString (const QueueItem & item); - + static std::string toString (const QueueItemList & itemlist, const std::string & sep = ", "); - + virtual std::ostream & dumpOn(std::ostream & str ) const; - + friend std::ostream& operator<<(std::ostream&, const QueueItem & item); - + virtual std::string asString (void ) const; - + // ---------------------------------- accessors - - WorldPtr world (void) const { return _world; } + + World_Ptr world (void) const { return _world; } int priority (void) const { return _priority; } void setPriority (int priority) { _priority = priority; } int size (void) const { return _size; } - + // ---------------------------------- methods - - void copy (constQueueItemPtr from); - + + void copy (QueueItem_constPtr from); + bool isBranch (void) const { return _type == QUEUE_ITEM_TYPE_BRANCH; } bool isConflict (void) const { return _type == QUEUE_ITEM_TYPE_CONFLICT; } bool isGroup (void) const { return _type == QUEUE_ITEM_TYPE_GROUP; } bool isInstall (void) const { return _type == QUEUE_ITEM_TYPE_INSTALL; } bool isRequire (void) const { return _type == QUEUE_ITEM_TYPE_REQUIRE; } bool isUninstall (void) const { return _type == QUEUE_ITEM_TYPE_UNINSTALL; } - - virtual bool process (ResolverContextPtr context, QueueItemList & qil) = 0; - virtual QueueItemPtr copy (void) const = 0; - virtual int cmp (constQueueItemPtr item) const = 0; - int compare (constQueueItemPtr item) const { return CMP(_type, item->_type); } - + + virtual bool process (ResolverContext_Ptr context, QueueItemList & qil) = 0; + virtual QueueItem_Ptr copy (void) const = 0; + virtual int cmp (QueueItem_constPtr item) const = 0; + int compare (QueueItem_constPtr item) const { return CMP(_type, item->_type); } + // isRedundant true == can be dropped from any branch - virtual bool isRedundant (ResolverContextPtr context) const = 0; - + virtual bool isRedundant (ResolverContext_Ptr context) const = 0; + // isSatisfied true == can be dropped from any queue, and any // branch containing it can also be dropped - virtual bool isSatisfied (ResolverContextPtr context) const = 0; - - void addInfo (ResolverInfoPtr); - void logInfo (ResolverContextPtr); + virtual bool isSatisfied (ResolverContext_Ptr context) const = 0; + + void addInfo (ResolverInfo_Ptr); + void logInfo (ResolverContext_Ptr); }; - + /////////////////////////////////////////////////////////////////// };// namespace detail ///////////////////////////////////////////////////////////////////// diff --git a/zypp/solver/detail/QueueItemBranch.cc b/zypp/solver/detail/QueueItemBranch.cc index 5f42845..bf7d950 100644 --- a/zypp/solver/detail/QueueItemBranch.cc +++ b/zypp/solver/detail/QueueItemBranch.cc @@ -25,7 +25,7 @@ #include ///////////////////////////////////////////////////////////////////////// -namespace zypp +namespace zypp { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// namespace solver @@ -33,20 +33,20 @@ namespace zypp ///////////////////////////////////////////////////////////////////// namespace detail { /////////////////////////////////////////////////////////////////// - + using namespace std; - - IMPL_DERIVED_POINTER(QueueItemBranch,QueueItem); - + + IMPL_PTR_TYPE(QueueItemBranch); + //--------------------------------------------------------------------------- - + string QueueItemBranch::asString ( void ) const { return toString (*this); } - - + + string QueueItemBranch::toString ( const QueueItemBranch & item) { @@ -59,44 +59,44 @@ namespace zypp res += "]"; return res; } - - + + ostream & QueueItemBranch::dumpOn( ostream & str ) const { str << asString(); return str; } - - + + ostream& operator<<( ostream& os, const QueueItemBranch & item) { return os << item.asString(); } - + //--------------------------------------------------------------------------- - - QueueItemBranch::QueueItemBranch (WorldPtr world) + + QueueItemBranch::QueueItemBranch (World_Ptr world) : QueueItem (QUEUE_ITEM_TYPE_BRANCH, world) { } - - + + QueueItemBranch::~QueueItemBranch() { } - + //--------------------------------------------------------------------------- - + void - QueueItemBranch::addItem (QueueItemPtr subitem) + QueueItemBranch::addItem (QueueItem_Ptr subitem) { - assert (this != subitem); + assert (static_cast(this) != subitem); #if 0 // We want to keep the list of possible items sorted for easy comparison later. for (QueueItemList::iterator pos = _possible_items.begin(); pos != _possible_items.end(); pos++) { - + if ((*pos)->cmp(subitem) >= 0) { // found a larger one _possible_items.insert (pos, subitem); // insert before return; @@ -104,141 +104,141 @@ namespace zypp } #endif _possible_items.push_back (subitem); // no larger found, subitem must be largest - + return; } - - + + bool - QueueItemBranch::contains (QueueItemPtr possible_subbranch) + QueueItemBranch::contains (QueueItem_Ptr possible_subbranch) { - QueueItemBranchPtr branch = (QueueItemBranchPtr)possible_subbranch; - + QueueItemBranch_Ptr branch = dynamic_pointer_cast(possible_subbranch); + if (branch == NULL || !branch->isBranch()) { return false; } - - + + if (_possible_items.size() < branch->_possible_items.size()) { return false; } - + QueueItemList::iterator iter = _possible_items.begin(); QueueItemList::iterator iter_sub = branch->_possible_items.begin(); - + /* For every item inside the possible sub-branch, look for a matching item in the branch. If we can't find a match, fail. (We can do this in one pass since the possible_items lists are sorted) */ while (iter_sub != branch->_possible_items.end()) { - + while (iter != _possible_items.end() && (*iter)->cmp (*iter_sub)) { iter++; } - + if (iter == _possible_items.end()) return false; - + iter++; iter_sub++; } - + return true; } - + //--------------------------------------------------------------------------- - + bool - QueueItemBranch::process (ResolverContextPtr context, QueueItemList & qil) + QueueItemBranch::process (ResolverContext_Ptr context, QueueItemList & qil) { _DBG("RC_SPEW") << "QueueItemBranch::process(" << asString() << ")" << endl; - + QueueItemList live_branches; unsigned int branch_count; bool did_something = true; - + for (QueueItemList::const_iterator iter = _possible_items.begin(); iter != _possible_items.end(); iter++) { - - QueueItemPtr item = *iter; - + + QueueItem_Ptr item = *iter; + if (item->isSatisfied (context)) goto finished; - + /* Drop any useless branch items */ if (! item->isRedundant (context)) { live_branches.push_front (item); } } - + branch_count = live_branches.size(); - + if (branch_count == 0) { - + /* Do nothing */ - + } else if (branch_count == 1) { - + /* If we just have one possible item, process it. */ - - QueueItemPtr item = live_branches.front(); + + QueueItem_Ptr item = live_branches.front(); did_something = item->process (context, qil); - + /* Set the item pointer to NULL inside of our original branch item, since our call to rc_queue_item_process is now responsible for freeing it. */ - + for (QueueItemList::iterator iter = _possible_items.begin(); iter != _possible_items.end(); iter++) { if (*iter == item) { _possible_items.erase (iter); break; } } - + } else if (branch_count == _possible_items.size()) { - + /* Nothing was eliminated, so just pass the branch through (and set it to NULL so that it won't get freed when we exit. */ - + qil.push_front (this); // FIXME: dont free item = NULL; did_something = false; - + } else { //fprintf (stderr, "QueueItemBranch::process rebranching\n"); - QueueItemBranchPtr new_branch = new QueueItemBranch (world()); + QueueItemBranch_Ptr new_branch = new QueueItemBranch (world()); for (QueueItemList::const_iterator iter = live_branches.begin(); iter != live_branches.end(); iter++) { new_branch->addItem ((*iter)->copy()); } qil.push_front (new_branch); } - + finished: //FIXME rc_queue_item_free (item); - + return did_something; } - - + + int - QueueItemBranch::cmp (constQueueItemPtr item) const + QueueItemBranch::cmp (QueueItem_constPtr item) const { int cmp = this->compare (item); // assures equal type if (cmp != 0) return cmp; - - constQueueItemBranchPtr branch = item; - + + QueueItemBranch_constPtr branch = dynamic_pointer_cast(item); + /* First, sort by # of possible items. */ cmp = CMP(_possible_items.size(), branch->_possible_items.size()); if (cmp != 0) return cmp; - + /* We can do a by-item cmp since the possible items are kept in sorted order. */ QueueItemList::const_iterator ia = _possible_items.begin(); QueueItemList::const_iterator ib = branch->_possible_items.begin(); - + while (ia != _possible_items.end() && ib != branch->_possible_items.end()) { if (*ia && *ib) { cmp = (*ia)->cmp (*ib); @@ -249,28 +249,33 @@ namespace zypp ia++; ib++; } - + /* Both lists should end at the same time, since we initially sorted on length. */ assert (ia == _possible_items.end() && ib == branch->_possible_items.end()); - + return 0; } - - - QueueItemPtr + + /***/ + QueueItem_Ptr QueueItemBranch::copy (void) const { - QueueItemBranchPtr new_branch = new QueueItemBranch (world()); - ((QueueItemPtr)new_branch)->copy((constQueueItemPtr)this); - + QueueItemBranch_Ptr new_branch = new QueueItemBranch (world()); +#if 0 + //original code + ((QueueItem_Ptr)new_branch)->copy((QueueItem_constPtr)this); +#else +#warning Check whether this is the intended behaviour + new_branch->QueueItem::copy(this); +#endif for (QueueItemList::const_iterator iter = _possible_items.begin(); iter != _possible_items.end(); iter++) { - QueueItemPtr cpy = (*iter)->copy(); + QueueItem_Ptr cpy = (*iter)->copy(); new_branch->_possible_items.push_front (cpy); } - + return new_branch; } - + /////////////////////////////////////////////////////////////////// };// namespace detail ///////////////////////////////////////////////////////////////////// diff --git a/zypp/solver/detail/QueueItemBranch.h b/zypp/solver/detail/QueueItemBranch.h index 6697e9f..f508488 100644 --- a/zypp/solver/detail/QueueItemBranch.h +++ b/zypp/solver/detail/QueueItemBranch.h @@ -24,14 +24,15 @@ #include #include -#include +#include +#include #include #include #include ///////////////////////////////////////////////////////////////////////// -namespace zypp +namespace zypp { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// namespace solver @@ -39,52 +40,52 @@ namespace zypp ///////////////////////////////////////////////////////////////////// namespace detail { /////////////////////////////////////////////////////////////////// - + /////////////////////////////////////////////////////////////////// // // CLASS NAME : QueueItemBranch - + class QueueItemBranch : public QueueItem { - REP_BODY(QueueItemBranch); - + + private: std::string _label; QueueItemList _possible_items; - + public: - - QueueItemBranch (WorldPtr world); + + QueueItemBranch (World_Ptr world); virtual ~QueueItemBranch(); - + // ---------------------------------- I/O - + static std::string toString (const QueueItemBranch & item); - + virtual std::ostream & dumpOn(std::ostream & str ) const; - + friend std::ostream& operator<<(std::ostream&, const QueueItemBranch & item); - + std::string asString (void ) const; - + // ---------------------------------- accessors - + QueueItemList possibleItems (void) const { return _possible_items; } - + const std::string & label (void) const { return _label; } void setLabel (const std::string & label) { _label = label; } - + bool isEmpty (void) const { return _possible_items.empty(); } - + // ---------------------------------- methods - - virtual bool process (ResolverContextPtr context, QueueItemList & qil); - virtual QueueItemPtr copy (void) const; - virtual int cmp (constQueueItemPtr item) const; - virtual bool isRedundant (ResolverContextPtr context) const { return false; } - virtual bool isSatisfied (ResolverContextPtr context) const { return false; } - - void addItem (QueueItemPtr subitem); - bool contains (QueueItemPtr possible_subbranch); + + virtual bool process (ResolverContext_Ptr context, QueueItemList & qil); + virtual QueueItem_Ptr copy (void) const; + virtual int cmp (QueueItem_constPtr item) const; + virtual bool isRedundant (ResolverContext_Ptr context) const { return false; } + virtual bool isSatisfied (ResolverContext_Ptr context) const { return false; } + + void addItem (QueueItem_Ptr subitem); + bool contains (QueueItem_Ptr possible_subbranch); }; /////////////////////////////////////////////////////////////////// @@ -95,5 +96,5 @@ namespace zypp /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// };// namespace zypp -///////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////// #endif // _QueueItemBranch_h diff --git a/zypp/solver/detail/QueueItemBranchPtr.h b/zypp/solver/detail/QueueItemBranchPtr.h index ed330fc..e3a82b3 100644 --- a/zypp/solver/detail/QueueItemBranchPtr.h +++ b/zypp/solver/detail/QueueItemBranchPtr.h @@ -1,5 +1,5 @@ /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* QueueItemBranchPtr.h +/* QueueItemBranch_Ptr.h * * Copyright (C) 2005 SUSE Linux Products GmbH * @@ -18,14 +18,14 @@ * 02111-1307, USA. */ -#ifndef _QueueItemBranchPtr_h -#define _QueueItemBranchPtr_h +#ifndef _QueueItemBranch_Ptr_h +#define _QueueItemBranch_Ptr_h -#include -#include +#include "zypp/base/PtrTypes.h" +#include ///////////////////////////////////////////////////////////////////////// -namespace zypp +namespace zypp { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// namespace solver @@ -33,12 +33,12 @@ namespace zypp ///////////////////////////////////////////////////////////////////// namespace detail { /////////////////////////////////////////////////////////////////// - + /////////////////////////////////////////////////////////////////// - // CLASS NAME : QueueItemBranchPtr - // CLASS NAME : constQueueItemBranchPtr + // CLASS NAME : QueueItemBranch_Ptr + // CLASS NAME : QueueItemBranch_constPtr /////////////////////////////////////////////////////////////////// - DEFINE_DERIVED_POINTER(QueueItemBranch,QueueItem); + DEFINE_PTR_TYPE(QueueItemBranch); /////////////////////////////////////////////////////////////////// };// namespace detail @@ -49,4 +49,4 @@ namespace zypp /////////////////////////////////////////////////////////////////////// };// namespace zypp ///////////////////////////////////////////////////////////////////////// -#endif // _QueueItemBranchPtr_h +#endif // _QueueItemBranch_Ptr_h diff --git a/zypp/solver/detail/QueueItemConflict.cc b/zypp/solver/detail/QueueItemConflict.cc index f5ae7e1..f18b2f6 100644 --- a/zypp/solver/detail/QueueItemConflict.cc +++ b/zypp/solver/detail/QueueItemConflict.cc @@ -36,7 +36,7 @@ #include ///////////////////////////////////////////////////////////////////////// -namespace zypp +namespace zypp { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// namespace solver @@ -46,18 +46,18 @@ namespace zypp { /////////////////////////////////////////////////////////////////// using namespace std; - - IMPL_DERIVED_POINTER(QueueItemConflict,QueueItem); - + + IMPL_PTR_TYPE(QueueItemConflict); + //--------------------------------------------------------------------------- - + string QueueItemConflict::asString ( void ) const { return toString (*this); } - - + + string QueueItemConflict::toString ( const QueueItemConflict & item) { @@ -69,55 +69,55 @@ namespace zypp res += "]"; return res; } - - + + ostream & QueueItemConflict::dumpOn( ostream & str ) const { str << asString(); return str; } - - + + ostream& operator<<( ostream& os, const QueueItemConflict & item) { return os << item.asString(); } - + //--------------------------------------------------------------------------- - - QueueItemConflict::QueueItemConflict (WorldPtr world, const Capability & dep, constResItemPtr resItem) + + QueueItemConflict::QueueItemConflict (World_Ptr world, const Capability & dep, ResItem_constPtr resItem) : QueueItem (QUEUE_ITEM_TYPE_CONFLICT, world) , _dep (dep) , _conflicting_resItem (resItem) , _actually_an_obsolete (false) { } - - + + QueueItemConflict::~QueueItemConflict() { } - + //--------------------------------------------------------------------------- - + #if PHI - + // on conflict, try to find upgrade candidates for the installed resItem triggering the conflict // there are cases where upgrading prevents the conflict // rc tends to uninstall the resItem // phi tends to upgrade the resItem // testcases: exercise-02conflict-08-test.xml, exercise-02conflict-09-test.xml - + typedef struct { - ResolverContextPtr context; + ResolverContext_Ptr context; CResItemList upgrades; } UpgradeCandidateInfo; - - + + static bool - upgrade_candidates_cb (constResItemPtr resItem, const Capability & cap, void *data) + upgrade_candidates_cb (ResItem_constPtr resItem, const Capability & cap, void *data) { //fprintf (stderr, "upgrade_candidates_cb(%s,%s)\n", resItem->asString().c_str(), cap.asString().c_str()); UpgradeCandidateInfo *info = (UpgradeCandidateInfo *)data; @@ -126,46 +126,46 @@ namespace zypp } return true; } - + #endif // PHI - - + + typedef struct { - WorldPtr world; - constResItemPtr conflicting_resItem; + World_Ptr world; + ResItem_constPtr conflicting_resItem; const Capability dep; - ResolverContextPtr context; + ResolverContext_Ptr context; QueueItemList & new_items; - + string pkg_str; string dep_str; - + bool actually_an_obsolete; } ConflictProcessInfo; - - + + static bool - conflict_process_cb (constResItemPtr resItem, const Capability & cap, void *data) + conflict_process_cb (ResItem_constPtr resItem, const Capability & cap, void *data) { ConflictProcessInfo *info = (ConflictProcessInfo *)data; ResItemStatus status; string pkg_str, cap_str, msg; - ResolverInfoPtr log_info; - CapFactory factory; - + ResolverInfo_Ptr log_info; + CapFactory factory; + _DBG("RC_SPEW") << "conflict_process_cb (resolvable[" << resItem->asString() <<"], cap[" << cap.asString() << "], info [" << info->conflicting_resItem->asString() << "]" << endl; _DBG("RC_SPEW") << "conflict_process_cb (info->dep [" << info->dep.asString() << "]" << endl; - + /* We conflict with ourself. For the purpose of installing ourself, we * just ignore it, but it's Debian's way of saying that one and only one * resItem with this provide may exist on the system at a time. */ - + if (info->conflicting_resItem && resItem->equals (info->conflicting_resItem)) { return true; } - + /* FIXME: This should probably be a GVersion capability. */ /* Obsoletes don't apply to virtual provides, only the resItems * themselves. A provide is "virtual" if it's not the same spec @@ -176,48 +176,48 @@ namespace zypp resItem->name(), Rel::EQ, resItem->edition()); - + if (info->actually_an_obsolete && capTest != cap) { return true; } - + pkg_str = resItem->asString(); cap_str = cap.asString(); - + status = info->context->getStatus (resItem); - + _DBG("RC_SPEW") << "conflict_process_cb (resolvable[" << resItem->asString() << "]<" << ResolverContext::toString(status) << ">" << endl; - + switch (status) { - + case RESOLVABLE_STATUS_INSTALLED: case RESOLVABLE_STATUS_TO_BE_INSTALLED_SOFT: { - QueueItemUninstallPtr uninstall; - ResolverInfoPtr log_info; - + QueueItemUninstall_Ptr uninstall; + ResolverInfo_Ptr log_info; + #if PHI // maybe an upgrade can resolve the conflict ? // check if other resItem is available which upgrades - + // find non-installed packages which provide the conflicting name - + UpgradeCandidateInfo upgrade_info; upgrade_info.context = info->context; - + Capability maybe_upgrade_dep = factory.parse ( resItem->kind(), resItem->name(), Rel::ANY, Edition::noepoch); info->world->foreachProvidingResItem (maybe_upgrade_dep, upgrade_candidates_cb, (void *)&upgrade_info); - + #endif - + uninstall = new QueueItemUninstall (info->world, resItem, "conflict"); uninstall->setDependency (info->dep); - + if (info->actually_an_obsolete) { uninstall->setDueToObsolete (); log_info = new ResolverInfoObsoletes (resItem, info->conflicting_resItem); @@ -225,51 +225,51 @@ namespace zypp uninstall->setDueToConflict (); log_info = new ResolverInfoConflictsWith (resItem, info->conflicting_resItem); } - + uninstall->addInfo (log_info); - + #if PHI if (upgrade_info.upgrades.empty ()) { #endif - + info->new_items.push_back (uninstall); - + #if PHI } else { // there are upgrade candidates for the conflicting resItem // branch to: 1. uninstall, 2. upgrade (for each upgrading resItem) - - QueueItemBranchPtr branch = new QueueItemBranch (info->world); - + + QueueItemBranch_Ptr branch = new QueueItemBranch (info->world); + branch->addItem (uninstall); // try uninstall - + for (CResItemList::const_iterator iter = upgrade_info.upgrades.begin(); iter != upgrade_info.upgrades.end(); iter++) { - QueueItemInstallPtr upgrade = new QueueItemInstall (info->world, *iter); + QueueItemInstall_Ptr upgrade = new QueueItemInstall (info->world, *iter); upgrade->setUpgrades (resItem); branch->addItem (upgrade); // try upgrade } info->new_items.push_back (branch); } #endif - + break; } - + case RESOLVABLE_STATUS_TO_BE_INSTALLED: { msg = string ("A conflict over ") + info->dep_str + " (" + cap_str + ") requires the removal of the to-be-installed resolvable " + pkg_str; - - ResolverInfoMiscPtr misc_info = new ResolverInfoMisc (resItem,RESOLVER_INFO_PRIORITY_VERBOSE, msg); - + + ResolverInfoMisc_Ptr misc_info = new ResolverInfoMisc (resItem,RESOLVER_INFO_PRIORITY_VERBOSE, msg); + misc_info->flagAsError (); if (info->conflicting_resItem) { misc_info->addRelatedResItem (info->conflicting_resItem); } info->context->addInfo (misc_info); - + break; } - + case RESOLVABLE_STATUS_UNINSTALLED: { info->context->setStatus (resItem, RESOLVABLE_STATUS_TO_BE_UNINSTALLED); msg = string ("Marking ") + pkg_str + " as uninstallable due to conflicts over " + info->dep_str + " (" + cap_str + ")"; @@ -277,74 +277,74 @@ namespace zypp msg += " from "; msg += info->pkg_str; } - - ResolverInfoMiscPtr misc_info = new ResolverInfoMisc (NULL, RESOLVER_INFO_PRIORITY_VERBOSE, msg); - + + ResolverInfoMisc_Ptr misc_info = new ResolverInfoMisc (NULL, RESOLVER_INFO_PRIORITY_VERBOSE, msg); + misc_info->addRelatedResItem (resItem); if (info->conflicting_resItem) { misc_info->addRelatedResItem(info->conflicting_resItem); } info->context->addInfo (misc_info); - + break; } - + case RESOLVABLE_STATUS_TO_BE_UNINSTALLED: case RESOLVABLE_STATUS_TO_BE_UNINSTALLED_DUE_TO_OBSOLETE: /* This is the easy case -- we do nothing. */ break; - + default: abort(); } - + return true; } - - + + bool - QueueItemConflict::process (ResolverContextPtr context, QueueItemList & new_items) + QueueItemConflict::process (ResolverContext_Ptr context, QueueItemList & new_items) { _DBG("RC_SPEW") << "QueueItemConflict::process(" << this->asString() << ")" << endl; - + ConflictProcessInfo info = { world(), _conflicting_resItem, _dep, context, new_items, "", "", _actually_an_obsolete }; - + if (_conflicting_resItem) { info.pkg_str = _conflicting_resItem->asString(); } info.dep_str = _dep.asString(); - + world()->foreachProvidingResItem (_dep, conflict_process_cb, (void *)&info); - + // FIXME: free self - + return true; } - - + + //--------------------------------------------------------------------------- - - QueueItemPtr + + QueueItem_Ptr QueueItemConflict::copy (void) const { - QueueItemConflictPtr new_conflict = new QueueItemConflict (world(), _dep, _conflicting_resItem); - ((QueueItemPtr)new_conflict)->copy((constQueueItemPtr)this); - + QueueItemConflict_Ptr new_conflict = new QueueItemConflict (world(), _dep, _conflicting_resItem); + ((QueueItem_Ptr)new_conflict)->copy((QueueItem_constPtr)this); + // _actually_an_obsolete is not being copied ! - + return new_conflict; } - - + + int - QueueItemConflict::cmp (constQueueItemPtr item) const + QueueItemConflict::cmp (QueueItem_constPtr item) const { int cmp = this->compare (item); // assures equal type if (cmp != 0) return cmp; - - constQueueItemConflictPtr conflict = item; + + QueueItemConflict_constPtr conflict = dynamic_pointer_cast(item); if ( _dep != conflict->dependency()) cmp = -1; diff --git a/zypp/solver/detail/QueueItemConflict.h b/zypp/solver/detail/QueueItemConflict.h index 25ce463..04a352f 100644 --- a/zypp/solver/detail/QueueItemConflict.h +++ b/zypp/solver/detail/QueueItemConflict.h @@ -24,15 +24,16 @@ #include #include -#include +#include +#include #include #include #include #include ///////////////////////////////////////////////////////////////////////// -namespace zypp +namespace zypp { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// namespace solver @@ -40,51 +41,51 @@ namespace zypp ///////////////////////////////////////////////////////////////////// namespace detail { /////////////////////////////////////////////////////////////////// - + /////////////////////////////////////////////////////////////////// // // CLASS NAME : QueueItemConflict - + class QueueItemConflict : public QueueItem { - REP_BODY(QueueItemConflict); - + + private: const Capability _dep; - constResItemPtr _conflicting_resItem; - + ResItem_constPtr _conflicting_resItem; + bool _actually_an_obsolete; - + public: - - QueueItemConflict (WorldPtr world, const Capability & dep, constResItemPtr resItem); + + QueueItemConflict (World_Ptr world, const Capability & dep, ResItem_constPtr resItem); virtual ~QueueItemConflict(); - + // ---------------------------------- I/O - + static std::string toString (const QueueItemConflict & item); - + virtual std::ostream & dumpOn(std::ostream & str ) const; - + friend std::ostream& operator<<(std::ostream&, const QueueItemConflict & item); - + std::string asString (void ) const; - + // ---------------------------------- accessors - + const Capability & dependency (void) const { return _dep; } bool actuallyAnObsolete (void) const { return _actually_an_obsolete; } void setActuallyAnObsolete (void) { _actually_an_obsolete = true; } - + // ---------------------------------- methods - - virtual bool process (ResolverContextPtr context, QueueItemList & qil); - virtual QueueItemPtr copy (void) const; - virtual int cmp (constQueueItemPtr item) const; - virtual bool isRedundant (ResolverContextPtr context) const { return false; } - virtual bool isSatisfied (ResolverContextPtr context) const { return false; } - + + virtual bool process (ResolverContext_Ptr context, QueueItemList & qil); + virtual QueueItem_Ptr copy (void) const; + virtual int cmp (QueueItem_constPtr item) const; + virtual bool isRedundant (ResolverContext_Ptr context) const { return false; } + virtual bool isSatisfied (ResolverContext_Ptr context) const { return false; } + }; - + /////////////////////////////////////////////////////////////////// };// namespace detail ///////////////////////////////////////////////////////////////////// diff --git a/zypp/solver/detail/QueueItemConflictPtr.h b/zypp/solver/detail/QueueItemConflictPtr.h index 755927d..a2d8605 100644 --- a/zypp/solver/detail/QueueItemConflictPtr.h +++ b/zypp/solver/detail/QueueItemConflictPtr.h @@ -1,5 +1,5 @@ /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* QueueItemConflictPtr.h +/* QueueItemConflict_Ptr.h * * Copyright (C) 2005 SUSE Linux Products GmbH * @@ -18,14 +18,14 @@ * 02111-1307, USA. */ -#ifndef _QueueItemConflictPtr_h -#define _QueueItemConflictPtr_h +#ifndef _QueueItemConflict_Ptr_h +#define _QueueItemConflict_Ptr_h -#include -#include +#include "zypp/base/PtrTypes.h" +#include ///////////////////////////////////////////////////////////////////////// -namespace zypp +namespace zypp { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// namespace solver @@ -35,10 +35,10 @@ namespace zypp { /////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// - // CLASS NAME : QueueItemConflictPtr - // CLASS NAME : constQueueItemConflictPtr + // CLASS NAME : QueueItemConflict_Ptr + // CLASS NAME : QueueItemConflict_constPtr /////////////////////////////////////////////////////////////////// - DEFINE_DERIVED_POINTER(QueueItemConflict,QueueItem); + DEFINE_PTR_TYPE(QueueItemConflict); /////////////////////////////////////////////////////////////////// };// namespace detail @@ -49,4 +49,4 @@ namespace zypp /////////////////////////////////////////////////////////////////////// };// namespace zypp ///////////////////////////////////////////////////////////////////////// -#endif // _QueueItemConflictPtr_h +#endif // _QueueItemConflict_Ptr_h diff --git a/zypp/solver/detail/QueueItemGroup.cc b/zypp/solver/detail/QueueItemGroup.cc index 3d3cdfc..34cb18d 100644 --- a/zypp/solver/detail/QueueItemGroup.cc +++ b/zypp/solver/detail/QueueItemGroup.cc @@ -24,7 +24,7 @@ #include ///////////////////////////////////////////////////////////////////////// -namespace zypp +namespace zypp { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// namespace solver @@ -32,20 +32,20 @@ namespace zypp ///////////////////////////////////////////////////////////////////// namespace detail { /////////////////////////////////////////////////////////////////// - + using namespace std; - - IMPL_DERIVED_POINTER(QueueItemGroup,QueueItem); - + + IMPL_PTR_TYPE(QueueItemGroup); + //--------------------------------------------------------------------------- - + string QueueItemGroup::asString ( void ) const { return toString (*this); } - - + + string QueueItemGroup::toString ( const QueueItemGroup & item) { @@ -54,86 +54,86 @@ namespace zypp ret += "]"; return ret; } - - + + ostream & QueueItemGroup::dumpOn( ostream & str ) const { str << asString(); return str; } - - + + ostream& operator<<( ostream& os, const QueueItemGroup & item) { return os << item.asString(); } - + //--------------------------------------------------------------------------- - - QueueItemGroup::QueueItemGroup (WorldPtr world) + + QueueItemGroup::QueueItemGroup (World_Ptr world) : QueueItem (QUEUE_ITEM_TYPE_GROUP, world) { } - - + + QueueItemGroup::~QueueItemGroup() { } - + //--------------------------------------------------------------------------- - + bool - QueueItemGroup::process (ResolverContextPtr context, QueueItemList & new_items) + QueueItemGroup::process (ResolverContext_Ptr context, QueueItemList & new_items) { _DBG("RC_SPEW") << "QueueItemGroup::process" << endl; - + bool did_something = false; - + // Just move all of the group's subitems onto the new_items list. - + for (QueueItemList::const_iterator iter = _subitems.begin(); iter != _subitems.end(); iter++) { new_items.push_front (*iter); did_something = true; } - + _subitems.clear(); - + // FIXME: delete self - + return did_something; } - - - QueueItemPtr + + + QueueItem_Ptr QueueItemGroup::copy (void) const { - QueueItemGroupPtr new_group = new QueueItemGroup (world()); - ((QueueItemPtr)new_group)->copy((constQueueItemPtr)this); - + QueueItemGroup_Ptr new_group = new QueueItemGroup (world()); + ((QueueItem_Ptr)new_group)->copy((QueueItem_constPtr)this); + for (QueueItemList::const_iterator iter = _subitems.begin(); iter != _subitems.end(); iter++) { new_group->_subitems.push_back ((*iter)->copy()); } return new_group; } - - + + int - QueueItemGroup::cmp (constQueueItemPtr item) const + QueueItemGroup::cmp (QueueItem_constPtr item) const { int cmp = this->compare (item); // assures equal type if (cmp != 0) return cmp; - - constQueueItemGroupPtr group = item; - + + QueueItemGroup_constPtr group = dynamic_pointer_cast(item); + // First, sort by # of subitems - + cmp = CMP(_subitems.size(), group->_subitems.size()); if (cmp) return cmp; - + // We can do a by-item cmp since the possible items are kept in sorted order. QueueItemList::const_iterator iter2; for (QueueItemList::const_iterator iter = _subitems.begin(), iter2 = group->_subitems.begin(); @@ -143,13 +143,13 @@ namespace zypp return cmp; } } - + return 0; } - - + + void - QueueItemGroup::addItem (QueueItemPtr subitem) + QueueItemGroup::addItem (QueueItem_Ptr subitem) { // We need to keep the list sorted for comparison purposes. _subitems.push_back (subitem); @@ -164,5 +164,5 @@ namespace zypp /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// };// namespace zypp -///////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////// diff --git a/zypp/solver/detail/QueueItemGroup.h b/zypp/solver/detail/QueueItemGroup.h index ad805fb..0a7febc 100644 --- a/zypp/solver/detail/QueueItemGroup.h +++ b/zypp/solver/detail/QueueItemGroup.h @@ -24,14 +24,15 @@ #include #include -#include +#include +#include #include #include #include ///////////////////////////////////////////////////////////////////////// -namespace zypp +namespace zypp { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// namespace solver @@ -43,40 +44,40 @@ namespace zypp /////////////////////////////////////////////////////////////////// // // CLASS NAME : QueueItemGroup - + class QueueItemGroup : public QueueItem { - REP_BODY(QueueItemGroup); - + + private: QueueItemList _subitems; - + public: - - QueueItemGroup (WorldPtr world); + + QueueItemGroup (World_Ptr world); virtual ~QueueItemGroup(); - + // ---------------------------------- I/O - + static std::string toString (const QueueItemGroup & item); - + virtual std::ostream & dumpOn(std::ostream & str ) const; - + friend std::ostream& operator<<(std::ostream&, const QueueItemGroup & item); - + std::string asString (void ) const; - + // ---------------------------------- accessors - - + + // ---------------------------------- methods - - virtual bool process (ResolverContextPtr context, QueueItemList & qil); - virtual QueueItemPtr copy (void) const; - virtual int cmp (constQueueItemPtr item) const; - virtual bool isRedundant (ResolverContextPtr context) const { return false; } - virtual bool isSatisfied (ResolverContextPtr context) const { return false; } - - void addItem (QueueItemPtr subitem); + + virtual bool process (ResolverContext_Ptr context, QueueItemList & qil); + virtual QueueItem_Ptr copy (void) const; + virtual int cmp (QueueItem_constPtr item) const; + virtual bool isRedundant (ResolverContext_Ptr context) const { return false; } + virtual bool isSatisfied (ResolverContext_Ptr context) const { return false; } + + void addItem (QueueItem_Ptr subitem); }; /////////////////////////////////////////////////////////////////// diff --git a/zypp/solver/detail/QueueItemGroupPtr.h b/zypp/solver/detail/QueueItemGroupPtr.h index 15adffc..361bec3 100644 --- a/zypp/solver/detail/QueueItemGroupPtr.h +++ b/zypp/solver/detail/QueueItemGroupPtr.h @@ -1,5 +1,5 @@ /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* QueueItemGroupPtr.h +/* QueueItemGroup_Ptr.h * * Copyright (C) 2005 SUSE Linux Products GmbH * @@ -18,14 +18,14 @@ * 02111-1307, USA. */ -#ifndef _QueueItemGroupPtr_h -#define _QueueItemGroupPtr_h +#ifndef _QueueItemGroup_Ptr_h +#define _QueueItemGroup_Ptr_h -#include -#include +#include "zypp/base/PtrTypes.h" +#include ///////////////////////////////////////////////////////////////////////// -namespace zypp +namespace zypp { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// namespace solver @@ -35,11 +35,11 @@ namespace zypp { /////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// - // CLASS NAME : QueueItemGroupPtr - // CLASS NAME : constQueueItemGroupPtr + // CLASS NAME : QueueItemGroup_Ptr + // CLASS NAME : QueueItemGroup_constPtr /////////////////////////////////////////////////////////////////// - DEFINE_DERIVED_POINTER(QueueItemGroup,QueueItem); - + DEFINE_PTR_TYPE(QueueItemGroup); + /////////////////////////////////////////////////////////////////// };// namespace detail ///////////////////////////////////////////////////////////////////// @@ -50,4 +50,4 @@ namespace zypp };// namespace zypp //////////////////////////////////////////////////////////////////////// -#endif // _QueueItemGroupPtr_h +#endif // _QueueItemGroup_Ptr_h diff --git a/zypp/solver/detail/QueueItemInstall.cc b/zypp/solver/detail/QueueItemInstall.cc index 4c1f049..5458aeb 100644 --- a/zypp/solver/detail/QueueItemInstall.cc +++ b/zypp/solver/detail/QueueItemInstall.cc @@ -48,7 +48,7 @@ namespace zypp using namespace std; - IMPL_DERIVED_POINTER(QueueItemInstall,QueueItem); + IMPL_PTR_TYPE(QueueItemInstall); //--------------------------------------------------------------------------- @@ -103,14 +103,14 @@ namespace zypp //--------------------------------------------------------------------------- - QueueItemInstall::QueueItemInstall (WorldPtr world, constResItemPtr resItem) + QueueItemInstall::QueueItemInstall (World_Ptr world, ResItem_constPtr resItem) : QueueItem (QUEUE_ITEM_TYPE_INSTALL, world) , _resItem (resItem) , _channel_priority (0) , _other_penalty (0) , _explicitly_requested (false) { - constResItemPtr upgrades = world->findInstalledResItem (resItem); + ResItem_constPtr upgrades = world->findInstalledResItem (resItem); _DBG("RC_SPEW") << "QueueItemInstall::QueueItemInstall(" << resItem->asString() << ") upgrades "; if (upgrades!=NULL) { @@ -134,7 +134,7 @@ namespace zypp //--------------------------------------------------------------------------- bool - QueueItemInstall::isSatisfied (ResolverContextPtr context) const + QueueItemInstall::isSatisfied (ResolverContext_Ptr context) const { return context->resItemIsPresent (_resItem); } @@ -145,7 +145,7 @@ namespace zypp // Handle system resItem's that conflict with us -> uninstall them static bool - build_conflict_list (constResItemPtr resItem, const Capability & dep, void *data) + build_conflict_list (ResItem_constPtr resItem, const Capability & dep, void *data) { CResItemList *rl = (CResItemList *)data; rl->push_front (resItem); @@ -153,11 +153,11 @@ namespace zypp } bool - QueueItemInstall::process (ResolverContextPtr context, QueueItemList & qil) + QueueItemInstall::process (ResolverContext_Ptr context, QueueItemList & qil) { _DBG("RC_SPEW") << "QueueItemInstall::process(" << this->asString() << ")" << endl; - constResItemPtr resItem = _resItem; + ResItem_constPtr resItem = _resItem; string res_name = resItem->asString(); string msg; ResItemStatus status = context->getStatus (resItem); @@ -168,7 +168,7 @@ namespace zypp if (_upgrades && _resItem->equals (_upgrades)) { - ResolverInfoPtr info; + ResolverInfo_Ptr info; _DBG("RC_SPEW") << "upgrades equal resItem, skipping" << endl; @@ -206,13 +206,13 @@ namespace zypp && resItem_status_is_to_be_uninstalled (context->getStatus (resItem)) && !_needed_by.empty()) { - QueueItemUninstallPtr uninstall_item; + QueueItemUninstall_Ptr uninstall_item; for (CResItemList::const_iterator iter = _needed_by.begin(); iter != _needed_by.end(); iter++) { uninstall_item = new QueueItemUninstall (world(), *iter, "uninstallable resolvable"); qil.push_front (uninstall_item); } - + goto finished; } @@ -227,7 +227,7 @@ namespace zypp } else { - QueueItemUninstallPtr uninstall_item; + QueueItemUninstall_Ptr uninstall_item; _DBG("RC_SPEW") << "upgrade install of " << resItem->asString() << endl; @@ -245,7 +245,7 @@ namespace zypp /* Log which resItem need this install */ if (!_needed_by.empty()) { - ResolverInfoNeededByPtr info; + ResolverInfoNeededBy_Ptr info; info = new ResolverInfoNeededBy (resItem); info->addRelatedResItemList (_needed_by); @@ -278,7 +278,7 @@ namespace zypp const Capability dep = *iter; if (!context->requirementIsMet (dep, false)) { _DBG("RC_SPEW") << "this requires " << dep.asString() << endl; - QueueItemRequirePtr req_item = new QueueItemRequire (world(), dep); + QueueItemRequire_Ptr req_item = new QueueItemRequire (world(), dep); req_item->addResItem (resItem); qil.push_front (req_item); } @@ -290,7 +290,7 @@ namespace zypp for (CapSet::const_iterator iter = deps.begin(); iter != deps.end(); iter++) { const Capability dep = *iter; _DBG("RC_SPEW") << "this conflicts with '" << dep.asString() << "'" << endl; - QueueItemConflictPtr conflict_item = new QueueItemConflict (world(), dep, resItem); + QueueItemConflict_Ptr conflict_item = new QueueItemConflict (world(), dep, resItem); qil.push_front (conflict_item); } @@ -300,7 +300,7 @@ namespace zypp for (CapSet::const_iterator iter = deps.begin(); iter != deps.end(); iter++) { const Capability dep = *iter; _DBG("RC_SPEW") << "this obsoletes " << dep.asString() << endl; - QueueItemConflictPtr conflict_item = new QueueItemConflict (world(), dep, resItem); + QueueItemConflict_Ptr conflict_item = new QueueItemConflict (world(), dep, resItem); conflict_item->setActuallyAnObsolete(); qil.push_front (conflict_item); } @@ -315,9 +315,9 @@ namespace zypp } for (CResItemList::const_iterator iter = conflicts.begin(); iter != conflicts.end(); iter++) { - constResItemPtr conflicting_resItem = *iter; - ResolverInfoPtr log_info; - QueueItemUninstallPtr uninstall_item; + ResItem_constPtr conflicting_resItem = *iter; + ResolverInfo_Ptr log_info; + QueueItemUninstall_Ptr uninstall_item; /* Check to see if we conflict with ourself and don't create * an uninstall item for it if we do. This is Debian's way of @@ -337,18 +337,18 @@ namespace zypp qil.push_front (uninstall_item); } } - + finished: - + return true; } - QueueItemPtr + QueueItem_Ptr QueueItemInstall::copy (void) const { - QueueItemInstallPtr new_install = new QueueItemInstall (world(), _resItem); - ((QueueItemPtr)new_install)->copy((constQueueItemPtr)this); + QueueItemInstall_Ptr new_install = new QueueItemInstall (world(), _resItem); + ((QueueItem_Ptr)new_install)->copy((QueueItem_constPtr)this); new_install->_upgrades = _upgrades; new_install->_deps_satisfied_by_this_install = CapSet(_deps_satisfied_by_this_install.begin(), _deps_satisfied_by_this_install.end()); @@ -362,12 +362,12 @@ namespace zypp int - QueueItemInstall::cmp (constQueueItemPtr item) const + QueueItemInstall::cmp (QueueItem_constPtr item) const { int cmp = this->compare (item); if (cmp != 0) return cmp; - constQueueItemInstallPtr install = item; + QueueItemInstall_constPtr install = dynamic_pointer_cast(item); return ResItem::compare (_resItem, install->_resItem); } @@ -381,7 +381,7 @@ namespace zypp void - QueueItemInstall::addNeededBy (constResItemPtr resItem) + QueueItemInstall::addNeededBy (ResItem_constPtr resItem) { _needed_by.push_front (resItem); } diff --git a/zypp/solver/detail/QueueItemInstall.h b/zypp/solver/detail/QueueItemInstall.h index 1c37ba0..e518fee 100644 --- a/zypp/solver/detail/QueueItemInstall.h +++ b/zypp/solver/detail/QueueItemInstall.h @@ -24,15 +24,16 @@ #include #include -#include +#include +#include #include #include #include #include ///////////////////////////////////////////////////////////////////////// -namespace zypp +namespace zypp { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// namespace solver @@ -44,64 +45,64 @@ namespace zypp /////////////////////////////////////////////////////////////////// // // CLASS NAME : QueueItemInstall - + class QueueItemInstall : public QueueItem { - REP_BODY(QueueItemInstall); - + + private: - constResItemPtr _resItem; - constResItemPtr _upgrades; + ResItem_constPtr _resItem; + ResItem_constPtr _upgrades; CapSet _deps_satisfied_by_this_install; CResItemList _needed_by; int _channel_priority; int _other_penalty; - + bool _explicitly_requested; - + public: - - QueueItemInstall (WorldPtr world, constResItemPtr resItem); + + QueueItemInstall (World_Ptr world, ResItem_constPtr resItem); virtual ~QueueItemInstall(); - + // ---------------------------------- I/O - + static std::string toString (const QueueItemInstall & item); - + virtual std::ostream & dumpOn(std::ostream & str ) const; - + friend std::ostream& operator<<(std::ostream&, const QueueItemInstall & item); - + std::string asString (void ) const; - + // ---------------------------------- accessors - - constResItemPtr resItem (void) const { return _resItem; } - - constResItemPtr upgrades (void) const { return _upgrades; } - void setUpgrades (constResItemPtr upgrades) { _upgrades = upgrades; } - + + ResItem_constPtr resItem (void) const { return _resItem; } + + ResItem_constPtr upgrades (void) const { return _upgrades; } + void setUpgrades (ResItem_constPtr upgrades) { _upgrades = upgrades; } + int channelPriority (void) const { return _channel_priority; } void setChannelPriority (int channel_priority) { _channel_priority = channel_priority; } - + int otherPenalty (void) { return _other_penalty; } void setOtherPenalty (int other_penalty) { _other_penalty = other_penalty; } - + void setExplicitlyRequested (void) { _explicitly_requested = true; } - + // ---------------------------------- methods - - virtual bool process (ResolverContextPtr context, QueueItemList & qil); - virtual QueueItemPtr copy (void) const; - virtual int cmp (constQueueItemPtr item) const; - - virtual bool isRedundant (ResolverContextPtr context) const { return false; } - virtual bool isSatisfied (ResolverContextPtr context) const; - + + virtual bool process (ResolverContext_Ptr context, QueueItemList & qil); + virtual QueueItem_Ptr copy (void) const; + virtual int cmp (QueueItem_constPtr item) const; + + virtual bool isRedundant (ResolverContext_Ptr context) const { return false; } + virtual bool isSatisfied (ResolverContext_Ptr context) const; + void addDependency (const Capability & dep); - void addNeededBy (const constResItemPtr resItem); - + void addNeededBy (const ResItem_constPtr resItem); + }; - + /////////////////////////////////////////////////////////////////// };// namespace detail ///////////////////////////////////////////////////////////////////// diff --git a/zypp/solver/detail/QueueItemInstallPtr.h b/zypp/solver/detail/QueueItemInstallPtr.h index 291240b..57b7e4f 100644 --- a/zypp/solver/detail/QueueItemInstallPtr.h +++ b/zypp/solver/detail/QueueItemInstallPtr.h @@ -1,5 +1,5 @@ /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* QueueItemInstallPtr.h +/* QueueItemInstall_Ptr.h * * Copyright (C) 2005 SUSE Linux Products GmbH * @@ -18,14 +18,14 @@ * 02111-1307, USA. */ -#ifndef _QueueItemInstallPtr_h -#define _QueueItemInstallPtr_h +#ifndef _QueueItemInstall_Ptr_h +#define _QueueItemInstall_Ptr_h -#include -#include +#include "zypp/base/PtrTypes.h" +#include ///////////////////////////////////////////////////////////////////////// -namespace zypp +namespace zypp { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// namespace solver @@ -35,10 +35,10 @@ namespace zypp { /////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// - // CLASS NAME : QueueItemInstallPtr - // CLASS NAME : constQueueItemInstallPtr + // CLASS NAME : QueueItemInstall_Ptr + // CLASS NAME : QueueItemInstall_constPtr /////////////////////////////////////////////////////////////////// - DEFINE_DERIVED_POINTER(QueueItemInstall,QueueItem); + DEFINE_PTR_TYPE(QueueItemInstall); /////////////////////////////////////////////////////////////////// };// namespace detail @@ -49,4 +49,4 @@ namespace zypp /////////////////////////////////////////////////////////////////////// };// namespace zypp ///////////////////////////////////////////////////////////////////////// -#endif // _QueueItemInstallPtr_h +#endif // _QueueItemInstall_Ptr_h diff --git a/zypp/solver/detail/QueueItemPtr.h b/zypp/solver/detail/QueueItemPtr.h index 30c07b8..635e41b 100644 --- a/zypp/solver/detail/QueueItemPtr.h +++ b/zypp/solver/detail/QueueItemPtr.h @@ -1,5 +1,5 @@ /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* QueueItemPtr.h +/* QueueItem_Ptr.h * * Copyright (C) 2005 SUSE Linux Products GmbH * @@ -18,10 +18,10 @@ * 02111-1307, USA. */ -#ifndef _QueueItemPtr_h -#define _QueueItemPtr_h +#ifndef _QueueItem_Ptr_h +#define _QueueItem_Ptr_h -#include +#include "zypp/base/PtrTypes.h" ///////////////////////////////////////////////////////////////////////// namespace zypp @@ -34,10 +34,10 @@ namespace zypp { /////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// - // CLASS NAME : QueueItemPtr - // CLASS NAME : constQueueItemPtr + // CLASS NAME : QueueItem_Ptr + // CLASS NAME : QueueItem_constPtr /////////////////////////////////////////////////////////////////// - DEFINE_BASE_POINTER(QueueItem); + DEFINE_PTR_TYPE(QueueItem); /////////////////////////////////////////////////////////////////// };// namespace detail @@ -48,4 +48,4 @@ namespace zypp /////////////////////////////////////////////////////////////////////// };// namespace zypp ///////////////////////////////////////////////////////////////////////// -#endif // _QueueItemPtr_h +#endif // _QueueItem_Ptr_h diff --git a/zypp/solver/detail/QueueItemRequire.cc b/zypp/solver/detail/QueueItemRequire.cc index 5f0d68f..a4c59c3 100644 --- a/zypp/solver/detail/QueueItemRequire.cc +++ b/zypp/solver/detail/QueueItemRequire.cc @@ -19,8 +19,6 @@ * 02111-1307, USA. */ -#include - #include #include #include @@ -34,7 +32,7 @@ #include ///////////////////////////////////////////////////////////////////////// -namespace zypp +namespace zypp { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// namespace solver @@ -42,20 +40,20 @@ namespace zypp ///////////////////////////////////////////////////////////////////// namespace detail { /////////////////////////////////////////////////////////////////// - + using namespace std; - - IMPL_DERIVED_POINTER(QueueItemRequire,QueueItem); - + + IMPL_PTR_TYPE(QueueItemRequire); + //--------------------------------------------------------------------------- - + string QueueItemRequire::asString ( void ) const { return toString (*this); } - - + + string QueueItemRequire::toString ( const QueueItemRequire & item) { @@ -76,28 +74,28 @@ namespace zypp if (item._remove_only) ret += ", Remove Only"; if (item._is_child) ret += ", Child"; ret += "]"; - + return ret; } - - + + ostream & QueueItemRequire::dumpOn( ostream & str ) const { str << asString(); return str; } - - + + ostream& operator<<( ostream& os, const QueueItemRequire & item) { return os << item.asString(); } - + //--------------------------------------------------------------------------- - - QueueItemRequire::QueueItemRequire (WorldPtr world, const Capability & dep) + + QueueItemRequire::QueueItemRequire (World_Ptr world, const Capability & dep) : QueueItem (QUEUE_ITEM_TYPE_REQUIRE, world) , _dep (dep) , _requiring_resItem (NULL) @@ -107,42 +105,42 @@ namespace zypp , _is_child (false) { } - - + + QueueItemRequire::~QueueItemRequire() { } - + //--------------------------------------------------------------------------- - + void - QueueItemRequire::addResItem (constResItemPtr resItem) + QueueItemRequire::addResItem (ResItem_constPtr resItem) { assert (_requiring_resItem == NULL); _requiring_resItem = resItem; } - - + + //--------------------------------------------------------------------------- - - typedef std::map UniqTable; - + + typedef std::map UniqTable; + typedef struct { - constResItemPtr resItem; + ResItem_constPtr resItem; const Capability *dep; - ResolverContextPtr context; - WorldPtr world; + ResolverContext_Ptr context; + World_Ptr world; CResItemList providers; UniqTable *uniq; } RequireProcessInfo; - - + + static bool - require_process_cb (constResItemPtr resItem, const Capability & cap, void *data) + require_process_cb (ResItem_constPtr resItem, const Capability & cap, void *data) { RequireProcessInfo *info = (RequireProcessInfo *)data; ResItemStatus status; - + status = info->context->getStatus (resItem); //fprintf (stderr, "require_process_cb(res: %s, spec %s, status %s)\n", resItem->asString().c_str(), cap.asString().c_str(), ResolverContext::toString(status).c_str()); //fprintf (stderr, "require_process_cb(info->dep: %s)\n", info->dep ? info->dep->asString().c_str() : "(null)"); @@ -153,30 +151,30 @@ namespace zypp && *(info->dep) != cap) { return true; } - + if ((! resItem_status_is_to_be_uninstalled (status)) && ! info->context->isParallelInstall (resItem) && info->uniq->find(resItem) == info->uniq->end() && info->context->resItemIsPossible (resItem) && ! info->world->resItemIsLocked (resItem)) { - + info->providers.push_front (resItem); (*(info->uniq))[resItem] = true; } - + return true; } - - + + static bool - no_installable_providers_info_cb (constResItemPtr resItem, const Capability & cap, void *data) + no_installable_providers_info_cb (ResItem_constPtr resItem, const Capability & cap, void *data) { RequireProcessInfo *info = (RequireProcessInfo *)data; ResItemStatus status; string msg_str; - + status = info->context->getStatus (resItem); - + if (resItem_status_is_to_be_uninstalled (status)) { msg_str = resItem->name() + " provides " + cap.asString() + ", but is scheduled to be uninstalled."; } else if (info->context->isParallelInstall (resItem)) { @@ -186,32 +184,32 @@ namespace zypp } else if (info->world->resItemIsLocked (resItem)) { msg_str = resItem->name() + " provides " + cap.asString() + ", but it is locked."; } - + if (!msg_str.empty()) { info->context->addInfoString (info->resItem, RESOLVER_INFO_PRIORITY_VERBOSE, msg_str); } - + return true; } - - + + static bool - look_for_upgrades_cb (constResItemPtr resItem, void *data) + look_for_upgrades_cb (ResItem_constPtr resItem, void *data) { CResItemList *rl = (CResItemList *)data; rl->push_front (resItem); return true; } - - + + static bool - codependent_resItems (constResItemPtr r1, constResItemPtr r2) + codependent_resItems (ResItem_constPtr r1, ResItem_constPtr r2) { string name1 = r1->name(); string name2 = r2->name(); int len1 = name1.size(); int len2 = name2.size(); - + if (len2 < len1) { string swap = name1; int swap_len = len1; @@ -220,111 +218,111 @@ namespace zypp len1 = len2; len2 = swap_len; } - + // foo and foo-bar are automatically co-dependent if (len1 < len2 && strncmp (name1.c_str(), name2.c_str(), len1) == 0 && name2[len1] == '-') { return true; } - + return false; } - - + + bool - QueueItemRequire::process (ResolverContextPtr context, QueueItemList & new_items) + QueueItemRequire::process (ResolverContext_Ptr context, QueueItemList & new_items) { if (getenv ("RC_SPEW")) fprintf (stderr, "QueueItemRequire::process(%s)\n", this->asString().c_str()); - + if (context->requirementIsMet (_dep, _is_child)) { if (getenv ("RC_SPEW")) fprintf (stderr, "requirement is already met in current context\n"); // rc_queue_item_free (item); return true; } - + RequireProcessInfo info; - + info.resItem = _requiring_resItem; info.dep = _is_child ? &_dep : NULL; info.context = context; info.world = world(); info.uniq = new UniqTable(); //FIXME: op: g_hash_table_new (rc_resItem_spec_hash, rc_resItem_spec_equal); - + int num_providers = 0; - + if (! _remove_only) { - + world()->foreachProvidingResItem (_dep, require_process_cb, &info); - + num_providers = info.providers.size(); - + if (getenv ("RC_SPEW")) fprintf (stderr, "requirement is met by %d resolvable\n", num_providers); } - + std::string msg; - + if (num_providers == 0) { - + if (getenv ("RC_SPEW")) fprintf (stderr, "Unfulfilled requirement, try different solution\n"); - - QueueItemUninstallPtr uninstall_item = NULL; - QueueItemBranchPtr branch_item = NULL; + + QueueItemUninstall_Ptr uninstall_item = NULL; + QueueItemBranch_Ptr branch_item = NULL; bool explore_uninstall_branch = true; - + if (_upgraded_resItem == NULL) { - ResolverInfoPtr err_info; - + ResolverInfo_Ptr err_info; + msg = string ("There are no ") + (_remove_only ? "alternative installed" : "installable") + " providers of " + _dep.asString(); if (_requiring_resItem != NULL) { msg += " for "; msg += _requiring_resItem->asString(); } - + err_info = new ResolverInfoMisc (_requiring_resItem, RESOLVER_INFO_PRIORITY_VERBOSE, msg); - + context->addInfo (err_info); - + // Maybe we can add some extra info on why none of the providers are suitable. world()->foreachProvidingResItem (_dep, no_installable_providers_info_cb, (void *)&info); } - + // If this is an upgrade, we might be able to avoid removing stuff by upgrading it instead. if (_upgraded_resItem != NULL && _requiring_resItem != NULL) { - + CResItemList upgrade_list; - + world()->foreachUpgrade (_requiring_resItem, new Channel(CHANNEL_TYPE_ANY), look_for_upgrades_cb, (void *)&upgrade_list); - + if (!upgrade_list.empty()) { string label, req_str, up_str; - + branch_item = new QueueItemBranch (world()); - + req_str = _requiring_resItem->asString(); up_str = _upgraded_resItem->asString(); - + label = string ("for requiring ") + _dep.asString() + " for " + req_str + " when upgrading " + up_str; branch_item->setLabel (label); //fprintf (stderr, "Branching: %s\n", label.c_str()); for (CResItemList::const_iterator iter = upgrade_list.begin(); iter != upgrade_list.end(); iter++) { - constResItemPtr upgrade_resItem = *iter; - QueueItemInstallPtr install_item; - + ResItem_constPtr upgrade_resItem = *iter; + QueueItemInstall_Ptr install_item; + if (context->resItemIsPossible (upgrade_resItem)) { - + install_item = new QueueItemInstall (world(), upgrade_resItem); install_item->setUpgrades (_requiring_resItem); branch_item->addItem (install_item); - - ResolverInfoNeededByPtr upgrade_info = new ResolverInfoNeededBy (upgrade_resItem); + + ResolverInfoNeededBy_Ptr upgrade_info = new ResolverInfoNeededBy (upgrade_resItem); upgrade_info->addRelatedResItem (_upgraded_resItem); install_item->addInfo (upgrade_info); - + // If an upgrade resItem has its requirements met, don't do the uninstall branch. // FIXME: should we also look at conflicts here? - + if (explore_uninstall_branch) { CapSet requires = upgrade_resItem->requires(); CapSet::const_iterator iter = requires.begin(); @@ -338,66 +336,66 @@ namespace zypp explore_uninstall_branch = false; } } - + } /* if (context->resItemIsPossible ( ... */ } /* for (iter = upgrade_list; ... */ } /* if (upgrade_list) ... */ - + if (!upgrade_list.empty() && branch_item->isEmpty ()) { - + for (CResItemList::const_iterator iter = upgrade_list.begin(); iter != upgrade_list.end(); iter++) { string str; string p1, p2; - + p1 = _requiring_resItem->asString(); p2 = (*iter)->asString(); str = string ("Upgrade to ") + p2 + " to avoid removing " + p1 + " is not possible."; - - ResolverInfoMiscPtr misc_info = new ResolverInfoMisc (NULL, RESOLVER_INFO_PRIORITY_VERBOSE, str); + + ResolverInfoMisc_Ptr misc_info = new ResolverInfoMisc (NULL, RESOLVER_INFO_PRIORITY_VERBOSE, str); misc_info->addRelatedResItem (_requiring_resItem); misc_info->addRelatedResItem (*iter); context->addInfo (misc_info); - + explore_uninstall_branch = true; } - + // // The exception: we always want to consider uninstalling // when the requirement has resulted from a resItem losing // one of it's provides. - + } else if (!upgrade_list.empty() && explore_uninstall_branch && codependent_resItems (_requiring_resItem, _upgraded_resItem) && _lost_resItem == NULL) { explore_uninstall_branch = false; } - + } /* if (_upgrade_resItem && _requiring_resItem) ... */ - + // We always consider uninstalling when in verification mode. - + if (context->verifying()) { explore_uninstall_branch = true; } - + if (explore_uninstall_branch && _requiring_resItem) { - ResolverInfoPtr log_info; + ResolverInfo_Ptr log_info; uninstall_item = new QueueItemUninstall (world(),_requiring_resItem, "unsatisfied requirements"); uninstall_item->setDependency (_dep); - + if (_lost_resItem) { log_info = new ResolverInfoDependsOn (_requiring_resItem, _lost_resItem); uninstall_item->addInfo (log_info); } - + if (_remove_only) uninstall_item->setRemoveOnly (); } - + if (uninstall_item && branch_item) { - branch_item->addItem (uninstall_item); + branch_item->addItem (uninstall_item); new_items.push_front (branch_item); } else if (uninstall_item) { new_items.push_front (uninstall_item); @@ -406,76 +404,77 @@ namespace zypp } else { // We can't do anything to resolve the missing requirement, so we fail. string msg = string ("Can't satisfy requirement '") + _dep.asString() + "'"; - + context->addErrorString (NULL, msg); } - + } else if (num_providers == 1) { - + if (getenv ("RC_SPEW")) fprintf (stderr, "Found exactly one resolvable, installing it.\n"); - - QueueItemInstallPtr install_item = new QueueItemInstall (world(), info.providers.front()); + + QueueItemInstall_Ptr install_item = new QueueItemInstall (world(), info.providers.front()); install_item->addDependency (_dep); - + // The requiring resItem could be NULL if the requirement was added as an extra dependency. if (_requiring_resItem) { install_item->addNeededBy (_requiring_resItem); } new_items.push_front (install_item); - + } else if (num_providers > 1) { - + if (getenv ("RC_SPEW")) fprintf (stderr, "Found more than one resolvable, branching.\n"); - + //fprintf (stderr, "Found more than one resItem, branching.\n"); - QueueItemBranchPtr branch_item = new QueueItemBranch (world()); - + QueueItemBranch_Ptr branch_item = new QueueItemBranch (world()); + for (CResItemList::const_iterator iter = info.providers.begin(); iter != info.providers.end(); iter++) { - QueueItemInstallPtr install_item = new QueueItemInstall (world(), *iter); + QueueItemInstall_Ptr install_item = new QueueItemInstall (world(), *iter); install_item->addDependency (_dep); branch_item->addItem (install_item); - + // The requiring resItem could be NULL if the requirement was added as an extra dependency. if (_requiring_resItem) { install_item->addNeededBy (_requiring_resItem); } } - + new_items.push_front (branch_item); - + } else { abort (); } - - + + // rc_queue_item_free (item); return true; } - + //--------------------------------------------------------------------------- - - QueueItemPtr + + QueueItem_Ptr QueueItemRequire::copy (void) const { - QueueItemRequirePtr new_require = new QueueItemRequire (world(), _dep); - ((QueueItemPtr)new_require)->copy((constQueueItemPtr)this); - + QueueItemRequire_Ptr new_require = new QueueItemRequire (world(), _dep); +#warning wrong casts + ((QueueItem_Ptr)new_require)->copy((QueueItem_constPtr)this); + new_require->_requiring_resItem = _requiring_resItem; new_require->_upgraded_resItem = _upgraded_resItem; new_require->_remove_only = _remove_only; - + return new_require; } - - + + int - QueueItemRequire::cmp (constQueueItemPtr item) const + QueueItemRequire::cmp (QueueItem_constPtr item) const { int cmp = this->compare (item); // assures equal type if (cmp != 0) return cmp; - - constQueueItemRequirePtr require = item; + + QueueItemRequire_constPtr require = dynamic_pointer_cast(item); if (_dep != require->dependency()) { @@ -483,7 +482,7 @@ namespace zypp } return cmp; } - + /////////////////////////////////////////////////////////////////// };// namespace detail ///////////////////////////////////////////////////////////////////// diff --git a/zypp/solver/detail/QueueItemRequire.h b/zypp/solver/detail/QueueItemRequire.h index 21d43eb..c800f24 100644 --- a/zypp/solver/detail/QueueItemRequire.h +++ b/zypp/solver/detail/QueueItemRequire.h @@ -24,15 +24,16 @@ #include #include -#include +#include +#include #include #include #include #include ///////////////////////////////////////////////////////////////////////// -namespace zypp +namespace zypp { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// namespace solver @@ -40,58 +41,58 @@ namespace zypp ///////////////////////////////////////////////////////////////////// namespace detail { /////////////////////////////////////////////////////////////////// - + /////////////////////////////////////////////////////////////////// // // CLASS NAME : QueueItemRequire - + class QueueItemRequire : public QueueItem { - REP_BODY(QueueItemRequire); - + + private: const Capability _dep; - constResItemPtr _requiring_resItem; - constResItemPtr _upgraded_resItem; - constResItemPtr _lost_resItem; + ResItem_constPtr _requiring_resItem; + ResItem_constPtr _upgraded_resItem; + ResItem_constPtr _lost_resItem; bool _remove_only; bool _is_child; - + public: - - QueueItemRequire (WorldPtr world, const Capability & dep); + + QueueItemRequire (World_Ptr world, const Capability & dep); virtual ~QueueItemRequire(); - + // ---------------------------------- I/O - + static std::string toString (const QueueItemRequire & item); - + virtual std::ostream & dumpOn(std::ostream & str ) const; - + friend std::ostream& operator<<(std::ostream&, const QueueItemRequire & item); - + std::string asString (void ) const; - + // ---------------------------------- accessors - + const Capability & dependency (void) const { return _dep; } - + void setRemoveOnly (void) { _remove_only = true; } - void setUpgradedResItem (constResItemPtr upgraded_resItem) { _upgraded_resItem = upgraded_resItem; } - void setLostResItem (constResItemPtr lost_resItem) { _lost_resItem = lost_resItem; } - + void setUpgradedResItem (ResItem_constPtr upgraded_resItem) { _upgraded_resItem = upgraded_resItem; } + void setLostResItem (ResItem_constPtr lost_resItem) { _lost_resItem = lost_resItem; } + // ---------------------------------- methods - - virtual bool process (ResolverContextPtr context, QueueItemList & qil); - virtual QueueItemPtr copy (void) const; - virtual int cmp (constQueueItemPtr item) const; - virtual bool isRedundant (ResolverContextPtr context) const { return false; } - virtual bool isSatisfied (ResolverContextPtr context) const { return false; } - - void addResItem (constResItemPtr resItem); - - + + virtual bool process (ResolverContext_Ptr context, QueueItemList & qil); + virtual QueueItem_Ptr copy (void) const; + virtual int cmp (QueueItem_constPtr item) const; + virtual bool isRedundant (ResolverContext_Ptr context) const { return false; } + virtual bool isSatisfied (ResolverContext_Ptr context) const { return false; } + + void addResItem (ResItem_constPtr resItem); + + }; - + /////////////////////////////////////////////////////////////////// };// namespace detail ///////////////////////////////////////////////////////////////////// diff --git a/zypp/solver/detail/QueueItemRequirePtr.h b/zypp/solver/detail/QueueItemRequirePtr.h index d4c6c23..396d8fe 100644 --- a/zypp/solver/detail/QueueItemRequirePtr.h +++ b/zypp/solver/detail/QueueItemRequirePtr.h @@ -1,5 +1,5 @@ /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* QueueItemRequirePtr.h +/* QueueItemRequire_Ptr.h * * Copyright (C) 2005 SUSE Linux Products GmbH * @@ -18,14 +18,14 @@ * 02111-1307, USA. */ -#ifndef _QueueItemRequirePtr_h -#define _QueueItemRequirePtr_h +#ifndef _QueueItemRequire_Ptr_h +#define _QueueItemRequire_Ptr_h -#include -#include +#include "zypp/base/PtrTypes.h" +#include ///////////////////////////////////////////////////////////////////////// -namespace zypp +namespace zypp { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// namespace solver @@ -35,10 +35,10 @@ namespace zypp { /////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// - // CLASS NAME : QueueItemRequirePtr - // CLASS NAME : constQueueItemRequirePtr + // CLASS NAME : QueueItemRequire_Ptr + // CLASS NAME : QueueItemRequire_constPtr /////////////////////////////////////////////////////////////////// - DEFINE_DERIVED_POINTER(QueueItemRequire,QueueItem); + DEFINE_PTR_TYPE(QueueItemRequire); /////////////////////////////////////////////////////////////////// };// namespace detail @@ -49,4 +49,4 @@ namespace zypp /////////////////////////////////////////////////////////////////////// };// namespace zypp ///////////////////////////////////////////////////////////////////////// -#endif // _QueueItemRequirePtr_h +#endif // _QueueItemRequire_Ptr_h diff --git a/zypp/solver/detail/QueueItemUninstall.cc b/zypp/solver/detail/QueueItemUninstall.cc index 1e225ce..d9637c0 100644 --- a/zypp/solver/detail/QueueItemUninstall.cc +++ b/zypp/solver/detail/QueueItemUninstall.cc @@ -28,7 +28,7 @@ #include ///////////////////////////////////////////////////////////////////////// -namespace zypp +namespace zypp { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// namespace solver @@ -36,25 +36,25 @@ namespace zypp ///////////////////////////////////////////////////////////////////// namespace detail { /////////////////////////////////////////////////////////////////// - + using namespace std; - - IMPL_DERIVED_POINTER(QueueItemUninstall,QueueItem); - + + IMPL_PTR_TYPE(QueueItemUninstall); + //--------------------------------------------------------------------------- - + string QueueItemUninstall::asString ( void ) const { return toString (*this); } - - + + string QueueItemUninstall::toString ( const QueueItemUninstall & item) { string ret = "[Uninstall: "; - + ret += item._resItem->asString(); ret += " ("; ret += item._reason; ret += ")"; if (item._dep_leading_to_uninstall != Capability()) { @@ -71,28 +71,28 @@ namespace zypp if (item._due_to_obsolete) ret += ", Due To Obsolete"; if (item._unlink) ret += ", Unlink"; ret += "]"; - + return ret; } - - + + ostream & QueueItemUninstall::dumpOn( ostream & str ) const { str << asString(); return str; } - - + + ostream& operator<<( ostream& os, const QueueItemUninstall & item) { return os << item.asString(); } - + //--------------------------------------------------------------------------- - - QueueItemUninstall::QueueItemUninstall (WorldPtr world, constResItemPtr resItem, const std::string & reason) + + QueueItemUninstall::QueueItemUninstall (World_Ptr world, ResItem_constPtr resItem, const std::string & reason) : QueueItem (QUEUE_ITEM_TYPE_UNINSTALL, world) , _resItem (resItem) , _reason (reason) @@ -105,14 +105,14 @@ namespace zypp , _unlink (false) { } - - + + QueueItemUninstall::~QueueItemUninstall() { } - + //--------------------------------------------------------------------------- - + void QueueItemUninstall::setUnlink () { @@ -121,84 +121,84 @@ namespace zypp processed later. We want to process unlinks as late as possible... this will make our "is this item in use" check more accurate. */ setPriority (0); - + return; } - + //--------------------------------------------------------------------------- - + typedef struct { - ResolverContextPtr context; + ResolverContext_Ptr context; bool cancel_unlink; } UnlinkCheckInfo; - - + + static bool - unlink_check_cb (constResItemPtr resItem, const Capability & dep, void *data) + unlink_check_cb (ResItem_constPtr resItem, const Capability & dep, void *data) { UnlinkCheckInfo *info = (UnlinkCheckInfo *)data; - + if (info->cancel_unlink) - return true; - + return true; + if (! info->context->resItemIsPresent (resItem)) return true; - + if (info->context->requirementIsMet (dep, false)) return true; - + info->cancel_unlink = true; - + return true; } - + typedef struct { - WorldPtr world; - ResolverContextPtr context; - constResItemPtr uninstalled_resItem; - constResItemPtr upgraded_resItem; + World_Ptr world; + ResolverContext_Ptr context; + ResItem_constPtr uninstalled_resItem; + ResItem_constPtr upgraded_resItem; QueueItemList *require_items; bool remove_only; } UninstallProcessInfo; - - + + static bool - uninstall_process_cb (constResItemPtr resItem, const Capability & dep, void *data) + uninstall_process_cb (ResItem_constPtr resItem, const Capability & dep, void *data) { UninstallProcessInfo *info = (UninstallProcessInfo *)data; - + if (! info->context->resItemIsPresent (resItem)) return true; - + if (info->context->requirementIsMet (dep, false)) return true; - - QueueItemRequirePtr require_item = new QueueItemRequire (info->world, dep); + + QueueItemRequire_Ptr require_item = new QueueItemRequire (info->world, dep); require_item->addResItem (resItem); if (info->remove_only) { require_item->setRemoveOnly (); } require_item->setUpgradedResItem (info->upgraded_resItem); require_item->setLostResItem (info->uninstalled_resItem); - + info->require_items->push_front (require_item); - + return true; } - - + + bool - QueueItemUninstall::process (ResolverContextPtr context, QueueItemList & qil) + QueueItemUninstall::process (ResolverContext_Ptr context, QueueItemList & qil) { ResItemStatus status; string pkg_str; - + pkg_str = _resItem->asString(); - + status = context->getStatus (_resItem); - + if (getenv ("RC_SPEW")) fprintf (stderr, "QueueItemUninstall::process(<%s>%s)%s\n", ResolverContext::toString(status).c_str(), _resItem->asString().c_str(), _unlink ? "[unlink]" : ""); - + /* In the case of an unlink, we only want to uninstall the resItem if it is being used by something else. We can't really determine this with 100% accuracy, since some later queue item could cause something that requires @@ -208,120 +208,120 @@ namespace zypp (2) Is guaranteed to terminate. (!) so this will have to do. In practice, I don't think that this is a serious problem. */ - + if (_unlink) { bool unlink_cancelled = false; - + /* If the resItem is to-be-installed, obviously it is being use! */ if (status == RESOLVABLE_STATUS_TO_BE_INSTALLED) { - + unlink_cancelled = true; - + } else if (status == RESOLVABLE_STATUS_INSTALLED) { UnlinkCheckInfo info; - + /* Flag the resItem as to-be-uninstalled so that it won't satisfy any other resItem's deps during this check. */ context->setStatus (_resItem, RESOLVABLE_STATUS_TO_BE_UNINSTALLED); - + info.context = context; info.cancel_unlink = false; - + CapSet provides = _resItem->provides(); for (CapSet::const_iterator iter = provides.begin(); iter != provides.end() && ! info.cancel_unlink; iter++) { world()->foreachRequiringResItem (*iter, unlink_check_cb, &info); } - + /* Set the status back to normal. */ context->setStatus (_resItem, status); - + if (info.cancel_unlink) unlink_cancelled = true; } - + if (unlink_cancelled) { string msg = pkg_str + " is required by other installed resolvable, so it won't be unlinked."; context->addInfoString (_resItem, RESOLVER_INFO_PRIORITY_VERBOSE, msg); goto finished; } } - + context->uninstallResItem (_resItem, _upgraded_to != NULL, _due_to_obsolete, _unlink); - + if (status == RESOLVABLE_STATUS_INSTALLED) { - + if (! _explicitly_requested && world()->resItemIsLocked (_resItem)) { string msg = pkg_str + " is locked, and cannot be uninstalled."; context->addErrorString (_resItem, msg); goto finished; } - + this->logInfo (context); - + if (_dep_leading_to_uninstall != Capability() && !_due_to_conflict && !_due_to_obsolete) { - ResolverInfoPtr info = new ResolverInfoMissingReq (_resItem, _dep_leading_to_uninstall); + ResolverInfo_Ptr info = new ResolverInfoMissingReq (_resItem, _dep_leading_to_uninstall); context->addInfo (info); } - + CapSet provides = _resItem->provides(); for (CapSet::const_iterator iter = provides.begin(); iter != provides.end(); iter++) { UninstallProcessInfo info; - + info.world = world(); info.context = context; info.uninstalled_resItem = _resItem; info.upgraded_resItem = _upgraded_to; info.require_items = &qil; info.remove_only = _remove_only; - + world()->foreachRequiringResItem (*iter, uninstall_process_cb, &info); } } - + finished: // FIXME rc_queue_item_free (item); - + return true; } - + //--------------------------------------------------------------------------- - + int - QueueItemUninstall::cmp (constQueueItemPtr item) const + QueueItemUninstall::cmp (QueueItem_constPtr item) const { int cmp = this->compare (item); // assures equal type if (cmp != 0) return cmp; - - constQueueItemUninstallPtr uninstall = item; + + QueueItemUninstall_constPtr uninstall = dynamic_pointer_cast(item); return ResItem::compare (_resItem, uninstall->_resItem); } - - - QueueItemPtr + + + QueueItem_Ptr QueueItemUninstall::copy (void) const { - QueueItemUninstallPtr new_uninstall = new QueueItemUninstall (world(), _resItem, _reason); - ((QueueItemPtr)new_uninstall)->copy((constQueueItemPtr)this); - - + QueueItemUninstall_Ptr new_uninstall = new QueueItemUninstall (world(), _resItem, _reason); + ((QueueItem_Ptr)new_uninstall)->copy((QueueItem_constPtr)this); + + new_uninstall->_resItem = _resItem; new_uninstall->_dep_leading_to_uninstall = _dep_leading_to_uninstall; new_uninstall->_upgraded_to = _upgraded_to; - + new_uninstall->_explicitly_requested = _explicitly_requested; new_uninstall->_remove_only = _remove_only; new_uninstall->_due_to_conflict = _due_to_conflict; new_uninstall->_due_to_obsolete = _due_to_obsolete; new_uninstall->_unlink = _unlink; - + return new_uninstall; } - + /////////////////////////////////////////////////////////////////// };// namespace detail ///////////////////////////////////////////////////////////////////// diff --git a/zypp/solver/detail/QueueItemUninstall.h b/zypp/solver/detail/QueueItemUninstall.h index bddeffe..c3ef274 100644 --- a/zypp/solver/detail/QueueItemUninstall.h +++ b/zypp/solver/detail/QueueItemUninstall.h @@ -24,15 +24,16 @@ #include #include -#include +#include +#include #include #include #include #include ///////////////////////////////////////////////////////////////////////// -namespace zypp +namespace zypp { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// namespace solver @@ -40,61 +41,61 @@ namespace zypp ///////////////////////////////////////////////////////////////////// namespace detail { /////////////////////////////////////////////////////////////////// - + /////////////////////////////////////////////////////////////////// // // CLASS NAME : QueueItemUninstall - + class QueueItemUninstall : public QueueItem { - REP_BODY(QueueItemUninstall); - + + private: - constResItemPtr _resItem; + ResItem_constPtr _resItem; const std::string _reason; Capability _dep_leading_to_uninstall; - constResItemPtr _upgraded_to; - + ResItem_constPtr _upgraded_to; + bool _explicitly_requested; bool _remove_only; bool _due_to_conflict; bool _due_to_obsolete; bool _unlink; - + public: - - QueueItemUninstall (WorldPtr world, constResItemPtr resItem, const std::string & reason); + + QueueItemUninstall (World_Ptr world, ResItem_constPtr resItem, const std::string & reason); virtual ~QueueItemUninstall(); - + // ---------------------------------- I/O - + static std::string toString (const QueueItemUninstall & item); - + virtual std::ostream & dumpOn(std::ostream & str ) const; - + friend std::ostream& operator<<(std::ostream&, const QueueItemUninstall & item); - + std::string asString (void ) const; - + // ---------------------------------- accessors - + void setDependency (const Capability & dep) { _dep_leading_to_uninstall = dep; } void setExplicitlyRequested (void) { _explicitly_requested = true; } void setRemoveOnly (void) { _remove_only = true; } - void setUpgradedTo (constResItemPtr resItem) { _upgraded_to = resItem; } + void setUpgradedTo (ResItem_constPtr resItem) { _upgraded_to = resItem; } void setDueToConflict (void) { _due_to_conflict = true; } void setDueToObsolete (void) { _due_to_obsolete = true; } void setUnlink (void); - + // ---------------------------------- methods - - virtual bool process (ResolverContextPtr context, QueueItemList & qil); - virtual QueueItemPtr copy (void) const; - virtual int cmp (constQueueItemPtr item) const; - virtual bool isRedundant (ResolverContextPtr context) const { return false; } - virtual bool isSatisfied (ResolverContextPtr context) const { return false; } - + + virtual bool process (ResolverContext_Ptr context, QueueItemList & qil); + virtual QueueItem_Ptr copy (void) const; + virtual int cmp (QueueItem_constPtr item) const; + virtual bool isRedundant (ResolverContext_Ptr context) const { return false; } + virtual bool isSatisfied (ResolverContext_Ptr context) const { return false; } + }; - + /////////////////////////////////////////////////////////////////// };// namespace detail ///////////////////////////////////////////////////////////////////// diff --git a/zypp/solver/detail/QueueItemUninstallPtr.h b/zypp/solver/detail/QueueItemUninstallPtr.h index ec8c183..5c208ba 100644 --- a/zypp/solver/detail/QueueItemUninstallPtr.h +++ b/zypp/solver/detail/QueueItemUninstallPtr.h @@ -1,5 +1,5 @@ /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* QueueItemUninstallPtr.h +/* QueueItemUninstall_Ptr.h * * Copyright (C) 2005 SUSE Linux Products GmbH * @@ -18,14 +18,14 @@ * 02111-1307, USA. */ -#ifndef _QueueItemUninstallPtr_h -#define _QueueItemUninstallPtr_h +#ifndef _QueueItemUninstall_Ptr_h +#define _QueueItemUninstall_Ptr_h -#include -#include +#include "zypp/base/PtrTypes.h" +#include ///////////////////////////////////////////////////////////////////////// -namespace zypp +namespace zypp { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// namespace solver @@ -35,10 +35,10 @@ namespace zypp { /////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// - // CLASS NAME : QueueItemUninstallPtr - // CLASS NAME : constQueueItemUninstallPtr + // CLASS NAME : QueueItemUninstall_Ptr + // CLASS NAME : QueueItemUninstall_constPtr /////////////////////////////////////////////////////////////////// - DEFINE_DERIVED_POINTER(QueueItemUninstall,QueueItem); + DEFINE_PTR_TYPE(QueueItemUninstall); /////////////////////////////////////////////////////////////////// };// namespace detail @@ -49,4 +49,4 @@ namespace zypp /////////////////////////////////////////////////////////////////////// };// namespace zypp ///////////////////////////////////////////////////////////////////////// -#endif // _QueueItemUninstallPtr_h +#endif // _QueueItemUninstall_Ptr_h diff --git a/zypp/solver/detail/ResItem.cc b/zypp/solver/detail/ResItem.cc index 218728d..0d15339 100644 --- a/zypp/solver/detail/ResItem.cc +++ b/zypp/solver/detail/ResItem.cc @@ -20,7 +20,6 @@ * 02111-1307, USA. */ -#include #include #include #include @@ -40,7 +39,7 @@ ///////////////////////////////////////////////////////////////////////// -namespace zypp +namespace zypp { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// namespace solver @@ -48,12 +47,12 @@ namespace zypp ///////////////////////////////////////////////////////////////////// namespace detail { /////////////////////////////////////////////////////////////////// - + using namespace std; - - - IMPL_BASE_POINTER(ResItem); - + + + IMPL_PTR_TYPE(ResItem); + //--------------------------------------------------------------------------- string @@ -67,14 +66,14 @@ namespace zypp return res + "]"; } - + string ResItem::asString ( bool full ) const { return toString (*this, full); } - - + + string ResItem::toString ( const ResItem & resItem, bool full ) { @@ -87,9 +86,9 @@ namespace zypp res += resItem.kind().asString(); res += ":"; } - + res += resItem.name(); - + string ed = resItem.edition().asString(); if (!ed.empty() && ed != "EDITION-UNSPEC") @@ -102,27 +101,27 @@ namespace zypp res += "."; res += resItem.arch().asString(); } - + if (!resItem.channel()->system()) { res += "["; res += (resItem.channel() == NULL) ? "(channel?)" : resItem.channel()->name(); res += "]"; } if (!full) return res; - + if (resItem.isInstalled()) res += ""; if (resItem.local()) res += ""; - + res += "FileSize "; - res += stringutil::numstring (resItem.fileSize()); + res += str::numstring (resItem.fileSize()); res += ", InstalledSize "; - res += stringutil::numstring (resItem.installedSize()); - + res += str::numstring (resItem.installedSize()); + if (!resItem.requires().empty()) { res += ", Requires: "; res += capSetToString(resItem.requires()); } - + if (!resItem.provides().empty()) { res += ", Provides: "; res += capSetToString(resItem.provides()); @@ -135,7 +134,7 @@ namespace zypp res += ", Obsoletes: "; res += capSetToString(resItem.obsoletes()); } - + if (!resItem.suggests().empty()) { res += ", Suggests: "; res += capSetToString(resItem.suggests()); @@ -150,8 +149,8 @@ namespace zypp } return res; } - - + + string ResItem::toString ( const CResItemList & rl, bool full ) { @@ -162,24 +161,24 @@ namespace zypp } return res + "]"; } - - + + ostream & ResItem::dumpOn( ostream & str ) const { str << asString(); return str; } - - + + ostream& operator<<( ostream& os, const ResItem& edition) { return os << edition.asString(); } - + //--------------------------------------------------------------------------- - + ResItem::ResItem (const Resolvable::Kind & kind, const string & name, int epoch, const string & version, const string & release, const Arch & arch) : _channel (false) , _installed (false) @@ -187,7 +186,7 @@ namespace zypp , _locked (false) , _file_size (0) , _installed_size (0) - + { Edition _edition( version, release, zypp::str::numstring(epoch) ); @@ -203,33 +202,33 @@ namespace zypp shared_ptr selImpl; zypp::Selection::Ptr sel( zypp::detail::makeResolvableAndImpl( name, _edition, arch, selImpl ) ); - _resObject = sel; - } else if (kind == "Product") + _resObject = sel; + } else if (kind == "Product") { // shared_ptr proImpl; // zypp::Product::Ptr pro( zypp::detail::makeResolvableAndImpl( name, _edition, arch, // proImpl ) ); -// _resObject = pro; +// _resObject = pro; } else if (kind == "Patch") { shared_ptr patchImpl; zypp::Patch::Ptr patch( zypp::detail::makeResolvableAndImpl( name, _edition, arch, patchImpl ) ); - _resObject = patch; + _resObject = patch; } else if (kind == "Script") { shared_ptr scriptImpl; zypp::Script::Ptr script( zypp::detail::makeResolvableAndImpl( name, _edition, arch, scriptImpl ) ); - _resObject = script; + _resObject = script; } else if (kind == "Message") { shared_ptr messageImpl; zypp::Message::Ptr message( zypp::detail::makeResolvableAndImpl( name, _edition, arch, messageImpl ) ); - _resObject = message; + _resObject = message; } - + } ResItem::ResItem(const ResObject::Ptr & resObject) @@ -243,13 +242,13 @@ namespace zypp assert (resObject); _resObject = resObject; } - + ResItem::~ResItem() { } - + //--------------------------------------------------------------------------- - + bool ResItem::isInstalled () const { @@ -261,7 +260,7 @@ namespace zypp } bool - ResItem::equals(constResItemPtr item) const { + ResItem::equals(ResItem_constPtr item) const { return ((kind() == item->kind()) && (name() == item->name()) && Edition::compare( edition(), item->edition()) == 0); @@ -273,9 +272,9 @@ namespace zypp return ((compKind == kind()) && (compName == name()) && Edition::compare( compEdition, edition()) == 0); - } - - int ResItem::compare (constResItemPtr res1, constResItemPtr res2) { + } + + int ResItem::compare (ResItem_constPtr res1, ResItem_constPtr res2) { int rc = 0; const string name1 = res1->name(); @@ -292,7 +291,7 @@ namespace zypp return rc; } - + /////////////////////////////////////////////////////////////////// };// namespace detail ///////////////////////////////////////////////////////////////////// diff --git a/zypp/solver/detail/ResItem.h b/zypp/solver/detail/ResItem.h index 6b9deac..e578545 100644 --- a/zypp/solver/detail/ResItem.h +++ b/zypp/solver/detail/ResItem.h @@ -23,9 +23,13 @@ #include #include -#include +#include #include +#include "zypp/base/ReferenceCounted.h" +#include "zypp/base/NonCopyable.h" +#include "zypp/base/PtrTypes.h" + #include #include #include @@ -35,7 +39,7 @@ #include ///////////////////////////////////////////////////////////////////////// -namespace zypp +namespace zypp { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// namespace solver @@ -44,83 +48,83 @@ namespace zypp namespace detail { /////////////////////////////////////////////////////////////////// - typedef std::list ResItemList; - typedef std::list CResItemList; - - typedef bool (*ResItemFn) (ResItemPtr r, void *data); - typedef bool (*CResItemFn) (constResItemPtr r, void *data); - typedef bool (*ResItemPairFn) (constResItemPtr r1, constResItemPtr r2, void *data); - typedef bool (*ResItemAndDepFn) (constResItemPtr r, const Capability & dep, void *data); - + typedef std::list ResItemList; + typedef std::list CResItemList; + + typedef bool (*ResItemFn) (ResItem_Ptr r, void *data); + typedef bool (*CResItemFn) (ResItem_constPtr r, void *data); + typedef bool (*ResItemPairFn) (ResItem_constPtr r1, ResItem_constPtr r2, void *data); + typedef bool (*ResItemAndDepFn) (ResItem_constPtr r, const Capability & dep, void *data); + /////////////////////////////////////////////////////////////////// // // CLASS NAME : ResItem /** * **/ - - class ResItem : public CountedRep { - REP_BODY(ResItem); - + + class ResItem : public base::ReferenceCounted, private base::NonCopyable { + + private: - constChannelPtr _channel; - + Channel_constPtr _channel; + bool _installed; bool _local; bool _locked; - + size_t _file_size; size_t _installed_size; - + protected: - + // ---------------------------------- accessors - + void setLocal (bool local) { _local = local; } ResObject::Ptr _resObject; - + public: - + ResItem(const Resolvable::Kind & kind, const std::string & name, int epoch = Edition::noepoch, const std::string & version = "", const std::string & release = "", const Arch & arch = Arch()); ResItem(const ResObject::Ptr & resObject); - ResItem(const XmlNodePtr node); - + ResItem(const XmlNode_Ptr node); + virtual ~ResItem(); - + // ---------------------------------- I/O - - const XmlNodePtr asXmlNode (void) const; - + + const XmlNode_Ptr asXmlNode (void) const; + static std::string toString ( const ResItem & res, bool full = false ); - + static std::string toString ( const CResItemList & reslist, bool full = false ); - + virtual std::ostream & dumpOn( std::ostream & str ) const; - + friend std::ostream& operator<<( std::ostream & str, const ResItem & str); - + std::string asString ( bool full = false ) const; - + // ---------------------------------- accessors - - constChannelPtr channel() const { return _channel; } - void setChannel (constChannelPtr channel) { _channel = channel; } - + + Channel_constPtr channel() const { return _channel; } + void setChannel (Channel_constPtr channel) { _channel = channel; } + bool locked () const { return _locked; } void setLocked (bool locked) { _locked = locked; } - + bool isInstalled() const; // does *not* reflect _installed void setInstalled (bool installed) { _installed = installed; } - + bool local() const { return _local; } - + size_t fileSize() const { return _file_size; } void setFileSize (size_t file_size) { _file_size = file_size; } - + size_t installedSize() const { return _installed_size; } void setInstalledSize (size_t installed_size) { _installed_size = installed_size; } - + const CapSet & requires() const { return _resObject->deps().requires(); } const CapSet & provides() const { return _resObject->deps().provides(); } const CapSet & conflicts() const { return _resObject->deps().conflicts(); } @@ -134,7 +138,7 @@ namespace zypp ResObject::constPtr resObject() { return _resObject; } // Spec definitions - + const Edition & edition() const { return _resObject->edition(); } const std::string & version() const { return edition().version(); } const std::string & release() const { return edition().release(); } @@ -143,12 +147,12 @@ namespace zypp const Arch & arch() const { return _resObject->arch(); } const Resolvable::Kind & kind() const { return _resObject->kind(); } const std::string name() const { return _resObject->name(); } - bool equals(constResItemPtr item) const; + bool equals(ResItem_constPtr item) const; bool equals(const Resolvable::Kind & kind, const std::string & name, const Edition & edition) const; - - static int compare (constResItemPtr res1, constResItemPtr res2); - + + static int compare (ResItem_constPtr res1, ResItem_constPtr res2); + }; /////////////////////////////////////////////////////////////////// diff --git a/zypp/solver/detail/ResItemAndDependency.cc b/zypp/solver/detail/ResItemAndDependency.cc index 1bbfbb0..14bed93 100644 --- a/zypp/solver/detail/ResItemAndDependency.cc +++ b/zypp/solver/detail/ResItemAndDependency.cc @@ -21,13 +21,11 @@ #include "config.h" -#include - #include #include ///////////////////////////////////////////////////////////////////////// -namespace zypp +namespace zypp { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// namespace solver @@ -35,28 +33,28 @@ namespace zypp ///////////////////////////////////////////////////////////////////// namespace detail { /////////////////////////////////////////////////////////////////// - + using namespace std; - - IMPL_BASE_POINTER(ResItemAndDependency); - + + IMPL_PTR_TYPE(ResItemAndDependency); + //--------------------------------------------------------------------------- - - ResItemAndDependency::ResItemAndDependency (constResItemPtr resItem, const Capability & dependency) + + ResItemAndDependency::ResItemAndDependency (ResItem_constPtr resItem, const Capability & dependency) : _resItem(resItem) , _dependency(dependency) { } - + //--------------------------------------------------------------------------- - + string ResItemAndDependency::asString (bool full) const { return toString (*this, full); } - - + + string ResItemAndDependency::toString ( const ResItemAndDependency & r_and_d, bool full ) { @@ -67,27 +65,27 @@ namespace zypp res += "}"; return res; } - - + + ostream & ResItemAndDependency::dumpOn (ostream & str) const { str << asString(); return str; } - - + + ostream & operator<< (ostream & os, const ResItemAndDependency & r_and_d) { return os << r_and_d.asString(); } - + //--------------------------------------------------------------------------- - + /* This function also checks channels in addition to just dep relations */ /* FIXME: rc_resItem_dep_verify_relation already checks the channel */ - + bool ResItemAndDependency::verifyRelation (const Capability & dep) const { @@ -96,19 +94,17 @@ namespace zypp // don't check the channel, thereby honoring conflicts from installed resItems to to-be-installed resItems return dep.matches (_dependency); #else - if (!dep.matches (_dependency)) { + //if (!dep.matches (_dependency)) { return false; - } -#endif -#if 0 + //} if (getenv ("SPEW_DEP")) fprintf (stderr, "ResItemAndDependency::verifyRelation _resItem->channel() %s, dep->channel() %s\n", _resItem->channel()->asString().c_str(), dep->channel()->asString().c_str()); return _resItem->channel()->equals (dep->channel()); + #endif #else return true; #endif - #endif } - + /////////////////////////////////////////////////////////////////// };// namespace detail ///////////////////////////////////////////////////////////////////// diff --git a/zypp/solver/detail/ResItemAndDependency.h b/zypp/solver/detail/ResItemAndDependency.h index c27be6d..e6933ab 100644 --- a/zypp/solver/detail/ResItemAndDependency.h +++ b/zypp/solver/detail/ResItemAndDependency.h @@ -27,12 +27,16 @@ #include #include +#include "zypp/base/ReferenceCounted.h" +#include "zypp/base/NonCopyable.h" +#include "zypp/base/PtrTypes.h" + #include #include #include ///////////////////////////////////////////////////////////////////////// -namespace zypp +namespace zypp { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// namespace solver @@ -41,49 +45,49 @@ namespace zypp namespace detail { /////////////////////////////////////////////////////////////////// -typedef std::multimap ResItemTable; - typedef std::multimap ResItemAndDependencyTable; - +typedef std::multimap ResItemTable; + typedef std::multimap ResItemAndDependencyTable; + #if PHI - typedef std::list CResItemAndDependencyList; + typedef std::list CResItemAndDependencyList; #endif - + /////////////////////////////////////////////////////////////////// // // CLASS NAME : ResItemAndDependency - - class ResItemAndDependency: public CountedRep { - REP_BODY(ResItemAndDependency); - + + class ResItemAndDependency: public base::ReferenceCounted, private base::NonCopyable { + + private: - constResItemPtr _resItem; + ResItem_constPtr _resItem; const Capability _dependency; - + public: - - ResItemAndDependency (constResItemPtr resItem, const Capability & dependency); + + ResItemAndDependency (ResItem_constPtr resItem, const Capability & dependency); ~ResItemAndDependency () {} - + // ---------------------------------- I/O - + static std::string toString (const ResItemAndDependency & r_and_d, bool full = false); - + virtual std::ostream & dumpOn(std::ostream & str ) const; - + friend std::ostream& operator<<(std::ostream&, const ResItemAndDependency & r_and_d); - + std::string asString (bool full = false) const; - + // ---------------------------------- accessors - - constResItemPtr resItem() const { return _resItem; } + + ResItem_constPtr resItem() const { return _resItem; } const Capability & dependency() const { return _dependency; } - + // ---------------------------------- methods - + bool verifyRelation (const Capability & dep) const; }; - + /////////////////////////////////////////////////////////////////// };// namespace detail ///////////////////////////////////////////////////////////////////// diff --git a/zypp/solver/detail/ResItemAndDependencyPtr.h b/zypp/solver/detail/ResItemAndDependencyPtr.h index ec78a05..ce407d7 100644 --- a/zypp/solver/detail/ResItemAndDependencyPtr.h +++ b/zypp/solver/detail/ResItemAndDependencyPtr.h @@ -1,5 +1,5 @@ /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* ResItemAndDependencyPtr.h +/* ResItemAndDependency_Ptr.h * * Copyright (C) 2005 SUSE Linux Products GmbH * @@ -18,10 +18,10 @@ * 02111-1307, USA. */ -#ifndef _ResItemAndDependencyPtr_h -#define _ResItemAndDependencyPtr_h +#ifndef _ResItemAndDependency_Ptr_h +#define _ResItemAndDependency_Ptr_h -#include +#include "zypp/base/PtrTypes.h" #include ///////////////////////////////////////////////////////////////////////// @@ -35,10 +35,10 @@ namespace zypp { /////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// - // CLASS NAME : ResItemAndDependencyPtr - // CLASS NAME : constResItemAndDependencyPtr + // CLASS NAME : ResItemAndDependency_Ptr + // CLASS NAME : ResItemAndDependency_constPtr /////////////////////////////////////////////////////////////////// - DEFINE_BASE_POINTER(ResItemAndDependency); + DEFINE_PTR_TYPE(ResItemAndDependency); /////////////////////////////////////////////////////////////////// };// namespace detail @@ -49,4 +49,4 @@ namespace zypp /////////////////////////////////////////////////////////////////////// };// namespace zypp ///////////////////////////////////////////////////////////////////////// -#endif // _ResItemAndDependencyPtr_h +#endif // _ResItemAndDependency_Ptr_h diff --git a/zypp/solver/detail/ResItemPtr.h b/zypp/solver/detail/ResItemPtr.h index 376be9e..9c841f5 100644 --- a/zypp/solver/detail/ResItemPtr.h +++ b/zypp/solver/detail/ResItemPtr.h @@ -1,5 +1,5 @@ /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* ResItemPtr.h +/* ResItem_Ptr.h * * Copyright (C) 2005 SUSE Linux Products GmbH * @@ -18,10 +18,10 @@ * 02111-1307, USA. */ -#ifndef _ResItemPtr_h -#define _ResItemPtr_h +#ifndef _ResItem_Ptr_h +#define _ResItem_Ptr_h -#include +#include "zypp/base/PtrTypes.h" #include ///////////////////////////////////////////////////////////////////////// @@ -35,10 +35,10 @@ namespace zypp { /////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// - // CLASS NAME : ResItemPtr - // CLASS NAME : constResItemPtr + // CLASS NAME : ResItem_Ptr + // CLASS NAME : ResItem_constPtr /////////////////////////////////////////////////////////////////// - DEFINE_BASE_POINTER(ResItem); + DEFINE_PTR_TYPE(ResItem); /////////////////////////////////////////////////////////////////// };// namespace detail @@ -49,4 +49,4 @@ namespace zypp /////////////////////////////////////////////////////////////////////// };// namespace zypp ///////////////////////////////////////////////////////////////////////// -#endif // _ResItemPtr_h +#endif // _ResItem_Ptr_h diff --git a/zypp/solver/detail/Resolver.cc b/zypp/solver/detail/Resolver.cc index 3a01a6d..c23734e 100644 --- a/zypp/solver/detail/Resolver.cc +++ b/zypp/solver/detail/Resolver.cc @@ -28,7 +28,7 @@ #include ///////////////////////////////////////////////////////////////////////// -namespace zypp +namespace zypp { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// namespace solver @@ -36,44 +36,44 @@ namespace zypp ///////////////////////////////////////////////////////////////////// namespace detail { /////////////////////////////////////////////////////////////////// - + using namespace std; - - IMPL_BASE_POINTER(Resolver); - + + IMPL_PTR_TYPE(Resolver); + //--------------------------------------------------------------------------- - + string Resolver::asString ( void ) const { return toString (*this); } - - + + string Resolver::toString ( const Resolver & resolver ) { return ""; } - - + + ostream & Resolver::dumpOn( ostream & str ) const { str << asString(); return str; } - - + + ostream& operator<<( ostream& os, const Resolver & resolver) { return os << resolver.asString(); } - + //--------------------------------------------------------------------------- - - Resolver::Resolver (WorldPtr world) + + Resolver::Resolver (World_Ptr world) : _current_channel (NULL) , _world (world) , _timeout_seconds (0) @@ -83,37 +83,37 @@ namespace zypp , _timed_out (false) { } - - + + Resolver::~Resolver() { } - + //--------------------------------------------------------------------------- - - WorldPtr + + World_Ptr Resolver::world (void) const { if (_world == NULL) return World::globalWorld(); - + return _world; } - + //--------------------------------------------------------------------------- - + void - Resolver::addSubscribedChannel (constChannelPtr channel) + Resolver::addSubscribedChannel (Channel_constPtr channel) { fprintf (stderr, "Resolver::addSubscribedChannel() not implemented\n"); } - + void - Resolver::addResItemToInstall (constResItemPtr resItem) + Resolver::addResItemToInstall (ResItem_constPtr resItem) { _resItems_to_install.push_front (resItem); } - + void Resolver::addResItemsToInstallFromList (CResItemList & rl) { @@ -121,13 +121,13 @@ namespace zypp addResItemToInstall (*iter); } } - + void - Resolver::addResItemToRemove (constResItemPtr resItem) + Resolver::addResItemToRemove (ResItem_constPtr resItem) { _resItems_to_remove.push_front (resItem); } - + void Resolver::addResItemsToRemoveFromList (CResItemList & rl) { @@ -135,48 +135,48 @@ namespace zypp addResItemToRemove (*iter); } } - + void - Resolver::addResItemToVerify (constResItemPtr resItem) + Resolver::addResItemToVerify (ResItem_constPtr resItem) { _resItems_to_verify.push_front (resItem); _resItems_to_verify.sort (); //(GCompareFunc) rc_resItem_compare_name); } - + void Resolver::addExtraDependency (const Capability & dependency) { _extra_deps.insert (dependency); } - + void Resolver::addExtraConflict (const Capability & dependency) { _extra_conflicts.insert (dependency); } - - + + //--------------------------------------------------------------------------- - + static bool - verify_system_cb (constResItemPtr resItem, void *data) + verify_system_cb (ResItem_constPtr resItem, void *data) { Resolver *resolver = (Resolver *)data; - + resolver->addResItemToVerify (resItem); - + return true; } - - + + void Resolver::verifySystem (void) { if (getenv ("RC_SPEW")) fprintf (stderr, "Resolver::verifySystem()\n"); world()->foreachResItem (new Channel(CHANNEL_TYPE_SYSTEM), verify_system_cb, this); - + _verifying = true; - + #if 0 // commented out in libredcarpet also /* Walk across the (sorted-by-name) list of installed packages and look for @@ -184,7 +184,7 @@ namespace zypp containing multiple group items. Each group item corresponds to removing all but one of the duplicates. */ - + for (CResItemList::const_iterator i0 = _resItems_to_verify.begin(); i0 != _resItems_to_verify.end();) { CResItemList::const_iterator i1 = i0; i1++; @@ -192,149 +192,149 @@ namespace zypp for (; i1 != _resItems_to_verify.end()&& ! (*i0)->compareName (*i1); i1++) { //empty } - + if (i1 != i2) { - QueueItemBranchPtr branch_item; - + QueueItemBranch_Ptr branch_item; + branch_item = new QueueItemBranch(world()); - + for (CResItemList::const_iterator i = i0; i != i1; i++) { - - QueueItemGroupPtr grp_item = new QueueItemGroup(world()); - + + QueueItemGroup_Ptr grp_item = new QueueItemGroup(world()); + for (CResItemList::const_iterator j = i0; j != i1; j++) { - constPackagePtr dup_pkg = *j; - QueueItemUninstallPtr uninstall_item; - + Package_constPtr dup_pkg = *j; + QueueItemUninstall_Ptr uninstall_item; + if (i != j) { uninstall_item = new QueueItemUninstall (world(), dup_pkg, "duplicate install"); grp_item->addItem (uninstall_item); } - + } - + branch_item->adddIitem (grp_item); } - + _initial_items.push_back (branch_item); } - + i0 = i1; } #endif - + /* OK, that was fun. Now just resolve the dependencies. */ resolveDependencies (); - + return; } - - + + //--------------------------------------------------------------------------- - - + + void Resolver::resolveDependencies (void) { - + time_t t_start, t_now; bool extremely_noisy = getenv ("RC_SPEW") != NULL; bool have_local_resItems = false; - + if (extremely_noisy) fprintf (stderr, "Resolver::resolveDependencies()\n"); - + /* Walk through are list of to-be-installed packages and see if any of them are local. */ - + for (CResItemList::const_iterator iter = _resItems_to_install.begin(); iter != _resItems_to_install.end(); iter++) { if ((*iter)->local()) { have_local_resItems = true; break; } } - - WorldPtr the_world = world(); - StoreWorldPtr local_world = NULL; - MultiWorldPtr local_multiworld = NULL; - - ChannelPtr local_channel = NULL; - + + World_Ptr the_world = world(); + StoreWorld_Ptr local_world = NULL; + MultiWorld_Ptr local_multiworld = NULL; + + Channel_Ptr local_channel = NULL; + if (have_local_resItems) { local_multiworld = new MultiWorld(); local_world = new StoreWorld(); - + local_channel = new Channel ("", "Local ResItems", "@local", ""); - + local_world->addChannel (local_channel); - + local_multiworld->addSubworld (local_world); local_multiworld->addSubworld (the_world); - + the_world = local_multiworld; } - + // create initial_queue - - ResolverQueuePtr initial_queue = new ResolverQueue(); - + + ResolverQueue_Ptr initial_queue = new ResolverQueue(); + /* Stick the current/subscribed channel and world info into the context */ - + initial_queue->context()->setWorld(the_world); - + initial_queue->context()->setCurrentChannel (_current_channel); - + /* If this is a verify, we do a "soft resolution" */ - + initial_queue->context()->setVerifying (_verifying); - + /* Add extra items. */ - + for (QueueItemList::const_iterator iter = _initial_items.begin(); iter != _initial_items.end(); iter++) { initial_queue->addItem (*iter); } _initial_items.clear(); - + for (CResItemList::const_iterator iter = _resItems_to_install.begin(); iter != _resItems_to_install.end(); iter++) { - constResItemPtr r = *iter; - + ResItem_constPtr r = *iter; + /* Add local packages to our dummy channel. */ if (r->local()) { assert (local_channel != NULL); - ResItemPtr r1 = ResItemPtr::cast_away_const (r); + ResItem_Ptr r1 = const_pointer_cast(r); r1->setChannel (local_channel); local_world->addResItem (r); } - + initial_queue->addResItemToInstall (r); } - + for (CResItemList::const_iterator iter = _resItems_to_remove.begin(); iter != _resItems_to_remove.end(); iter++) { initial_queue->addResItemToRemove (*iter, true /* remove-only mode */); } - + for (CResItemList::const_iterator iter = _resItems_to_verify.begin(); iter != _resItems_to_verify.end(); iter++) { initial_queue->addResItemToVerify (*iter); } - + for (CapSet::const_iterator iter = _extra_deps.begin(); iter != _extra_deps.end(); iter++) { initial_queue->addExtraDependency (*iter); } - + for (CapSet::const_iterator iter = _extra_conflicts.begin(); iter != _extra_conflicts.end(); iter++) { initial_queue->addExtraConflict (*iter); } - + if (extremely_noisy) fprintf (stderr, "Initial Queue: [%s]\n", initial_queue->asString().c_str()); - + _pending_queues.push_front (initial_queue); - + time (&t_start); - + while (!_pending_queues.empty()) { - + if (extremely_noisy) { printf ("Pend %ld / Cmpl %ld / Prun %ld / Defr %ld / Invl %ld\n\n", (long) _pending_queues.size(), (long) _complete_queues.size(), (long) _pruned_queues.size(), (long) _deferred_queues.size(), (long) _invalid_queues.size()); } - + if (_timeout_seconds > 0) { time (&t_now); if (difftime (t_now, t_start) > _timeout_seconds) { @@ -342,70 +342,70 @@ namespace zypp break; } } - - ResolverQueuePtr queue = _pending_queues.front(); + + ResolverQueue_Ptr queue = _pending_queues.front(); _pending_queues.pop_front(); - ResolverContextPtr context = queue->context(); - + ResolverContext_Ptr context = queue->context(); + queue->process(); - + if (queue->isInvalid ()) { if (extremely_noisy) printf ("Invalid Queue\n"); _invalid_queues.push_front (queue); - + } else if (queue->isEmpty ()) { if (extremely_noisy) printf ("Empty Queue\n"); - + _complete_queues.push_front (queue); - + ++_valid_solution_count; - + /* Compare this solution to our previous favorite. In the case of a tie, the first solution wins --- yeah, I know this is lame, but it shouldn't be an issue too much of the time. */ - + if (_best_context == NULL || _best_context->compare (context) < 0) { - + _best_context = context; } - + } else if (_best_context != NULL && _best_context->partialCompare (context) > 0) { - + /* If we aren't currently as good as our previous best complete solution, this solution gets pruned. */ - + if (extremely_noisy) printf ("PRUNED!\n"); - + _pruned_queues.push_front(queue); - + } else { - + /* If our queue is isn't empty and isn't invalid, that can only mean one thing: we are down to nothing but branches. */ - + queue->splitFirstBranch (_pending_queues, _deferred_queues); } - + /* If we have run out of pending queues w/o finding any solutions, and if we have deferred queues, make the first deferred queue pending. */ - + if (_pending_queues.empty() && _complete_queues.empty() && !_deferred_queues.empty()) { _pending_queues.push_front (_deferred_queues.front()); } } - + if (extremely_noisy) { printf ("Pend %ld / Cmpl %ld / Prun %ld / Defr %ld / Invl %ld\n--------\n", (long) _pending_queues.size(), (long) _complete_queues.size(), (long) _pruned_queues.size(), (long) _deferred_queues.size(), (long) _invalid_queues.size()); } - + return; } - + /////////////////////////////////////////////////////////////////// };// namespace detail ///////////////////////////////////////////////////////////////////// diff --git a/zypp/solver/detail/Resolver.h b/zypp/solver/detail/Resolver.h index 275c11a..093d73c 100644 --- a/zypp/solver/detail/Resolver.h +++ b/zypp/solver/detail/Resolver.h @@ -24,7 +24,11 @@ #include #include -#include +#include + +#include "zypp/base/ReferenceCounted.h" +#include "zypp/base/NonCopyable.h" +#include "zypp/base/PtrTypes.h" #include #include @@ -33,7 +37,7 @@ #include ///////////////////////////////////////////////////////////////////////// -namespace zypp +namespace zypp { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// namespace solver @@ -41,94 +45,94 @@ namespace zypp ///////////////////////////////////////////////////////////////////// namespace detail { /////////////////////////////////////////////////////////////////// - + /////////////////////////////////////////////////////////////////// // // CLASS NAME : Resolver - class Resolver : public CountedRep { - REP_BODY(Resolver); - - private: - constChannelPtr _current_channel; + class Resolver : public base::ReferenceCounted, private base::NonCopyable { - WorldPtr _world; - + + private: + Channel_constPtr _current_channel; + + World_Ptr _world; + int _timeout_seconds; bool _verifying; - + QueueItemList _initial_items; CResItemList _resItems_to_install; CResItemList _resItems_to_remove; CResItemList _resItems_to_verify; - + CapSet _extra_deps; CapSet _extra_conflicts; - + ResolverQueueList _pending_queues; ResolverQueueList _pruned_queues; ResolverQueueList _complete_queues; ResolverQueueList _deferred_queues; ResolverQueueList _invalid_queues; - + int _valid_solution_count; - - ResolverContextPtr _best_context; + + ResolverContext_Ptr _best_context; bool _timed_out; - + public: - - Resolver (WorldPtr world = NULL); + + Resolver (World_Ptr world = NULL); virtual ~Resolver(); - + // ---------------------------------- I/O - + static std::string toString (const Resolver & resolver); - + virtual std::ostream & dumpOn(std::ostream & str ) const; - + friend std::ostream& operator<<(std::ostream&, const Resolver & resolver); - + std::string asString (void ) const; - + // ---------------------------------- accessors - + QueueItemList initialItems () const { return _initial_items; } - + ResolverQueueList pendingQueues () const { return _pending_queues; } ResolverQueueList prunedQueues () const { return _pruned_queues; } ResolverQueueList completeQueues () const { return _complete_queues; } ResolverQueueList deferredQueues () const { return _deferred_queues; } ResolverQueueList invalidQueues () const { return _invalid_queues; } - - ResolverContextPtr bestContext (void) const { return _best_context; } - + + ResolverContext_Ptr bestContext (void) const { return _best_context; } + // ---------------------------------- methods - + void setTimeout (int seconds) { _timeout_seconds = seconds; } - - WorldPtr world (void) const; // returns global world if _world == NULL - void setWorld (WorldPtr world) { _world = world; } - - void setCurrentChannel (constChannelPtr channel) { _current_channel = channel; } - void addSubscribedChannel (constChannelPtr channel); - - void addResItemToInstall (constResItemPtr resItem); + + World_Ptr world (void) const; // returns global world if _world == NULL + void setWorld (World_Ptr world) { _world = world; } + + void setCurrentChannel (Channel_constPtr channel) { _current_channel = channel; } + void addSubscribedChannel (Channel_constPtr channel); + + void addResItemToInstall (ResItem_constPtr resItem); void addResItemsToInstallFromList (CResItemList & rl); - - void addResItemToRemove (constResItemPtr resItem); + + void addResItemToRemove (ResItem_constPtr resItem); void addResItemsToRemoveFromList (CResItemList & rl); - - void addResItemToVerify (constResItemPtr resItem); - + + void addResItemToVerify (ResItem_constPtr resItem); + void addExtraDependency (const Capability & dependency); void addExtraConflict (const Capability & dependency); - + void verifySystem (void); void resolveDependencies (void); - + }; - + /////////////////////////////////////////////////////////////////// };// namespace detail ///////////////////////////////////////////////////////////////////// diff --git a/zypp/solver/detail/ResolverContext.cc b/zypp/solver/detail/ResolverContext.cc index db04316..15bfe29 100644 --- a/zypp/solver/detail/ResolverContext.cc +++ b/zypp/solver/detail/ResolverContext.cc @@ -21,15 +21,16 @@ #include -#include +#include #include #include +#include #include #include ///////////////////////////////////////////////////////////////////////// -namespace zypp +namespace zypp { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// namespace solver @@ -37,13 +38,13 @@ namespace zypp ///////////////////////////////////////////////////////////////////// namespace detail { /////////////////////////////////////////////////////////////////// - + using namespace std; - - IMPL_BASE_POINTER(ResolverContext); - + + IMPL_PTR_TYPE(ResolverContext); + //--------------------------------------------------------------------------- - + string ResolverContext::toString (const ResItemStatus & status) { @@ -59,63 +60,63 @@ namespace zypp case RESOLVABLE_STATUS_TO_BE_UNINSTALLED_DUE_TO_UNLINK: ret = "to be uninstalled due to unlink"; break; default: ret = "Huh ?"; break; } - + return ret; } - + //--------------------------------------------------------------------------- - + string ResolverContext::asString ( void ) const { return toString (*this); } - - + + string ResolverContext::toString ( const ResolverContext & context ) { string ret; if (context._parent != NULL) { ret += "Parent: ["; - ret += stringutil::form("<@%p> ", (const void *)(context._parent)); + ret += str::form("<@%p> ", (const void *)(context._parent.get())); ret += context._parent->asString(); ret += "],\n\t"; } - ret += stringutil::form ("Download Size: %lld", context._download_size); - ret += stringutil::form (", Install Size: %lld", context._install_size); - ret += stringutil::form (", Total Priority: %d", context._total_priority); - ret += stringutil::form (", Min Priority: %d", context._min_priority); - ret += stringutil::form (", Max Priority: %d", context._max_priority); - ret += stringutil::form (", Other Penalties: %d", context._other_penalties); + ret += str::form ("Download Size: %lld", context._download_size); + ret += str::form (", Install Size: %lld", context._install_size); + ret += str::form (", Total Priority: %d", context._total_priority); + ret += str::form (", Min Priority: %d", context._min_priority); + ret += str::form (", Max Priority: %d", context._max_priority); + ret += str::form (", Other Penalties: %d", context._other_penalties); if (context._current_channel != 0) { ret += ", Current Channel"; ret += context._current_channel->asString(); } if (context._verifying) ret += ", Verifying"; if (context._invalid) ret += ", Invalid"; - + return ret; } - - + + ostream & ResolverContext::dumpOn( ostream & str ) const { str << asString(); return str; } - - + + ostream& operator<<( ostream& os, const ResolverContext & ResolverContext) { return os << ResolverContext.asString(); } - + //--------------------------------------------------------------------------- - - ResolverContext::ResolverContext (ResolverContextPtr parent) + + ResolverContext::ResolverContext (ResolverContext_Ptr parent) : _parent (parent) , _refs (0) , _world (NULL) @@ -142,17 +143,17 @@ namespace zypp _verifying = parent->_verifying; } else { _min_priority = MAXINT; - } + } } - - + + ResolverContext::~ResolverContext() { } - + //--------------------------------------------------------------------------- - - WorldPtr + + World_Ptr ResolverContext::world (void) const { if (_world == NULL) { @@ -160,43 +161,43 @@ namespace zypp } return _world; } - - + + void - ResolverContext::setStatus (constResItemPtr resItem, ResItemStatus status) + ResolverContext::setStatus (ResItem_constPtr resItem, ResItemStatus status) { if (_invalid) return; - + ResItemStatus old_status = getStatus (resItem); - + if (status != old_status) { _status[resItem] = status; } - + // Update our cache if we changed the status of the last checked resItem. - + if (_last_checked_resItem == resItem) _last_checked_status = status; } - - + + ResItemStatus - ResolverContext::getStatus (constResItemPtr resItem) + ResolverContext::getStatus (ResItem_constPtr resItem) { ResItemStatus status = RESOLVABLE_STATUS_UNKNOWN; - + // We often end up getting the status of the same resItem several times // in a row. By caching the status of the last checked resItem, we can // in practice eliminate the need for any hash table lookups in about // 50% of our calls to get_status. - + if (resItem == _last_checked_resItem) { return _last_checked_status; } - - ResolverContextPtr context = this; - + + ResolverContext_Ptr context = this; + while (status == RESOLVABLE_STATUS_UNKNOWN && context != NULL) { StatusTable::const_iterator pos = context->_status.find (resItem); @@ -205,197 +206,197 @@ namespace zypp } context = context->_parent; } - + if (status == RESOLVABLE_STATUS_UNKNOWN) { status = resItem->isInstalled() ? RESOLVABLE_STATUS_INSTALLED : RESOLVABLE_STATUS_UNINSTALLED; } - + _last_checked_resItem = resItem; _last_checked_status = status; - + return status; } - - + + bool - ResolverContext::installResItem (constResItemPtr resItem, bool is_soft, int other_penalty) + ResolverContext::installResItem (ResItem_constPtr resItem, bool is_soft, int other_penalty) { ResItemStatus status, new_status; int priority; std::string msg; - + status = getStatus (resItem); if (getenv ("RC_SPEW")) fprintf (stderr, "ResolverContext[%p]::installResItem(<%s>%s)\n", this, ResolverContext::toString(status).c_str(), resItem->asString().c_str()); - + if (resItem_status_is_to_be_uninstalled (status) && status != RESOLVABLE_STATUS_TO_BE_UNINSTALLED_DUE_TO_UNLINK) { msg = string ("Can't install ") + resItem->asString() + " since it is already marked as needing to be uninstalled"; - + addErrorString (resItem, msg); return false; } - + if (resItem_status_is_to_be_installed (status)) { return true; } - + if (isParallelInstall (resItem)) { msg = string ("Can't install ") + resItem->asString() + ", since a resolvable of the same name is already marked as needing to be installed"; addErrorString (resItem, msg); return false; } - + if (is_soft) new_status = RESOLVABLE_STATUS_TO_BE_INSTALLED_SOFT; else if (status == RESOLVABLE_STATUS_TO_BE_UNINSTALLED_DUE_TO_UNLINK) new_status = RESOLVABLE_STATUS_INSTALLED; else new_status = RESOLVABLE_STATUS_TO_BE_INSTALLED; - + setStatus (resItem, new_status); - + if (status == RESOLVABLE_STATUS_UNINSTALLED) { /* FIXME: Incomplete */ _download_size += resItem->fileSize(); _install_size += resItem->installedSize(); - + if (resItem->local()) priority = 0; else { priority = getChannelPriority (resItem->channel ()); } - + if (priority < _min_priority) _min_priority = priority; if (priority > _max_priority) _max_priority = priority; - + _other_penalties += other_penalty; - + } - + return true; } - - + + bool - ResolverContext::upgradeResItem (constResItemPtr resItem, constResItemPtr old_resItem, bool is_soft, int other_penalty) + ResolverContext::upgradeResItem (ResItem_constPtr resItem, ResItem_constPtr old_resItem, bool is_soft, int other_penalty) { ResItemStatus status; int priority; - + if (getenv ("RC_SPEW")) fprintf (stderr, "ResolverContext[%p]::upgradeResItem(%s upgrades %s)\n", this, resItem->asString().c_str(), old_resItem->asString().c_str()); - + status = getStatus (resItem); - + if (resItem_status_is_to_be_uninstalled (status)) return false; - + if (resItem_status_is_to_be_installed (status)) return true; - + setStatus (resItem, is_soft ? RESOLVABLE_STATUS_TO_BE_INSTALLED_SOFT : RESOLVABLE_STATUS_TO_BE_INSTALLED); - + if (status == RESOLVABLE_STATUS_UNINSTALLED) { - + _download_size += resItem->fileSize(); - + // FIXME: Incomplete // We should change installed_size to reflect the difference in // installed size between the old and new versions. - + if (resItem->local()) priority = 0; else { priority = getChannelPriority (resItem->channel()); } - + if (priority < _min_priority) _min_priority = priority; if (priority > _max_priority) _max_priority = priority; - + _other_penalties += other_penalty; } - + return true; } - - + + bool - ResolverContext::uninstallResItem (constResItemPtr resItem, bool part_of_upgrade, bool due_to_obsolete, bool due_to_unlink) + ResolverContext::uninstallResItem (ResItem_constPtr resItem, bool part_of_upgrade, bool due_to_obsolete, bool due_to_unlink) { ResItemStatus status, new_status; std::string msg; - + if (getenv ("RC_SPEW")) fprintf (stderr, "ResolverContext[%p]::uninstallResItem(%s %s %s %s)\n", this, resItem->asString().c_str(), part_of_upgrade ? "part_of_upgrade" : "", due_to_obsolete ? "due_to_obsolete": "", due_to_unlink ? "due_to_unlink" : ""); - + assert (! (due_to_obsolete && due_to_unlink)); - + status = getStatus (resItem); - + if (status == RESOLVABLE_STATUS_TO_BE_INSTALLED) { msg = resItem->asString() + " is scheduled to be installed, but this is not possible because of dependency problems."; addErrorString (resItem, msg); return false; } - + if (resItem_status_is_to_be_uninstalled (status) && status != RESOLVABLE_STATUS_TO_BE_UNINSTALLED_DUE_TO_UNLINK) { return true; } - + if (status == RESOLVABLE_STATUS_UNINSTALLED || status == RESOLVABLE_STATUS_TO_BE_UNINSTALLED_DUE_TO_UNLINK) { msg = string ("Marking resolvable ") + resItem->asString() + " as uninstallable"; addInfoString (resItem, RESOLVER_INFO_PRIORITY_VERBOSE, msg); } - - + + if (due_to_obsolete) new_status = RESOLVABLE_STATUS_TO_BE_UNINSTALLED_DUE_TO_OBSOLETE; else if (due_to_unlink) new_status = RESOLVABLE_STATUS_TO_BE_UNINSTALLED_DUE_TO_UNLINK; else new_status = RESOLVABLE_STATUS_TO_BE_UNINSTALLED; - + setStatus (resItem, new_status); - + if (status == RESOLVABLE_STATUS_INSTALLED) { /* FIXME: incomplete */ } - + return true; } - - + + bool - ResolverContext::resItemIsPresent (constResItemPtr resItem) + ResolverContext::resItemIsPresent (ResItem_constPtr resItem) { ResItemStatus status; - + status = getStatus (resItem); //fprintf (stderr, "ResolverContext::resItemIsPresent(<%s>%s)\n", ResolverContext::toString(status).c_str(), resItem->asString().c_str()); if (status == RESOLVABLE_STATUS_UNKNOWN) return false; - + return (status == RESOLVABLE_STATUS_INSTALLED) || resItem_status_is_to_be_installed (status); } - - + + bool - ResolverContext::resItemIsAbsent (constResItemPtr resItem) + ResolverContext::resItemIsAbsent (ResItem_constPtr resItem) { ResItemStatus status; - + status = getStatus (resItem); if (status == RESOLVABLE_STATUS_UNKNOWN) return false; - + return status == RESOLVABLE_STATUS_UNINSTALLED || resItem_status_is_to_be_uninstalled (status); } - - + + //--------------------------------------------------------------------------- // marked - + void ResolverContext::foreachMarkedResItem (MarkedResItemFn fn, void *data) const { - constResolverContextPtr context = this; + ResolverContext_constPtr context = this; while (context) { for (StatusTable::const_iterator iter = context->_status.begin(); iter != context->_status.end(); iter++) { fn (iter->first, iter->second, data); @@ -403,109 +404,109 @@ namespace zypp context = context->_parent; } } - - + + //--------------------------------------------------------------------------- // collect - + static void - marked_resItem_collector (constResItemPtr resItem, ResItemStatus status, void *data) + marked_resItem_collector (ResItem_constPtr resItem, ResItemStatus status, void *data) { CResItemList *rl = (CResItemList *)data; rl->push_back (resItem); } - - + + CResItemList ResolverContext::getMarkedResItems (void) const { CResItemList rl; - + foreachMarkedResItem (marked_resItem_collector, &rl); - + return rl; } - + //--------------------------------------------------------------------------- // install - + typedef struct { - WorldPtr world; + World_Ptr world; MarkedResItemFn fn; CResItemList *rl; int count; } InstallInfo; - + static void - install_pkg_cb (constResItemPtr resItem, ResItemStatus status, void *data) + install_pkg_cb (ResItem_constPtr resItem, ResItemStatus status, void *data) { InstallInfo *info = (InstallInfo *)data; if (resItem_status_is_to_be_installed (status) && ! resItem->isInstalled () && info->world->findInstalledResItem (resItem) == NULL) { - + if (info->fn) info->fn (resItem, status, info->rl); ++info->count; } } - - + + int ResolverContext::foreachInstall (MarkedResItemFn fn, void *data) const { CResItemList *rl = (CResItemList *)data; InstallInfo info = { world(), fn, rl, 0 }; - + foreachMarkedResItem (install_pkg_cb, (void *)&info); - + return info.count; } - - + + static void - context_resItem_collector (constResItemPtr resItem, ResItemStatus status, void *data) + context_resItem_collector (ResItem_constPtr resItem, ResItemStatus status, void *data) { CResItemList *rl = (CResItemList *)data; if (resItem_status_is_to_be_installed (status) || (resItem_status_is_to_be_uninstalled (status) && resItem->isInstalled ())) { rl->push_front (resItem); - } + } } - - + + CResItemList ResolverContext::getInstalls (void) const { CResItemList rl; - + foreachInstall (context_resItem_collector, (void *)&rl); - + return rl; } - - + + //--------------------------------------------------------------------------- // upgrade - + typedef struct { - WorldPtr world; + World_Ptr world; MarkedResItemPairFn fn; void *data; - ResolverContextPtr context; + ResolverContext_Ptr context; int count; } UpgradeInfo; - + static void - upgrade_pkg_cb (constResItemPtr resItem, ResItemStatus status, void *data) + upgrade_pkg_cb (ResItem_constPtr resItem, ResItemStatus status, void *data) { UpgradeInfo *info = (UpgradeInfo *)data; - - constResItemPtr to_be_upgraded; + + ResItem_constPtr to_be_upgraded; ResItemStatus tbu_status; - + if (resItem_status_is_to_be_installed (status) && ! resItem->isInstalled ()) { - + to_be_upgraded = info->world->findInstalledResItem (resItem); if (to_be_upgraded) { tbu_status = info->context->getStatus (to_be_upgraded); @@ -516,57 +517,57 @@ namespace zypp } } } - - + + int ResolverContext::foreachUpgrade (MarkedResItemPairFn fn, void *data) { UpgradeInfo info = { world(), fn, data, this, 0 }; - + foreachMarkedResItem (upgrade_pkg_cb, (void *)&info); - + return info.count; } - - + + static void - pair_resItem_collector (constResItemPtr resItem, ResItemStatus status, constResItemPtr old, ResItemStatus old_status, void *data) + pair_resItem_collector (ResItem_constPtr resItem, ResItemStatus status, ResItem_constPtr old, ResItemStatus old_status, void *data) { CResItemList *rl = (CResItemList *)data; rl->push_back (resItem); } - - + + CResItemList ResolverContext::getUpgrades (void) { CResItemList rl; - + foreachUpgrade (pair_resItem_collector, (void *)&rl); - + return rl; } - - + + //--------------------------------------------------------------------------- // uninstall - - typedef std::map UpgradeTable; - + + typedef std::map UpgradeTable; + typedef struct { MarkedResItemFn fn; CResItemList *rl; UpgradeTable upgrade_hash; int count; } UninstallInfo; - + static void - uninstall_pkg_cb (constResItemPtr resItem, ResItemStatus status, void *data) + uninstall_pkg_cb (ResItem_constPtr resItem, ResItemStatus status, void *data) { UninstallInfo *info = (UninstallInfo *)data; - + UpgradeTable::const_iterator pos = info->upgrade_hash.find(resItem->name()); - + if (resItem_status_is_to_be_uninstalled (status) && pos == info->upgrade_hash.end()) { if (info->fn) @@ -574,158 +575,158 @@ namespace zypp ++info->count; } } - + static void - build_upgrade_hash_cb (constResItemPtr resItem_add, ResItemStatus status_add, constResItemPtr resItem_del, ResItemStatus status_del, void *data) + build_upgrade_hash_cb (ResItem_constPtr resItem_add, ResItemStatus status_add, ResItem_constPtr resItem_del, ResItemStatus status_del, void *data) { UpgradeTable *upgrade_hash = (UpgradeTable *)data; (*upgrade_hash)[resItem_del->name()] = resItem_del; } - - + + int ResolverContext::foreachUninstall (MarkedResItemFn fn, void *data) { UninstallInfo info; // inits upgrade_hash - + info.fn = fn; info.rl = (CResItemList *)data; info.count = 0; - + foreachUpgrade (build_upgrade_hash_cb, (void *)&(info.upgrade_hash)); foreachMarkedResItem (uninstall_pkg_cb, (void *)&info); - + return info.count; } - - + + CResItemList ResolverContext::getUninstalls (void) { CResItemList rl; - + foreachUninstall (context_resItem_collector, (void *)&rl); - + return rl; } - - + + //--------------------------------------------------------------------------- - + static void - install_count_cb (constResItemPtr resItem, ResItemStatus status, void *data) + install_count_cb (ResItem_constPtr resItem, ResItemStatus status, void *data) { int *count = (int *)data; if (! resItem->isInstalled ()) { ++*count; } } - + int ResolverContext::installCount (void) const { int count = 0; - + foreachInstall (install_count_cb, (void *)&count); - + return count; } - - + + static void - uninstall_count_cb (constResItemPtr resItem, ResItemStatus status, void *data) + uninstall_count_cb (ResItem_constPtr resItem, ResItemStatus status, void *data) { int *count = (int *)data; if (resItem->isInstalled ()) { ++*count; } } - - + + int ResolverContext::uninstallCount (void) { int count = 0; - + foreachUninstall (uninstall_count_cb, (void *)&count); - + return count; } - - + + int ResolverContext::upgradeCount (void) { return foreachUpgrade ((MarkedResItemPairFn)NULL, (void *)NULL); } - - + + //--------------------------------------------------------------------------- // info - + void - ResolverContext::addInfo (ResolverInfoPtr info) + ResolverContext::addInfo (ResolverInfo_Ptr info) { if (getenv ("RC_SPEW")) fprintf (stderr, "ResolverContext[%p]::addInfo(%s)\n", this, info->asString().c_str()); _log.push_back (info); - + // _propagated_importance = false; - + if (info->error ()) { - + if (! _invalid) { - ResolverInfoPtr info = new ResolverInfoMisc (NULL, RESOLVER_INFO_PRIORITY_VERBOSE, "Marking this resolution attempt as invalid."); + ResolverInfo_Ptr info = new ResolverInfoMisc (NULL, RESOLVER_INFO_PRIORITY_VERBOSE, "Marking this resolution attempt as invalid."); info->flagAsError (); _log.push_back (info); } - + _invalid = true; } } - - + + void - ResolverContext::addInfoString (constResItemPtr resItem, int priority, string msg) + ResolverContext::addInfoString (ResItem_constPtr resItem, int priority, string msg) { // if (getenv ("RC_SPEW")) fprintf (stderr, "ResolverContext::addInfoString(%s) %s\n", resItem ? resItem->asString().c_str() : "", msg.c_str()); - ResolverInfoPtr info = new ResolverInfoMisc (resItem, priority, msg); + ResolverInfo_Ptr info = new ResolverInfoMisc (resItem, priority, msg); addInfo (info); } - - + + void - ResolverContext::addErrorString (constResItemPtr resItem, string msg) + ResolverContext::addErrorString (ResItem_constPtr resItem, string msg) { - ResolverInfoPtr info = new ResolverInfoMisc (resItem, RESOLVER_INFO_PRIORITY_VERBOSE, msg); + ResolverInfo_Ptr info = new ResolverInfoMisc (resItem, RESOLVER_INFO_PRIORITY_VERBOSE, msg); info->flagAsError (); addInfo (info); } - - + + //--------------------------------------------------------------------------- // foreach info - + // We call a resItem mentioned by an error info an "error-resItem". // We call a resItem mentioned by an important info an "important-resItem". // // The rules: // (1) An info item that mentions an error-resItem is important. // (2) An info item is about an important-resItem is important. - + static void mark_important_info (InfoList & il) { CResItemList error_list; // FIXME, a map is faster - + bool did_something; int pass_num = 1; - + /* First of all, store all error-resItems in a list. */ - + for (InfoList::iterator iter = il.begin(); iter != il.end(); iter++) { if ((*iter) != NULL // list items might be set to NULL && (*iter)->error ()) { - constResItemPtr resItem = (*iter)->resItem(); + ResItem_constPtr resItem = (*iter)->resItem(); if (resItem != NULL) { CResItemList::iterator pos; for (pos = error_list.begin(); pos != error_list.end(); pos++) { @@ -736,17 +737,22 @@ namespace zypp error_list.push_front (resItem); } } - + CResItemList resItems; - - constResolverInfoContainerPtr c = *iter; // check if it really is a container + + ResolverInfoContainer_constPtr c = dynamic_pointer_cast(*iter); // check if it really is a container if (c != NULL) resItems = c->resItems(); - + for (CResItemList::iterator res_iter = resItems.begin(); res_iter != resItems.end(); res_iter++) { CResItemList::iterator pos; for (pos = error_list.begin(); pos != error_list.end(); pos++) { +#if 0 +#warning FIXIT FIXIT FIXIT FIXIT FIXIT FIXIT FIXIT FIXIT FIXIT FIXIT FIXIT FIXIT + // compares ResItem* and ResolverInfo* + // What is this supposed to do? if (*pos == *iter) break; +#endif } if (pos == error_list.end()) { error_list.push_front (*res_iter); @@ -754,40 +760,40 @@ namespace zypp } } } - + CResItemList important_list; // FIXME, hash is faster - + do { ++pass_num; assert (pass_num < 10000); - + did_something = false; - + for (InfoList::iterator iter = il.begin(); iter != il.end(); iter++) { if ((*iter) != NULL // list items might be set to NULL && (*iter)->important ()) { bool should_be_important = false; - + for (CResItemList::const_iterator res_iter = error_list.begin(); res_iter != error_list.end() && ! should_be_important; res_iter++) { - constResolverInfoContainerPtr c = *iter; + ResolverInfoContainer_constPtr c = dynamic_pointer_cast(*iter); if (c != NULL // check if it really is a container && c->mentions (*res_iter)) { should_be_important = true; } } - + for (CResItemList::const_iterator res_iter = important_list.begin(); res_iter != important_list.end() && ! should_be_important; res_iter++) { if ((*iter)->isAbout (*res_iter)) { should_be_important = true; break; } } - + if (should_be_important) { did_something = true; (*iter)->flagAsImportant (); CResItemList resItems; - constResolverInfoContainerPtr c = *iter; // check if it really is a container + ResolverInfoContainer_constPtr c = dynamic_pointer_cast(*iter); // check if it really is a container if (c != NULL) resItems = c->resItems(); for (CResItemList::iterator res_iter = resItems.begin(); res_iter != resItems.end(); res_iter++) { CResItemList::iterator pos; @@ -802,20 +808,20 @@ namespace zypp } } } - + } while (did_something); - + } - - + + void - ResolverContext::foreachInfo (ResItemPtr resItem, int priority, ResolverInfoFn fn, void *data) + ResolverContext::foreachInfo (ResItem_Ptr resItem, int priority, ResolverInfoFn fn, void *data) { InfoList info_list; - - ResolverContextPtr context = this; - - + + ResolverContext_Ptr context = this; + + // Assemble a list of copies of all of the info objects while (context != NULL) { for (InfoList::iterator iter = context->_log.begin(); iter != context->_log.end(); iter++) { @@ -829,12 +835,12 @@ namespace zypp #if 0 // Merge info objects for (InfoList::iterator iter = info_list.begin(); iter != info_list.end(); iter++) { - - ResolverInfoPtr info1 = (*iter); + + ResolverInfo_Ptr info1 = (*iter); InfoList::iterator subiter = iter; if (info1 != NULL) { for (subiter++; subiter != info_list.end(); subiter++) { - ResolverInfoPtr info2 = *subiter; + ResolverInfo_Ptr info2 = *subiter; if (info2 && info1->merge (info2)) { *subiter = NULL; } @@ -843,30 +849,30 @@ namespace zypp } #endif mark_important_info (info_list); - + // Walk across the list of info objects and invoke our callback - + for (InfoList::iterator iter = info_list.begin(); iter != info_list.end(); iter++) { if (*iter != NULL) { fn (*iter, data); } } } - - - + + + static void - get_info_foreach_cb (ResolverInfoPtr info, void *data) + get_info_foreach_cb (ResolverInfo_Ptr info, void *data) { InfoList *il = (InfoList *)data; - + if (info->important ()) { il->push_back (info); } } - - - + + + InfoList ResolverContext::getInfo (void) { @@ -874,79 +880,79 @@ namespace zypp foreachInfo (NULL, -1, get_info_foreach_cb, (void *)&il); return il; } - - + + //--------------------------------------------------------------------------- // spew - + static void - spew_pkg_cb (constResItemPtr resItem, ResItemStatus status, void *unused) + spew_pkg_cb (ResItem_constPtr resItem, ResItemStatus status, void *unused) { printf (" %s (%s)\n", resItem->asString().c_str(), ResolverContext::toString(status).c_str()); } - - + + void - spew_pkg2_cb (constResItemPtr resItem1, ResItemStatus status1, constResItemPtr resItem2, ResItemStatus status2, void *unused) + spew_pkg2_cb (ResItem_constPtr resItem1, ResItemStatus status1, ResItem_constPtr resItem2, ResItemStatus status2, void *unused) { const char *s1, *s2; - + s1 = resItem1->asString().c_str(); s2 = resItem2->asString().c_str(); - + printf (" %s (%s) => %s (%s)\n", s2, ResolverContext::toString(status2).c_str(), s1, ResolverContext::toString(status1).c_str()); } - - + + void ResolverContext::spew (void) { printf ("TO INSTALL:\n"); foreachInstall (spew_pkg_cb, NULL); printf ("\n"); - + printf ("TO REMOVE:\n"); foreachUninstall (spew_pkg_cb, NULL); printf ("\n"); - + printf ("TO UPGRADE:\n"); foreachUpgrade (spew_pkg2_cb, NULL); printf ("\n"); } - - + + static void - spew_info_cb (ResolverInfoPtr info, void *unused) + spew_info_cb (ResolverInfo_Ptr info, void *unused) { const char *msg = info->asString().c_str(); if (info->error ()) printf ("[ERROR] "); else if (info->important()) printf ("[>>>>>] "); printf ("%s\n", msg); } - - + + void ResolverContext::spewInfo (void) { if (getenv ("RC_SPEW")) fprintf (stderr, "ResolverContext[%p]::spewInfo()\n", this); foreachInfo (NULL, -1, spew_info_cb, NULL); } - + //--------------------------------------------------------------------------- // requirements - + typedef struct { - ResolverContextPtr context; + ResolverContext_Ptr context; const Capability *dep; bool flag; } RequirementMetInfo; - - + + static bool - requirement_met_cb (constResItemPtr resItem, const Capability & cap, void *data) + requirement_met_cb (ResItem_constPtr resItem, const Capability & cap, void *data) { RequirementMetInfo *info = (RequirementMetInfo *)data; - + // info->dep is set for resItem set children. If it is set, query the // exact version only. if ((info->dep == NULL @@ -955,61 +961,61 @@ namespace zypp { info->flag = true; } - + //fprintf (stderr, "requirement_met_cb(%s, %s) [info->dep %s] -> %s\n", resItem->asString().c_str(), cap.asString().c_str(), info->dep != NULL ? info->dep->asString().c_str() : "(none)", info->flag ? "true" : "false"); return ! info->flag; } - - + + bool ResolverContext::requirementIsMet (const Capability & dependency, bool is_child) { RequirementMetInfo info; - + info.context = this; info.dep = is_child ? &dependency : NULL; info.flag = false; - + world()->foreachProvidingResItem (dependency, requirement_met_cb, (void *)&info); - + return info.flag; } - - + + //--------------------------------------------------------------------------- - + static bool - requirement_possible_cb (constResItemPtr resItem, const Capability & cap, void *data) + requirement_possible_cb (ResItem_constPtr resItem, const Capability & cap, void *data) { RequirementMetInfo *info = (RequirementMetInfo *)data; - + ResItemStatus status = info->context->getStatus (resItem); - + if (! resItem_status_is_to_be_uninstalled (status) || status == RESOLVABLE_STATUS_TO_BE_UNINSTALLED_DUE_TO_UNLINK) { info->flag = true; } - + return ! info->flag; } - - + + bool ResolverContext::requirementIsPossible (const Capability & dep) { RequirementMetInfo info; - + info.context = this; info.flag = false; - + world()->foreachProvidingResItem (dep, requirement_possible_cb, (void *)&info); - + return info.flag; } - - + + bool - ResolverContext::resItemIsPossible (constResItemPtr resItem) + ResolverContext::resItemIsPossible (ResItem_constPtr resItem) { CapSet requires = resItem->requires(); for (CapSet::iterator iter = requires.begin(); iter != requires.end(); iter++) { @@ -1017,19 +1023,19 @@ namespace zypp return false; } } - + return true; } - + //--------------------------------------------------------------------------- - + typedef struct { - constResItemPtr res; + ResItem_constPtr res; bool flag; } DupNameCheckInfo; - + static void - dup_name_check_cb (constResItemPtr resItem, ResItemStatus status, void *data) + dup_name_check_cb (ResItem_constPtr resItem, ResItemStatus status, void *data) { DupNameCheckInfo *info = (DupNameCheckInfo *)data; if (! info->flag @@ -1039,102 +1045,102 @@ namespace zypp info->flag = true; } } - + bool - ResolverContext::isParallelInstall (constResItemPtr resItem) + ResolverContext::isParallelInstall (ResItem_constPtr resItem) { DupNameCheckInfo info; - + info.res = resItem; info.flag = false; foreachMarkedResItem (dup_name_check_cb, (void *)&info); - + return info.flag; } - - + + int - ResolverContext::getChannelPriority (constChannelPtr channel) const + ResolverContext::getChannelPriority (Channel_constPtr channel) const { bool is_subscribed; int priority; - + is_subscribed = channel->isSubscribed (); priority = channel->getPriority (is_subscribed); - + return priority; } - + //--------------------------------------------------------------------------- - + static int num_cmp (double a, double b) { return (b < a) - (a < b); } - + static int rev_num_cmp (double a, double b) { return (a < b) - (b < a); } - + static double - churn_factor (ResolverContextPtr a) + churn_factor (ResolverContext_Ptr a) { return a->upgradeCount() + (2.0 * a->installCount ()) + (4.0 * a->uninstallCount ()); } - + int - ResolverContext::partialCompare (ResolverContextPtr context) + ResolverContext::partialCompare (ResolverContext_Ptr context) { int cmp = 0; if (this != context) { - + // High numbers are good... we don't want solutions containing low-priority channels. cmp = num_cmp (_min_priority, context->_min_priority); - + if (cmp == 0) { - + // High numbers are bad. Less churn is better. cmp = rev_num_cmp (churn_factor (this), churn_factor (context)); - + if (cmp == 0) { - + // High numbers are bad. Bigger #s means more penalties. cmp = rev_num_cmp (_other_penalties, context->_other_penalties); } } - } - + } + return cmp; } - + int - ResolverContext::compare (ResolverContextPtr context) + ResolverContext::compare (ResolverContext_Ptr context) { int cmp; - + if (this == context) return 0; - + cmp = partialCompare (context); if (cmp) return cmp; - + /* High numbers are bad. Smaller downloads are best. */ cmp = rev_num_cmp (_download_size, context->_download_size); if (cmp) return cmp; - + /* High numbers are bad. Less disk space consumed is good. */ cmp = rev_num_cmp (_install_size, context->_install_size); if (cmp) return cmp; - + return 0; } - + /////////////////////////////////////////////////////////////////// };// namespace detail ///////////////////////////////////////////////////////////////////// diff --git a/zypp/solver/detail/ResolverContext.h b/zypp/solver/detail/ResolverContext.h index a8a42f7..a44596e 100644 --- a/zypp/solver/detail/ResolverContext.h +++ b/zypp/solver/detail/ResolverContext.h @@ -25,7 +25,11 @@ #include #include #include -#include +#include + +#include "zypp/base/ReferenceCounted.h" +#include "zypp/base/NonCopyable.h" +#include "zypp/base/PtrTypes.h" #include #include @@ -34,7 +38,7 @@ #include ///////////////////////////////////////////////////////////////////////// -namespace zypp +namespace zypp { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// namespace solver @@ -42,7 +46,7 @@ namespace zypp ///////////////////////////////////////////////////////////////////// namespace detail { /////////////////////////////////////////////////////////////////// - + typedef enum { RESOLVABLE_STATUS_UNKNOWN = 0, RESOLVABLE_STATUS_INSTALLED, @@ -53,38 +57,38 @@ namespace zypp RESOLVABLE_STATUS_TO_BE_UNINSTALLED_DUE_TO_OBSOLETE, RESOLVABLE_STATUS_TO_BE_UNINSTALLED_DUE_TO_UNLINK } ResItemStatus; - + #define resItem_status_is_to_be_installed(x) (((x) == RESOLVABLE_STATUS_TO_BE_INSTALLED) || ((x) == RESOLVABLE_STATUS_TO_BE_INSTALLED_SOFT)) #define resItem_status_is_to_be_uninstalled(x) (((x) == RESOLVABLE_STATUS_TO_BE_UNINSTALLED) || ((x) == RESOLVABLE_STATUS_TO_BE_UNINSTALLED_DUE_TO_OBSOLETE) || ((x) == RESOLVABLE_STATUS_TO_BE_UNINSTALLED_DUE_TO_UNLINK)) - - typedef std::map StatusTable; - typedef std::list InfoList; - - - typedef void (*ResolverContextFn) (ResolverContextPtr ctx, void * data); - typedef void (*MarkedResItemFn) (constResItemPtr res, ResItemStatus status, void *data); - typedef void (*MarkedResItemPairFn) (constResItemPtr res1, ResItemStatus status1, constResItemPtr res2, ResItemStatus status2, void *data); - - + + typedef std::map StatusTable; + typedef std::list InfoList; + + + typedef void (*ResolverContextFn) (ResolverContext_Ptr ctx, void * data); + typedef void (*MarkedResItemFn) (ResItem_constPtr res, ResItemStatus status, void *data); + typedef void (*MarkedResItemPairFn) (ResItem_constPtr res1, ResItemStatus status1, ResItem_constPtr res2, ResItemStatus status2, void *data); + + /////////////////////////////////////////////////////////////////// // // CLASS NAME : ResolverContext - class ResolverContext : public CountedRep { - REP_BODY(ResolverContext); - + class ResolverContext : public base::ReferenceCounted, private base::NonCopyable { + + private: - - ResolverContextPtr _parent; - + + ResolverContext_Ptr _parent; + int _refs; - - WorldPtr _world; + + World_Ptr _world; StatusTable _status; - + // just a caching mechanism - constResItemPtr _last_checked_resItem; + ResItem_constPtr _last_checked_resItem; ResItemStatus _last_checked_status; - + InfoList _log; unsigned long long _download_size; unsigned long long _install_size; @@ -92,92 +96,92 @@ namespace zypp int _min_priority; int _max_priority; int _other_penalties; - constChannelPtr _current_channel; + Channel_constPtr _current_channel; bool _verifying; bool _invalid; - + public: - ResolverContext (ResolverContextPtr parent = NULL); + ResolverContext (ResolverContext_Ptr parent = NULL); virtual ~ResolverContext(); - + // ---------------------------------- I/O - + static std::string toString (const ResolverContext & context); virtual std::ostream & dumpOn(std::ostream & str ) const; friend std::ostream& operator<<(std::ostream&, const ResolverContext & context); std::string asString (void ) const; - + static std::string toString (const ResItemStatus & status); - + // ---------------------------------- accessors - - WorldPtr world (void) const; // gets global world, if _world == NULL - void setWorld (WorldPtr world) { _world = world; } - - constChannelPtr currentChannel (void) const { return _current_channel; } - void setCurrentChannel (constChannelPtr channel) { _current_channel = channel; } - + + World_Ptr world (void) const; // gets global world, if _world == NULL + void setWorld (World_Ptr world) { _world = world; } + + Channel_constPtr currentChannel (void) const { return _current_channel; } + void setCurrentChannel (Channel_constPtr channel) { _current_channel = channel; } + unsigned long long downloadSize(void) const { return _download_size; } unsigned long long installSize(void) const { return _install_size; } int totalPriority (void) const { return _total_priority; } int minPriority (void) const { return _min_priority; } int maxPriority (void) const { return _max_priority; } int otherPenalties (void) const { return _other_penalties; } - + bool isValid (void) const { return !_invalid; } bool isInvalid (void) const { return _invalid; } - + bool verifying (void) const { return _verifying; } void setVerifying (bool verifying) { _verifying = verifying; } - + // ---------------------------------- methods - - ResItemStatus getStatus (constResItemPtr res); // non-const, because its caching - void setStatus (constResItemPtr res, ResItemStatus status); - - bool installResItem (constResItemPtr resItem, bool is_soft, int other_penalty); - bool upgradeResItem (constResItemPtr new_resItem, constResItemPtr old_resItem, bool is_soft, int other_penalty); - bool uninstallResItem (constResItemPtr resItem, bool part_of_upgrade, bool due_to_obsolete, bool due_to_unlink); - - bool resItemIsPresent (constResItemPtr resItem); - bool resItemIsAbsent (constResItemPtr resItem); - + + ResItemStatus getStatus (ResItem_constPtr res); // non-const, because its caching + void setStatus (ResItem_constPtr res, ResItemStatus status); + + bool installResItem (ResItem_constPtr resItem, bool is_soft, int other_penalty); + bool upgradeResItem (ResItem_constPtr new_resItem, ResItem_constPtr old_resItem, bool is_soft, int other_penalty); + bool uninstallResItem (ResItem_constPtr resItem, bool part_of_upgrade, bool due_to_obsolete, bool due_to_unlink); + + bool resItemIsPresent (ResItem_constPtr resItem); + bool resItemIsAbsent (ResItem_constPtr resItem); + void foreachMarkedResItem (MarkedResItemFn fn, void *data) const; CResItemList getMarkedResItems (void) const; - + int foreachInstall (MarkedResItemFn fn, void *data) const; CResItemList getInstalls (void) const; int installCount (void) const; - + int foreachUninstall (MarkedResItemFn fn, void *data); // non-const, calls foreachUpgrade CResItemList getUninstalls (void); int uninstallCount (void); - + int foreachUpgrade (MarkedResItemPairFn fn, void *data); // non-const, calls getStatus CResItemList getUpgrades (void); int upgradeCount (void); - - void addInfo (ResolverInfoPtr info); - void addInfoString (constResItemPtr resItem, int priority, std::string str); - void addErrorString (constResItemPtr resItem, std::string str); - - void foreachInfo (ResItemPtr resItem, int priority, ResolverInfoFn fn, void *data); + + void addInfo (ResolverInfo_Ptr info); + void addInfoString (ResItem_constPtr resItem, int priority, std::string str); + void addErrorString (ResItem_constPtr resItem, std::string str); + + void foreachInfo (ResItem_Ptr resItem, int priority, ResolverInfoFn fn, void *data); InfoList getInfo (void); - + void spew (void); void spewInfo (void); - + bool requirementIsMet (const Capability & dep, bool is_child); bool requirementIsPossible (const Capability & dep); - bool resItemIsPossible (constResItemPtr resItem); - bool isParallelInstall (constResItemPtr resItem); - - int getChannelPriority (constChannelPtr channel) const; - - int partialCompare (ResolverContextPtr context); // non-const, calls uninstall/upgrade Count - int compare (ResolverContextPtr context); + bool resItemIsPossible (ResItem_constPtr resItem); + bool isParallelInstall (ResItem_constPtr resItem); + + int getChannelPriority (Channel_constPtr channel) const; + + int partialCompare (ResolverContext_Ptr context); // non-const, calls uninstall/upgrade Count + int compare (ResolverContext_Ptr context); }; - + /////////////////////////////////////////////////////////////////// };// namespace detail ///////////////////////////////////////////////////////////////////// @@ -188,4 +192,4 @@ namespace zypp };// namespace zypp ///////////////////////////////////////////////////////////////////////// #endif // _ResolverContext_h - + diff --git a/zypp/solver/detail/ResolverContextPtr.h b/zypp/solver/detail/ResolverContextPtr.h index 17a03d8..3d130a6 100644 --- a/zypp/solver/detail/ResolverContextPtr.h +++ b/zypp/solver/detail/ResolverContextPtr.h @@ -1,5 +1,5 @@ /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* ResolverContextPtr.h +/* ResolverContext_Ptr.h * * Copyright (C) 2005 SUSE Linux Products GmbH * @@ -18,10 +18,10 @@ * 02111-1307, USA. */ -#ifndef _ResolverContextPtr_h -#define _ResolverContextPtr_h +#ifndef _ResolverContext_Ptr_h +#define _ResolverContext_Ptr_h -#include +#include "zypp/base/PtrTypes.h" ///////////////////////////////////////////////////////////////////////// namespace zypp @@ -34,10 +34,10 @@ namespace zypp { /////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// - // CLASS NAME : ResolverContextPtr - // CLASS NAME : constResolverContextPtr + // CLASS NAME : ResolverContext_Ptr + // CLASS NAME : ResolverContext_constPtr /////////////////////////////////////////////////////////////////// - DEFINE_BASE_POINTER(ResolverContext); + DEFINE_PTR_TYPE(ResolverContext); /////////////////////////////////////////////////////////////////// };// namespace detail @@ -49,4 +49,4 @@ namespace zypp };// namespace zypp ///////////////////////////////////////////////////////////////////////// -#endif // _ResolverContextPtr_h +#endif // _ResolverContext_Ptr_h diff --git a/zypp/solver/detail/ResolverInfo.cc b/zypp/solver/detail/ResolverInfo.cc index a2ced29..5393079 100644 --- a/zypp/solver/detail/ResolverInfo.cc +++ b/zypp/solver/detail/ResolverInfo.cc @@ -35,7 +35,7 @@ namespace zypp using namespace std; - IMPL_BASE_POINTER(ResolverInfo); + IMPL_PTR_TYPE(ResolverInfo); //--------------------------------------------------------------------------- @@ -130,7 +130,7 @@ namespace zypp //--------------------------------------------------------------------------- - ResolverInfo::ResolverInfo (ResolverInfoType type, constResItemPtr resItem, int priority) + ResolverInfo::ResolverInfo (ResolverInfoType type, ResItem_constPtr resItem, int priority) : _type (type) , _resItem (resItem) , _priority (priority) @@ -147,7 +147,7 @@ namespace zypp //--------------------------------------------------------------------------- bool - ResolverInfo::merge (ResolverInfoPtr to_be_merged) + ResolverInfo::merge (ResolverInfo_Ptr to_be_merged) { if (to_be_merged == NULL) return false; @@ -160,17 +160,17 @@ namespace zypp } void - ResolverInfo::copy (constResolverInfoPtr from) + ResolverInfo::copy (ResolverInfo_constPtr from) { _error = from->_error; _important = from->_important; } - ResolverInfoPtr + ResolverInfo_Ptr ResolverInfo::copy (void) const { - ResolverInfoPtr cpy = new ResolverInfo(_type, _resItem, _priority); + ResolverInfo_Ptr cpy = new ResolverInfo(_type, _resItem, _priority); cpy->copy (this); @@ -181,7 +181,7 @@ namespace zypp //--------------------------------------------------------------------------- bool - ResolverInfo::isAbout (constResItemPtr resItem) const + ResolverInfo::isAbout (ResItem_constPtr resItem) const { if (_resItem == NULL) return false; diff --git a/zypp/solver/detail/ResolverInfo.h b/zypp/solver/detail/ResolverInfo.h index 758c941..5e4d5a6 100644 --- a/zypp/solver/detail/ResolverInfo.h +++ b/zypp/solver/detail/ResolverInfo.h @@ -25,13 +25,18 @@ #include #include #include -#include +#include + +#include "zypp/base/ReferenceCounted.h" +#include "zypp/base/NonCopyable.h" +#include "zypp/base/PtrTypes.h" + #include #include #include ///////////////////////////////////////////////////////////////////////// -namespace zypp +namespace zypp { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// namespace solver @@ -39,7 +44,7 @@ namespace zypp ///////////////////////////////////////////////////////////////////// namespace detail { /////////////////////////////////////////////////////////////////// - + typedef enum { RESOLVER_INFO_TYPE_INVALID = 0, RESOLVER_INFO_TYPE_NEEDED_BY, @@ -50,68 +55,68 @@ namespace zypp RESOLVER_INFO_TYPE_MISSING_REQ, RESOLVER_INFO_TYPE_MISC } ResolverInfoType; - + #define RESOLVER_INFO_PRIORITY_USER 500 #define RESOLVER_INFO_PRIORITY_VERBOSE 100 #define RESOLVER_INFO_PRIORITY_DEBUGGING 0 - - typedef void (*ResolverInfoFn) (ResolverInfoPtr info, void *data); - - typedef std::list ResolverInfoList; - + + typedef void (*ResolverInfoFn) (ResolverInfo_Ptr info, void *data); + + typedef std::list ResolverInfoList; + /////////////////////////////////////////////////////////////////// // // CLASS NAME : ResolverInfo - - class ResolverInfo : public CountedRep { - - REP_BODY(ResolverInfo); - + + class ResolverInfo : public base::ReferenceCounted, private base::NonCopyable { + + + private: - + ResolverInfoType _type; - constResItemPtr _resItem; + ResItem_constPtr _resItem; int _priority; - + bool _error; bool _important; - + protected: - - ResolverInfo (ResolverInfoType type, constResItemPtr resItem, int priority); - + + ResolverInfo (ResolverInfoType type, ResItem_constPtr resItem, int priority); + public: - + virtual ~ResolverInfo(); - - void copy (constResolverInfoPtr from); - + + void copy (ResolverInfo_constPtr from); + // ---------------------------------- I/O - + static std::string toString (const ResolverInfo & context, bool full = false); virtual std::ostream & dumpOn(std::ostream & str ) const; friend std::ostream& operator<<(std::ostream&, const ResolverInfo & context); virtual std::string asString (void ) const; - + // ---------------------------------- accessors - + ResolverInfoType type (void) const { return _type; } - constResItemPtr resItem (void) const { return _resItem; } + ResItem_constPtr resItem (void) const { return _resItem; } int priority (void) const { return _priority; } - + int error (void) const { return _error; } void flagAsError (void) { _error = true; } int important (void) const { return _important; } void flagAsImportant (void) { _important = true; } - + // ---------------------------------- methods - - bool merge (ResolverInfoPtr to_be_merged); - virtual ResolverInfoPtr copy (void) const; - - bool isAbout (constResItemPtr resItem) const; + + bool merge (ResolverInfo_Ptr to_be_merged); + virtual ResolverInfo_Ptr copy (void) const; + + bool isAbout (ResItem_constPtr resItem) const; }; - + /////////////////////////////////////////////////////////////////// };// namespace detail ///////////////////////////////////////////////////////////////////// @@ -122,4 +127,4 @@ namespace zypp };// namespace zypp ///////////////////////////////////////////////////////////////////////// #endif // _ResolverInfo_h - + diff --git a/zypp/solver/detail/ResolverInfoChildOf.cc b/zypp/solver/detail/ResolverInfoChildOf.cc index f1ffcdc..edd45d6 100644 --- a/zypp/solver/detail/ResolverInfoChildOf.cc +++ b/zypp/solver/detail/ResolverInfoChildOf.cc @@ -35,7 +35,7 @@ namespace zypp using namespace std; - IMPL_DERIVED_POINTER(ResolverInfoChildOf, ResolverInfo); + IMPL_PTR_TYPE(ResolverInfoChildOf); //--------------------------------------------------------------------------- @@ -76,7 +76,7 @@ namespace zypp //--------------------------------------------------------------------------- - ResolverInfoChildOf::ResolverInfoChildOf (constResItemPtr resItem, constResItemPtr dependency) + ResolverInfoChildOf::ResolverInfoChildOf (ResItem_constPtr resItem, ResItem_constPtr dependency) : ResolverInfoContainer (RESOLVER_INFO_TYPE_CHILD_OF, resItem, RESOLVER_INFO_PRIORITY_USER, dependency) { } @@ -89,12 +89,12 @@ namespace zypp //--------------------------------------------------------------------------- - ResolverInfoPtr + ResolverInfo_Ptr ResolverInfoChildOf::copy (void) const { - ResolverInfoChildOfPtr cpy = new ResolverInfoChildOf(resItem(), NULL); + ResolverInfoChildOf_Ptr cpy = new ResolverInfoChildOf(resItem(), NULL); - ((ResolverInfoContainerPtr)cpy)->copy (this); + ((ResolverInfoContainer_Ptr)cpy)->copy (this); return cpy; } diff --git a/zypp/solver/detail/ResolverInfoChildOf.h b/zypp/solver/detail/ResolverInfoChildOf.h index a62baf5..d907b3d 100644 --- a/zypp/solver/detail/ResolverInfoChildOf.h +++ b/zypp/solver/detail/ResolverInfoChildOf.h @@ -41,13 +41,13 @@ namespace zypp class ResolverInfoChildOf : public ResolverInfoContainer { - REP_BODY(ResolverInfoChildOf); + private: public: - ResolverInfoChildOf (constResItemPtr resItem, constResItemPtr dependency); + ResolverInfoChildOf (ResItem_constPtr resItem, ResItem_constPtr dependency); virtual ~ResolverInfoChildOf(); // ---------------------------------- I/O @@ -61,7 +61,7 @@ namespace zypp // ---------------------------------- methods - virtual ResolverInfoPtr copy (void) const; + virtual ResolverInfo_Ptr copy (void) const; }; /////////////////////////////////////////////////////////////////// diff --git a/zypp/solver/detail/ResolverInfoChildOfPtr.h b/zypp/solver/detail/ResolverInfoChildOfPtr.h index 4d85d79..5c6f78e 100644 --- a/zypp/solver/detail/ResolverInfoChildOfPtr.h +++ b/zypp/solver/detail/ResolverInfoChildOfPtr.h @@ -1,5 +1,5 @@ /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* ResolverInfoChildOfPtr.h +/* ResolverInfoChildOf_Ptr.h * * Copyright (C) 2005 SUSE Linux Products GmbH * @@ -18,10 +18,10 @@ * 02111-1307, USA. */ -#ifndef _ResolverInfoChildOfPtr_h -#define _ResolverInfoChildOfPtr_h +#ifndef _ResolverInfoChildOf_Ptr_h +#define _ResolverInfoChildOf_Ptr_h -#include +#include "zypp/base/PtrTypes.h" #include ///////////////////////////////////////////////////////////////////////// @@ -35,10 +35,10 @@ namespace zypp { /////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// - // CLASS NAME : ResolverInfoChildOfPtr - // CLASS NAME : constResolverInfoChildOfPtr + // CLASS NAME : ResolverInfoChildOf_Ptr + // CLASS NAME : ResolverInfoChildOf_constPtr /////////////////////////////////////////////////////////////////// - DEFINE_DERIVED_POINTER(ResolverInfoChildOf, ResolverInfo); + DEFINE_PTR_TYPE(ResolverInfoChildOf); /////////////////////////////////////////////////////////////////// };// namespace detail @@ -49,4 +49,4 @@ namespace zypp /////////////////////////////////////////////////////////////////////// };// namespace zypp ///////////////////////////////////////////////////////////////////////// -#endif // _ResolverInfoChildOfPtr_h +#endif // _ResolverInfoChildOf_Ptr_h diff --git a/zypp/solver/detail/ResolverInfoConflictsWith.cc b/zypp/solver/detail/ResolverInfoConflictsWith.cc index 025bfcf..c0afc6a 100644 --- a/zypp/solver/detail/ResolverInfoConflictsWith.cc +++ b/zypp/solver/detail/ResolverInfoConflictsWith.cc @@ -36,7 +36,7 @@ namespace zypp using namespace std; - IMPL_DERIVED_POINTER(ResolverInfoConflictsWith, ResolverInfo); + IMPL_PTR_TYPE(ResolverInfoConflictsWith); //--------------------------------------------------------------------------- @@ -76,7 +76,7 @@ namespace zypp //--------------------------------------------------------------------------- - ResolverInfoConflictsWith::ResolverInfoConflictsWith (constResItemPtr resItem, constResItemPtr with) + ResolverInfoConflictsWith::ResolverInfoConflictsWith (ResItem_constPtr resItem, ResItem_constPtr with) : ResolverInfoContainer (RESOLVER_INFO_TYPE_CONFLICTS_WITH, resItem, RESOLVER_INFO_PRIORITY_USER, with) { } @@ -89,12 +89,12 @@ namespace zypp //--------------------------------------------------------------------------- - ResolverInfoPtr + ResolverInfo_Ptr ResolverInfoConflictsWith::copy (void) const { - ResolverInfoConflictsWithPtr cpy = new ResolverInfoConflictsWith(resItem(), NULL); + ResolverInfoConflictsWith_Ptr cpy = new ResolverInfoConflictsWith(resItem(), NULL); - ((ResolverInfoContainerPtr)cpy)->copy (this); + ((ResolverInfoContainer_Ptr)cpy)->copy (this); return cpy; } diff --git a/zypp/solver/detail/ResolverInfoConflictsWith.h b/zypp/solver/detail/ResolverInfoConflictsWith.h index 083d94b..ab8f250 100644 --- a/zypp/solver/detail/ResolverInfoConflictsWith.h +++ b/zypp/solver/detail/ResolverInfoConflictsWith.h @@ -41,13 +41,13 @@ namespace zypp class ResolverInfoConflictsWith : public ResolverInfoContainer { - REP_BODY(ResolverInfoConflictsWith); + private: public: - ResolverInfoConflictsWith (constResItemPtr resItem, constResItemPtr with); + ResolverInfoConflictsWith (ResItem_constPtr resItem, ResItem_constPtr with); virtual ~ResolverInfoConflictsWith(); // ---------------------------------- I/O @@ -62,7 +62,7 @@ namespace zypp // ---------------------------------- methods - virtual ResolverInfoPtr copy (void) const; + virtual ResolverInfo_Ptr copy (void) const; }; /////////////////////////////////////////////////////////////////// diff --git a/zypp/solver/detail/ResolverInfoConflictsWithPtr.h b/zypp/solver/detail/ResolverInfoConflictsWithPtr.h index e8fb66c..19e6ab5 100644 --- a/zypp/solver/detail/ResolverInfoConflictsWithPtr.h +++ b/zypp/solver/detail/ResolverInfoConflictsWithPtr.h @@ -1,5 +1,5 @@ /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* ResolverInfoConflictsWithPtr.h +/* ResolverInfoConflictsWith_Ptr.h * * Copyright (C) 2005 SUSE Linux Products GmbH * @@ -18,10 +18,10 @@ * 02111-1307, USA. */ -#ifndef _ResolverInfoConflictsWithPtr_h -#define _ResolverInfoConflictsWithPtr_h +#ifndef _ResolverInfoConflictsWith_Ptr_h +#define _ResolverInfoConflictsWith_Ptr_h -#include +#include "zypp/base/PtrTypes.h" #include ///////////////////////////////////////////////////////////////////////// @@ -35,10 +35,10 @@ namespace zypp { /////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// - // CLASS NAME : ResolverInfoConflictsWithPtr - // CLASS NAME : constResolverInfoConflictsWithPtr + // CLASS NAME : ResolverInfoConflictsWith_Ptr + // CLASS NAME : ResolverInfoConflictsWith_constPtr /////////////////////////////////////////////////////////////////// - DEFINE_DERIVED_POINTER(ResolverInfoConflictsWith, ResolverInfo); + DEFINE_PTR_TYPE(ResolverInfoConflictsWith); /////////////////////////////////////////////////////////////////// };// namespace detail @@ -49,4 +49,4 @@ namespace zypp /////////////////////////////////////////////////////////////////////// };// namespace zypp ///////////////////////////////////////////////////////////////////////// -#endif // _ResolverInfoConflictsWithPtr_h +#endif // _ResolverInfoConflictsWith_Ptr_h diff --git a/zypp/solver/detail/ResolverInfoContainer.cc b/zypp/solver/detail/ResolverInfoContainer.cc index 8a547e8..8fddfbe 100644 --- a/zypp/solver/detail/ResolverInfoContainer.cc +++ b/zypp/solver/detail/ResolverInfoContainer.cc @@ -35,7 +35,7 @@ namespace zypp using namespace std; - IMPL_DERIVED_POINTER(ResolverInfoContainer, ResolverInfo); + IMPL_PTR_TYPE(ResolverInfoContainer); //--------------------------------------------------------------------------- @@ -79,7 +79,7 @@ namespace zypp //--------------------------------------------------------------------------- - ResolverInfoContainer::ResolverInfoContainer (ResolverInfoType type, constResItemPtr resItem, int priority, constResItemPtr child) + ResolverInfoContainer::ResolverInfoContainer (ResolverInfoType type, ResItem_constPtr resItem, int priority, ResItem_constPtr child) : ResolverInfo (type, resItem, priority) { if (child != NULL) @@ -94,14 +94,14 @@ namespace zypp //--------------------------------------------------------------------------- bool - ResolverInfoContainer::merge (ResolverInfoContainerPtr to_be_merged) + ResolverInfoContainer::merge (ResolverInfoContainer_Ptr to_be_merged) { bool res; - res = ((ResolverInfoPtr)this)->merge ((ResolverInfoPtr)to_be_merged); + res = ((ResolverInfo_Ptr)this)->merge ((ResolverInfo_Ptr)to_be_merged); if (!res) return res; - typedef std::map SeenTable; + typedef std::map SeenTable; SeenTable seen_packages; for (CResItemList::const_iterator iter = _resItem_list.begin(); iter != _resItem_list.end(); iter++) { @@ -122,9 +122,9 @@ namespace zypp void - ResolverInfoContainer::copy (constResolverInfoContainerPtr from) + ResolverInfoContainer::copy (ResolverInfoContainer_constPtr from) { - ((ResolverInfoPtr)this)->copy(from); + ((ResolverInfo_Ptr)this)->copy(from); for (CResItemList::const_iterator iter = from->_resItem_list.begin(); iter != from->_resItem_list.end(); iter++) { _resItem_list.push_back (*iter); @@ -132,10 +132,10 @@ namespace zypp } - ResolverInfoPtr + ResolverInfo_Ptr ResolverInfoContainer::copy (void) const { - ResolverInfoContainerPtr cpy = new ResolverInfoContainer(type(), resItem(), priority()); + ResolverInfoContainer_Ptr cpy = new ResolverInfoContainer(type(), resItem(), priority()); cpy->copy (this); @@ -166,7 +166,7 @@ namespace zypp bool - ResolverInfoContainer::mentions (constResItemPtr resItem) const + ResolverInfoContainer::mentions (ResItem_constPtr resItem) const { if (isAbout(resItem)) return true; @@ -184,7 +184,7 @@ namespace zypp void - ResolverInfoContainer::addRelatedResItem (constResItemPtr resItem) + ResolverInfoContainer::addRelatedResItem (ResItem_constPtr resItem) { if (!mentions(resItem)) { _resItem_list.push_front (resItem); diff --git a/zypp/solver/detail/ResolverInfoContainer.h b/zypp/solver/detail/ResolverInfoContainer.h index 330573e..bef217e 100644 --- a/zypp/solver/detail/ResolverInfoContainer.h +++ b/zypp/solver/detail/ResolverInfoContainer.h @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include #include @@ -45,7 +45,7 @@ namespace zypp class ResolverInfoContainer : public ResolverInfo { - REP_BODY(ResolverInfoContainer); + private: @@ -53,12 +53,12 @@ namespace zypp protected: - ResolverInfoContainer (ResolverInfoType type, constResItemPtr resItem, int priority, constResItemPtr child = NULL); + ResolverInfoContainer (ResolverInfoType type, ResItem_constPtr resItem, int priority, ResItem_constPtr child = NULL); public: virtual ~ResolverInfoContainer(); - void copy (constResolverInfoContainerPtr from); + void copy (ResolverInfoContainer_constPtr from); // ---------------------------------- I/O @@ -73,13 +73,13 @@ namespace zypp // ---------------------------------- methods - virtual bool merge (ResolverInfoContainerPtr to_be_merged); - virtual ResolverInfoPtr copy (void) const; + virtual bool merge (ResolverInfoContainer_Ptr to_be_merged); + virtual ResolverInfo_Ptr copy (void) const; std::string resItemsToString (bool names_only) const; - bool mentions (constResItemPtr resItem) const; - void addRelatedResItem (constResItemPtr resItem); + bool mentions (ResItem_constPtr resItem) const; + void addRelatedResItem (ResItem_constPtr resItem); void addRelatedResItemList (const CResItemList & resItems); }; diff --git a/zypp/solver/detail/ResolverInfoContainerPtr.h b/zypp/solver/detail/ResolverInfoContainerPtr.h index e110582..11bfc82 100644 --- a/zypp/solver/detail/ResolverInfoContainerPtr.h +++ b/zypp/solver/detail/ResolverInfoContainerPtr.h @@ -1,5 +1,5 @@ /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* ResolverInfoContainerPtr.h +/* ResolverInfoContainer_Ptr.h * * Copyright (C) 2005 SUSE Linux Products GmbH * @@ -18,14 +18,14 @@ * 02111-1307, USA. */ -#ifndef _ResolverInfoContainerPtr_h -#define _ResolverInfoContainerPtr_h +#ifndef _ResolverInfoContainer_Ptr_h +#define _ResolverInfoContainer_Ptr_h -#include -#include +#include "zypp/base/PtrTypes.h" +#include ///////////////////////////////////////////////////////////////////////// -namespace zypp +namespace zypp { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// namespace solver @@ -35,11 +35,11 @@ namespace zypp { /////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// - // CLASS NAME : ResolverInfoContainerPtr - // CLASS NAME : constResolverInfoContainerPtr + // CLASS NAME : ResolverInfoContainer_Ptr + // CLASS NAME : ResolverInfoContainer_constPtr /////////////////////////////////////////////////////////////////// - DEFINE_DERIVED_POINTER(ResolverInfoContainer,ResolverInfo); - + DEFINE_PTR_TYPE(ResolverInfoContainer); + /////////////////////////////////////////////////////////////////// };// namespace detail ///////////////////////////////////////////////////////////////////// @@ -49,4 +49,4 @@ namespace zypp /////////////////////////////////////////////////////////////////////// };// namespace zypp ///////////////////////////////////////////////////////////////////////// -#endif // _ResolverInfoContainerPtr_h +#endif // _ResolverInfoContainer_Ptr_h diff --git a/zypp/solver/detail/ResolverInfoDependsOn.cc b/zypp/solver/detail/ResolverInfoDependsOn.cc index 2691331..d6b5f86 100644 --- a/zypp/solver/detail/ResolverInfoDependsOn.cc +++ b/zypp/solver/detail/ResolverInfoDependsOn.cc @@ -36,7 +36,7 @@ namespace zypp using namespace std; - IMPL_DERIVED_POINTER(ResolverInfoDependsOn, ResolverInfo); + IMPL_PTR_TYPE(ResolverInfoDependsOn); //--------------------------------------------------------------------------- @@ -76,7 +76,7 @@ namespace zypp //--------------------------------------------------------------------------- - ResolverInfoDependsOn::ResolverInfoDependsOn (constResItemPtr resItem, constResItemPtr on) + ResolverInfoDependsOn::ResolverInfoDependsOn (ResItem_constPtr resItem, ResItem_constPtr on) : ResolverInfoContainer (RESOLVER_INFO_TYPE_DEPENDS_ON, resItem, RESOLVER_INFO_PRIORITY_USER, on) { } @@ -88,12 +88,12 @@ namespace zypp //--------------------------------------------------------------------------- - ResolverInfoPtr + ResolverInfo_Ptr ResolverInfoDependsOn::copy (void) const { - ResolverInfoDependsOnPtr cpy = new ResolverInfoDependsOn(resItem(), NULL); + ResolverInfoDependsOn_Ptr cpy = new ResolverInfoDependsOn(resItem(), NULL); - ((ResolverInfoContainerPtr)cpy)->copy (this); + ((ResolverInfoContainer_Ptr)cpy)->copy (this); return cpy; } diff --git a/zypp/solver/detail/ResolverInfoDependsOn.h b/zypp/solver/detail/ResolverInfoDependsOn.h index df900de..50dab78 100644 --- a/zypp/solver/detail/ResolverInfoDependsOn.h +++ b/zypp/solver/detail/ResolverInfoDependsOn.h @@ -42,13 +42,13 @@ namespace zypp class ResolverInfoDependsOn : public ResolverInfoContainer { - REP_BODY(ResolverInfoDependsOn); + private: public: - ResolverInfoDependsOn (constResItemPtr resItem, constResItemPtr on); + ResolverInfoDependsOn (ResItem_constPtr resItem, ResItem_constPtr on); virtual ~ResolverInfoDependsOn(); // ---------------------------------- I/O @@ -62,7 +62,7 @@ namespace zypp // ---------------------------------- methods - virtual ResolverInfoPtr copy (void) const; + virtual ResolverInfo_Ptr copy (void) const; }; diff --git a/zypp/solver/detail/ResolverInfoDependsOnPtr.h b/zypp/solver/detail/ResolverInfoDependsOnPtr.h index 47e7701..cae558b 100644 --- a/zypp/solver/detail/ResolverInfoDependsOnPtr.h +++ b/zypp/solver/detail/ResolverInfoDependsOnPtr.h @@ -1,5 +1,5 @@ /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* ResolverInfoDependsOnPtr.h +/* ResolverInfoDependsOn_Ptr.h * * Copyright (C) 2005 SUSE Linux Products GmbH * @@ -18,10 +18,10 @@ * 02111-1307, USA. */ -#ifndef _ResolverInfoDependsOnPtr_h -#define _ResolverInfoDependsOnPtr_h +#ifndef _ResolverInfoDependsOn_Ptr_h +#define _ResolverInfoDependsOn_Ptr_h -#include +#include "zypp/base/PtrTypes.h" #include ///////////////////////////////////////////////////////////////////////// @@ -35,10 +35,10 @@ namespace zypp { /////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// - // CLASS NAME : ResolverInfoDependsOnPtr - // CLASS NAME : constResolverInfoDependsOnPtr + // CLASS NAME : ResolverInfoDependsOn_Ptr + // CLASS NAME : ResolverInfoDependsOn_constPtr /////////////////////////////////////////////////////////////////// - DEFINE_DERIVED_POINTER(ResolverInfoDependsOn, ResolverInfo); + DEFINE_PTR_TYPE(ResolverInfoDependsOn); /////////////////////////////////////////////////////////////////// };// namespace detail @@ -51,4 +51,4 @@ namespace zypp ///////////////////////////////////////////////////////////////////////// -#endif // _ResolverInfoDependsOnPtr_h +#endif // _ResolverInfoDependsOn_Ptr_h diff --git a/zypp/solver/detail/ResolverInfoMisc.cc b/zypp/solver/detail/ResolverInfoMisc.cc index ada7391..9b4c589 100644 --- a/zypp/solver/detail/ResolverInfoMisc.cc +++ b/zypp/solver/detail/ResolverInfoMisc.cc @@ -25,7 +25,7 @@ #include ///////////////////////////////////////////////////////////////////////// -namespace zypp +namespace zypp { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// namespace solver @@ -35,19 +35,19 @@ namespace zypp { /////////////////////////////////////////////////////////////////// using namespace std; - - IMPL_DERIVED_POINTER(ResolverInfoMisc, ResolverInfo); - + + IMPL_PTR_TYPE(ResolverInfoMisc); + //--------------------------------------------------------------------------- - - + + string ResolverInfoMisc::asString ( void ) const { return toString (*this); } - - + + string ResolverInfoMisc::toString ( const ResolverInfoMisc & misc) { @@ -65,84 +65,84 @@ namespace zypp if (!misc._trigger.empty()) { res += string (", Trigger: ") + misc._trigger + "\n"; } - + return res; } - - + + ostream & ResolverInfoMisc::dumpOn( ostream & str ) const { str << asString(); return str; } - - + + ostream& operator<<( ostream& os, const ResolverInfoMisc & misc) { return os << misc.asString(); } - + //--------------------------------------------------------------------------- - - ResolverInfoMisc::ResolverInfoMisc (constResItemPtr resItem, int priority, const string & msg) + + ResolverInfoMisc::ResolverInfoMisc (ResItem_constPtr resItem, int priority, const string & msg) : ResolverInfoContainer (RESOLVER_INFO_TYPE_MISC, resItem, priority) , _msg (msg) { } - - + + ResolverInfoMisc::~ResolverInfoMisc () { } - + //--------------------------------------------------------------------------- - + bool - ResolverInfoMisc::merge (ResolverInfoPtr info) + ResolverInfoMisc::merge (ResolverInfo_Ptr info) { bool res; - ResolverInfoMiscPtr to_be_merged = info; - - res = ((ResolverInfoPtr)this)->merge ((ResolverInfoPtr)to_be_merged); + ResolverInfoMisc_Ptr to_be_merged = dynamic_pointer_cast(info); + + res = ResolverInfo::merge(to_be_merged); if (!res) return res; - + if (!_msg.empty() && !to_be_merged->_msg.empty() && _msg == to_be_merged->_msg) { return true; } - + return false; } - - - ResolverInfoPtr + + + ResolverInfo_Ptr ResolverInfoMisc::copy (void) const { - ResolverInfoMiscPtr cpy = new ResolverInfoMisc(resItem(), priority(), _msg); - - ((ResolverInfoContainerPtr)cpy)->copy (this); - + ResolverInfoMisc_Ptr cpy = new ResolverInfoMisc(resItem(), priority(), _msg); + + ((ResolverInfoContainer_Ptr)cpy)->copy (this); + return cpy; } - + //--------------------------------------------------------------------------- - + void ResolverInfoMisc::addAction (const std::string & action_msg) { _action = action_msg; } - - + + void ResolverInfoMisc::addTrigger (const std::string & trigger_msg) { _trigger = trigger_msg; } - + /////////////////////////////////////////////////////////////////// };// namespace detail ///////////////////////////////////////////////////////////////////// diff --git a/zypp/solver/detail/ResolverInfoMisc.h b/zypp/solver/detail/ResolverInfoMisc.h index e9e5b0a..85950b5 100644 --- a/zypp/solver/detail/ResolverInfoMisc.h +++ b/zypp/solver/detail/ResolverInfoMisc.h @@ -42,7 +42,7 @@ namespace zypp class ResolverInfoMisc : public ResolverInfoContainer { - REP_BODY(ResolverInfoMisc); + private: @@ -52,7 +52,7 @@ namespace zypp public: - ResolverInfoMisc (constResItemPtr resItem, int priority, const std::string & msg); + ResolverInfoMisc (ResItem_constPtr resItem, int priority, const std::string & msg); virtual ~ResolverInfoMisc(); // ---------------------------------- I/O @@ -66,8 +66,8 @@ namespace zypp // ---------------------------------- methods - virtual bool merge (ResolverInfoPtr to_be_merged); - virtual ResolverInfoPtr copy (void) const; + virtual bool merge (ResolverInfo_Ptr to_be_merged); + virtual ResolverInfo_Ptr copy (void) const; void addAction (const std::string & action_msg); void addTrigger (const std::string & trigger_msg); diff --git a/zypp/solver/detail/ResolverInfoMiscPtr.h b/zypp/solver/detail/ResolverInfoMiscPtr.h index bd1f154..73717a2 100644 --- a/zypp/solver/detail/ResolverInfoMiscPtr.h +++ b/zypp/solver/detail/ResolverInfoMiscPtr.h @@ -1,5 +1,5 @@ /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* ResolverInfoMiscPtr.h +/* ResolverInfoMisc_Ptr.h * * Copyright (C) 2005 SUSE Linux Products GmbH * @@ -18,10 +18,10 @@ * 02111-1307, USA. */ -#ifndef _ResolverInfoMiscPtr_h -#define _ResolverInfoMiscPtr_h +#ifndef _ResolverInfoMisc_Ptr_h +#define _ResolverInfoMisc_Ptr_h -#include +#include "zypp/base/PtrTypes.h" #include ///////////////////////////////////////////////////////////////////////// @@ -35,10 +35,10 @@ namespace zypp { /////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// - // CLASS NAME : ResolverInfoMiscPtr - // CLASS NAME : constResolverInfoMiscPtr + // CLASS NAME : ResolverInfoMisc_Ptr + // CLASS NAME : ResolverInfoMisc_constPtr /////////////////////////////////////////////////////////////////// - DEFINE_DERIVED_POINTER(ResolverInfoMisc, ResolverInfo); + DEFINE_PTR_TYPE(ResolverInfoMisc); /////////////////////////////////////////////////////////////////// };// namespace detail @@ -50,4 +50,4 @@ namespace zypp };// namespace zypp ///////////////////////////////////////////////////////////////////////// -#endif // _ResolverInfoMiscPtr_h +#endif // _ResolverInfoMisc_Ptr_h diff --git a/zypp/solver/detail/ResolverInfoMissingReq.cc b/zypp/solver/detail/ResolverInfoMissingReq.cc index 83ddcc0..2a4932f 100644 --- a/zypp/solver/detail/ResolverInfoMissingReq.cc +++ b/zypp/solver/detail/ResolverInfoMissingReq.cc @@ -36,7 +36,7 @@ namespace zypp using namespace std; - IMPL_DERIVED_POINTER(ResolverInfoMissingReq, ResolverInfo); + IMPL_PTR_TYPE(ResolverInfoMissingReq); //--------------------------------------------------------------------------- @@ -76,7 +76,7 @@ namespace zypp //--------------------------------------------------------------------------- - ResolverInfoMissingReq::ResolverInfoMissingReq (constResItemPtr resItem, const Capability & missing_req) + ResolverInfoMissingReq::ResolverInfoMissingReq (ResItem_constPtr resItem, const Capability & missing_req) : ResolverInfo (RESOLVER_INFO_TYPE_MISSING_REQ, resItem, RESOLVER_INFO_PRIORITY_USER) , _missing_req (missing_req) { @@ -89,12 +89,12 @@ namespace zypp //--------------------------------------------------------------------------- - ResolverInfoPtr + ResolverInfo_Ptr ResolverInfoMissingReq::copy (void) const { - ResolverInfoMissingReqPtr cpy = new ResolverInfoMissingReq(resItem(), _missing_req); + ResolverInfoMissingReq_Ptr cpy = new ResolverInfoMissingReq(resItem(), _missing_req); - ((ResolverInfoPtr)cpy)->copy (this); + ((ResolverInfo_Ptr)cpy)->copy (this); return cpy; } diff --git a/zypp/solver/detail/ResolverInfoMissingReq.h b/zypp/solver/detail/ResolverInfoMissingReq.h index a869385..742dc32 100644 --- a/zypp/solver/detail/ResolverInfoMissingReq.h +++ b/zypp/solver/detail/ResolverInfoMissingReq.h @@ -42,7 +42,7 @@ namespace zypp class ResolverInfoMissingReq : public ResolverInfo { - REP_BODY(ResolverInfoMissingReq); + private: @@ -50,7 +50,7 @@ namespace zypp public: - ResolverInfoMissingReq (constResItemPtr resItem, const Capability & missing_req); + ResolverInfoMissingReq (ResItem_constPtr resItem, const Capability & missing_req); virtual ~ResolverInfoMissingReq(); // ---------------------------------- I/O @@ -64,7 +64,7 @@ namespace zypp // ---------------------------------- methods - virtual ResolverInfoPtr copy (void) const; + virtual ResolverInfo_Ptr copy (void) const; }; diff --git a/zypp/solver/detail/ResolverInfoMissingReqPtr.h b/zypp/solver/detail/ResolverInfoMissingReqPtr.h index f448dd7..4067616 100644 --- a/zypp/solver/detail/ResolverInfoMissingReqPtr.h +++ b/zypp/solver/detail/ResolverInfoMissingReqPtr.h @@ -1,5 +1,5 @@ /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* ResolverInfoMissingReqPtr.h +/* ResolverInfoMissingReq_Ptr.h * * Copyright (C) 2005 SUSE Linux Products GmbH * @@ -18,10 +18,10 @@ * 02111-1307, USA. */ -#ifndef _ResolverInfoMissingReqPtr_h -#define _ResolverInfoMissingReqPtr_h +#ifndef _ResolverInfoMissingReq_Ptr_h +#define _ResolverInfoMissingReq_Ptr_h -#include +#include "zypp/base/PtrTypes.h" #include ///////////////////////////////////////////////////////////////////////// @@ -35,10 +35,10 @@ namespace zypp { /////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// - // CLASS NAME : ResolverInfoMissingReqPtr - // CLASS NAME : constResolverInfoMissingReqPtr + // CLASS NAME : ResolverInfoMissingReq_Ptr + // CLASS NAME : ResolverInfoMissingReq_constPtr /////////////////////////////////////////////////////////////////// - DEFINE_DERIVED_POINTER(ResolverInfoMissingReq, ResolverInfo); + DEFINE_PTR_TYPE(ResolverInfoMissingReq); /////////////////////////////////////////////////////////////////// };// namespace detail @@ -50,4 +50,4 @@ namespace zypp };// namespace zypp ///////////////////////////////////////////////////////////////////////// -#endif // _ResolverInfoMissingReqPtr_h +#endif // _ResolverInfoMissingReq_Ptr_h diff --git a/zypp/solver/detail/ResolverInfoNeededBy.cc b/zypp/solver/detail/ResolverInfoNeededBy.cc index d0490d9..bc3cd50 100644 --- a/zypp/solver/detail/ResolverInfoNeededBy.cc +++ b/zypp/solver/detail/ResolverInfoNeededBy.cc @@ -36,7 +36,7 @@ namespace zypp using namespace std; - IMPL_DERIVED_POINTER(ResolverInfoNeededBy, ResolverInfo); + IMPL_PTR_TYPE(ResolverInfoNeededBy); //--------------------------------------------------------------------------- @@ -76,7 +76,7 @@ namespace zypp //--------------------------------------------------------------------------- - ResolverInfoNeededBy::ResolverInfoNeededBy (constResItemPtr resItem) + ResolverInfoNeededBy::ResolverInfoNeededBy (ResItem_constPtr resItem) : ResolverInfoContainer (RESOLVER_INFO_TYPE_NEEDED_BY, resItem, RESOLVER_INFO_PRIORITY_USER, NULL) { } @@ -88,12 +88,12 @@ namespace zypp //--------------------------------------------------------------------------- - ResolverInfoPtr + ResolverInfo_Ptr ResolverInfoNeededBy::copy (void) const { - ResolverInfoNeededByPtr cpy = new ResolverInfoNeededBy(resItem()); + ResolverInfoNeededBy_Ptr cpy = new ResolverInfoNeededBy(resItem()); - ((ResolverInfoContainerPtr)cpy)->copy (this); + ((ResolverInfoContainer_Ptr)cpy)->copy (this); return cpy; } diff --git a/zypp/solver/detail/ResolverInfoNeededBy.h b/zypp/solver/detail/ResolverInfoNeededBy.h index 9eaf8aa..a26f694 100644 --- a/zypp/solver/detail/ResolverInfoNeededBy.h +++ b/zypp/solver/detail/ResolverInfoNeededBy.h @@ -41,13 +41,13 @@ namespace zypp class ResolverInfoNeededBy : public ResolverInfoContainer { - REP_BODY(ResolverInfoNeededBy); + private: public: - ResolverInfoNeededBy (constResItemPtr resItem); + ResolverInfoNeededBy (ResItem_constPtr resItem); virtual ~ResolverInfoNeededBy(); // ---------------------------------- I/O @@ -61,7 +61,7 @@ namespace zypp // ---------------------------------- methods - virtual ResolverInfoPtr copy (void) const; + virtual ResolverInfo_Ptr copy (void) const; }; /////////////////////////////////////////////////////////////////// diff --git a/zypp/solver/detail/ResolverInfoNeededByPtr.h b/zypp/solver/detail/ResolverInfoNeededByPtr.h index 8b0e74b..b43485b 100644 --- a/zypp/solver/detail/ResolverInfoNeededByPtr.h +++ b/zypp/solver/detail/ResolverInfoNeededByPtr.h @@ -1,5 +1,5 @@ /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* ResolverInfoNeededByPtr.h +/* ResolverInfoNeededBy_Ptr.h * * Copyright (C) 2005 SUSE Linux Products GmbH * @@ -18,10 +18,10 @@ * 02111-1307, USA. */ -#ifndef _ResolverInfoNeededByPtr_h -#define _ResolverInfoNeededByPtr_h +#ifndef _ResolverInfoNeededBy_Ptr_h +#define _ResolverInfoNeededBy_Ptr_h -#include +#include "zypp/base/PtrTypes.h" #include ///////////////////////////////////////////////////////////////////////// @@ -35,10 +35,10 @@ namespace zypp { /////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// - // CLASS NAME : ResolverInfoNeededByPtr - // CLASS NAME : constResolverInfoNeededByPtr + // CLASS NAME : ResolverInfoNeededBy_Ptr + // CLASS NAME : ResolverInfoNeededBy_constPtr /////////////////////////////////////////////////////////////////// - DEFINE_DERIVED_POINTER(ResolverInfoNeededBy, ResolverInfo); + DEFINE_PTR_TYPE(ResolverInfoNeededBy); /////////////////////////////////////////////////////////////////// };// namespace detail @@ -50,4 +50,4 @@ namespace zypp };// namespace zypp ///////////////////////////////////////////////////////////////////////// -#endif // _ResolverInfoNeededByPtr_h +#endif // _ResolverInfoNeededBy_Ptr_h diff --git a/zypp/solver/detail/ResolverInfoObsoletes.cc b/zypp/solver/detail/ResolverInfoObsoletes.cc index 450f7d6..64cf23f 100644 --- a/zypp/solver/detail/ResolverInfoObsoletes.cc +++ b/zypp/solver/detail/ResolverInfoObsoletes.cc @@ -36,7 +36,7 @@ namespace zypp using namespace std; - IMPL_DERIVED_POINTER(ResolverInfoObsoletes, ResolverInfo); + IMPL_PTR_TYPE(ResolverInfoObsoletes); //--------------------------------------------------------------------------- @@ -76,7 +76,7 @@ namespace zypp //--------------------------------------------------------------------------- - ResolverInfoObsoletes::ResolverInfoObsoletes (constResItemPtr resItem, constResItemPtr obsoletes) + ResolverInfoObsoletes::ResolverInfoObsoletes (ResItem_constPtr resItem, ResItem_constPtr obsoletes) : ResolverInfoContainer (RESOLVER_INFO_TYPE_OBSOLETES, resItem, RESOLVER_INFO_PRIORITY_USER, obsoletes) { } @@ -88,12 +88,12 @@ namespace zypp //--------------------------------------------------------------------------- - ResolverInfoPtr + ResolverInfo_Ptr ResolverInfoObsoletes::copy (void) const { - ResolverInfoObsoletesPtr cpy = new ResolverInfoObsoletes(resItem(), NULL); + ResolverInfoObsoletes_Ptr cpy = new ResolverInfoObsoletes(resItem(), NULL); - ((ResolverInfoContainerPtr)cpy)->copy (this); + ((ResolverInfoContainer_Ptr)cpy)->copy (this); return cpy; } diff --git a/zypp/solver/detail/ResolverInfoObsoletes.h b/zypp/solver/detail/ResolverInfoObsoletes.h index e790e02..763094f 100644 --- a/zypp/solver/detail/ResolverInfoObsoletes.h +++ b/zypp/solver/detail/ResolverInfoObsoletes.h @@ -41,13 +41,13 @@ namespace zypp class ResolverInfoObsoletes : public ResolverInfoContainer { - REP_BODY(ResolverInfoObsoletes); + private: public: - ResolverInfoObsoletes (constResItemPtr resItem, constResItemPtr obsoletes); + ResolverInfoObsoletes (ResItem_constPtr resItem, ResItem_constPtr obsoletes); virtual ~ResolverInfoObsoletes(); // ---------------------------------- I/O @@ -61,7 +61,7 @@ namespace zypp // ---------------------------------- methods - virtual ResolverInfoPtr copy (void) const; + virtual ResolverInfo_Ptr copy (void) const; }; /////////////////////////////////////////////////////////////////// };// namespace detail diff --git a/zypp/solver/detail/ResolverInfoObsoletesPtr.h b/zypp/solver/detail/ResolverInfoObsoletesPtr.h index 3c659f5..4faabda 100644 --- a/zypp/solver/detail/ResolverInfoObsoletesPtr.h +++ b/zypp/solver/detail/ResolverInfoObsoletesPtr.h @@ -1,5 +1,5 @@ /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* ResolverInfoObsoletesPtr.h +/* ResolverInfoObsoletes_Ptr.h * * Copyright (C) 2005 SUSE Linux Products GmbH * @@ -18,10 +18,10 @@ * 02111-1307, USA. */ -#ifndef _ResolverInfoObsoletesPtr_h -#define _ResolverInfoObsoletesPtr_h +#ifndef _ResolverInfoObsoletes_Ptr_h +#define _ResolverInfoObsoletes_Ptr_h -#include +#include "zypp/base/PtrTypes.h" #include ///////////////////////////////////////////////////////////////////////// @@ -35,10 +35,10 @@ namespace zypp { /////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// - // CLASS NAME : ResolverInfoObsoletesPtr - // CLASS NAME : constResolverInfoObsoletesPtr + // CLASS NAME : ResolverInfoObsoletes_Ptr + // CLASS NAME : ResolverInfoObsoletes_constPtr /////////////////////////////////////////////////////////////////// - DEFINE_DERIVED_POINTER(ResolverInfoObsoletes, ResolverInfo); + DEFINE_PTR_TYPE(ResolverInfoObsoletes); /////////////////////////////////////////////////////////////////// };// namespace detail @@ -51,4 +51,4 @@ namespace zypp ///////////////////////////////////////////////////////////////////////// -#endif // _ResolverInfoObsoletesPtr_h +#endif // _ResolverInfoObsoletes_Ptr_h diff --git a/zypp/solver/detail/ResolverInfoPtr.h b/zypp/solver/detail/ResolverInfoPtr.h index d3d2d26..41f7e46 100644 --- a/zypp/solver/detail/ResolverInfoPtr.h +++ b/zypp/solver/detail/ResolverInfoPtr.h @@ -1,5 +1,5 @@ /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* ResolverInfoPtr.h +/* ResolverInfo_Ptr.h * * Copyright (C) 2005 SUSE Linux Products GmbH * @@ -18,10 +18,10 @@ * 02111-1307, USA. */ -#ifndef _ResolverInfoPtr_h -#define _ResolverInfoPtr_h +#ifndef _ResolverInfo_Ptr_h +#define _ResolverInfo_Ptr_h -#include +#include "zypp/base/PtrTypes.h" ///////////////////////////////////////////////////////////////////////// namespace zypp @@ -34,10 +34,10 @@ namespace zypp { /////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// - // CLASS NAME : ResolverInfoPtr - // CLASS NAME : constResolverInfoPtr + // CLASS NAME : ResolverInfo_Ptr + // CLASS NAME : ResolverInfo_constPtr /////////////////////////////////////////////////////////////////// - DEFINE_BASE_POINTER(ResolverInfo); + DEFINE_PTR_TYPE(ResolverInfo); /////////////////////////////////////////////////////////////////// };// namespace detail @@ -49,4 +49,4 @@ namespace zypp };// namespace zypp ///////////////////////////////////////////////////////////////////////// -#endif // _ResolverInfoPtr_h +#endif // _ResolverInfo_Ptr_h diff --git a/zypp/solver/detail/ResolverPtr.h b/zypp/solver/detail/ResolverPtr.h index a057b15..0f6579c 100644 --- a/zypp/solver/detail/ResolverPtr.h +++ b/zypp/solver/detail/ResolverPtr.h @@ -1,5 +1,5 @@ /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* ResolverPtr.h +/* Resolver_Ptr.h * * Copyright (C) 2005 SUSE Linux Products GmbH * @@ -18,10 +18,10 @@ * 02111-1307, USA. */ -#ifndef _ResolverPtr_h -#define _ResolverPtr_h +#ifndef _Resolver_Ptr_h +#define _Resolver_Ptr_h -#include +#include "zypp/base/PtrTypes.h" ///////////////////////////////////////////////////////////////////////// namespace zypp @@ -34,10 +34,10 @@ namespace zypp { /////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// - // CLASS NAME : ResolverPtr - // CLASS NAME : constResolverPtr + // CLASS NAME : Resolver_Ptr + // CLASS NAME : Resolver_constPtr /////////////////////////////////////////////////////////////////// - DEFINE_BASE_POINTER(Resolver); + DEFINE_PTR_TYPE(Resolver); /////////////////////////////////////////////////////////////////// };// namespace detail ///////////////////////////////////////////////////////////////////// @@ -49,4 +49,4 @@ namespace zypp ///////////////////////////////////////////////////////////////////////// -#endif // _ResolverPtr_h +#endif // _Resolver_Ptr_h diff --git a/zypp/solver/detail/ResolverQueue.cc b/zypp/solver/detail/ResolverQueue.cc index 7802226..24a6de2 100644 --- a/zypp/solver/detail/ResolverQueue.cc +++ b/zypp/solver/detail/ResolverQueue.cc @@ -21,6 +21,7 @@ #include +#include #include #include #include @@ -31,10 +32,8 @@ #include #include -#include - ///////////////////////////////////////////////////////////////////////// -namespace zypp +namespace zypp { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// namespace solver @@ -42,153 +41,153 @@ namespace zypp ///////////////////////////////////////////////////////////////////// namespace detail { /////////////////////////////////////////////////////////////////// - + using namespace std; - - IMPL_BASE_POINTER(ResolverQueue); - + + IMPL_PTR_TYPE(ResolverQueue); + //--------------------------------------------------------------------------- - - + + //--------------------------------------------------------------------------- - + string ResolverQueue::asString ( void ) const { return toString (*this); } - - + + string ResolverQueue::toString ( const ResolverQueue & resolverqueue ) { string res; - - res += stringutil::form ("Context [%p]", (const void *)resolverqueue._context); + + res += str::form ("Context [%p]", (const void *)resolverqueue._context.get()); res += ", Items:\n\t"; res += QueueItem::toString (resolverqueue._items, ",\n\t"); - + return res; } - - + + ostream & ResolverQueue::dumpOn( ostream & str ) const { str << asString(); return str; } - - + + ostream& operator<<( ostream& os, const ResolverQueue & resolverqueue) { return os << resolverqueue.asString(); } - + //--------------------------------------------------------------------------- - - ResolverQueue::ResolverQueue (ResolverContextPtr context) + + ResolverQueue::ResolverQueue (ResolverContext_Ptr context) : _context (context) { if (context == NULL) _context = new ResolverContext(); } - - + + ResolverQueue::~ResolverQueue() { } - + //--------------------------------------------------------------------------- - + void - ResolverQueue::addResItemToInstall (constResItemPtr resItem) + ResolverQueue::addResItemToInstall (ResItem_constPtr resItem) { - QueueItemInstallPtr item; - + QueueItemInstall_Ptr item; + if (_context->resItemIsPresent (resItem)) { printf ("%s is already installed", resItem->asString().c_str()); return; } - + item = new QueueItemInstall (_context->world(), resItem); item->setExplicitlyRequested (); - + addItem (item); } - - + + void - ResolverQueue::addResItemToRemove (constResItemPtr resItem, bool remove_only_mode) + ResolverQueue::addResItemToRemove (ResItem_constPtr resItem, bool remove_only_mode) { - QueueItemUninstallPtr item; - + QueueItemUninstall_Ptr item; + if (_context->resItemIsAbsent (resItem)) return; - + item = new QueueItemUninstall (_context->world(), resItem, "user request"); if (remove_only_mode) item->setRemoveOnly (); - + item->setExplicitlyRequested (); - + addItem (item); } - - + + void - ResolverQueue::addResItemToVerify (constResItemPtr resItem) + ResolverQueue::addResItemToVerify (ResItem_constPtr resItem) { - WorldPtr world; - + World_Ptr world; + world = _context->world (); - + CapSet requires = resItem->requires(); for (CapSet::const_iterator iter = requires.begin(); iter != requires.end(); iter++) { - QueueItemRequirePtr item = new QueueItemRequire (world, *iter); + QueueItemRequire_Ptr item = new QueueItemRequire (world, *iter); item->addResItem (resItem); addItem (item); } - + CapSet conflicts = resItem->conflicts(); for (CapSet::const_iterator iter = conflicts.begin(); iter != conflicts.end(); iter++) { - QueueItemConflictPtr item = new QueueItemConflict (world, *iter, resItem); + QueueItemConflict_Ptr item = new QueueItemConflict (world, *iter, resItem); addItem (item); } } - - + + void ResolverQueue::addExtraDependency (const Capability & dep) { - QueueItemRequirePtr item = new QueueItemRequire (_context->world(), dep); + QueueItemRequire_Ptr item = new QueueItemRequire (_context->world(), dep); addItem (item); } - - + + void ResolverQueue::addExtraConflict (const Capability & dep) { - QueueItemConflictPtr item = new QueueItemConflict (_context->world(), dep, NULL); + QueueItemConflict_Ptr item = new QueueItemConflict (_context->world(), dep, NULL); addItem (item); } - - + + void - ResolverQueue::addItem (QueueItemPtr item) + ResolverQueue::addItem (QueueItem_Ptr item) { _items.push_front (item); } - - + + bool ResolverQueue::isInvalid () { return _context->isInvalid(); } - - + + bool ResolverQueue::containsOnlyBranches () { @@ -196,12 +195,12 @@ namespace zypp if (!(*iter)->isBranch()) return false; } - + return true; } - + //--------------------------------------------------------------------------- - + static int itemlist_max_priority (const QueueItemList & qil) { @@ -211,28 +210,28 @@ namespace zypp max_priority = (*iter)->priority(); } } - + return max_priority; } - - - + + + bool ResolverQueue::processOnce () { QueueItemList new_items; int max_priority; bool did_something = false; - + if (getenv ("QUEUE_SPEW")) fprintf (stderr, "ResolverQueue::processOnce(%s), %d items\n", asString().c_str(), (int) _items.size()); while ( (max_priority = itemlist_max_priority (_items)) >= 0 && _context->isValid () ) { - + bool did_something_recently = false; - + if (getenv ("QUEUE_SPEW")) fprintf (stderr, "ResolverQueue::processOnce() inside loop\n"); for (QueueItemList::iterator iter = _items.begin(); iter != _items.end() && _context->isValid();) { - QueueItemPtr item = *iter; + QueueItem_Ptr item = *iter; if (getenv ("QUEUE_SPEW")) fprintf (stderr, "=====> 1st pass: [%s]\n", item->asString().c_str()); QueueItemList::iterator next = iter; next++; if (item && item->priority() == max_priority) { @@ -243,30 +242,30 @@ namespace zypp } iter = next; } - + if (did_something_recently) { did_something = true; } } - + _items = new_items; if (getenv ("QUEUE_SPEW")) fprintf (stderr, "%d items after first pass\n", (int) _items.size()); - - /* + + /* Now make a second pass over the queue, removing any super-branches. (If one branch contains all of the possible items of another branch, - the larger branch can be dropped. + the larger branch can be dropped. */ - + // if (getenv ("QUEUE_SPEW")) fprintf (stderr, "ResolverQueue::processOnce() second pass\n"); for (QueueItemList::iterator iter = _items.begin(); iter != _items.end();) { QueueItemList::iterator next = iter; next++; - QueueItemPtr item = *iter; - + QueueItem_Ptr item = *iter; + if (getenv ("QUEUE_SPEW")) fprintf (stderr, "=====> 2nd pass: [%s]\n", item->asString().c_str()); if (item->isBranch()) { if (getenv ("QUEUE_SPEW")) fprintf (stderr, "ResolverQueue::processOnce() is branch\n"); - QueueItemBranchPtr branch = (QueueItemBranchPtr)item; + QueueItemBranch_Ptr branch = dynamic_pointer_cast(item); for (QueueItemList::const_iterator iter2 = _items.begin(); iter2 != _items.end(); iter2++) { if (getenv ("QUEUE_SPEW")) fprintf (stderr, "Compare branch with [%s]\n", (*iter2)->asString().c_str()); if (iter != iter2 @@ -280,23 +279,23 @@ namespace zypp iter = next; } if (getenv ("QUEUE_SPEW")) fprintf (stderr, "did %sthing: %d items\n", did_something ? "some" : "no", (int)_items.size()); - + return did_something; } - - + + void ResolverQueue::process () { bool very_noisy; - + very_noisy = getenv ("RC_SPEW") != NULL; - + if (very_noisy) { printf ("----- Processing -----\n"); spew (); } - + while (_context->isValid () && ! isEmpty () && processOnce ()) { @@ -306,97 +305,97 @@ namespace zypp } } } - - + + //--------------------------------------------------------------------------- - - static ResolverQueuePtr - copy_queue_except_for_branch (ResolverQueuePtr queue, QueueItemPtr branch_item, QueueItemPtr subitem) + + static ResolverQueue_Ptr + copy_queue_except_for_branch (ResolverQueue_Ptr queue, QueueItem_Ptr branch_item, QueueItem_Ptr subitem) { - ResolverContextPtr new_context; - ResolverQueuePtr new_queue; - + ResolverContext_Ptr new_context; + ResolverQueue_Ptr new_queue; + new_context = new ResolverContext (queue->context()); new_queue = new ResolverQueue (new_context); - + QueueItemList qil = queue->items(); for (QueueItemList::const_iterator iter = qil.begin(); iter != qil.end(); iter++) { - QueueItemPtr item = *iter; - QueueItemPtr new_item; - + QueueItem_Ptr item = *iter; + QueueItem_Ptr new_item; + if (item == branch_item) { new_item = subitem->copy (); - + if (new_item->isInstall()) { - QueueItemInstallPtr install_item = (QueueItemInstallPtr)new_item; - + QueueItemInstall_Ptr install_item = dynamic_pointer_cast(new_item); + /* Penalties are negative priorities */ int penalty; penalty = - queue->context()->getChannelPriority (install_item->resItem()->channel()); - + install_item->setOtherPenalty (penalty); } - + } else { - + new_item = item->copy (); - + } - + new_queue->addItem (new_item); } - + return new_queue; } - - + + void ResolverQueue::splitFirstBranch (ResolverQueueList & new_queues, ResolverQueueList & deferred_queues) { - QueueItemBranchPtr first_branch = NULL; - typedef std::map DeferTable; + QueueItemBranch_Ptr first_branch = NULL; + typedef std::map DeferTable; DeferTable to_defer; - + for (QueueItemList::const_iterator iter = _items.begin(); iter != _items.end() && first_branch == NULL; iter++) { - QueueItemPtr item = *iter; + QueueItem_Ptr item = *iter; if (item->isBranch()) { - first_branch = (QueueItemBranchPtr)item; + first_branch = dynamic_pointer_cast(item); } } - + if (first_branch == NULL) return; - - /* + + /* Check for deferrable items: if we have two install items where the to-be-installed resItems have the same name, then we will defer the lower-priority install if one of the following is true: (1) Both resItems have the same version (2) The lower-priority channel is a previous version. */ - + QueueItemList possible_items = first_branch->possibleItems(); for (QueueItemList::const_iterator iter = possible_items.begin(); iter != possible_items.end(); iter++) { QueueItemList::const_iterator iter2 = iter; for (iter2++; iter2 != possible_items.end(); iter2++) { - QueueItemPtr item = *iter; - QueueItemPtr item2 = *iter2; - + QueueItem_Ptr item = *iter; + QueueItem_Ptr item2 = *iter2; + if (item->isInstall() && item2->isInstall()) { - constResItemPtr r = ((QueueItemInstallPtr) item)->resItem(); - constResItemPtr r2 = ((QueueItemInstallPtr) item2)->resItem(); - constChannelPtr channel = r->channel(); - constChannelPtr channel2 = r2->channel(); + ResItem_constPtr r = (dynamic_pointer_cast(item))->resItem(); + ResItem_constPtr r2 = (dynamic_pointer_cast(item2))->resItem(); + Channel_constPtr channel = r->channel(); + Channel_constPtr channel2 = r2->channel(); int priority, priority2; - + priority = channel->getPriority (channel->isSubscribed()); priority2 = channel2->getPriority (channel2->isSubscribed()); - + if (priority != priority2 && r->name() == r2->name()) { if (r->version() == r2->version() || (priority < priority2 && ResItem::compare (r, r2) < 0) || (priority > priority2 && ResItem::compare (r, r2) > 0)) { - + if (priority < priority2) to_defer[item] = item; else /* if (priority > priority2) */ @@ -406,14 +405,14 @@ namespace zypp } } } - - + + for (QueueItemList::const_iterator iter = possible_items.begin(); iter != possible_items.end(); iter++) { - ResolverQueuePtr new_queue; - QueueItemPtr new_item = *iter; - - new_queue = copy_queue_except_for_branch (this, (QueueItemPtr) first_branch, new_item); - + ResolverQueue_Ptr new_queue; + QueueItem_Ptr new_item = *iter; + + new_queue = copy_queue_except_for_branch (this, (QueueItem_Ptr) first_branch, new_item); + DeferTable::const_iterator pos = to_defer.find (new_item); if (pos != to_defer.end()) { deferred_queues.push_back (new_queue); @@ -421,27 +420,27 @@ namespace zypp new_queues.push_back (new_queue); } } - + } - - + + void ResolverQueue::spew () { printf ("Resolver Queue: %s\n", _context->isInvalid() ? "INVALID" : ""); - + if (_items.empty()) { - + printf (" (empty)\n"); - + } else { - + for (QueueItemList::const_iterator iter = _items.begin(); iter != _items.end(); iter++) { printf (" %s\n", (*iter)->asString().c_str()); } - + } - + printf ("\n"); fflush (stdout); } @@ -454,5 +453,5 @@ namespace zypp /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// };// namespace zypp -///////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////// diff --git a/zypp/solver/detail/ResolverQueue.h b/zypp/solver/detail/ResolverQueue.h index 9ca5af2..69312da 100644 --- a/zypp/solver/detail/ResolverQueue.h +++ b/zypp/solver/detail/ResolverQueue.h @@ -25,7 +25,11 @@ #include #include #include -#include +#include + +#include "zypp/base/ReferenceCounted.h" +#include "zypp/base/NonCopyable.h" +#include "zypp/base/PtrTypes.h" #include #include @@ -34,7 +38,7 @@ #include ///////////////////////////////////////////////////////////////////////// -namespace zypp +namespace zypp { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// namespace solver @@ -42,59 +46,59 @@ namespace zypp ///////////////////////////////////////////////////////////////////// namespace detail { /////////////////////////////////////////////////////////////////// - - typedef std::list ResolverQueueList; - + + typedef std::list ResolverQueueList; + /////////////////////////////////////////////////////////////////// // // CLASS NAME : ResolverQueue - - class ResolverQueue : public CountedRep { - - REP_BODY(ResolverQueue); - + + class ResolverQueue : public base::ReferenceCounted, private base::NonCopyable { + + + private: - - ResolverContextPtr _context; + + ResolverContext_Ptr _context; QueueItemList _items; - + public: - ResolverQueue (ResolverContextPtr context = NULL); + ResolverQueue (ResolverContext_Ptr context = NULL); virtual ~ResolverQueue(); - + // ---------------------------------- I/O - + static std::string toString (const ResolverQueue & context); virtual std::ostream & dumpOn(std::ostream & str ) const; friend std::ostream& operator<<(std::ostream&, const ResolverQueue & context); std::string asString (void ) const; - + // ---------------------------------- accessors - - ResolverContextPtr context (void) const { return _context; } + + ResolverContext_Ptr context (void) const { return _context; } QueueItemList items(void) const { return _items; } - + // ---------------------------------- methods - - - void addResItemToInstall (constResItemPtr resItem); - void addResItemToRemove (constResItemPtr resItem, bool remove_only_mode); - void addResItemToVerify (constResItemPtr resItem); + + + void addResItemToInstall (ResItem_constPtr resItem); + void addResItemToRemove (ResItem_constPtr resItem, bool remove_only_mode); + void addResItemToVerify (ResItem_constPtr resItem); void addExtraDependency (const Capability & dep); void addExtraConflict (const Capability & dep); - void addItem (QueueItemPtr item); - + void addItem (QueueItem_Ptr item); + bool isEmpty () const { return _items.empty(); } bool isInvalid (); bool containsOnlyBranches (); - + bool processOnce (); void process (); - + void splitFirstBranch (ResolverQueueList & new_queues, ResolverQueueList & deferred_queues); - + void spew (); - + }; /////////////////////////////////////////////////////////////////// };// namespace detail @@ -107,4 +111,4 @@ namespace zypp ///////////////////////////////////////////////////////////////////////// #endif // _ResolverQueue_h - + diff --git a/zypp/solver/detail/ResolverQueuePtr.h b/zypp/solver/detail/ResolverQueuePtr.h index edd943d..655334c 100644 --- a/zypp/solver/detail/ResolverQueuePtr.h +++ b/zypp/solver/detail/ResolverQueuePtr.h @@ -1,5 +1,5 @@ /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* ResolverQueuePtr.h +/* ResolverQueue_Ptr.h * * Copyright (C) 2005 SUSE Linux Products GmbH * @@ -18,10 +18,10 @@ * 02111-1307, USA. */ -#ifndef _ResolverQueuePtr_h -#define _ResolverQueuePtr_h +#ifndef _ResolverQueue_Ptr_h +#define _ResolverQueue_Ptr_h -#include +#include "zypp/base/PtrTypes.h" ///////////////////////////////////////////////////////////////////////// namespace zypp @@ -34,10 +34,10 @@ namespace zypp { /////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// - // CLASS NAME : ResolverQueuePtr - // CLASS NAME : constResolverQueuePtr + // CLASS NAME : ResolverQueue_Ptr + // CLASS NAME : ResolverQueue_constPtr /////////////////////////////////////////////////////////////////// - DEFINE_BASE_POINTER(ResolverQueue); + DEFINE_PTR_TYPE(ResolverQueue); /////////////////////////////////////////////////////////////////// };// namespace detail @@ -50,4 +50,4 @@ namespace zypp ///////////////////////////////////////////////////////////////////////// -#endif // _ResolverQueuePtr_h +#endif // _ResolverQueue_Ptr_h diff --git a/zypp/solver/detail/Section.cc b/zypp/solver/detail/Section.cc index 2877bdf..d1f859c 100644 --- a/zypp/solver/detail/Section.cc +++ b/zypp/solver/detail/Section.cc @@ -19,14 +19,11 @@ * 02111-1307, USA. */ -#include - #include - #include ///////////////////////////////////////////////////////////////////////// -namespace zypp +namespace zypp { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// namespace solver @@ -34,23 +31,23 @@ namespace zypp ///////////////////////////////////////////////////////////////////// namespace detail { /////////////////////////////////////////////////////////////////// - + using namespace std; - + string Section::asString ( void ) const { return toString (*this); } - - + + string Section::asUserString ( void ) const { return toUserString (*this); } - - + + string Section::toString ( const Section & section ) { @@ -74,7 +71,7 @@ namespace zypp } return ("misc"); } - + string Section::toUserString ( const Section & section ) { @@ -96,30 +93,30 @@ namespace zypp default: rc_debug (RC_DEBUG_LEVEL_WARNING, "invalid section number %d\n", section.section()); } - + return ("Miscellaneous"); } - + ostream & Section::dumpOn( ostream & str ) const { str << asString(); return str; } - - + + ostream& operator<<( ostream& os, const Section& section) { return os << section.asString(); } - + //--------------------------------------------------------------------------- - + Section::Section(const char *section_str) { _section = SECTION_MISC; - + if (section_str != NULL) { switch (*section_str) { case 'd': @@ -189,14 +186,14 @@ namespace zypp break; } } // if != NULL - + } - - + + Section::~Section() { } - + /////////////////////////////////////////////////////////////////// };// namespace detail ///////////////////////////////////////////////////////////////////// diff --git a/zypp/solver/detail/Section.h b/zypp/solver/detail/Section.h index e069520..d468ef7 100644 --- a/zypp/solver/detail/Section.h +++ b/zypp/solver/detail/Section.h @@ -23,12 +23,10 @@ #define _Section_h #include -#include - -#include +#include ///////////////////////////////////////////////////////////////////////// -namespace zypp +namespace zypp { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// namespace solver @@ -36,7 +34,7 @@ namespace zypp ///////////////////////////////////////////////////////////////////// namespace detail { /////////////////////////////////////////////////////////////////// - + /////////////////////////////////////////////////////////////////// // // CLASS NAME : Section @@ -44,9 +42,9 @@ namespace zypp * **/ class Section { - + private: - + typedef enum { SECTION_OFFICE = 0, SECTION_IMAGING, @@ -64,45 +62,45 @@ namespace zypp SECTION_MISC, SECTION_LAST } section_t; - + section_t _section; - + private: section_t section () const { return _section; } - + public: - + Section(const char *section_str); virtual ~Section(); - + // ---------------------------------- I/O - + static std::string toString ( const Section & section); static std::string toUserString ( const Section & section); - + virtual std::ostream & dumpOn( std::ostream & str ) const; - + friend std::ostream& operator<<( std::ostream&, const Section & section); - + std::string asString ( void ) const; std::string asUserString ( void ) const; - + // ---------------------------------- accessors - + // equality bool operator==( const Section & section) const { return _section == section.section(); } - + // inequality bool operator!=( const Section & section) const { return !(*this == section); } - + }; - - typedef Section * SectionPtr; - + + typedef Section * Section_Ptr; + /////////////////////////////////////////////////////////////////// };// namespace detail ///////////////////////////////////////////////////////////////////// diff --git a/zypp/solver/detail/ServiceWorld.cc b/zypp/solver/detail/ServiceWorld.cc index b3075d3..6a452d6 100644 --- a/zypp/solver/detail/ServiceWorld.cc +++ b/zypp/solver/detail/ServiceWorld.cc @@ -33,7 +33,7 @@ namespace zypp using namespace std; - IMPL_DERIVED_POINTER(ServiceWorld, World); + IMPL_PTR_TYPE(ServiceWorld); //--------------------------------------------------------------------------- diff --git a/zypp/solver/detail/ServiceWorld.h b/zypp/solver/detail/ServiceWorld.h index 25487b0..0c1dc55 100644 --- a/zypp/solver/detail/ServiceWorld.h +++ b/zypp/solver/detail/ServiceWorld.h @@ -23,7 +23,7 @@ #define _ServiceWorld_h #include -#include +#include #include #include @@ -40,14 +40,14 @@ namespace zypp namespace detail { /////////////////////////////////////////////////////////////////// - typedef bool (*ServiceWorldAssembleFn) (ServiceWorldPtr service, void *error); // GError **error + typedef bool (*ServiceWorldAssembleFn) (ServiceWorld_Ptr service, void *error); // GError **error /////////////////////////////////////////////////////////////////// // // CLASS NAME : ServiceWorld class ServiceWorld : public StoreWorld { - REP_BODY(ServiceWorld); + private: diff --git a/zypp/solver/detail/ServiceWorldPtr.h b/zypp/solver/detail/ServiceWorldPtr.h index ace267a..8ad5ca0 100644 --- a/zypp/solver/detail/ServiceWorldPtr.h +++ b/zypp/solver/detail/ServiceWorldPtr.h @@ -1,5 +1,5 @@ /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* ServiceWorldPtr.h +/* ServiceWorld_Ptr.h * * Copyright (C) 2005 SUSE Linux Products GmbH * @@ -18,10 +18,10 @@ * 02111-1307, USA. */ -#ifndef _ServiceWorldPtr_h -#define _ServiceWorldPtr_h +#ifndef _ServiceWorld_Ptr_h +#define _ServiceWorld_Ptr_h -#include +#include "zypp/base/PtrTypes.h" #include ///////////////////////////////////////////////////////////////////////// @@ -35,10 +35,10 @@ namespace zypp { /////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// - // CLASS NAME : ServiceWorldPtr - // CLASS NAME : constServiceWorldPtr + // CLASS NAME : ServiceWorld_Ptr + // CLASS NAME : ServiceWorld_constPtr /////////////////////////////////////////////////////////////////// - DEFINE_DERIVED_POINTER(ServiceWorld, World); + DEFINE_PTR_TYPE(ServiceWorld); /////////////////////////////////////////////////////////////////// };// namespace detail ///////////////////////////////////////////////////////////////////// @@ -50,4 +50,4 @@ namespace zypp ///////////////////////////////////////////////////////////////////////// -#endif // _ServiceWorldPtr_h +#endif // _ServiceWorld_Ptr_h diff --git a/zypp/solver/detail/Spec.cc b/zypp/solver/detail/Spec.cc index 187a7c5..1ab0d50 100644 --- a/zypp/solver/detail/Spec.cc +++ b/zypp/solver/detail/Spec.cc @@ -36,7 +36,7 @@ namespace zypp using namespace std; - IMPL_BASE_POINTER(Spec); + IMPL_PTR_TYPE(Spec); //--------------------------------------------------------------------------- @@ -116,10 +116,10 @@ namespace zypp } - Spec::Spec (constXmlNodePtr node) + Spec::Spec (XmlNode_constPtr node) : _kind (ResTraits::kind) // Fixme: should be type like unknown { - fprintf (stderr, "Spec::Spec (constXmlNodePtr node)\nNot implemented\n"); + fprintf (stderr, "Spec::Spec (XmlNode_constPtr node)\nNot implemented\n"); abort(); } @@ -131,7 +131,7 @@ namespace zypp // needed during xml parsing (-> XmlParser) - constSpecPtr + Spec_constPtr Spec::copy (void) const { return new Spec (_kind, _name, _edition); @@ -212,7 +212,7 @@ namespace zypp bool - Spec::match(constSpecPtr spec) const { + Spec::match(Spec_constPtr spec) const { return ((_kind == spec->kind()) && (_name == spec->name()) && Edition::compare( _edition, spec->edition()) == 0); @@ -220,7 +220,7 @@ namespace zypp bool - Spec::equals(constSpecPtr spec) const { + Spec::equals(Spec_constPtr spec) const { //fprintf (stderr, "<%s> equals <%s>\n", asString(true).c_str(), spec->asString(true).c_str()); return ((_kind == spec->kind()) && (_name == spec->name()) @@ -249,7 +249,7 @@ namespace zypp } - int Spec::compare (constSpecPtr spec1, constSpecPtr spec2) { + int Spec::compare (Spec_constPtr spec1, Spec_constPtr spec2) { int rc = 0; const string name1 = spec1->name(); diff --git a/zypp/solver/detail/Spec.h b/zypp/solver/detail/Spec.h index 53da9f6..e060864 100644 --- a/zypp/solver/detail/Spec.h +++ b/zypp/solver/detail/Spec.h @@ -22,12 +22,15 @@ #ifndef _Spec_h #define _Spec_h -#include #include -#include +#include +#include -#include +#include "zypp/base/ReferenceCounted.h" +#include "zypp/base/NonCopyable.h" +#include "zypp/base/PtrTypes.h" +#include #include #include #include @@ -35,7 +38,7 @@ #include ///////////////////////////////////////////////////////////////////////// -namespace zypp +namespace zypp { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// namespace solver @@ -70,83 +73,83 @@ class Name : public Ustring { /** * **/ - - class Spec : public CountedRep { - REP_BODY(Spec); - + + class Spec : public base::ReferenceCounted, private base::NonCopyable { + + private: Resolvable::Kind _kind; Name _name; Edition _edition; Arch _arch; - + public: typedef std::list SpecList; - + Spec( const Resolvable::Kind & kind, const std::string & name, int epoch = Edition::noepoch, const std::string & version = "", const std::string & release = "", const zypp::Arch & arch = Arch()); - + Spec (const Resolvable::Kind & kind, const std::string & name, const Edition & edition, const Arch & arch = Arch()); - - Spec (constXmlNodePtr node); - + + Spec (XmlNode_constPtr node); + virtual ~Spec(); - + // ---------------------------------- I/O - + const xmlNodePtr asXmlNode (const char *name) const; - + static std::string toString ( const Spec & spec, bool full = false ); - + virtual std::ostream & dumpOn( std::ostream & str ) const; - + friend std::ostream& operator<<( std::ostream&, const Spec& ); - + std::string asString ( bool full = false ) const; - + // ---------------------------------- accessors - + const std::string & version() const { return _edition.version(); } void setVersion (const std::string & version); - + const std::string & release() const { return _edition.release(); } void setRelease (const std::string & release); - + const int epoch() const { return _edition.epoch(); } void setEpoch (int epoch); bool hasEpoch() const { return _edition.epoch() > 0; } - + const Arch & arch() const { return _arch; } void setArch (const Arch & arch) { _arch = arch; } void setArch (const std::string & arch) { _arch = Arch(arch); } - + const Resolvable::Kind & kind() const { return _kind; } void setKind (const Resolvable::Kind & kind) { _kind = kind; } - + const std::string name() const { return _name; } void setName (const std::string & name) { _name = Name(name.c_str()); } - + const Edition & edition() const { return _edition; } void setEdition (const Edition & edition) { _edition = edition; } - + // calculate hash HashValue hash (void) const; - + // match operator - bool match(constSpecPtr spec) const; - bool equals (constSpecPtr spec) const; - + bool match(Spec_constPtr spec) const; + bool equals (Spec_constPtr spec) const; + // find spec in SpecList by name const Spec * findByName (const SpecList &speclist, const Name & name) const; - static int compare (constSpecPtr spec1, constSpecPtr spec2); - + static int compare (Spec_constPtr spec1, Spec_constPtr spec2); + // copy - - constSpecPtr copy (void) const; + + Spec_constPtr copy (void) const; }; /////////////////////////////////////////////////////////////////// };// namespace detail diff --git a/zypp/solver/detail/SpecPtr.h b/zypp/solver/detail/SpecPtr.h index 5ced399..92b0868 100644 --- a/zypp/solver/detail/SpecPtr.h +++ b/zypp/solver/detail/SpecPtr.h @@ -1,5 +1,5 @@ /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* SpecPtr.h +/* Spec_Ptr.h * * Copyright (C) 2005 SUSE Linux Products GmbH * @@ -18,10 +18,10 @@ * 02111-1307, USA. */ -#ifndef _SpecPtr_h -#define _SpecPtr_h +#ifndef _Spec_Ptr_h +#define _Spec_Ptr_h -#include +#include "zypp/base/PtrTypes.h" ///////////////////////////////////////////////////////////////////////// @@ -35,10 +35,10 @@ namespace zypp { /////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// - // CLASS NAME : SpecPtr - // CLASS NAME : constSpecPtr + // CLASS NAME : Spec_Ptr + // CLASS NAME : Spec_constPtr /////////////////////////////////////////////////////////////////// - DEFINE_BASE_POINTER(Spec); + DEFINE_PTR_TYPE(Spec); /////////////////////////////////////////////////////////////////// };// namespace detail @@ -51,4 +51,4 @@ namespace zypp ///////////////////////////////////////////////////////////////////////// -#endif // _SpecPtr_h +#endif // _Spec_Ptr_h diff --git a/zypp/solver/detail/StoreWorld.cc b/zypp/solver/detail/StoreWorld.cc index 422be2c..99e362b 100644 --- a/zypp/solver/detail/StoreWorld.cc +++ b/zypp/solver/detail/StoreWorld.cc @@ -21,8 +21,6 @@ #include "config.h" -#include - #include #include #include @@ -31,7 +29,7 @@ #include ///////////////////////////////////////////////////////////////////////// -namespace zypp +namespace zypp { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// namespace solver @@ -39,191 +37,191 @@ namespace zypp ///////////////////////////////////////////////////////////////////// namespace detail { /////////////////////////////////////////////////////////////////// - + using namespace std; - - IMPL_DERIVED_POINTER(StoreWorld, World); - + + IMPL_PTR_TYPE(StoreWorld); + //--------------------------------------------------------------------------- - + string StoreWorld::asString ( void ) const { return toString (*this); } - - + + string StoreWorld::toString ( const StoreWorld & storeworld ) { string res (""); - + return res; } - - + + ostream & StoreWorld::dumpOn (ostream & str) const { str << asString(); return str; } - - + + ostream & operator<< (ostream & os, const StoreWorld & storeworld) { return os << storeworld.asString(); } - + //--------------------------------------------------------------------------- - + StoreWorld::StoreWorld (WorldType type) : World (type) { } - - + + StoreWorld::~StoreWorld() { fprintf (stderr, "*** deleting store world[%p]: %s\n", this, World::toString(type()).c_str()); } - - + + //--------------------------------------------------------------------------- - + // Add/remove resItems - + bool - StoreWorld::addResItem (constResItemPtr resItem) + StoreWorld::addResItem (ResItem_constPtr resItem) { - ResItemAndDependencyPtr r_and_d; + ResItemAndDependency_Ptr r_and_d; const char *package_name; - constChannelPtr channel; + Channel_constPtr channel; bool actually_added_package = false; - + if (resItem == NULL) return false; - + channel = resItem->channel (); - -// fprintf (stderr, "StoreWorld[%p]::addResItem(%s) [%s]\n", this, ((constSpecPtr)resItem)->asString().c_str(), channel?channel->name():"?"); - - + +// fprintf (stderr, "StoreWorld[%p]::addResItem(%s) [%s]\n", this, ((Spec_constPtr)resItem)->asString().c_str(), channel?channel->name():"?"); + + /* Before we do anything, check to make sure that a resItem of the same name isn't already in that channel. If there is a duplicate, we keep the one with the most recent version number and drop the other. - + This check only applies to resItems in a channel. We have to allow for multiple installs. Grrrr... */ - + if (!resItem->isInstalled ()) { // its not a system package - - constResItemPtr dup_res; - + + ResItem_constPtr dup_res; + /* Filter out resItems with totally incompatible arches */ if ( !resItem->arch().compatibleWith(Arch::System)) { rc_debug (RC_DEBUG_LEVEL_DEBUG, "Ignoring resItem with incompatible arch: Arch '%s', %s", resItem->arch().asString().c_str(), resItem->asString(true).c_str()); goto finished; } - + package_name = resItem->name().c_str(); dup_res = findResItem (channel, package_name); - + /* This shouldn't happen (and would be caught by the check below, because cmp will equal 0), but it never hurts to check and produce a more explicit warning message. */ - + if (resItem == dup_res) { rc_debug (RC_DEBUG_LEVEL_WARNING, "Ignoring re-add of resItem '%s'", package_name); goto finished; } - + if (dup_res != NULL) { int cmp; - + cmp = ResItem::compare (resItem, dup_res); //fprintf (stderr, "res: %s, dup_res %s, cmp %d\n", resItem->asString().c_str(), dup_res->asString().c_str(), cmp); - - /* If the resItem we are trying to add has a lower + + /* If the resItem we are trying to add has a lower version number, just ignore it. */ - + if (cmp < 0) { rc_debug (RC_DEBUG_LEVEL_INFO, "Not adding resItem '%s'.\n\tA newer version is already in the channel.", resItem->asString().c_str()); rc_debug (RC_DEBUG_LEVEL_INFO, "\t%s", dup_res->asString().c_str()); goto finished; } - + #if 0 /* If the version numbers are equal, we ignore the resItem to add if it has a less-preferable arch. If both resItems have the same version # and arch, we favor the first resItem and just return. */ - + if (cmp == 0 && arch_score > dup_arch_score) { rc_debug (RC_DEBUG_LEVEL_INFO, "Not adding resItem '%s'.\n\tAnother resItem with the same version but with a preferred arch is already in the channel.", resItem->asString().c_str()); rc_debug (RC_DEBUG_LEVEL_INFO, "\t%s", dup_res->asString().c_str()); goto finished; } #endif - + /* Otherwise we throw out the old resItem and proceed with adding the newer one. */ - + rc_debug (RC_DEBUG_LEVEL_INFO, "Replacing resItem '%s'.\n\tAnother resItem in the channel has the same name and a superior %s.", dup_res->asString().c_str(), cmp ? "version" : "arch"); rc_debug (RC_DEBUG_LEVEL_INFO, "\t%s", resItem->asString().c_str()); - + removeResItem (dup_res); } } - + actually_added_package = true; - + if (channel && !channel->hidden()) { touchResItemSequenceNumber (); } - + /* StoreWorld all of our resItems in a hash by name. */ _resItems_by_name.insert (ResItemTable::value_type (resItem->name(), resItem)); - + /* StoreWorld all of the resItem's provides in a hash by name. */ for (CapSet::const_iterator i = resItem->provides().begin(); i != resItem->provides().end(); i++) { r_and_d = new ResItemAndDependency (resItem, *i); - + _provides_by_name.insert (ResItemAndDependencyTable::value_type (r_and_d->dependency().name(), r_and_d)); } - + /* StoreWorld all of the resItem's requires in a hash by name. */ - + for (CapSet::const_iterator i = resItem->requires().begin(); i != resItem->requires().end(); i++) { r_and_d = new ResItemAndDependency (resItem, *i); - + _requires_by_name.insert (ResItemAndDependencyTable::value_type (r_and_d->dependency().name(), r_and_d)); } - + /* "Recommends" are treated as requirements. */ #warning Recommends are treated as requirements - + for (CapSet::const_iterator i = resItem->recommends().begin(); i != resItem->recommends().end(); i++) { r_and_d = new ResItemAndDependency (resItem, *i); - + _requires_by_name.insert (ResItemAndDependencyTable::value_type (r_and_d->dependency().name(), r_and_d)); } - + /* StoreWorld all of the resItem's conflicts in a hash by name. */ - + for (CapSet::const_iterator i = resItem->conflicts().begin(); i != resItem->conflicts().end(); i++) { r_and_d = new ResItemAndDependency (resItem, *i); _conflicts_by_name.insert (ResItemAndDependencyTable::value_type (r_and_d->dependency().name(), r_and_d)); } - + finished: - + return actually_added_package; } - - + + void StoreWorld::addResItemsFromList (const CResItemList & slist) { @@ -235,15 +233,15 @@ namespace zypp } return; } - + //--------------------------------------------------------------------------- - + static void - resItem_table_remove (ResItemTable & table, constResItemPtr resItem) + resItem_table_remove (ResItemTable & table, ResItem_constPtr resItem) { const string name = resItem->name(); for (ResItemTable::iterator pos = table.lower_bound(name); pos != table.upper_bound(name); pos++) { - constResItemPtr res = pos->second; + ResItem_constPtr res = pos->second; if (res == resItem) { table.erase (pos); break; @@ -251,16 +249,16 @@ namespace zypp } return; } - - + + static void - resItem_and_dependency_table_remove (ResItemAndDependencyTable & table, constResItemPtr resItem) + resItem_and_dependency_table_remove (ResItemAndDependencyTable & table, ResItem_constPtr resItem) { const string name = resItem->name(); // FIXME: this is inefficient but lower_bound can't to strcasecmp :-( // for (ResItemAndDependencyTable::iterator pos = table.lower_bound(name); pos != table.upper_bound(name); pos++) { for (ResItemAndDependencyTable::iterator pos = table.begin(); pos != table.end(); pos++) { - constResItemAndDependencyPtr r_and_d = pos->second; + ResItemAndDependency_constPtr r_and_d = pos->second; if (r_and_d->resItem() == resItem) { table.erase (pos); break; @@ -268,70 +266,70 @@ namespace zypp } return; } - + void - StoreWorld::removeResItem (constResItemPtr resItem) + StoreWorld::removeResItem (ResItem_constPtr resItem) { if (getenv("RC_SPEW")) fprintf (stderr, "StoreWorld::removeResItem (%s)\n", resItem->asString().c_str()); - - constChannelPtr channel = resItem->channel (); - + + Channel_constPtr channel = resItem->channel (); + if (! (channel && channel->hidden ())) touchResItemSequenceNumber (); - + resItem_and_dependency_table_remove (_provides_by_name, resItem); resItem_and_dependency_table_remove (_requires_by_name, resItem); resItem_and_dependency_table_remove (_conflicts_by_name, resItem); - + resItem_table_remove (_resItems_by_name, resItem); - + return; } - - + + void - StoreWorld::removeResItems (constChannelPtr channel) + StoreWorld::removeResItems (Channel_constPtr channel) { fprintf (stderr, "StoreWorld::removeResItems(%s) not implemented\n", channel->asString().c_str()); } - - + + void StoreWorld::clear () { fprintf (stderr, "StoreWorld::clear() not implemented\n"); } - + //--------------------------------------------------------------------------- // Single resItem queries - + static bool - installed_version_cb (constResItemPtr resItem, void *data) + installed_version_cb (ResItem_constPtr resItem, void *data) { - constResItemPtr *installed = (constResItemPtr *)data; - + ResItem_constPtr *installed = (ResItem_constPtr *)data; + if (resItem->isInstalled ()) { *installed = resItem; return false; } return true; } - - - constResItemPtr - StoreWorld::findInstalledResItem (constResItemPtr resItem) + + + ResItem_constPtr + StoreWorld::findInstalledResItem (ResItem_constPtr resItem) { - constResItemPtr installed; + ResItem_constPtr installed; sync (); - + foreachResItemByName (resItem->name(), new Channel(CHANNEL_TYPE_ANY) /* is this right? */, installed_version_cb, &installed); - + return installed; } - - + + // - // findResItem + // findResItem // @channel: A non-wildcard #Channel. // @name: The name of a resItem. // @@ -342,59 +340,59 @@ namespace zypp // Return value: The matching resItem, or %NULL if no such // resItem exists. // - - constResItemPtr - StoreWorld::findResItem (constChannelPtr channel, const char *name) const + + ResItem_constPtr + StoreWorld::findResItem (Channel_constPtr channel, const char *name) const { syncConditional (channel); for (ResItemTable::const_iterator pos = _resItems_by_name.lower_bound(name); pos != _resItems_by_name.upper_bound(name); pos++) { - constResItemPtr res = pos->second; + ResItem_constPtr res = pos->second; if (res->channel() == channel) { return res; } } return NULL; } - - - constResItemPtr - StoreWorld::findResItemWithConstraint (constChannelPtr channel, const char *name, const Capability & constraint, bool is_and) const + + + ResItem_constPtr + StoreWorld::findResItemWithConstraint (Channel_constPtr channel, const char *name, const Capability & constraint, bool is_and) const { fprintf (stderr, "StoreWorld::findResItemWithConstraint() not implemented\n"); return 0; } - - - ChannelPtr - StoreWorld::guessResItemChannel (constResItemPtr resItem) const + + + Channel_Ptr + StoreWorld::guessResItemChannel (ResItem_constPtr resItem) const { fprintf (stderr, "StoreWorld::guessResItemChannel(%s) not implemented\n", resItem->asString().c_str()); return 0; } - - + + //----------------------------------------------------------------------------- // foreach resItem - + typedef struct { - ChannelPtr channel; + Channel_Ptr channel; CResItemFn callback; void *data; int count; bool short_circuit; } ForeachResItemInfo; - - + + static void - foreach_resItem_cb (const string &name, constResItemPtr resItem, void *data) + foreach_resItem_cb (const string &name, ResItem_constPtr resItem, void *data) { ForeachResItemInfo *info = (ForeachResItemInfo *)data; - + if (info->short_circuit) return; - + /* FIXME: we should filter out dup uninstalled resItems. */ - + if (resItem && info->channel->equals(resItem->channel ())) { if (info->callback) { if (! info->callback (resItem, info->data)) @@ -403,49 +401,49 @@ namespace zypp ++info->count; } } - - + + int - StoreWorld::foreachResItem (ChannelPtr channel, CResItemFn fn, void *data) + StoreWorld::foreachResItem (Channel_Ptr channel, CResItemFn fn, void *data) { return foreachResItemByName ("", channel, fn, data); } - - + + int - StoreWorld::foreachResItemByName (const std::string & name, ChannelPtr channel, CResItemFn fn, void *data) + StoreWorld::foreachResItemByName (const std::string & name, Channel_Ptr channel, CResItemFn fn, void *data) { if (name.empty()) { - + ForeachResItemInfo info; - + info.channel = channel; info.callback = fn; info.data = data; info.count = 0; info.short_circuit = false; - + for (ResItemTable::const_iterator iter = _resItems_by_name.begin(); iter != _resItems_by_name.end(); iter++) { foreach_resItem_cb (iter->first, iter->second, (void *)&info); } - + return info.short_circuit ? -1 : info.count; } - - + + ResItemTable installed; // FIXME: rc_resItem_spec_equal int count = 0; - + for (ResItemTable::const_iterator iter = _resItems_by_name.lower_bound(name); iter != _resItems_by_name.upper_bound(name); iter++) { - constResItemPtr resItem = iter->second; + ResItem_constPtr resItem = iter->second; if (resItem->isInstalled()) { const string str = resItem->asString(); installed.insert (ResItemTable::value_type(str,resItem)); } - } - + } + for (ResItemTable::const_iterator iter = _resItems_by_name.lower_bound(name); iter != _resItems_by_name.upper_bound(name); iter++) { - constResItemPtr resItem = iter->second; + ResItem_constPtr resItem = iter->second; if (channel->equals (resItem->channel())) { if (resItem->isInstalled() || installed.find(resItem->asString()) == installed.end()) { @@ -459,26 +457,26 @@ namespace zypp } } } - + finished: - + return count; } - - + + int - StoreWorld::foreachResItemByMatch (constMatchPtr match, CResItemFn fn, void *data) + StoreWorld::foreachResItemByMatch (Match_constPtr match, CResItemFn fn, void *data) { fprintf (stderr, "StoreWorld::foreachResItemByMatch () not implemented\n"); return 0; } - - + + //----------------------------------------------------------------------------- // iterater over resItems with dependency - - typedef std::map InstalledTable; - + + typedef std::map InstalledTable; + int StoreWorld::foreachProvidingResItem (const Capability & dep, ResItemAndDepFn fn, void *data) { @@ -486,17 +484,17 @@ namespace zypp InstalledTable installed; //fprintf (stderr, "StoreWorld::foreachProvidingResItem(%s)\n", dep->asString().c_str()); for (ResItemAndDependencyTable::const_iterator iter = _provides_by_name.lower_bound(dep.name()); iter != _provides_by_name.upper_bound(dep.name()); iter++) { - constResItemAndDependencyPtr r_and_d = iter->second; - constResItemPtr res = r_and_d->resItem(); + ResItemAndDependency_constPtr r_and_d = iter->second; + ResItem_constPtr res = r_and_d->resItem(); //fprintf (stderr, "StoreWorld::foreachProvidingResItem(): %s\n", res->asString(true).c_str()); if (res != NULL && res->isInstalled ()) { installed[res] = r_and_d; } } - + for (ResItemAndDependencyTable::const_iterator iter = _provides_by_name.lower_bound(dep.name()); iter != _provides_by_name.upper_bound(dep.name()); iter++) { - constResItemAndDependencyPtr r_and_d = iter->second; - + ResItemAndDependency_constPtr r_and_d = iter->second; + if (r_and_d && r_and_d->verifyRelation (dep)) { //fprintf (stderr, "found: %s\n", r_and_d->resItem()->asString(true).c_str()); /* If we have multiple identical resItems in RCWorld, @@ -504,7 +502,7 @@ namespace zypp skip the rest. */ if (r_and_d->resItem()->isInstalled() || installed.find(r_and_d->resItem()) == installed.end()) { - + if (fn) { if (! fn(r_and_d->resItem(), r_and_d->dependency(), data)) { count = -1; @@ -515,37 +513,37 @@ namespace zypp } } } - + finished: - + return count; } - + int StoreWorld::foreachRequiringResItem (const Capability & dep, ResItemAndDepFn fn, void *data) { int count = 0; InstalledTable installed; - - + + for (ResItemAndDependencyTable::const_iterator iter = _requires_by_name.lower_bound(dep.name()); iter != _requires_by_name.upper_bound(dep.name()); iter++) { - constResItemAndDependencyPtr r_and_d = iter->second; - constResItemPtr res = r_and_d->resItem(); + ResItemAndDependency_constPtr r_and_d = iter->second; + ResItem_constPtr res = r_and_d->resItem(); if (res != NULL && res->isInstalled ()) { //fprintf (stderr, "is installed: %s\n", res->asString(true).c_str()); installed[res] = r_and_d; } } - + for (ResItemAndDependencyTable::const_iterator iter = _requires_by_name.lower_bound(dep.name()); iter != _requires_by_name.upper_bound(dep.name()); iter++) { - constResItemAndDependencyPtr r_and_d = iter->second; - + ResItemAndDependency_constPtr r_and_d = iter->second; + if (r_and_d ) {//&& r_and_d->dependency().matches (dep)) { - + /* Skip dups if one of them in installed. */ if (r_and_d->resItem()->isInstalled() || installed.find(r_and_d->resItem()) == installed.end()) { - + if (fn) { if (! fn(r_and_d->resItem(), r_and_d->dependency(), data)) { count = -1; @@ -556,13 +554,13 @@ namespace zypp } } } - + finished: - + return count; } - - + + int StoreWorld::foreachConflictingResItem (const Capability & dep, ResItemAndDepFn fn, void *data) { @@ -570,25 +568,25 @@ namespace zypp InstalledTable installed; //fprintf (stderr, "StoreWorld::foreachConflictingResItem (%s)\n", dep->name().c_str()); for (ResItemAndDependencyTable::const_iterator iter = _conflicts_by_name.lower_bound(dep.name()); iter != _conflicts_by_name.upper_bound(dep.name()); iter++) { - constResItemAndDependencyPtr r_and_d = iter->second; - constResItemPtr res = r_and_d->resItem(); + ResItemAndDependency_constPtr r_and_d = iter->second; + ResItem_constPtr res = r_and_d->resItem(); //fprintf (stderr, "==> %s\n", res->asString().c_str()); if (res != NULL && res->isInstalled ()) { installed[res] = r_and_d; } } - + for (ResItemAndDependencyTable::const_iterator iter = _conflicts_by_name.lower_bound(dep.name()); iter != _conflicts_by_name.upper_bound(dep.name()); iter++) { - constResItemAndDependencyPtr r_and_d = iter->second; - + ResItemAndDependency_constPtr r_and_d = iter->second; + if (r_and_d) //fprintf (stderr, "==> %s verify %s ? %s\n", r_and_d->asString().c_str(), dep->asString().c_str(), r_and_d->verifyRelation (dep) ? "Y" : "N"); if (r_and_d && r_and_d->verifyRelation (dep)) { - + /* Skip dups if one of them in installed. */ if (r_and_d->resItem()->isInstalled() || installed.find(r_and_d->resItem()) == installed.end()) { - + if (fn) { if (! fn(r_and_d->resItem(), r_and_d->dependency(), data)) { count = -1; @@ -599,38 +597,38 @@ namespace zypp } } } - + finished: - + return count; } - + //----------------------------------------------------------------------------- // channel functions - + void - StoreWorld::addChannel (ChannelPtr channel) + StoreWorld::addChannel (Channel_Ptr channel) { if (channel == NULL) return; - + channel->setWorld (this); channel->setImmutable (true); - + _channels.push_back (channel); - + touchChannelSequenceNumber (); } - - + + void - StoreWorld::removeChannel (constChannelPtr channel) + StoreWorld::removeChannel (Channel_constPtr channel) { if (channel == NULL || ! containsChannel (channel)) return; - + removeResItems (channel); - + for (ChannelList::iterator iter = _channels.begin(); iter != _channels.end(); iter++) { if ((*iter)->equals (channel)) { _channels.erase (iter); @@ -639,10 +637,10 @@ namespace zypp } } } - - + + bool - StoreWorld::containsChannel (constChannelPtr channel) const + StoreWorld::containsChannel (Channel_constPtr channel) const { for (ChannelList::const_iterator iter = _channels.begin(); iter != _channels.end(); iter++) { if ((*iter)->equals (channel)) { @@ -651,16 +649,16 @@ namespace zypp } return false; } - - - ChannelPtr + + + Channel_Ptr StoreWorld::getChannelByName (const char *channel_name) const { if (channel_name == NULL || *channel_name == 0) { return NULL; } - + for (ChannelList::const_iterator iter = _channels.begin(); iter != _channels.end(); iter++) { if (strcasecmp ((*iter)->name(), channel_name) == 0) { return *iter; @@ -668,16 +666,16 @@ namespace zypp } return NULL; } - - - ChannelPtr + + + Channel_Ptr StoreWorld::getChannelByAlias (const char *alias) const { if (alias == NULL || *alias == 0) { return NULL; } - + for (ChannelList::const_iterator iter = _channels.begin(); iter != _channels.end(); iter++) { if (strcasecmp ((*iter)->alias(), alias) == 0) { return *iter; @@ -685,16 +683,16 @@ namespace zypp } return NULL; } - - - ChannelPtr + + + Channel_Ptr StoreWorld::getChannelById (const char *channel_id) const { if (channel_id == NULL || *channel_id == 0) { return NULL; } - + for (ChannelList::const_iterator iter = _channels.begin(); iter != _channels.end(); iter++) { if (strcasecmp ((*iter)->id(), channel_id) == 0) { return *iter; @@ -702,8 +700,8 @@ namespace zypp } return NULL; } - - + + int StoreWorld::foreachChannel (ChannelFn fn, void *data) const { @@ -715,7 +713,7 @@ namespace zypp } return count; } - + /////////////////////////////////////////////////////////////////// };// namespace detail ///////////////////////////////////////////////////////////////////// diff --git a/zypp/solver/detail/StoreWorld.h b/zypp/solver/detail/StoreWorld.h index 8dd711c..1ad910b 100644 --- a/zypp/solver/detail/StoreWorld.h +++ b/zypp/solver/detail/StoreWorld.h @@ -50,7 +50,7 @@ namespace zypp // CLASS NAME : StoreWorld class StoreWorld : public World { - REP_BODY(StoreWorld); + private: @@ -61,7 +61,7 @@ namespace zypp ResItemAndDependencyTable _requires_by_name; ResItemAndDependencyTable _conflicts_by_name; - PackmanPtr _packman; + Packman_Ptr _packman; ChannelList _channels; @@ -88,17 +88,17 @@ namespace zypp // Add/remove resItems - bool addResItem (constResItemPtr resItem); + bool addResItem (ResItem_constPtr resItem); void addResItemsFromList (const CResItemList & slist); - void removeResItem (constResItemPtr resItem); - void removeResItems (constChannelPtr channel); + void removeResItem (ResItem_constPtr resItem); + void removeResItems (Channel_constPtr channel); void clear (); // Iterate over resItems - virtual int foreachResItem (ChannelPtr channel, CResItemFn fn, void *data); - virtual int foreachResItemByName (const std::string & name, ChannelPtr channel, CResItemFn fn, void *data); - virtual int foreachResItemByMatch (constMatchPtr match, CResItemFn fn, void *data); + virtual int foreachResItem (Channel_Ptr channel, CResItemFn fn, void *data); + virtual int foreachResItemByName (const std::string & name, Channel_Ptr channel, CResItemFn fn, void *data); + virtual int foreachResItemByMatch (Match_constPtr match, CResItemFn fn, void *data); // Iterate across provides or requirement @@ -108,23 +108,23 @@ namespace zypp // Channels - void addChannel (ChannelPtr channel); - void removeChannel (constChannelPtr channel); + void addChannel (Channel_Ptr channel); + void removeChannel (Channel_constPtr channel); - virtual bool containsChannel (constChannelPtr channel) const; + virtual bool containsChannel (Channel_constPtr channel) const; - virtual ChannelPtr getChannelByName (const char *channel_name) const; - virtual ChannelPtr getChannelByAlias (const char *alias) const; - virtual ChannelPtr getChannelById (const char *channel_id) const; + virtual Channel_Ptr getChannelByName (const char *channel_name) const; + virtual Channel_Ptr getChannelByAlias (const char *alias) const; + virtual Channel_Ptr getChannelById (const char *channel_id) const; virtual int foreachChannel (ChannelFn fn, void *data) const; // Single resItem queries - virtual constResItemPtr findInstalledResItem (constResItemPtr resItem); - virtual constResItemPtr findResItem (constChannelPtr channel, const char *name) const; - virtual constResItemPtr findResItemWithConstraint (constChannelPtr channel, const char *name, const Capability & constraint, bool is_and) const; - virtual ChannelPtr guessResItemChannel (constResItemPtr resItem) const; + virtual ResItem_constPtr findInstalledResItem (ResItem_constPtr resItem); + virtual ResItem_constPtr findResItem (Channel_constPtr channel, const char *name) const; + virtual ResItem_constPtr findResItemWithConstraint (Channel_constPtr channel, const char *name, const Capability & constraint, bool is_and) const; + virtual Channel_Ptr guessResItemChannel (ResItem_constPtr resItem) const; }; /////////////////////////////////////////////////////////////////// diff --git a/zypp/solver/detail/StoreWorldPtr.h b/zypp/solver/detail/StoreWorldPtr.h index 34375b5..2b814d1 100644 --- a/zypp/solver/detail/StoreWorldPtr.h +++ b/zypp/solver/detail/StoreWorldPtr.h @@ -1,5 +1,5 @@ /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* StoreWorldPtr.h +/* StoreWorld_Ptr.h * * Copyright (C) 2005 SUSE Linux Products GmbH * @@ -18,10 +18,10 @@ * 02111-1307, USA. */ -#ifndef _StoreWorldPtr_h -#define _StoreWorldPtr_h +#ifndef _StoreWorld_Ptr_h +#define _StoreWorld_Ptr_h -#include +#include "zypp/base/PtrTypes.h" #include @@ -36,10 +36,10 @@ namespace zypp { /////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// - // CLASS NAME : StoreWorldPtr - // CLASS NAME : constStoreWorldPtr + // CLASS NAME : StoreWorld_Ptr + // CLASS NAME : StoreWorld_constPtr /////////////////////////////////////////////////////////////////// - DEFINE_DERIVED_POINTER(StoreWorld, World); + DEFINE_PTR_TYPE(StoreWorld); /////////////////////////////////////////////////////////////////// };// namespace detail @@ -51,4 +51,4 @@ namespace zypp };// namespace zypp ///////////////////////////////////////////////////////////////////////// -#endif // _StoreWorldPtr_h +#endif // _StoreWorld_Ptr_h diff --git a/zypp/solver/detail/Subscription.cc b/zypp/solver/detail/Subscription.cc index 00c5848..eef4839 100644 --- a/zypp/solver/detail/Subscription.cc +++ b/zypp/solver/detail/Subscription.cc @@ -19,21 +19,19 @@ * 02111-1307, USA. */ -#include - -#include -#include -#include +#include +#include #include #include -#include -#include +#include +#include +#include #include ///////////////////////////////////////////////////////////////////////// -namespace zypp +namespace zypp { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// namespace solver @@ -41,55 +39,55 @@ namespace zypp ///////////////////////////////////////////////////////////////////// namespace detail { /////////////////////////////////////////////////////////////////// - + using namespace std; - + #define SUBSCRIPTION_PATH "/var/adm/zypp" #define OLD_SUBSCRIPTION_PATH "/var/lib/rcd" #define SUBSCRIPTION_NAME "/subscriptions.xml" - + #define DEFAULT_SUBSCRIPTION_FILE SUBSCRIPTION_PATH SUBSCRIPTION_NAME #define OLD_SUBSCRIPTION_FILE OLD_SUBSCRIPTION_PATH SUBSCRIPTION_NAME - + /* Old subscriptions expire in 60 days */ #define OLD_SUBSCRIPTION_EXPIRATION 60*24*60*60 - + SubscriptionList Subscription::subscriptions; bool Subscription::subscriptions_changed = false; const char *Subscription::subscription_file = DEFAULT_SUBSCRIPTION_FILE; - + //--------------------------------------------------------------------------- - + string Subscription::asString ( void ) const { return toString (*this); } - - + + string Subscription::toString ( const Subscription & s) { return ""; } - + ostream & Subscription::dumpOn( ostream & str ) const { str << asString(); return str; } - - + + ostream& operator<<( ostream& os, const Subscription & s) { return os << s.asString(); } - + //--------------------------------------------------------------------------- - - + + void Subscription::save (void) { @@ -98,23 +96,23 @@ namespace zypp char buf[64]; time_t now; int save_retval; - + if (! subscriptions_changed) return; - + time (&now); - + root = xmlNewNode (NULL, (const xmlChar*)"subscriptions"); xmlNewProp (root, (const xmlChar*)"version", (const xmlChar*)"2.0"); - + doc = xmlNewDoc ((const xmlChar*)"1.0"); xmlDocSetRootElement (doc, root); - + for (SubscriptionList::iterator iter = subscriptions.begin(); iter != subscriptions.end(); iter++) { xmlNode *sub_node; - + Subscription *sub = *iter; - + /* Drop "old" (i.e. imported from 1.x) subscriptions that we haven't seen for a while. */ if (sub->_old) { @@ -122,21 +120,21 @@ namespace zypp if (elapsed > OLD_SUBSCRIPTION_EXPIRATION) continue; } - + sub_node = xmlNewChild (root, NULL, (const xmlChar*)"channel", NULL); - + xmlNewProp (sub_node, (const xmlChar*)"id", (const xmlChar*)(sub->_channel_id.c_str())); - + snprintf (buf, sizeof (buf), "%ld", (long) sub->_last_seen); xmlNewProp (sub_node, (const xmlChar*)"last_seen", (const xmlChar*)buf); - + if (sub->_old) xmlNewProp (sub_node, (const xmlChar*)"old", (const xmlChar*)"1"); } - + save_retval = xmlSaveFile (subscription_file, doc); xmlFreeDoc (doc); - + if (save_retval > 0) { /* Writing out the subscription file succeeded. */ subscriptions_changed = false; @@ -145,215 +143,215 @@ namespace zypp rc_debug (RC_DEBUG_LEVEL_WARNING, "Subscription will not be saved!"); } } - - + + void Subscription::load_old_subscriptions (void) { static bool tried_to_do_this_already = false; xmlDoc *doc; - XmlNodePtr node; - + XmlNode_Ptr node; + if (tried_to_do_this_already) return; tried_to_do_this_already = true; - + if (access (OLD_SUBSCRIPTION_FILE, R_OK) != 0) { rc_debug (RC_DEBUG_LEVEL_WARNING, "Can't find rcd 1.x subscription file '%s'", OLD_SUBSCRIPTION_FILE); return; } - + doc = xmlParseFile (OLD_SUBSCRIPTION_FILE); if (doc == NULL) { rc_debug (RC_DEBUG_LEVEL_ERROR, "Can't parse rcd 1.x subscription file '%s'", OLD_SUBSCRIPTION_FILE); return; } - + node = new XmlNode (xmlDocGetRootElement (doc)); - + if (!node->equals("subscriptions")) { rc_debug (RC_DEBUG_LEVEL_ERROR, "rcd 1.x subscription file '%s' is malformed", OLD_SUBSCRIPTION_FILE); return; } - + rc_debug (RC_DEBUG_LEVEL_INFO, "Importing rcd 1.x subscriptions."); - + node = node->children(); - + while (node != NULL) { - + if (node->equals ("channel")) { const char *id_str; - + id_str = node->getProp ("channel_id"); if (id_str && *id_str) { - + Subscription *sub = new Subscription (id_str); sub->_old = true; - + subscriptions.push_back (sub); } } - + node = node->next(); } - + /* If we've imported old subscriptions, we need to write them out immediately into the new subscriptions file. */ - + subscriptions_changed = true; save (); } - - + + void Subscription::load (void) { xmlDoc *doc; - XmlNodePtr node; - + XmlNode_Ptr node; + if (access (subscription_file, R_OK) != 0) { load_old_subscriptions (); return; } - + doc = xmlParseFile (subscription_file); if (doc == NULL) { rc_debug (RC_DEBUG_LEVEL_ERROR, "Can't parse subscription file '%s'", subscription_file); return; } - + node = new XmlNode (xmlDocGetRootElement (doc)); - + if (! node->equals ("subscriptions")) { rc_debug (RC_DEBUG_LEVEL_ERROR, "Subscription file '%s' is malformed", subscription_file); return; } - + node = node->children(); - + while (node != NULL) { - + if (node->equals ("channel")) { const char *id_str, *last_seen_str; - + id_str = node->getProp ("id"); last_seen_str = node->getProp ("last_seen"); - + if (id_str && *id_str) { Subscription *sub = new Subscription (id_str); - + if (last_seen_str) sub->_last_seen = (time_t) atol (last_seen_str); else sub->_last_seen = time (NULL); - + sub->_old = node->getUnsignedIntValueDefault("old", 0); - + subscriptions.push_back (sub); } - + free ((void *)id_str); free ((void *)last_seen_str); - + } - + node = node->next(); } - + xmlFreeDoc (doc); } - + //--------------------------------------------------------------------------- - + bool - Subscription::match (constChannelPtr channel) + Subscription::match (Channel_constPtr channel) { bool match; - + /* Paranoia is the programmer's friend. */ if (channel == NULL) return false; if (channel->id() == NULL) return false; - + /* If this is an old (i.e. imported from 1.x) subscription, we compare it against the channel id's tail. */ - + if (_old) { const char *id = channel->legacyId (); int len1, len2; - + if (!id) return false; - + len1 = strlen (_channel_id.c_str()); len2 = strlen (id); - + if (len1 > len2) return false; - + /* If the tails match, mutate the Subscription into a new-style subscription for that channel. */ if (! strcmp (id + (len2 - len1), _channel_id.c_str())) { _channel_id = channel->id (); _old = false; subscriptions_changed = true; - + return true; } - + return false; } - + match = (_channel_id == channel->id ()); - + if (match) { time (&_last_seen); } - + return match; } - + //----------------------------------------------------------------------------- - + void Subscription::setFile (const char *path) { subscription_file = path; } - - + + bool - Subscription::status (constChannelPtr channel) + Subscription::status (Channel_constPtr channel) { if (subscriptions.empty()) load (); - + if (channel == NULL) return false; - + for (SubscriptionList::iterator iter = subscriptions.begin(); iter != subscriptions.end(); iter++) { Subscription *sub = *iter; if (sub->match (channel)) return true; } - + save (); - + return false; } - - + + void - Subscription::setStatus (constChannelPtr channel, bool subscribe_to_channel) + Subscription::setStatus (Channel_constPtr channel, bool subscribe_to_channel) { bool currently_subscribed; - + if (channel == NULL) return; - + currently_subscribed = status (channel); - + if (currently_subscribed && !subscribe_to_channel) { - + /* Unsubscribe to the channel */ for (SubscriptionList::iterator iter = subscriptions.begin(); iter != subscriptions.end(); iter++) { Subscription *sub = *iter; @@ -363,33 +361,33 @@ namespace zypp break; } } - + } else if (!currently_subscribed && subscribe_to_channel) { - + /* Subscribe to the channel */ Subscription *sub; sub = new Subscription (channel->id ()); subscriptions.push_back(sub); subscriptions_changed = true; } - + save (); } - + //--------------------------------------------------------------------------- - + Subscription::Subscription(const char *id) { _channel_id = string (id); _last_seen = time (NULL); _old = false; } - - + + Subscription::~Subscription() { } - + /////////////////////////////////////////////////////////////////// };// namespace detail ///////////////////////////////////////////////////////////////////// diff --git a/zypp/solver/detail/Subscription.h b/zypp/solver/detail/Subscription.h index aea100d..ac7672d 100644 --- a/zypp/solver/detail/Subscription.h +++ b/zypp/solver/detail/Subscription.h @@ -27,12 +27,11 @@ #include #include -#include #include ///////////////////////////////////////////////////////////////////////// -namespace zypp +namespace zypp { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// namespace solver @@ -44,53 +43,53 @@ namespace zypp /////////////////////////////////////////////////////////////////// // // CLASS NAME : Subscription - - + + class Subscription; typedef std::list SubscriptionList; - + class Subscription { - + private: - + static SubscriptionList subscriptions; static bool subscriptions_changed; static const char *subscription_file; - + std::string _channel_id; time_t _last_seen; bool _old; // subscription imported from an old-style subs file - - bool match (constChannelPtr channel); + + bool match (Channel_constPtr channel); static void save (void); static void load (void); static void load_old_subscriptions (void); - + public: - + Subscription (const char *id); virtual ~Subscription(); - + // ---------------------------------- I/O - + static std::string toString ( const Subscription & section); - + virtual std::ostream & dumpOn( std::ostream & str ) const; - + friend std::ostream& operator<<( std::ostream&, const Subscription & section); - + std::string asString ( void ) const; - + // ---------------------------------- accessors - + // ---------------------------------- methods - + void setFile (const char *file); - static bool status (constChannelPtr channel); - static void setStatus (constChannelPtr channel, bool channel_is_subscribed); - + static bool status (Channel_constPtr channel); + static void setStatus (Channel_constPtr channel, bool channel_is_subscribed); + }; - + /////////////////////////////////////////////////////////////////// };// namespace detail ///////////////////////////////////////////////////////////////////// diff --git a/zypp/solver/detail/UndumpWorld.cc b/zypp/solver/detail/UndumpWorld.cc index c9aec7c..179e832 100644 --- a/zypp/solver/detail/UndumpWorld.cc +++ b/zypp/solver/detail/UndumpWorld.cc @@ -34,7 +34,7 @@ namespace zypp using namespace std; - IMPL_DERIVED_POINTER(UndumpWorld, World); + IMPL_PTR_TYPE(UndumpWorld); //--------------------------------------------------------------------------- @@ -84,7 +84,7 @@ namespace zypp static bool - add_channel_cb (ChannelPtr channel, bool subscribed, void *data) + add_channel_cb (Channel_Ptr channel, bool subscribed, void *data) { UndumpWorld *undump = (UndumpWorld *)data; @@ -99,7 +99,7 @@ namespace zypp static bool - add_resItem_cb (constResItemPtr res, void *data) + add_resItem_cb (ResItem_constPtr res, void *data) { UndumpWorld *undump = (UndumpWorld *)data; @@ -110,7 +110,7 @@ namespace zypp static bool - add_lock_cb (constMatchPtr lock, void *data) + add_lock_cb (Match_constPtr lock, void *data) { UndumpWorld *undump = (UndumpWorld *)data; @@ -130,7 +130,7 @@ namespace zypp void - UndumpWorld::setSubscription (constChannelPtr channel, bool subscribe) + UndumpWorld::setSubscription (Channel_constPtr channel, bool subscribe) { // if (getenv("RC_SPEW")) fprintf (stderr, "UndumpWorld::setSubscription (%s, %s)\n", channel->asString().c_str(), subscribe?"subscribe":"unsubscribe"); for (ChannelSubscriptions::iterator i = _subscriptions.begin(); i != _subscriptions.end(); i++) { @@ -151,7 +151,7 @@ namespace zypp bool - UndumpWorld::isSubscribed (constChannelPtr channel) const + UndumpWorld::isSubscribed (Channel_constPtr channel) const { for (ChannelSubscriptions::const_iterator i = _subscriptions.begin(); i != _subscriptions.end(); i++) { if (*i == channel) { diff --git a/zypp/solver/detail/UndumpWorld.h b/zypp/solver/detail/UndumpWorld.h index 3234d00..21954cf 100644 --- a/zypp/solver/detail/UndumpWorld.h +++ b/zypp/solver/detail/UndumpWorld.h @@ -23,7 +23,7 @@ #define _UndumpWorld_h #include -#include +#include #include #include @@ -45,11 +45,11 @@ namespace zypp // CLASS NAME : UndumpWorld class UndumpWorld : public StoreWorld { - REP_BODY(UndumpWorld); + private: - typedef std::list ChannelSubscriptions; + typedef std::list ChannelSubscriptions; ChannelSubscriptions _subscriptions; public: @@ -72,8 +72,8 @@ namespace zypp // ---------------------------------- methods void load (const char *filename); - virtual bool isSubscribed (constChannelPtr channel) const; - virtual void setSubscription (constChannelPtr channel, bool is_subscribed); + virtual bool isSubscribed (Channel_constPtr channel) const; + virtual void setSubscription (Channel_constPtr channel, bool is_subscribed); }; /////////////////////////////////////////////////////////////////// diff --git a/zypp/solver/detail/UndumpWorldPtr.h b/zypp/solver/detail/UndumpWorldPtr.h index ef9e435..556275b 100644 --- a/zypp/solver/detail/UndumpWorldPtr.h +++ b/zypp/solver/detail/UndumpWorldPtr.h @@ -1,5 +1,5 @@ /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* UndumpWorldPtr.h +/* UndumpWorld_Ptr.h * * Copyright (C) 2005 SUSE Linux Products GmbH * @@ -18,10 +18,10 @@ * 02111-1307, USA. */ -#ifndef _UndumpWorldPtr_h -#define _UndumpWorldPtr_h +#ifndef _UndumpWorld_Ptr_h +#define _UndumpWorld_Ptr_h -#include +#include "zypp/base/PtrTypes.h" #include @@ -36,10 +36,10 @@ namespace zypp { /////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// - // CLASS NAME : UndumpWorldPtr - // CLASS NAME : constUndumpWorldPtr + // CLASS NAME : UndumpWorld_Ptr + // CLASS NAME : UndumpWorld_constPtr /////////////////////////////////////////////////////////////////// - DEFINE_DERIVED_POINTER(UndumpWorld, World); + DEFINE_PTR_TYPE(UndumpWorld); /////////////////////////////////////////////////////////////////// };// namespace detail @@ -50,4 +50,4 @@ namespace zypp /////////////////////////////////////////////////////////////////////// };// namespace zypp ///////////////////////////////////////////////////////////////////////// -#endif // _UndumpWorldPtr_h +#endif // _UndumpWorld_Ptr_h diff --git a/zypp/solver/detail/Ustring.h b/zypp/solver/detail/Ustring.h new file mode 100644 index 0000000..43555ec --- /dev/null +++ b/zypp/solver/detail/Ustring.h @@ -0,0 +1,280 @@ +/*---------------------------------------------------------------------\ +| ____ _ __ __ ___ | +| |__ / \ / / . \ . \ | +| / / \ V /| _/ _/ | +| / /__ | | | | | | | +| /_____||_| |_| |_| | +| | +\---------------------------------------------------------------------*/ +/** \file zypp/solver/detail/Ustring.h + * +*/ +#ifndef ZYPP_SOLVER_DETAIL_USTRING_H +#define ZYPP_SOLVER_DETAIL_USTRING_H + +#include +#include +#include + +#include "zypp/base/PtrTypes.h" + +/////////////////////////////////////////////////////////////////// +namespace zypp +{ ///////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////// + namespace solver + { ///////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////// + namespace detail + { ///////////////////////////////////////////////////////////////// + + /////////////////////////////////////////////////////////////////// + // + // CLASS NAME : UstringHash + /** + * @short A Hash of unique strings. + * + * A Hash of unique strings. + * + * @see Ustring + **/ + class UstringHash + { + + protected: + + typedef std::set UstringHash_type; + + UstringHash_type _UstringHash; + + public: + + const std::string & add( const std::string & nstr_r ) + { + return *(_UstringHash.insert( nstr_r ).first); + } + + /** + * Return the number of unique strings stored in the hash. + **/ + unsigned size() const { return _UstringHash.size(); } + unsigned long sum() const { + UstringHash_type::const_iterator it = _UstringHash.begin(); + UstringHash_type::const_iterator e = _UstringHash.end(); + unsigned long sum = 0; + while (it != e) + { + sum += it->size(); + it++; + } + return sum; + } + }; + /////////////////////////////////////////////////////////////////// + + /////////////////////////////////////////////////////////////////// + // + // CLASS NAME : Ustring + /** + * @short Unique strings + * + * Ustring provides an immutable string and uses a UstringHash + * to keep the strings representaion class (which contains the + * actual data) unique. + * + * That way Ustrings of the same value and using the same + * UstringHash can be stored at various locations, while the + * actual string data are stored only once. + * + * The UstringHash to use is passed to the constructor, and no + * more needed after the string has been stored. + * + * Conversion to string is possible and cheap, as the created + * string will, unless he's modified, share it's data with the + * one inside the Ustring. + * + * Comparison between Ustrings and strings are based on string. + * + * A -> operator is provided as an easy way to + * invoke const string methods, like size() or c_str(). + * + *
+       *   ustr->size(); // short for ((const std::string &)u).size();
+       * 
+ * + * Most common usage will be deriving some class from Ustring, + * that provides a static UstringHash, and some constructor. + * Everything else is provided by Ustring. + * + *
+       * class PkgName : public Ustring {
+       *   private:
+       *     static UstringHash _nameHash;
+       *   public:
+       *     explicit PkgName( const std::string & n = "" ) : Ustring( _nameHash, n ) {}
+       * };
+       * 
+ * + * @see UstringHash + * /todo Review and move it to base + **/ + class Ustring + { + + private: + + /** + * !!! It should actualy be const !!! + * But that way default copy and assingment can be used. + **/ + std::string _name; + + public: + /** + * Constructor calls @ref UstringHash::add on the given string, + * and stores the string returned from the hash. + **/ + Ustring( UstringHash & nameHash_r, const std::string & n ) + :_name( nameHash_r.add( n ) ) + {} + + public: + + /** + * Conversion to const std::string & + **/ + const std::string & asString() const { return _name; } + + /** + * Conversion to const std::string & + **/ + operator const std::string & () const { return asString(); } + + /** + * short for ((const std::string &)ustr).size(); + **/ + std::string::size_type size() const { return asString().size(); } + + /** + * short for ((const std::string &)ustr).empty(); + **/ + bool empty() const { return asString().empty(); } + + + int compare( const std::string & rhs ) const { + return asString().compare( rhs ); + } + + int compare( const Ustring & rhs ) const { + if ( *this == rhs ) + return 0; + return( *this < rhs ? -1 : 1 ); + } + + /** + * ustr->???(); // short for ((const std::string &)ustr).???(); + **/ + const std::string * operator->() const { return & asString(); } + + // operator == + + friend bool operator==( const Ustring & lhs, const Ustring & rhs ) { + // Ustrings share their string representation + return ( lhs->c_str() == rhs->c_str() ); + } + + friend bool operator==( const Ustring & lhs, const std::string & rhs ) { + return ( lhs.asString() == rhs ); + } + + friend bool operator==( const std::string & lhs, const Ustring & rhs ) { + return ( lhs == rhs.asString() ); + } + + // operator != + + friend bool operator!=( const Ustring & lhs, const Ustring & rhs ) { + return ( ! operator==( lhs, rhs ) ); + } + + friend bool operator!=( const Ustring & lhs, const std::string & rhs ) { + return ( ! operator==( lhs, rhs ) ); + } + + friend bool operator!=( const std::string & lhs, const Ustring & rhs ) { + return ( ! operator==( lhs, rhs ) ); + } + + // operator < + + friend bool operator<( const Ustring & lhs, const Ustring & rhs ) { + return ( lhs.asString() < rhs.asString() ); + } + + friend bool operator<( const Ustring & lhs, const std::string & rhs ) { + return ( lhs.asString() < rhs ); + } + + friend bool operator<( const std::string & lhs, const Ustring & rhs ) { + return ( lhs < rhs.asString() ); + } + + // operator > + + friend bool operator>( const Ustring & lhs, const Ustring & rhs ) { + return ( lhs.asString() > rhs.asString() ); + } + + friend bool operator>( const Ustring & lhs, const std::string & rhs ) { + return ( lhs.asString() > rhs ); + } + + friend bool operator>( const std::string & lhs, const Ustring & rhs ) { + return ( lhs > rhs.asString() ); + } + + // operator >= + + friend bool operator>=( const Ustring & lhs, const Ustring & rhs ) { + return ( ! operator<( lhs, rhs ) ); + } + + friend bool operator>=( const Ustring & lhs, const std::string & rhs ) { + return ( ! operator<( lhs, rhs ) ); + } + + friend bool operator>=( const std::string & lhs, const Ustring & rhs ) { + return ( ! operator<( lhs, rhs ) ); + } + + // operator <= + + friend bool operator<=( const Ustring & lhs, const Ustring & rhs ) { + return ( ! operator>( lhs, rhs ) ); + } + + friend bool operator<=( const Ustring & lhs, const std::string & rhs ) { + return ( ! operator>( lhs, rhs ) ); + } + + friend bool operator<=( const std::string & lhs, const Ustring & rhs ) { + return ( ! operator>( lhs, rhs ) ); + } + + // IO + + friend std::ostream & operator<<( std::ostream & str, const Ustring & obj ) { + return str << obj.asString(); + } + }; + + ///////////////////////////////////////////////////////////////// + } // namespace detail + /////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////// + } // namespace solver + /////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////// +} // namespace zypp +/////////////////////////////////////////////////////////////////// +#endif // ZYPP_SOLVER_DETAIL_USTRING_H diff --git a/zypp/solver/detail/World.cc b/zypp/solver/detail/World.cc index c7ed72a..9e2ffe3 100644 --- a/zypp/solver/detail/World.cc +++ b/zypp/solver/detail/World.cc @@ -21,11 +21,11 @@ #include -#include +#include #include ///////////////////////////////////////////////////////////////////////// -namespace zypp +namespace zypp { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// namespace solver @@ -35,13 +35,23 @@ namespace zypp { /////////////////////////////////////////////////////////////////// using namespace std; - - IMPL_BASE_POINTER(World); - - WorldPtr World::GlobalWorld = NULL; - + + IMPL_PTR_TYPE(World); + + World_Ptr World::GlobalWorld = NULL; + + void World::setGlobalWorld( MultiWorld_Ptr world ) + { + GlobalWorld = world; + } + + MultiWorld_Ptr World::globalWorld() + { + return dynamic_pointer_cast(GlobalWorld); + } + //--------------------------------------------------------------------------- - + string World::toString (WorldType type) { @@ -58,91 +68,91 @@ namespace zypp } return "???"; } - - + + string World::asString ( void ) const { return toString (*this); } - - + + string World::toString ( const World & world ) { return ""; } - - + + ostream & World::dumpOn( ostream & str ) const { str << asString(); return str; } - - + + ostream& operator<<( ostream& os, const World & world) { return os << world.asString(); } - + //--------------------------------------------------------------------------- - + World::World (WorldType type) : _type (type) { // fprintf (stderr, "*** creating world[%p]: %s\n", this, toString(_type).c_str()); } - - + + World::~World() { // fprintf (stderr, "*** deleting world[%p]: %s\n", this, toString(_type).c_str()); } - + //--------------------------------------------------------------------------- // sync/refresh functions - + bool World::sync (void) const { if (getenv("FIXME")) fprintf (stderr, "World::sync() not implemented\n"); return false; } - + bool - World::syncConditional (constChannelPtr channel) const + World::syncConditional (Channel_constPtr channel) const { if (getenv("FIXME")) fprintf (stderr, "World::syncConditional() not implemented\n"); return false; } - - - PendingPtr + + + Pending_Ptr World::refresh (void) { if (getenv("FIXME")) fprintf (stderr, "World::refresh() not implemented\n"); return 0; } - + bool World::hasRefresh (void) { if (getenv("FIXME")) fprintf (stderr, "World::hasRefresh() not implemented\n"); return false; } - - + + bool World::isRefreshing (void) { if (getenv("FIXME")) fprintf (stderr, "World::isRefreshing() not implemented\n"); return false; } - - + + /* These functions are for World-implementers only! Don't call them! */ void World::refreshBegin (void) @@ -150,187 +160,187 @@ namespace zypp if (getenv("FIXME")) fprintf (stderr, "World::refreshBegin() not implemented\n"); return; } - + void World::refreshComplete (void) { if (getenv("FIXME")) fprintf (stderr, "World::refreshComplete() not implemented\n"); return; } - + //--------------------------------------------------------------------------- // channels, subscriptions - + void - World::setSubscription (ChannelPtr channel, bool is_subscribed) + World::setSubscription (Channel_Ptr channel, bool is_subscribed) { bool curr_subs_status; - + if (channel == NULL) return; - + // if (getenv("RC_SPEW")) fprintf (stderr, "World::setSubscription (%s, %s)\n", channel->asString().c_str(), is_subscribed?"subscribe":"unsubscribe"); - + if (channel->system ()) { fprintf (stderr, "Can't subscribe to system channel '%s'\n", channel->name ()); return; } - + curr_subs_status = isSubscribed (channel); - + Subscription::setStatus (channel, is_subscribed); - + if (curr_subs_status != isSubscribed (channel)) touchSubscriptionSequenceNumber (); - + return; } - - + + bool - World::isSubscribed (constChannelPtr channel) const + World::isSubscribed (Channel_constPtr channel) const { if (channel == NULL) return false; // if (getenv("RC_SPEW")) fprintf (stderr, "World::isSubscribed (%s)\n", channel->asString().c_str()); - + if (channel->system ()) return false; - + return Subscription::status (channel) ? true : false; } - - - + + + //--------------------------------------------------------------------------- // ResItem Locks - + typedef struct { - constResItemPtr resItem; - WorldPtr world; + ResItem_constPtr resItem; + World_Ptr world; bool is_locked; } IsLockedInfo; - - + + static bool - is_locked_cb (constMatchPtr match, void *data) + is_locked_cb (Match_constPtr match, void *data) { IsLockedInfo *info = (IsLockedInfo *)data; - + if (match->test (info->resItem, info->world)) { info->is_locked = true; return false; } - + return true; } - - + + bool - World::resItemIsLocked (constResItemPtr resItem) + World::resItemIsLocked (ResItem_constPtr resItem) { IsLockedInfo info; - + info.resItem = resItem; info.world = this; info.is_locked = false; - + foreachLock (is_locked_cb, &info); - + return info.is_locked; } - - + + //--------------------------------------------------------------------------- // Transacting - + bool - World::canTransactResItem (constResItemPtr resItem) + World::canTransactResItem (ResItem_constPtr resItem) { if (getenv("FIXME")) fprintf (stderr, "World::canTransactResItem() not implemented\n"); return false; } - + bool World::transact (const ResItemList & installResItems, const ResItemList & remove_resItems, int flags) { if (getenv("FIXME")) fprintf (stderr, "World::transact() not implemented\n"); return false; } - - + + //--------------------------------------------------------------------------- // XML serialization - + void - World::serialize (XmlNodePtr parent) + World::serialize (XmlNode_Ptr parent) { if (getenv("FIXME")) fprintf (stderr, "World::serialize() not implemented\n"); return; } - + void World::toFile (const char *filename) { if (getenv("FIXME")) fprintf (stderr, "World::toFile() not implemented\n"); return; } - - + + //--------------------------------------------------------------------------- // Duplicating (primarily for atomic refreshes) - - WorldPtr + + World_Ptr World::dup (void) { if (getenv("FIXME")) fprintf (stderr, "World::dup() not implemented\n"); return 0; } - - + + //--------------------------------------------------------------------------- // only used for bindings - + void World::setRefreshFunction (WorldRefreshFn refresh_fn) { if (getenv("FIXME")) fprintf (stderr, "World::setRefreshFunction() not implemented\n"); return; } - - - + + + //----------------------------------------------------------------------------- // Upgrades - + typedef struct { - constResItemPtr original_resItem; + ResItem_constPtr original_resItem; CResItemFn fn; void *data; int count; - WorldPtr world; + World_Ptr world; } ForeachUpgradeInfo; - + static bool - foreach_upgrade_cb (constResItemPtr resItem, void *data) + foreach_upgrade_cb (ResItem_constPtr resItem, void *data) { ForeachUpgradeInfo *info = (ForeachUpgradeInfo *)data; int cmp; - + cmp = ResItem::compare (info->original_resItem, resItem); - + if (cmp >= 0) // original is already better return true; - + if (info->world->resItemIsLocked (resItem)) return true; - + if (info->fn) info->fn (resItem, info->data); ++info->count; - + return true; } - - + + // rc_world_foreach_upgrade: // @world: An #RCWorld. // @resItem: An #RCResItem. @@ -346,117 +356,117 @@ namespace zypp // Return value: The number of matching resItems // that the callback functions was invoked on, or // -1 in the case of an error. - + int - World::foreachUpgrade (constResItemPtr resItem, ChannelPtr channel, CResItemFn fn, void *data) + World::foreachUpgrade (ResItem_constPtr resItem, Channel_Ptr channel, CResItemFn fn, void *data) { ForeachUpgradeInfo info; - + syncConditional (channel); - + info.original_resItem = resItem; info.fn = fn; info.data = data; info.count = 0; info.world = this; - + foreachResItemByName (resItem->name(), channel, foreach_upgrade_cb, (void *)&info); - + return info.count; } - - - + + + typedef struct { - WorldPtr world; - constResItemPtr system_resItem; + World_Ptr world; + ResItem_constPtr system_resItem; CResItemList best_upgrades; bool subscribed_only; ResItemPairFn fn; void *data; int count; } SystemUpgradeInfo; - - + + static bool - foreach_system_upgrade_cb (constResItemPtr upgrade, void *data) + foreach_system_upgrade_cb (ResItem_constPtr upgrade, void *data) { SystemUpgradeInfo *info = (SystemUpgradeInfo *)data; - constChannelPtr channel = upgrade->channel(); + Channel_constPtr channel = upgrade->channel(); int cmp; - + if (info->subscribed_only) { if (!(channel && channel->isSubscribed ())) return true; } - + if (info->world->resItemIsLocked (upgrade)) return true; - + if (info->best_upgrades.empty()) { info->best_upgrades.push_back (upgrade); } else { /* All the versions are equal, so picking the first is fine */ - constResItemPtr best_up = info->best_upgrades.front(); - + ResItem_constPtr best_up = info->best_upgrades.front(); + cmp = ResItem::compare (best_up, upgrade); - + if (cmp <= 0) { /* We have a new best resItem... */ info->best_upgrades.pop_front(); info->best_upgrades.push_back (upgrade); } } - + return true; } - - + + static void - foreach_system_resItem_cb (const string & name, constResItemPtr resItem, SystemUpgradeInfo *info) + foreach_system_resItem_cb (const string & name, ResItem_constPtr resItem, SystemUpgradeInfo *info) { info->system_resItem = resItem; info->best_upgrades.clear(); - + /* If the resItem is excluded, skip it. */ if (info->world->resItemIsLocked (info->system_resItem)) return; - + info->world->foreachUpgrade (info->system_resItem, new Channel (CHANNEL_TYPE_NONSYSTEM), foreach_system_upgrade_cb, info); - + for (CResItemList::const_iterator iter = info->best_upgrades.begin(); iter != info->best_upgrades.end(); iter++) { - constResItemPtr upgrade = *iter; - + ResItem_constPtr upgrade = *iter; + if (info->fn) info->fn (info->system_resItem, upgrade, info->data); - + ++info->count; } - + info->best_upgrades.clear(); } - - typedef map UniqueTable; - + + typedef map UniqueTable; + static bool - build_unique_table_cb (constResItemPtr resItem, void *data) + build_unique_table_cb (ResItem_constPtr resItem, void *data) { UniqueTable *unique_table = (UniqueTable *)data; - + UniqueTable::const_iterator pos = unique_table->find (resItem->name()); - + if (pos != unique_table->end()) { if (ResItem::compare (resItem, pos->second) <= 0) return true; } - + (*unique_table)[resItem->name()] = resItem; - + return true; } - - + + /** * foreachSystemUpgrade: * @world: An #RCWorld. @@ -471,73 +481,73 @@ namespace zypp * Return value: The number of matching resItems that the callback * function was invoked on, or -1 in case of an error. **/ - + int World::foreachSystemUpgrade (bool subscribed_only, ResItemPairFn fn, void *data) { SystemUpgradeInfo info; UniqueTable unique_table; - + /* rc_world_foreach_resItem calls rc_world_sync */ - + foreachResItem (new Channel (CHANNEL_TYPE_SYSTEM), build_unique_table_cb, &unique_table); - + info.world = this; info.subscribed_only = subscribed_only; info.fn = fn; info.data = data; info.count = 0; - + for (UniqueTable::const_iterator iter = unique_table.begin(); iter != unique_table.end(); iter++) { foreach_system_resItem_cb (iter->first, iter->second, &info); } - + return info.count; } - - + + PackageUpdateList - World::getUpgrades (constResItemPtr resItem, constChannelPtr channel) + World::getUpgrades (ResItem_constPtr resItem, Channel_constPtr channel) { fprintf (stderr, "World::getUpgrades not implemented\n"); return PackageUpdateList(); } - - constResItemPtr - World::getBestUpgrade (constResItemPtr resItem, bool subscribed_only) + + ResItem_constPtr + World::getBestUpgrade (ResItem_constPtr resItem, bool subscribed_only) { fprintf (stderr, "World::getBestUpgrade not implemented\n"); return 0; } - - + + //----------------------------------------------------------------------------- // Locks - + int World::foreachLock (MatchFn fn, void *data) const { int count = 0; - + for (MatchList::const_iterator iter = _locks.begin(); iter != _locks.end(); iter++) { if (! fn (*iter, data)) return -1; ++count; } - + return count; } - - + + void - World::addLock (constMatchPtr lock) + World::addLock (Match_constPtr lock) { _locks.push_back (lock); } - - + + void - World::removeLock (constMatchPtr lock) + World::removeLock (Match_constPtr lock) { for (MatchList::iterator iter = _locks.begin(); iter != _locks.end(); iter++) { if (*iter == lock) { @@ -546,14 +556,14 @@ namespace zypp } } } - - + + void World::clearLocks (void) { _locks.clear(); } - + /////////////////////////////////////////////////////////////////// };// namespace detail ///////////////////////////////////////////////////////////////////// diff --git a/zypp/solver/detail/World.h b/zypp/solver/detail/World.h index c0a9caf..5ebe878 100644 --- a/zypp/solver/detail/World.h +++ b/zypp/solver/detail/World.h @@ -24,7 +24,11 @@ #include #include -#include +#include + +#include "zypp/base/ReferenceCounted.h" +#include "zypp/base/NonCopyable.h" +#include "zypp/base/PtrTypes.h" #include #include @@ -38,7 +42,7 @@ #include ///////////////////////////////////////////////////////////////////////// -namespace zypp +namespace zypp { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// namespace solver @@ -46,13 +50,13 @@ namespace zypp ///////////////////////////////////////////////////////////////////// namespace detail { /////////////////////////////////////////////////////////////////// - - typedef std::list WorldList; - + + typedef std::list WorldList; + class NameConflictInfo; - + ////////////////////////////////////////////////////////////////// - + typedef enum { PLAIN_WORLD = 0, STORE_WORLD, @@ -62,198 +66,198 @@ namespace zypp LOCALDIR_WORLD, SYSTEM_WORLD } WorldType; - - typedef bool (*WorldFn) (constWorldPtr world, void *user_data); - typedef PendingPtr (*WorldRefreshFn) (constWorldPtr world); - + + typedef bool (*WorldFn) (World_constPtr world, void *user_data); + typedef Pending_Ptr (*WorldRefreshFn) (World_constPtr world); + #if 0 - typedef bool (*WorldSyncFn) (constWorldPtr world, constChannelPtr channel); - typedef PackmanPtr (*WorldPackmanFn) (constWorldPtr world, const Resolvable::Kind & kind); - typedef void (*WorldSpewFn) (constWorldPtr world, FILE *out); - typedef constWorldPtr (*WorldDupFn) (constWorldPtr world); - - typedef bool (*WorldCanTransactResItemFn) (constWorldPtr world, constResItemPtr resItem); - typedef bool (*WorldTransactFn) (constWorldPtr world, const ResItemList & install_resItems, const ResItemList & remove_resItems, int flags); - - typedef bool (*WorldGetSubscribedFn) (const World *world, constChannelPtr channel); - typedef void (*WorldSetSubscribedFn) (World *world, ChannelPtr channel, bool subs_status); - + typedef bool (*WorldSyncFn) (World_constPtr world, Channel_constPtr channel); + typedef Packman_Ptr (*WorldPackmanFn) (World_constPtr world, const Resolvable::Kind & kind); + typedef void (*WorldSpewFn) (World_constPtr world, FILE *out); + typedef World_constPtr (*WorldDupFn) (World_constPtr world); + + typedef bool (*WorldCanTransactResItemFn) (World_constPtr world, ResItem_constPtr resItem); + typedef bool (*WorldTransactFn) (World_constPtr world, const ResItemList & install_resItems, const ResItemList & remove_resItems, int flags); + + typedef bool (*WorldGetSubscribedFn) (const World *world, Channel_constPtr channel); + typedef void (*WorldSetSubscribedFn) (World *world, Channel_Ptr channel, bool subs_status); + typedef int (*WorldForeachChannelFn) (const World *world, ChannelFn callback, void *user_data); - typedef int (*WorldForeachLockFn) (constWorldPtr world, MatchFn callback, void *user_data); - - typedef void (*WorldAddLockFn) (constWorldPtr world, constMatchPtr lock); - typedef void (*WorldRemoveLockFn) (constWorldPtr world, constMatchPtr lock); - typedef void (*WorldClearLockFn) (constWorldPtr world); - - typedef int (*WorldForeachResItemFn) (constWorldPtr world, const char *name, constChannelPtr channel, ResItemFn callback, void *user_data); - typedef int (*WorldForeachPackageDepFn) (constWorldPtr world, const Capability & dep, ResItemAndDepFn callback, void *user_data); - - typedef void (*WorldSerializeFn) (constWorldPtr world, constXmlNodePtr root); - typedef void (*WorldUnserializeFn) (constWorldPtr world, constXmlNodePtr node); - + typedef int (*WorldForeachLockFn) (World_constPtr world, MatchFn callback, void *user_data); + + typedef void (*WorldAddLockFn) (World_constPtr world, Match_constPtr lock); + typedef void (*WorldRemoveLockFn) (World_constPtr world, Match_constPtr lock); + typedef void (*WorldClearLockFn) (World_constPtr world); + + typedef int (*WorldForeachResItemFn) (World_constPtr world, const char *name, Channel_constPtr channel, ResItemFn callback, void *user_data); + typedef int (*WorldForeachPackageDepFn) (World_constPtr world, const Capability & dep, ResItemAndDepFn callback, void *user_data); + + typedef void (*WorldSerializeFn) (World_constPtr world, XmlNode_constPtr root); + typedef void (*WorldUnserializeFn) (World_constPtr world, XmlNode_constPtr node); + #endif - + /////////////////////////////////////////////////////////////////// // // CLASS NAME : World - - class World : public CountedRep { - REP_BODY(World); - + + class World : public base::ReferenceCounted, private base::NonCopyable { + + private: - static WorldPtr GlobalWorld; - + static World_Ptr GlobalWorld; + WorldType _type; - + /* The sequence numbers gets incremented every time the RCWorld is changed. */ - + unsigned int _seq_no_resItems; unsigned int _seq_no_channels; unsigned int _seq_no_subscriptions; unsigned int _seq_no_locks; - + /* Every world needs to be able to store locks, so we provide a place for that. Of course, derived classes are allowed to provide their own exotic lock semantics by providing their own *_lock_fn methods. */ MatchList _lock_store; - + bool _refresh_pending; - + /* a bad hack to keep us from emitting signals while finalizing */ bool _no_changed_signals; - + /* For unserialized worlds currently. If a world is read only, you can not refresh or transact on it. */ bool _read_only; - + MatchList _locks; - + public: - + World (WorldType type = PLAIN_WORLD); virtual ~World(); - + // ---------------------------------- I/O - + static std::string toString (const World & section); - + static std::string toString (WorldType type); - + virtual std::ostream & dumpOn(std::ostream & str ) const; - + friend std::ostream& operator<<(std::ostream&, const World & section); - + std::string asString (void ) const; - + // ---------------------------------- accessors - + WorldType type() const { return _type; } bool isPlainWorld () const { return _type == PLAIN_WORLD; } bool isUndumpWorld () const { return _type == UNDUMP_WORLD; } bool isMultiWorld () const { return _type == MULTI_WORLD; } bool isServiceWorld () const { return _type == SERVICE_WORLD; } - + unsigned int resItemSequenceNumber (void) const { return _seq_no_resItems; } unsigned int channelSequenceNumber (void) const { return _seq_no_channels; } unsigned int subscriptionSequenceNumber (void) const { return _seq_no_subscriptions; } unsigned int lockSequenceNumber (void) const { return _seq_no_locks; } - + void touchResItemSequenceNumber (void) { _seq_no_resItems++; } void touchChannelSequenceNumber (void) { _seq_no_channels++; } void touchSubscriptionSequenceNumber (void) { _seq_no_subscriptions++; } void touchLockSequenceNumber (void) { _seq_no_locks++; } - + MatchList locks (void) const { return _lock_store; } - + // ---------------------------------- methods - - static void setGlobalWorld (MultiWorldPtr world) { GlobalWorld = world; } - static MultiWorldPtr globalWorld (void) { return GlobalWorld; } - + + static void setGlobalWorld (MultiWorld_Ptr world); + static MultiWorld_Ptr globalWorld (void); + //RCPackman *get_packman (GType); - + bool sync (void) const; - virtual bool syncConditional (constChannelPtr channel) const; - PendingPtr refresh (void); + virtual bool syncConditional (Channel_constPtr channel) const; + Pending_Ptr refresh (void); bool hasRefresh (void); bool isRefreshing (void); - + /* These functions are for World-implementers only! Don't call them! */ void refreshBegin (void); void refreshComplete (void); - + virtual int foreachChannel (ChannelFn fn, void *user_data) const = 0; - - virtual void setSubscription (ChannelPtr channel, bool is_subscribed); - virtual bool isSubscribed (constChannelPtr channel) const; - + + virtual void setSubscription (Channel_Ptr channel, bool is_subscribed); + virtual bool isSubscribed (Channel_constPtr channel) const; + virtual ChannelList channels () const = 0; - virtual bool containsChannel (constChannelPtr channel) const = 0; - - virtual ChannelPtr getChannelByName (const char *channel_name) const = 0; - virtual ChannelPtr getChannelByAlias (const char *alias) const = 0; - virtual ChannelPtr getChannelById (const char *channel_id) const = 0; - + virtual bool containsChannel (Channel_constPtr channel) const = 0; + + virtual Channel_Ptr getChannelByName (const char *channel_name) const = 0; + virtual Channel_Ptr getChannelByAlias (const char *alias) const = 0; + virtual Channel_Ptr getChannelById (const char *channel_id) const = 0; + // ResItem Locks - + virtual int foreachLock (MatchFn fn, void *data) const; - - void addLock (constMatchPtr lock); - void removeLock (constMatchPtr lock); + + void addLock (Match_constPtr lock); + void removeLock (Match_constPtr lock); void clearLocks (); - - bool resItemIsLocked (constResItemPtr resItem); - + + bool resItemIsLocked (ResItem_constPtr resItem); + // Single resItem queries - - virtual constResItemPtr findInstalledResItem (constResItemPtr resItem) = 0; - virtual constResItemPtr findResItem (constChannelPtr channel, const char *name) const = 0; - virtual constResItemPtr findResItemWithConstraint (constChannelPtr channel, const char *name, const Capability & constraint, bool is_and) const = 0; - virtual ChannelPtr guessResItemChannel (constResItemPtr resItem) const = 0; - + + virtual ResItem_constPtr findInstalledResItem (ResItem_constPtr resItem) = 0; + virtual ResItem_constPtr findResItem (Channel_constPtr channel, const char *name) const = 0; + virtual ResItem_constPtr findResItemWithConstraint (Channel_constPtr channel, const char *name, const Capability & constraint, bool is_and) const = 0; + virtual Channel_Ptr guessResItemChannel (ResItem_constPtr resItem) const = 0; + // Iterate across resItems - - virtual int foreachResItem (ChannelPtr channel, CResItemFn fn, void *data) = 0; - virtual int foreachResItemByName (const std::string & name, ChannelPtr channel, CResItemFn fn, void *user_data) = 0; - virtual int foreachResItemByMatch (constMatchPtr match, CResItemFn fn, void *user_data) = 0; - + + virtual int foreachResItem (Channel_Ptr channel, CResItemFn fn, void *data) = 0; + virtual int foreachResItemByName (const std::string & name, Channel_Ptr channel, CResItemFn fn, void *user_data) = 0; + virtual int foreachResItemByMatch (Match_constPtr match, CResItemFn fn, void *user_data) = 0; + // Iterate across provides or requirement - + virtual int foreachProvidingResItem (const Capability & dep, ResItemAndDepFn fn, void *user_data) = 0; virtual int foreachRequiringResItem (const Capability & dep, ResItemAndDepFn fn, void *user_data) = 0; virtual int foreachConflictingResItem (const Capability & dep, ResItemAndDepFn fn, void *user_data) = 0; - + // upgrades - - int foreachUpgrade (constResItemPtr resItem, ChannelPtr channel, CResItemFn fn, void *data); - PackageUpdateList getUpgrades (constResItemPtr resItem, constChannelPtr channel); - constResItemPtr getBestUpgrade (constResItemPtr resItem, bool subscribed_only); + + int foreachUpgrade (ResItem_constPtr resItem, Channel_Ptr channel, CResItemFn fn, void *data); + PackageUpdateList getUpgrades (ResItem_constPtr resItem, Channel_constPtr channel); + ResItem_constPtr getBestUpgrade (ResItem_constPtr resItem, bool subscribed_only); int foreachSystemUpgrade (bool subscribed_only, ResItemPairFn fn, void *data); - + // provider - - bool getSingleProvider (const Capability & dep, constChannelPtr channel, constResItemPtr *resItem); - + + bool getSingleProvider (const Capability & dep, Channel_constPtr channel, ResItem_constPtr *resItem); + // Transacting - - bool canTransactResItem (constResItemPtr resItem); + + bool canTransactResItem (ResItem_constPtr resItem); bool transact (const ResItemList & installResItems, const ResItemList & remove_resItems, int flags); - + // XML serialization - - void serialize (XmlNodePtr parent); + + void serialize (XmlNode_Ptr parent); void toFile (const char *filename); - + // Duplicating (primarily for atomic refreshes) - WorldPtr dup (void); - + World_Ptr dup (void); + // only used for bindings void setRefreshFunction (WorldRefreshFn refresh_fn); - + }; - + /////////////////////////////////////////////////////////////////// };// namespace detail ///////////////////////////////////////////////////////////////////// diff --git a/zypp/solver/detail/WorldPtr.h b/zypp/solver/detail/WorldPtr.h index 2534c94..a98208a 100644 --- a/zypp/solver/detail/WorldPtr.h +++ b/zypp/solver/detail/WorldPtr.h @@ -1,5 +1,5 @@ /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* WorldPtr.h +/* World_Ptr.h * * Copyright (C) 2005 SUSE Linux Products GmbH * @@ -18,10 +18,10 @@ * 02111-1307, USA. */ -#ifndef _WorldPtr_h -#define _WorldPtr_h +#ifndef _World_Ptr_h +#define _World_Ptr_h -#include +#include "zypp/base/PtrTypes.h" ///////////////////////////////////////////////////////////////////////// namespace zypp @@ -34,10 +34,10 @@ namespace zypp { /////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// -// CLASS NAME : WorldPtr -// CLASS NAME : constWorldPtr +// CLASS NAME : World_Ptr +// CLASS NAME : World_constPtr /////////////////////////////////////////////////////////////////// -DEFINE_BASE_POINTER(World); +DEFINE_PTR_TYPE(World); /////////////////////////////////////////////////////////////////// };// namespace detail @@ -49,4 +49,4 @@ DEFINE_BASE_POINTER(World); };// namespace zypp ///////////////////////////////////////////////////////////////////////// -#endif // _WorldPtr_h +#endif // _World_Ptr_h diff --git a/zypp/solver/detail/XmlNode.cc b/zypp/solver/detail/XmlNode.cc index 510f190..5d1238e 100644 --- a/zypp/solver/detail/XmlNode.cc +++ b/zypp/solver/detail/XmlNode.cc @@ -37,7 +37,7 @@ namespace zypp using namespace std; - IMPL_BASE_POINTER(XmlNode); + IMPL_PTR_TYPE(XmlNode); //--------------------------------------------------------------------------- @@ -263,7 +263,7 @@ namespace zypp } - const XmlNodePtr + const XmlNode_Ptr XmlNode::getNode (const char *name) const { xmlNodePtr iter; diff --git a/zypp/solver/detail/XmlNode.h b/zypp/solver/detail/XmlNode.h index 2267a43..5eeb94e 100644 --- a/zypp/solver/detail/XmlNode.h +++ b/zypp/solver/detail/XmlNode.h @@ -29,10 +29,14 @@ #include #include +#include "zypp/base/ReferenceCounted.h" +#include "zypp/base/NonCopyable.h" +#include "zypp/base/PtrTypes.h" + #include ///////////////////////////////////////////////////////////////////////// -namespace zypp +namespace zypp { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// namespace solver @@ -45,9 +49,9 @@ namespace zypp // // CLASS NAME : XmlNode -class XmlNode : public CountedRep +class XmlNode : public base::ReferenceCounted, private base::NonCopyable { - REP_BODY(XmlNode); + private: const xmlNodePtr _node; @@ -71,8 +75,8 @@ class XmlNode : public CountedRep const char *name() const { return ((const char *)(_node->name)); } xmlNodePtr node() const { return (_node); } - XmlNodePtr next() const { return (_node->next == NULL ? NULL : new XmlNode (_node->next)); } - XmlNodePtr children() const { return (_node->xmlChildrenNode == NULL ? NULL : new XmlNode (_node->xmlChildrenNode)); } + XmlNode_Ptr next() const { return (_node->next == NULL ? NULL : new XmlNode (_node->next)); } + XmlNode_Ptr children() const { return (_node->xmlChildrenNode == NULL ? NULL : new XmlNode (_node->xmlChildrenNode)); } xmlElementType type() const { return (_node->type); } // ---------------------------------- methods @@ -86,7 +90,7 @@ class XmlNode : public CountedRep bool match (const char *str) const { return (! strcasecmp ((const char *)(_node->name), str)); } - const XmlNodePtr getNode (const char *name) const; + const XmlNode_Ptr getNode (const char *name) const; // The former will get either a property or a tag, whereas the latter will // get only a property diff --git a/zypp/solver/detail/XmlNodePtr.h b/zypp/solver/detail/XmlNodePtr.h index 36a14df..e55f359 100644 --- a/zypp/solver/detail/XmlNodePtr.h +++ b/zypp/solver/detail/XmlNodePtr.h @@ -1,5 +1,5 @@ /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* XmlNodePtr.h +/* XmlNode_Ptr.h * * Copyright (C) 2005 SUSE Linux Products GmbH * @@ -18,10 +18,10 @@ * 02111-1307, USA. */ -#ifndef _XmlNodePtr_h -#define _XmlNodePtr_h +#ifndef _XmlNode_Ptr_h +#define _XmlNode_Ptr_h -#include +#include "zypp/base/PtrTypes.h" /////////////////////////////////////////////////////////////////// namespace zypp @@ -35,10 +35,10 @@ namespace zypp /////////////////////////////////////////////////////////////////// - // CLASS NAME : XmlNodePtr - // CLASS NAME : constXmlNodePtr + // CLASS NAME : XmlNode_Ptr + // CLASS NAME : XmlNode_constPtr /////////////////////////////////////////////////////////////////// - DEFINE_BASE_POINTER(XmlNode); + DEFINE_PTR_TYPE(XmlNode); /////////////////////////////////////////////////////////////////// };// namespace detail @@ -50,4 +50,4 @@ namespace zypp };// namespace zypp /////////////////////////////////////////////////////////////////// -#endif // _XmlNodePtr_h +#endif // _XmlNode_Ptr_h diff --git a/zypp/solver/detail/XmlParser.cc b/zypp/solver/detail/XmlParser.cc index d0df8ff..13d93ee 100644 --- a/zypp/solver/detail/XmlParser.cc +++ b/zypp/solver/detail/XmlParser.cc @@ -227,7 +227,7 @@ namespace zypp //--------------------------------------------------------------------------- - XmlParser::XmlParser (constChannelPtr channel) + XmlParser::XmlParser (Channel_constPtr channel) : _channel (channel) , _processing (false) , _xml_context (NULL) @@ -555,7 +555,7 @@ namespace zypp // if (getenv ("RC_SPEW_XML")) fprintf (stderr, "XmlParser::packageEnd(%s)\n", name); if (!strcmp(name, "package")) { - PackageUpdatePtr update = NULL; + PackageUpdate_Ptr update = NULL; /* If possible, grab the version info from the most recent update. * Otherwise, try to find where the package provides itself and use @@ -604,7 +604,7 @@ namespace zypp _current_provides.insert (selfdep); } - PackagePtr package = new Package ( _channel, + Package_Ptr package = new Package ( _channel, _current_package_name, _current_package_edition, _current_package_arch); @@ -628,7 +628,7 @@ namespace zypp for (PackageUpdateList::iterator iter = _current_package_packageUpdateList.begin(); iter != _current_package_packageUpdateList.end(); iter++) { - PackageUpdatePtr update = *iter; + PackageUpdate_Ptr update = *iter; update->setPackage (package); package->addUpdate (update); } @@ -678,7 +678,7 @@ namespace zypp { // if (getenv ("RC_SPEW_XML")) fprintf (stderr, "XmlParser::updateEnd(%s)\n", name); - constChannelPtr channel; + Channel_constPtr channel; const char *url_prefix = NULL; assert(_current_update != NULL); @@ -739,8 +739,8 @@ namespace zypp if (!strcmp(name, "or")) { #if 0 - OrDependencyPtr or_dep = OrDependency::fromDependencyList (*_current_dep_list); - DependencyPtr dep = new Dependency (or_dep); + OrDependency_Ptr or_dep = OrDependency::fromDependencyList (*_current_dep_list); + Dependency_Ptr dep = new Dependency (or_dep); (*_current_dep_list).clear(); diff --git a/zypp/solver/detail/XmlParser.h b/zypp/solver/detail/XmlParser.h index e366f20..3e27ad1 100644 --- a/zypp/solver/detail/XmlParser.h +++ b/zypp/solver/detail/XmlParser.h @@ -25,7 +25,7 @@ #include #include -#include +#include #include #include @@ -33,7 +33,7 @@ #include ///////////////////////////////////////////////////////////////////////// -namespace zypp +namespace zypp { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// namespace solver @@ -41,12 +41,12 @@ namespace zypp ///////////////////////////////////////////////////////////////////// namespace detail { /////////////////////////////////////////////////////////////////// - - + + /////////////////////////////////////////////////////////////////// // // CLASS NAME : XmlParser - + class XmlParser { public: @@ -58,15 +58,15 @@ namespace zypp PARSER_DEP, }; typedef enum _XmlParserState XmlParserState; - + private: - constChannelPtr _channel; + Channel_constPtr _channel; bool _processing; xmlParserCtxtPtr _xml_context; XmlParserState _state; - + PackageList _all_packages; - + /* Temporary state */ bool _current_package_stored; std::string _current_package_name; @@ -82,7 +82,7 @@ namespace zypp bool _current_package_installOnly; bool _current_package_packageSet; PackageUpdateList _current_package_packageUpdateList; - + CapSet _current_requires; CapSet _current_provides; CapSet _current_conflicts; @@ -90,69 +90,69 @@ namespace zypp CapSet _current_recommends; CapSet _current_suggests; CapSet _current_obsoletes; - PackageUpdatePtr _current_update; - + PackageUpdate_Ptr _current_update; + // these point to one of the above lists during dependency parsing CapSet *_toplevel_dep_list; CapSet *_current_dep_list; - + char *_text_buffer; size_t _text_buffer_size; - + protected: void setState (XmlParserState state) { _state = state; } - + public: - - XmlParser (constChannelPtr channel); + + XmlParser (Channel_constPtr channel); virtual ~XmlParser(); - + // ---------------------------------- I/O - + static std::string toString ( const XmlParser & parser); - + virtual std::ostream & dumpOn( std::ostream & str ) const; - + friend std::ostream& operator<<( std::ostream & str, const XmlParser & parser); - + std::string asString ( void ) const; - + // ---------------------------------- accessors - + bool processing() const { return _processing; } void setProcessing (bool processing) { _processing = processing; } - + XmlParserState state (void) const { return _state; } - + #if 0 // are they needed ? - constChannelPtr channel() const { return _channel; } - void setChannel (constChannelPtr channel) { _channel = channel; } - + Channel_constPtr channel() const { return _channel; } + void setChannel (Channel_constPtr channel) { _channel = channel; } + xmlParserCtxtPtr xmlContext() const { return _xml_context; } void setXmlContext (xmlParserCtxtPtr xml_context) { _xml_context = xml_context; } #endif // ---------------------------------- methods - + void toBuffer (const char *data, size_t size); void releaseBuffer (void); // free _text_buffer - + void startElement(const char *name, const xmlChar **attrs); void endElement(const char *name); - + void toplevelStart(const char *name, const xmlChar **attrs); void packageStart(const char *name, const xmlChar **attrs); void historyStart(const char *name, const xmlChar **attrs); void dependencyStart(const char *name, const xmlChar **attrs); - + void updateEnd(const char *name); void packageEnd(const char *name); void historyEnd(const char *name); void dependencyEnd(const char *name); - + void parseChunk (const char *xmlbuf, size_t size); PackageList done (void); }; - + /////////////////////////////////////////////////////////////////// };// namespace detail ///////////////////////////////////////////////////////////////////// diff --git a/zypp/solver/detail/debug.cc b/zypp/solver/detail/debug.cc index 6cc24ff..e546976 100644 --- a/zypp/solver/detail/debug.cc +++ b/zypp/solver/detail/debug.cc @@ -17,7 +17,6 @@ */ -#include #include #include diff --git a/zypp/solver/detail/extract.cc b/zypp/solver/detail/extract.cc index f646120..ba651cc 100644 --- a/zypp/solver/detail/extract.cc +++ b/zypp/solver/detail/extract.cc @@ -43,9 +43,9 @@ namespace zypp int - extract_packages_from_xml_node (XmlNodePtr node, ChannelPtr channel, CResItemFn callback, void *data) + extract_packages_from_xml_node (XmlNode_Ptr node, Channel_Ptr channel, CResItemFn callback, void *data) { - PackagePtr package; + Package_Ptr package; int count = 0; _DBG("RC_SPEW_XML") << "extract_packages_from_xml_node ()" << endl; @@ -83,7 +83,7 @@ namespace zypp int - extract_packages_from_helix_buffer (const char *buf, size_t len, ChannelPtr channel, CResItemFn callback, void *data) + extract_packages_from_helix_buffer (const char *buf, size_t len, Channel_Ptr channel, CResItemFn callback, void *data) { unsigned int count = 0; PackageList packages; @@ -115,7 +115,7 @@ namespace zypp int - extract_packages_from_helix_file (const string & filename, ChannelPtr channel, CResItemFn callback, void *data) + extract_packages_from_helix_file (const string & filename, Channel_Ptr channel, CResItemFn callback, void *data) { Buffer *buf; int count; @@ -139,10 +139,10 @@ namespace zypp extract_packages_from_undump_buffer (const char *buf, size_t len, ChannelAndSubscribedFn channel_callback, CResItemFn resItem_callback, MatchFn lock_callback, void *data) { xmlDoc *doc; - XmlNodePtr dump_node; - ChannelPtr system_channel = NULL; - ChannelPtr current_channel = NULL; - XmlNodePtr channel_node; + XmlNode_Ptr dump_node; + Channel_Ptr system_channel = NULL; + Channel_Ptr current_channel = NULL; + XmlNode_Ptr channel_node; int count = 0; doc = parse_xml_from_buffer (buf, len); @@ -163,10 +163,10 @@ namespace zypp while (channel_node != NULL) { if (channel_node->equals("locks")) { - XmlNodePtr lock_node = channel_node->children(); + XmlNode_Ptr lock_node = channel_node->children(); while (lock_node) { - MatchPtr lock; + Match_Ptr lock; lock = new Match (lock_node); @@ -253,12 +253,12 @@ namespace zypp #if 0 /* ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** */ - static ResItemPtr + static ResItem_Ptr fill_debian_package (const char *buf, const char *url_prefix, int *off) { const char *ibuf; RCPackageUpdate *up = NULL; - ResItemPtr r; + ResItem_Ptr r; ResItemList requires, provides, conflicts, suggests, recommends; up = rc_package_update_new (); @@ -427,7 +427,7 @@ namespace zypp #endif int - extract_packages_from_debian_buffer (const char *buf, size_t len, ChannelPtr channel, CResItemFn callback, void *data) + extract_packages_from_debian_buffer (const char *buf, size_t len, Channel_Ptr channel, CResItemFn callback, void *data) { const char *pos; int count = 0; @@ -439,7 +439,7 @@ namespace zypp int off; /* All debian packages "have" epochs */ - ResItemPtr resItem = fill_debian_package (iter, channel->getFilePath (), &off); + ResItem_Ptr resItem = fill_debian_package (iter, channel->getFilePath (), &off); resItem->setEpoch (0); resItem->setArch ( Arch()); @@ -458,7 +458,7 @@ namespace zypp int - extract_packages_from_debian_file (const string & filename, ChannelPtr channel, CResItemFn callback, void *data) + extract_packages_from_debian_file (const string & filename, Channel_Ptr channel, CResItemFn callback, void *data) { Buffer *buf; int count; @@ -479,7 +479,7 @@ namespace zypp #if 0 /* ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** */ - PackagePtr + Package_Ptr extract_yum_package (const guint8 *data, size_t len, RCPackman *packman, char *url) { @@ -490,7 +490,7 @@ namespace zypp #else RCRpmman *rpmman; Header h; - PackagePtr p; + Package_Ptr p; RCPackageUpdate *pu; char *tmpc; int typ, n; @@ -537,7 +537,7 @@ namespace zypp int extract_packages_from_aptrpm_buffer (const guint8 *data, size_t len, RCPackman *packman, - ChannelPtr channel, + Channel_Ptr channel, CResItemFn callback, void * user_data) { @@ -586,7 +586,7 @@ namespace zypp while (cur_ptr != NULL) { Header h; - PackagePtr p; + Package_Ptr p; RCPackageUpdate *pu; int bytesleft, i; char *tmpc; @@ -669,11 +669,11 @@ namespace zypp int extract_packages_from_aptrpm_file (const char *filename, RCPackman *packman, - ChannelPtr channel, + Channel_Ptr channel, CResItemFn callback, void * user_data) { - WorldPtr world = *((WorldPtr *)data); + World_Ptr world = *((World_Ptr *)data); RCBuffer *buf; int count; @@ -696,10 +696,10 @@ namespace zypp /* ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** */ static void - package_into_hash (PackagePtr pkg, GHashTable *hash) + package_into_hash (Package_Ptr pkg, GHashTable *hash) { void * nameq; - PackagePtr hashed_pkg; + Package_Ptr hashed_pkg; nameq = GINT_TO_POINTER (RC_RESOLVABLE_SPEC (pkg)->nameq); hashed_pkg = g_hash_table_lookup (hash, nameq); @@ -713,7 +713,7 @@ namespace zypp } static bool - hash_recurse_cb (PackagePtr pkg, void * user_data) + hash_recurse_cb (Package_Ptr pkg, void * user_data) { GHashTable *hash = user_data; package_into_hash (pkg, hash); @@ -741,7 +741,7 @@ namespace zypp static void - add_fake_history (PackagePtr pkg) + add_fake_history (Package_Ptr pkg) { RCPackageUpdate *up; @@ -759,7 +759,7 @@ namespace zypp } PackagesFromDirInfo; static bool - packages_from_dir_cb (PackagePtr package, void * user_data) + packages_from_dir_cb (Package_Ptr package, void * user_data) { PackagesFromDirInfo *info = user_data; RCPackageUpdate *update; @@ -779,13 +779,13 @@ namespace zypp int extract_packages_from_directory (const char *path, - ChannelPtr channel, + Channel_Ptr channel, RCPackman *packman, bool recursive, CResItemFn callback, void * user_data) { - WorldPtr world = *((WorldPtr *)data); + World_Ptr world = *((World_Ptr *)data); GDir *dir; GHashTable *hash; struct HashIterInfo info; @@ -915,7 +915,7 @@ namespace zypp hash_recurse_cb, hash); } else if (g_file_test (file_path, G_FILE_TEST_IS_REGULAR)) { - PackagePtr pkg; + Package_Ptr pkg; pkg = rc_packman_query_file (packman, file_path, true); if (pkg != NULL) { diff --git a/zypp/solver/detail/extract.h b/zypp/solver/detail/extract.h index da954b5..707d411 100644 --- a/zypp/solver/detail/extract.h +++ b/zypp/solver/detail/extract.h @@ -47,23 +47,23 @@ namespace zypp namespace detail { /////////////////////////////////////////////////////////////////// - int extract_packages_from_helix_buffer (const char data[], size_t len, ChannelPtr channel, CResItemFn callback, void *data); - int extract_packages_from_helix_file (const std::string & filename, ChannelPtr channel, CResItemFn callback, void *data); + int extract_packages_from_helix_buffer (const char data[], size_t len, Channel_Ptr channel, CResItemFn callback, void *data); + int extract_packages_from_helix_file (const std::string & filename, Channel_Ptr channel, CResItemFn callback, void *data); - int extract_packages_from_xml_node (constXmlNodePtr node, ChannelPtr channel, ResItemFn callback, void *data); + int extract_packages_from_xml_node (XmlNode_constPtr node, Channel_Ptr channel, ResItemFn callback, void *data); - int extract_packages_from_debian_buffer (const char *data, size_t len, ChannelPtr channel, CResItemFn callback, void *data); - int extract_packages_from_debian_file (const std::string & filename, ChannelPtr channel, CResItemFn callback, void *data); + int extract_packages_from_debian_buffer (const char *data, size_t len, Channel_Ptr channel, CResItemFn callback, void *data); + int extract_packages_from_debian_file (const std::string & filename, Channel_Ptr channel, CResItemFn callback, void *data); - PackagePtr extract_yum_package (const char *data, size_t len, PackmanPtr packman, const std::string & url); + Package_Ptr extract_yum_package (const char *data, size_t len, Packman_Ptr packman, const std::string & url); - int extract_packages_from_aptrpm_buffer (const char *data, size_t len, PackmanPtr packman, ChannelPtr channel, ResItemFn callback, void *data); - int extract_packages_from_aptrpm_file (const std::string & filename, PackmanPtr packman, ChannelPtr channel, ResItemFn callback, void *data); + int extract_packages_from_aptrpm_buffer (const char *data, size_t len, Packman_Ptr packman, Channel_Ptr channel, ResItemFn callback, void *data); + int extract_packages_from_aptrpm_file (const std::string & filename, Packman_Ptr packman, Channel_Ptr channel, ResItemFn callback, void *data); int extract_packages_from_undump_buffer (const char *data, size_t len, ChannelAndSubscribedFn channel_callback, CResItemFn package_callback, MatchFn lock_callback, void *data); int extract_packages_from_undump_file (const std::string & filename, ChannelAndSubscribedFn channel_callback, CResItemFn package_callback, MatchFn lock_callback, void *data); - int extract_packages_from_directory (const std::string & path, ChannelPtr channel, PackmanPtr packman, bool recursive, ResItemFn callback, void *data); + int extract_packages_from_directory (const std::string & path, Channel_Ptr channel, Packman_Ptr packman, bool recursive, ResItemFn callback, void *data); /////////////////////////////////////////////////////////////////// };// namespace detail diff --git a/zypp/solver/detail/utils.cc b/zypp/solver/detail/utils.cc index 298c91e..e4a45c9 100644 --- a/zypp/solver/detail/utils.cc +++ b/zypp/solver/detail/utils.cc @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include -- 2.7.4