/** ** \file parse/metavar-map.hxx ** \brief Implementation of parse::MetavarMap. */ #pragma once #include #include #include #include #include namespace parse { template MetavarMap::MetavarMap(const std::string& name) : name_(name) , map_() {} template MetavarMap::~MetavarMap() { // At this point, every metavariable should have been taken from the map. assertion(map_.empty()) << *this << "not empty, aborting.\n"; } template std::string MetavarMap::show(unsigned key) const { return '_' + name_ + '(' + std::to_string(key) + ')'; } template std::ostream& MetavarMap::dump(std::ostream& ostr) const { ostr << "MetavarMap<" << name_ << "> = ["; if (map_.empty()) return ostr << " ]" << misc::iendl; ostr << misc::incindent; for (const auto& [k, v] : map_) ostr << misc::iendl << show(k) << " -> " << v; return ostr << misc::decendl << "]" << misc::iendl; } template std::string MetavarMap::append_(unsigned& count, Data* data) { map_[count] = data; return show(count++); } template Data* MetavarMap::take_(unsigned key) { return map_.take(key); } template std::ostream& operator<<(std::ostream& ostr, const MetavarMap& m) { return m.dump(ostr); } } // namespace parse