2 * Copyright 2013, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
6 * Ingo Weinhold <ingo_weinhold@gmx.de>
10 #include <package/solver/SolverProblemSolution.h>
12 #include <package/solver/SolverPackage.h>
15 static const char* const kToStringTexts
[] = {
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",
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
)
51 fSourcePackage(sourcePackage
),
52 fTargetPackage(targetPackage
),
58 BSolverProblemSolutionElement::~BSolverProblemSolutionElement()
63 BSolverProblemSolutionElement::BType
64 BSolverProblemSolutionElement::Type() const
71 BSolverProblemSolutionElement::SourcePackage() const
73 return fSourcePackage
;
78 BSolverProblemSolutionElement::TargetPackage() const
80 return fTargetPackage
;
85 BSolverProblemSolutionElement::Selection() const
92 BSolverProblemSolutionElement::ToString() const
95 if (index
>= sizeof(kToStringTexts
) / sizeof(kToStringTexts
[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()
125 BSolverProblemSolution::~BSolverProblemSolution()
131 BSolverProblemSolution::CountElements() const
133 return fElements
.CountItems();
137 const BSolverProblemSolution::Element
*
138 BSolverProblemSolution::ElementAt(int32 index
) const
140 return fElements
.ItemAt(index
);
145 BSolverProblemSolution::AppendElement(const Element
& element
)
147 Element
* newElement
= new(std::nothrow
) Element(element
);
148 if (newElement
== NULL
|| !fElements
.AddItem(newElement
)) {
157 } // namespace BPackageKit