#pragma once #include #include "property.hpp" class Properties { using props_t = std::map; public: props_t::iterator find(const std::string& key) { return props.find(key); } Property* at(const std::string& key) { auto it = props.find(key); return it == props.end() ? nullptr : it->second.get(); } template void set(const std::string& key, Args&&... args) { auto value = std::make_shared(std::forward(args)...); // try to emplace the item auto result = props.emplace(std::make_pair(key, value)); // return if we succedded if(result.second) return; // the key already exists, replace the value it holds result.first->second = std::move(value); } void set(const std::string& key, Property::sptr value) { props[key] = std::move(value); } void clear(const std::string& key) { props.erase(key); } template void accept(Handler& handler) const { bool first = true; for(auto& kv : props) { handler.handle(kv.first, *kv.second, first); if(first) first = false; } } private: props_t props; };