mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-29 17:16:15 +02:00
bc83b9dc1f
Known behavior changes: - `MemorySourceAccessor`'s comparison operators no longer forget to compare the `SourceAccessor` base class. Progress on #10832 What remains for that issue is hopefully much easier!
71 lines
2.2 KiB
C++
71 lines
2.2 KiB
C++
#include "derived-path-map.hh"
|
|
#include "util.hh"
|
|
|
|
namespace nix {
|
|
|
|
template<typename V>
|
|
typename DerivedPathMap<V>::ChildNode & DerivedPathMap<V>::ensureSlot(const SingleDerivedPath & k)
|
|
{
|
|
std::function<ChildNode &(const SingleDerivedPath & )> initIter;
|
|
initIter = [&](const auto & k) -> auto & {
|
|
return std::visit(overloaded {
|
|
[&](const SingleDerivedPath::Opaque & bo) -> auto & {
|
|
// will not overwrite if already there
|
|
return map[bo.path];
|
|
},
|
|
[&](const SingleDerivedPath::Built & bfd) -> auto & {
|
|
auto & n = initIter(*bfd.drvPath);
|
|
return n.childMap[bfd.output];
|
|
},
|
|
}, k.raw());
|
|
};
|
|
return initIter(k);
|
|
}
|
|
|
|
template<typename V>
|
|
typename DerivedPathMap<V>::ChildNode * DerivedPathMap<V>::findSlot(const SingleDerivedPath & k)
|
|
{
|
|
std::function<ChildNode *(const SingleDerivedPath & )> initIter;
|
|
initIter = [&](const auto & k) {
|
|
return std::visit(overloaded {
|
|
[&](const SingleDerivedPath::Opaque & bo) {
|
|
auto it = map.find(bo.path);
|
|
return it != map.end()
|
|
? &it->second
|
|
: nullptr;
|
|
},
|
|
[&](const SingleDerivedPath::Built & bfd) {
|
|
auto * n = initIter(*bfd.drvPath);
|
|
if (!n) return (ChildNode *)nullptr;
|
|
|
|
auto it = n->childMap.find(bfd.output);
|
|
return it != n->childMap.end()
|
|
? &it->second
|
|
: nullptr;
|
|
},
|
|
}, k.raw());
|
|
};
|
|
return initIter(k);
|
|
}
|
|
|
|
}
|
|
|
|
// instantiations
|
|
|
|
namespace nix {
|
|
|
|
template<>
|
|
bool DerivedPathMap<std::set<std::string>>::ChildNode::operator == (
|
|
const DerivedPathMap<std::set<std::string>>::ChildNode &) const noexcept = default;
|
|
|
|
// TODO libc++ 16 (used by darwin) missing `std::map::operator <=>`, can't do yet.
|
|
#if 0
|
|
template<>
|
|
std::strong_ordering DerivedPathMap<std::set<std::string>>::ChildNode::operator <=> (
|
|
const DerivedPathMap<std::set<std::string>>::ChildNode &) const noexcept = default;
|
|
#endif
|
|
|
|
template struct DerivedPathMap<std::set<std::string>>::ChildNode;
|
|
template struct DerivedPathMap<std::set<std::string>>;
|
|
|
|
};
|