move ResolverInfoMisc::toString to ResolverInfo and use it everywhere
authorKlaus Kaempf <kkaempf@suse.de>
Fri, 3 Feb 2006 15:32:52 +0000 (15:32 +0000)
committerKlaus Kaempf <kkaempf@suse.de>
Fri, 3 Feb 2006 15:32:52 +0000 (15:32 +0000)
zypp/solver/detail/ResolverInfo.cc
zypp/solver/detail/ResolverInfo.h
zypp/solver/detail/ResolverInfoChildOf.cc
zypp/solver/detail/ResolverInfoConflictsWith.cc
zypp/solver/detail/ResolverInfoContainer.cc
zypp/solver/detail/ResolverInfoDependsOn.cc
zypp/solver/detail/ResolverInfoMisc.cc
zypp/solver/detail/ResolverInfoMissingReq.cc
zypp/solver/detail/ResolverInfoNeededBy.cc
zypp/solver/detail/ResolverInfoObsoletes.cc

index 990aab7..29dd5cc 100644 (file)
  */
 
 #include <map>
+#include <sstream>
 
 #include "zypp/solver/detail/ResolverInfo.h"
+#include "zypp/Source.h"
+#include "zypp/Capability.h"
 #include "zypp/base/String.h"
 #include "zypp/base/Gettext.h"
 #include "zypp/base/Logger.h"
@@ -115,6 +118,40 @@ resolver_info_type_from_string (const char *str)
     return RESOLVER_INFO_TYPE_INVALID;
 }
 
+string
+ResolverInfo::toString (PoolItem_Ref item)
+{
+    ostringstream os;
+    if (!item) return "";
+
+    if (item->kind() != ResTraits<zypp::Package>::kind)
+       os << item->kind() << ':';
+    os  << item->name() << '-' << item->edition();
+    if (item->arch() != "") {
+       os << '.' << item->arch();
+    }
+    Source_Ref s = item->source();
+    if (s) {
+       string alias = s.alias();
+       if (!alias.empty()
+           && alias != "@system")
+       {
+           os << '[' << s.alias() << ']';
+       }
+    }
+    return os.str();
+}
+
+
+string
+ResolverInfo::toString (const Capability & capability)
+{
+    ostringstream os;
+    os << capability;
+    return os.str();
+}
+
+
 //---------------------------------------------------------------------------
 
 std::ostream &
@@ -125,7 +162,7 @@ ResolverInfo::dumpOn( std::ostream & os ) const
     os << "> ";
 
     if (_affected) {
-       os << _affected << ":";
+       os << toString (_affected);
     }
 
     if (_error) os << _(" Error!");
index 70e3f86..0d2c17e 100644 (file)
@@ -111,6 +111,9 @@ class ResolverInfo : public base::ReferenceCounted, private base::NonCopyable {
 
     // ---------------------------------- I/O
 
+    static std::string toString (PoolItem_Ref item);
+    static std::string toString (const Capability & capability);
+
     virtual std::ostream & dumpOn( std::ostream & str ) const;
     friend std::ostream& operator<<(std::ostream & str, const ResolverInfo & obj)
     { return obj.dumpOn (str); }
index ae90372..42f93f3 100644 (file)
@@ -50,7 +50,7 @@ ResolverInfoChildOf::dumpOn( std::ostream & os ) const
     ResolverInfo::dumpOn (os);
 
     ostringstream affected_str;
-    affected_str << affected();
+    affected_str << ResolverInfo::toString (affected());
 
     //Translator all.%s = name of packages,patches,....
     os << str::form (_("%s part of %s"),
index f68da05..1ae2852 100644 (file)
@@ -49,13 +49,13 @@ ResolverInfoConflictsWith::dumpOn( std::ostream & os ) const
 {
     ResolverInfo::dumpOn (os);
     ostringstream affected_str;
-    affected_str << affected();
+    affected_str << ResolverInfo::toString (affected());
 
     // Translator: all.%s = name of package, patch,...
     os << str::form (_("%s conflicts with %s"),
                            affected_str.str().c_str(),
                            itemsToString(false).c_str());
-         return os;
+    return os;
 }
 
 //---------------------------------------------------------------------------
index 6ee9a27..70110e4 100644 (file)
@@ -50,7 +50,7 @@ ResolverInfoContainer::dumpOn( std::ostream & os ) const
     os << "<resolverinfocontainer '";
     for (PoolItemList::const_iterator it = _item_list.begin(); it != _item_list.end(); ++it) {
        if (it != _item_list.begin()) os << ", ";
-       os << *it;
+       os << ResolverInfo::toString (*it);
     }
     os << "'>";
     return os;
@@ -150,7 +150,7 @@ ResolverInfoContainer::itemsToString (const bool names_only) const
             iter != _item_list.end(); iter++)
        {
            res << "\n- ";          
-           res << (*iter);
+           res << ResolverInfo::toString (*iter);
        }       
     }
 
index f79179d..58f417a 100644 (file)
@@ -49,7 +49,7 @@ ResolverInfoDependsOn::dumpOn( std::ostream & os ) const
     ResolverInfo::dumpOn (os);
 
     ostringstream affected_str;
-    affected_str << affected();
+    affected_str << ResolverInfo::toString (affected());
 
     // Translator: all.%s = name of package,patch,....
     os << str::form (_("%s depended on %s"),
index 3207ddb..a41812b 100644 (file)
@@ -51,10 +51,10 @@ ResolverInfoMisc::dumpOn( std::ostream & os ) const
     ResolverInfo::dumpOn (os);
 
     ostringstream affected_str;
-    affected_str << affected();
+    affected_str << ResolverInfo::toString(affected());
 
     if (!affected_str.str().empty()) os << affected_str.str();
-    os << message();
+    os << ">>" << message() << "<<";
     os << itemsToString(true);
     if (!_action.empty()) {
        os << _(", Action: ") << _action << endl;
@@ -121,31 +121,12 @@ translateResTraits (const Resolvable::Kind & kind)
 }
 
 
-static string
-toString (PoolItem_Ref item)
-{
-    ostringstream os;
-    ResObject::constPtr res = item.resolvable();
-    os << res->name() << " (" << res->edition() << "/" << res->source() << ")";
-    return os.str();
-}
-
-
-static string
-toString (const Capability & capability)
-{
-    ostringstream os;
-    os << capability;
-    return os.str();
-}
-
-
 std::string
 ResolverInfoMisc::message (void) const
 {
     string msg;
 
-    string affected_str = toString(affected());
+    string affected_str = ResolverInfo::toString(affected());
 
     switch (type()) {
 
@@ -263,7 +244,7 @@ ResolverInfoMisc::message (void) const
            // TranslatorExample: Updating foo-1.1 to foo-1.2
            // TranslatorExplanation: Just a progress indicator that something is scheduled for upgrade
            msg = str::form (_("Updating %s to %s"),
-                            toString (other()).c_str(),
+                            ResolverInfo::toString (other()).c_str(),
                             affected_str.c_str());
        }
        break;
@@ -302,7 +283,7 @@ ResolverInfoMisc::message (void) const
            // TranslatorExplanation: We just found out that 'foo' is not provided by anything else (an alternative)
            // TranslatorExplanation: removal of this resolvable would therefore break dependency
            // TranslatorExplanation: This is an error message explaining that the resolvable cannot be uninstalled
-           msg = str::form (_("There are no alternative installed providers of %s"), toString (_capability).c_str());
+           msg = str::form (_("There are no alternative installed providers of %s"), ResolverInfo::toString (_capability).c_str());
            if (affected()) {
                msg += " ";
                // Translator: 1.%s = name of package,patch....
@@ -327,7 +308,7 @@ ResolverInfoMisc::message (void) const
            // TranslatorExplanation: A resolvable is to be installed which requires foo
            // TranslatorExplanation: But there is nothing available to fulfill this requirement
            // TranslatorExplanation: This is an error message explaining that the resolvable cannot be installed
-           msg = str::form (_("There are no installable providers of %s"), toString (_capability).c_str());
+           msg = str::form (_("There are no installable providers of %s"), ResolverInfo::toString (_capability).c_str());
            if (affected()) {
                msg += " ";
                // Translator: 1.%s = name of package,patch....
@@ -351,7 +332,7 @@ ResolverInfoMisc::message (void) const
            // TranslatorExample: Upgrade to foo to avoid removing bar is not possible
            // TranslatorExplanation: bar requires something from foo
            msg = str::form (_("Upgrade to %s to avoid removing %s is not possible."),
-                                   toString (other()).c_str(),
+                                   ResolverInfo::toString (other()).c_str(),
                                    affected_str.c_str());
        }
        break;
@@ -367,8 +348,8 @@ ResolverInfoMisc::message (void) const
 
            // Translator: 1.%s = name of package,patch,...; 2.%s = dependency;
            msg = str::form (_("%s provides %s, but is scheduled to be uninstalled."),
-                            toString (other()).c_str(),
-                            toString (_capability).c_str());
+                            ResolverInfo::toString (other()).c_str(),
+                            ResolverInfo::toString (_capability).c_str());
        }
        break;
 
@@ -384,7 +365,7 @@ ResolverInfoMisc::message (void) const
            // Translator: 1.%s = name of package,patch,...; 2.%s = dependency; 3.%s type (package, patch, ...)
            msg = str::form (_("%s provides %s, but another version of that %s is already installed."),
                             other()->name().c_str(),
-                            toString (_capability).c_str(),
+                            ResolverInfo::toString (_capability).c_str(),
                             translateResTraits(other()->kind()).c_str());
        }
        break;
@@ -401,7 +382,7 @@ ResolverInfoMisc::message (void) const
            // Translator: 1.%s = name of package,patch,...; 2.%s = dependency;
            msg = str::form (_("%s provides %s, but it is uninstallable.  Try installing it on its own for more details."),
                             other()->name().c_str(),
-                            toString (_capability).c_str());
+                            ResolverInfo::toString (_capability).c_str());
        }
        break;
 
@@ -417,7 +398,7 @@ ResolverInfoMisc::message (void) const
            // Translator: 1.%s = name of package,patch,...; 2.%s = dependency;
            msg = str::form (_("%s provides %s, but it is locked."),
                             other()->name().c_str(),
-                            toString (_capability).c_str());
+                            ResolverInfo::toString (_capability).c_str());
        }
        break;
 
@@ -432,7 +413,7 @@ ResolverInfoMisc::message (void) const
 
            // Translator: 1.%s = dependency. 2.%s name of package, patch, ...
            msg = str::form (_("Can't satisfy requirement %s for %s"),
-                               toString (_capability).c_str(),
+                               ResolverInfo::toString (_capability).c_str(),
                                affected_str.c_str());
        }
        break;
@@ -506,8 +487,8 @@ ResolverInfoMisc::message (void) const
            // Translator: 1.%s and 2.%s = Dependency; 4.%s = name of package,patch,...
            // TranslatorExample: A conflict over foo (bar) requires the removal of to-be-installed xyz
            msg = str::form(_("A conflict over %s (%s) requires the removal of to-be-installed %s"),
-                           toString (_capability).c_str(),
-                           toString (_other_capability).c_str(),
+                           ResolverInfo::toString (_capability).c_str(),
+                           ResolverInfo::toString (_other_capability).c_str(),
                            affected_str.c_str());
        }
        break;
@@ -525,14 +506,14 @@ ResolverInfoMisc::message (void) const
            // TranslatorExample: Marking xyz as uninstallable due to conflicts over foo (bar)
            msg = str::form (_("Marking %s as uninstallable due to conflicts over %s"),
                                affected_str.c_str(),
-                               toString (_capability).c_str());
+                               ResolverInfo::toString (_capability).c_str());
            PoolItem_Ref  issuer = other();
            if (issuer) {
                msg += " ";
                // Translator: %s = name of package,patch
                // TranslatorExample: from abc
                msg += str::form (_("from %s"),
-                       toString (issuer).c_str());
+                       ResolverInfo::toString (issuer).c_str());
            }
        }
        break;
index ed0c6d0..e74c9c0 100644 (file)
@@ -50,7 +50,7 @@ ResolverInfoMissingReq::dumpOn( std::ostream & os ) const
     ResolverInfo::dumpOn (os);
 
     ostringstream affected_str;
-    affected_str << affected();
+    affected_str << ResolverInfo::toString (affected());
 
     ostringstream mis_str;
     mis_str << _missing;
index 0bab44a..cf0aff4 100644 (file)
@@ -50,7 +50,7 @@ ResolverInfoNeededBy::dumpOn( std::ostream & os ) const
     ResolverInfo::dumpOn (os);
 
     ostringstream affected_str;
-    affected_str << affected();
+    affected_str << ResolverInfo::toString (affected());
 
          // Translator: all.%s = name of package,patch,...
     os << str::form (_("%s is needed by %s"),
index 3adc8b0..d04e974 100644 (file)
@@ -49,7 +49,7 @@ ResolverInfoObsoletes::dumpOn( std::ostream & os ) const
     ResolverInfo::dumpOn (os);
 
     ostringstream affected_str;
-    affected_str << affected();
+    affected_str << ResolverInfo::toString (affected());
 
     // Translator: all.%s = name of package,patch,....
     os << str::form (_("%s is replaced by %s"),