From 8b5370313dcc00a45ea5c3e8b4c497bc00fd8e13 Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Tue, 11 Jun 2013 21:55:13 -0700 Subject: Allegedly remove all manual memory management --- src/common/intern-pool.hpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/common/intern-pool.hpp (limited to 'src/common/intern-pool.hpp') diff --git a/src/common/intern-pool.hpp b/src/common/intern-pool.hpp new file mode 100644 index 0000000..caa54e4 --- /dev/null +++ b/src/common/intern-pool.hpp @@ -0,0 +1,35 @@ +#ifndef INTERN_POOL_HPP +#define INTERN_POOL_HPP + +#include + +#include +#include +#include + +class InternPool +{ + std::map known; + std::vector names; +public: + size_t intern(const std::string& name) + { + auto pair = known.insert({name, known.size()}); + if (pair.second) + names.push_back(name); + assert (known.size() == names.size()); + return pair.first->second; + } + + const std::string& outtern(size_t sz) const + { + return names[sz]; + } + + size_t size() const + { + return known.size(); + } +}; + +#endif //INTERN_POOL_HPP -- cgit v1.2.3-60-g2f50