BPicture: Fix archive constructor.
[haiku.git] / src / kits / package / solver / SolverProblemSolution.cpp
blob26cf36f91fc7632bd2e9fa74b8985012455994b7
1 /*
2 * Copyright 2013, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Ingo Weinhold <ingo_weinhold@gmx.de>
7 */
10 #include <package/solver/SolverProblemSolution.h>
12 #include <package/solver/SolverPackage.h>
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%"
40 namespace BPackageKit {
43 // #pragma mark - BSolverProblemSolutionElement
46 BSolverProblemSolutionElement::BSolverProblemSolutionElement(BType type,
47 BSolverPackage* sourcePackage, BSolverPackage* targetPackage,
48 const BString& selection)
50 fType(type),
51 fSourcePackage(sourcePackage),
52 fTargetPackage(targetPackage),
53 fSelection(selection)
58 BSolverProblemSolutionElement::~BSolverProblemSolutionElement()
63 BSolverProblemSolutionElement::BType
64 BSolverProblemSolutionElement::Type() const
66 return fType;
70 BSolverPackage*
71 BSolverProblemSolutionElement::SourcePackage() const
73 return fSourcePackage;
77 BSolverPackage*
78 BSolverProblemSolutionElement::TargetPackage() const
80 return fTargetPackage;
84 const BString&
85 BSolverProblemSolutionElement::Selection() const
87 return fSelection;
91 BString
92 BSolverProblemSolutionElement::ToString() const
94 size_t index = fType;
95 if (index >= sizeof(kToStringTexts) / sizeof(kToStringTexts[0]))
96 index = 0;
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() : "?");
115 // #pragma mark - BSolverProblemSolution
118 BSolverProblemSolution::BSolverProblemSolution()
120 fElements(10, true)
125 BSolverProblemSolution::~BSolverProblemSolution()
130 int32
131 BSolverProblemSolution::CountElements() const
133 return fElements.CountItems();
137 const BSolverProblemSolution::Element*
138 BSolverProblemSolution::ElementAt(int32 index) const
140 return fElements.ItemAt(index);
144 bool
145 BSolverProblemSolution::AppendElement(const Element& element)
147 Element* newElement = new(std::nothrow) Element(element);
148 if (newElement == NULL || !fElements.AddItem(newElement)) {
149 delete newElement;
150 return false;
153 return true;
157 } // namespace BPackageKit