1 #ifndef BLOBS_WORLD_SET_HPP_
2 #define BLOBS_WORLD_SET_HPP_
16 int Add(const Type &t) {
17 int id = types.size();
18 if (!names.emplace(t.name, id).second) {
19 throw std::runtime_error("duplicate type name " + t.name);
21 types.emplace_back(t);
26 Type &operator [](int id) noexcept { return types[id]; }
27 const Type &operator [](int id) const noexcept { return types[id]; }
29 Type &operator [](const std::string &name) {
30 auto entry = names.find(name);
31 if (entry != names.end()) {
32 return types[entry->second];
34 throw std::runtime_error("unknown type " + name);
37 const Type &operator [](const std::string &name) const {
38 auto entry = names.find(name);
39 if (entry != names.end()) {
40 return types[entry->second];
42 throw std::runtime_error("unknown type " + name);
47 std::vector<Type> types;
48 std::map<std::string, int> names;