/** \file misc/scoped-map.hxx ** \brief Implementation of misc::scoped_map. */ #include #pragma once #include #include #include #include #include #include #include namespace misc { // FIXME DONE: Some code was deleted here. template void scoped_map::put(const Key& key, const Data& value) { scopes_.back().insert_or_assign(key, value); } template Data scoped_map::get(const Key& key) const requires(std::is_pointer_v) { if (auto data = scopes_.back().find(key); data != scopes_.back().end()) return data->second; return nullptr; } template Data scoped_map::get(const Key& key) const requires(!std::is_pointer_v) { if (auto data = scopes_.back().find(key); data != scopes_.back().end()) return data->second; throw std::range_error("Key is not in scope."); } template std::ostream& scoped_map::dump(std::ostream& ostr) const { ostr << "Printing\n"; const char* sep = "-------------------------\n"; int depth = 0; for (auto scope : scopes_) { ostr << sep << "Scope " << depth++ << incendl; for (auto kvp : scope) { ostr << kvp.first << " -> " << kvp.second << iendl; } ostr << decendl << sep; } ostr << "endprint\n"; return ostr; } template void scoped_map::scope_begin() { std::map new_scope; for (auto kvp : scopes_.back()) { new_scope.insert_or_assign(kvp.first, kvp.second); } scopes_.push_back(new_scope); } template void scoped_map::scope_end() { scopes_.pop_back(); } template inline std::ostream& operator<<(std::ostream& ostr, const scoped_map& tbl) { return tbl.dump(ostr); } } // namespace misc