1 /* 2 * Copyright 2013, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Ingo Weinhold <ingo_weinhold@gmx.de> 7 */ 8 9 10 #include <Catalog.h> 11 12 #include <package/solver/SolverProblem.h> 13 14 #include <package/solver/SolverPackage.h> 15 #include <package/solver/SolverProblemSolution.h> 16 17 18 #undef B_TRANSLATION_CONTEXT 19 #define B_TRANSLATION_CONTEXT "SolverProblem" 20 21 22 static const char* const kToStringTexts[] = { 23 B_TRANSLATE_MARK("unspecified problem"), 24 B_TRANSLATE_MARK("%source% does not belong to a distupgrade repository"), 25 B_TRANSLATE_MARK("%source% has inferior architecture"), 26 B_TRANSLATE_MARK("problem with installed package %source%"), 27 B_TRANSLATE_MARK("conflicting requests"), 28 B_TRANSLATE_MARK("nothing provides requested %dependency%"), 29 B_TRANSLATE_MARK("%dependency% is provided by the system"), 30 B_TRANSLATE_MARK("dependency problem"), 31 B_TRANSLATE_MARK("package %source% is not installable"), 32 B_TRANSLATE_MARK("nothing provides %dependency% needed by %source%"), 33 B_TRANSLATE_MARK("cannot install both %source% and %target%"), 34 B_TRANSLATE_MARK("package %source% conflicts with %dependency% provided " 35 "by %target%"), 36 B_TRANSLATE_MARK("package %source% obsoletes %dependency% provided by " 37 "%target%"), 38 B_TRANSLATE_MARK("installed package %source% obsoletes %dependency% " 39 "provided by %target%"), 40 B_TRANSLATE_MARK("package %source% implicitly obsoletes %dependency% " 41 "provided by %target%"), 42 B_TRANSLATE_MARK("package %source% requires %dependency%, but none of the " 43 "providers can be installed"), 44 B_TRANSLATE_MARK("package %source% conflicts with %dependency% provided by " 45 "itself") 46 }; 47 48 49 namespace BPackageKit { 50 51 52 BSolverProblem::BSolverProblem(BType type, BSolverPackage* sourcePackage, 53 BSolverPackage* targetPackage) 54 : 55 fType(type), 56 fSourcePackage(sourcePackage), 57 fTargetPackage(targetPackage), 58 fDependency(), 59 fSolutions(10, true) 60 { 61 } 62 63 64 BSolverProblem::BSolverProblem(BType type, BSolverPackage* sourcePackage, 65 BSolverPackage* targetPackage, 66 const BPackageResolvableExpression& dependency) 67 : 68 fType(type), 69 fSourcePackage(sourcePackage), 70 fTargetPackage(targetPackage), 71 fDependency(dependency), 72 fSolutions(10, true) 73 { 74 } 75 76 77 BSolverProblem::~BSolverProblem() 78 { 79 } 80 81 82 BSolverProblem::BType 83 BSolverProblem::Type() const 84 { 85 return fType; 86 } 87 88 89 BSolverPackage* 90 BSolverProblem::SourcePackage() const 91 { 92 return fSourcePackage; 93 } 94 95 96 BSolverPackage* 97 BSolverProblem::TargetPackage() const 98 { 99 return fTargetPackage; 100 } 101 102 103 const BPackageResolvableExpression& 104 BSolverProblem::Dependency() const 105 { 106 return fDependency; 107 } 108 109 110 int32 111 BSolverProblem::CountSolutions() const 112 { 113 return fSolutions.CountItems(); 114 } 115 116 117 const BSolverProblemSolution* 118 BSolverProblem::SolutionAt(int32 index) const 119 { 120 return fSolutions.ItemAt(index); 121 } 122 123 124 bool 125 BSolverProblem::AppendSolution(BSolverProblemSolution* solution) 126 { 127 return fSolutions.AddItem(solution); 128 } 129 130 131 BString 132 BSolverProblem::ToString() const 133 { 134 size_t index = fType; 135 if (index >= sizeof(kToStringTexts) / sizeof(kToStringTexts[0])) 136 index = 0; 137 138 return BString(B_TRANSLATE_NOCOLLECT(kToStringTexts[index])) 139 .ReplaceAll("%source%", 140 fSourcePackage != NULL 141 ? fSourcePackage->VersionedName().String() : "?") 142 .ReplaceAll("%target%", 143 fTargetPackage != NULL 144 ? fTargetPackage->VersionedName().String() : "?") 145 .ReplaceAll("%dependency%", 146 fDependency.InitCheck() == B_OK 147 ? fDependency.ToString().String() : "?"); 148 } 149 150 151 } // namespace BPackageKit 152