summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Andres Klode <julian.klode@canonical.com>2025-02-06 12:28:57 +0100
committerJulian Andres Klode <julian.klode@canonical.com>2025-02-07 20:59:43 +0100
commit8f4c09bb58b047a73328f935b9abeb4fe0b03ae1 (patch)
tree370537ff8892f76d35d878547a64e2c2e4d8126e
parentecb1399ca5f4917286d354b00dadb91c8075db1d (diff)
solver3: Add const where helpful
operator[] is a bit annoying here, but oh well, what can we do?
-rw-r--r--apt-pkg/solver3.cc8
-rw-r--r--apt-pkg/solver3.h26
2 files changed, 24 insertions, 10 deletions
diff --git a/apt-pkg/solver3.cc b/apt-pkg/solver3.cc
index f402d1ba3..36bdd9aeb 100644
--- a/apt-pkg/solver3.cc
+++ b/apt-pkg/solver3.cc
@@ -229,7 +229,7 @@ bool APT::Solver::Work::operator<(APT::Solver::Work const &b) const
return false;
}
-std::string APT::Solver::Clause::toString(pkgCache &cache)
+std::string APT::Solver::Clause::toString(pkgCache &cache) const
{
std::string out;
if (auto Pkg = reason.Pkg(cache); not Pkg.end())
@@ -242,7 +242,7 @@ std::string APT::Solver::Clause::toString(pkgCache &cache)
return out;
}
-std::string APT::Solver::Work::toString(pkgCache &cache)
+std::string APT::Solver::Work::toString(pkgCache &cache) const
{
std::ostringstream out;
if (erased)
@@ -255,7 +255,7 @@ std::string APT::Solver::Work::toString(pkgCache &cache)
}
// Prints an implication graph part of the form A -> B -> C, possibly with "not"
-std::string APT::Solver::WhyStr(Var reason)
+std::string APT::Solver::WhyStr(Var reason) const
{
std::vector<std::string> out;
@@ -997,7 +997,7 @@ bool APT::Solver::FromDepCache(pkgDepCache &depcache)
return Propagate();
}
-bool APT::Solver::ToDepCache(pkgDepCache &depcache)
+bool APT::Solver::ToDepCache(pkgDepCache &depcache) const
{
pkgDepCache::ActionGroup group(depcache);
for (auto P = cache.PkgBegin(); not P.end(); P++)
diff --git a/apt-pkg/solver3.h b/apt-pkg/solver3.h
index bbe3f3d56..9059552b7 100644
--- a/apt-pkg/solver3.h
+++ b/apt-pkg/solver3.h
@@ -105,14 +105,23 @@ class Solver
{
return pkgStates[P->ID];
}
+ inline const State &operator[](pkgCache::Package *P) const
+ {
+ return pkgStates[P->ID];
+ }
// \brief Helper function for safe access to version state.
inline State &operator[](pkgCache::Version *V)
{
return verStates[V->ID];
}
+ inline const State &operator[](pkgCache::Version *V) const
+ {
+ return verStates[V->ID];
+ }
// \brief Helper function for safe access to either state.
inline State &operator[](Var r);
+ inline const State &operator[](Var r) const;
mutable std::vector<char> pkgObsolete;
bool Obsolete(pkgCache::PkgIterator pkg) const;
@@ -221,13 +230,13 @@ class Solver
// \brief Apply the selections from the dep cache to the solver
[[nodiscard]] bool FromDepCache(pkgDepCache &depcache);
// \brief Apply the solver result to the depCache
- [[nodiscard]] bool ToDepCache(pkgDepCache &depcache);
+ [[nodiscard]] bool ToDepCache(pkgDepCache &depcache) const;
// \brief Solve the dependencies
[[nodiscard]] bool Solve();
// Print dependency chain
- std::string WhyStr(Var reason);
+ std::string WhyStr(Var reason) const;
};
}; // namespace APT
@@ -319,7 +328,7 @@ struct APT::Solver::Clause
inline Clause(Var reason, Group group, bool optional = false, bool negative = false) : reason(reason), group(group), optional(optional), negative(negative) {}
- std::string toString(pkgCache &cache);
+ std::string toString(pkgCache &cache) const;
};
/**
@@ -334,7 +343,7 @@ struct APT::Solver::Clause
*/
struct APT::Solver::Work
{
- Clause *clause;
+ const Clause *clause;
// \brief The depth at which the item has been added
depth_type depth;
@@ -353,8 +362,8 @@ struct APT::Solver::Work
bool erased{false};
bool operator<(APT::Solver::Work const &b) const;
- std::string toString(pkgCache &cache);
- inline Work(Clause *clause, depth_type depth) : clause(clause), depth(depth) {}
+ std::string toString(pkgCache &cache) const;
+ inline Work(const Clause *clause, depth_type depth) : clause(clause), depth(depth) {}
};
// \brief This essentially describes the install state in RFC2119 terms.
@@ -429,3 +438,8 @@ inline APT::Solver::State &APT::Solver::operator[](Var r)
return (*this)[cache.VerP + V];
return *rootState.get();
}
+
+inline const APT::Solver::State &APT::Solver::operator[](Var r) const
+{
+ return const_cast<Solver &>(*this)[r];
+}