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 <package/solver/SolverProblemSolution.h> 11 12 #include <package/solver/SolverPackage.h> 13 14 15 static const char* const kToStringTexts[] = { 16 "do something", 17 "do not keep %source% installed", 18 "do not install \"%selection%\"", 19 "do not install the most recent version of \"%selection%\"", 20 "do not forbid installation of %source%", 21 "do not deinstall \"%selection%\"", 22 "do not deinstall all resolvables \"%selection%\"", 23 "do not lock \"%selection%\"", 24 "keep %source% despite its inferior architecture", 25 "keep %source% from excluded repository", 26 "keep old %source%", 27 "install %source% despite its inferior architecture", 28 "install %source% from excluded repository", 29 "install %selection% despite its old version", 30 "allow downgrade of %source% to %target%", 31 "allow name change of %source% to %target%", 32 "allow architecture change of %source% to %target%", 33 "allow vendor change from \"%sourceVendor%\" (%source%) to " 34 "\"%targetVendor%\" (%target%)", 35 "allow replacement of %source% with %target%", 36 "allow deinstallation of %source%" 37 }; 38 39 40 namespace BPackageKit { 41 42 43 // #pragma mark - BSolverProblemSolutionElement 44 45 46 BSolverProblemSolutionElement::BSolverProblemSolutionElement(BType type, 47 BSolverPackage* sourcePackage, BSolverPackage* targetPackage, 48 const BString& selection) 49 : 50 fType(type), 51 fSourcePackage(sourcePackage), 52 fTargetPackage(targetPackage), 53 fSelection(selection) 54 { 55 } 56 57 58 BSolverProblemSolutionElement::~BSolverProblemSolutionElement() 59 { 60 } 61 62 63 BSolverProblemSolutionElement::BType 64 BSolverProblemSolutionElement::Type() const 65 { 66 return fType; 67 } 68 69 70 BSolverPackage* 71 BSolverProblemSolutionElement::SourcePackage() const 72 { 73 return fSourcePackage; 74 } 75 76 77 BSolverPackage* 78 BSolverProblemSolutionElement::TargetPackage() const 79 { 80 return fTargetPackage; 81 } 82 83 84 const BString& 85 BSolverProblemSolutionElement::Selection() const 86 { 87 return fSelection; 88 } 89 90 91 BString 92 BSolverProblemSolutionElement::ToString() const 93 { 94 size_t index = fType; 95 if (index >= sizeof(kToStringTexts) / sizeof(kToStringTexts[0])) 96 index = 0; 97 98 return BString(kToStringTexts[index]) 99 .ReplaceAll("%source%", 100 fSourcePackage != NULL 101 ? fSourcePackage->VersionedName().String() : "?") 102 .ReplaceAll("%target%", 103 fTargetPackage != NULL 104 ? fTargetPackage->VersionedName().String() : "?") 105 .ReplaceAll("%selection%", fSelection) 106 .ReplaceAll("%sourceVendor%", 107 fSourcePackage != NULL 108 ? fSourcePackage->Info().Vendor().String() : "?") 109 .ReplaceAll("%targetVendor%", 110 fTargetPackage != NULL 111 ? fTargetPackage->Info().Vendor().String() : "?"); 112 } 113 114 115 // #pragma mark - BSolverProblemSolution 116 117 118 BSolverProblemSolution::BSolverProblemSolution() 119 : 120 fElements(10, true) 121 { 122 } 123 124 125 BSolverProblemSolution::~BSolverProblemSolution() 126 { 127 } 128 129 130 int32 131 BSolverProblemSolution::CountElements() const 132 { 133 return fElements.CountItems(); 134 } 135 136 137 const BSolverProblemSolution::Element* 138 BSolverProblemSolution::ElementAt(int32 index) const 139 { 140 return fElements.ItemAt(index); 141 } 142 143 144 bool 145 BSolverProblemSolution::AppendElement(const Element& element) 146 { 147 Element* newElement = new(std::nothrow) Element(element); 148 if (newElement == NULL || !fElements.AddItem(newElement)) { 149 delete newElement; 150 return false; 151 } 152 153 return true; 154 } 155 156 157 } // namespace BPackageKit 158