diff options
| author | Julian Andres Klode <julian.klode@canonical.com> | 2025-02-06 12:28:57 +0100 |
|---|---|---|
| committer | Julian Andres Klode <julian.klode@canonical.com> | 2025-02-07 20:59:43 +0100 |
| commit | 8f4c09bb58b047a73328f935b9abeb4fe0b03ae1 (patch) | |
| tree | 370537ff8892f76d35d878547a64e2c2e4d8126e /apt-pkg/solver3.h | |
| parent | ecb1399ca5f4917286d354b00dadb91c8075db1d (diff) | |
solver3: Add const where helpful
operator[] is a bit annoying here, but oh well, what can we
do?
Diffstat (limited to 'apt-pkg/solver3.h')
| -rw-r--r-- | apt-pkg/solver3.h | 26 |
1 files changed, 20 insertions, 6 deletions
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]; +} |
