1 #ifndef BLANK_WORLD_BLOCKTYPEREGISTRY_HPP_
2 #define BLANK_WORLD_BLOCKTYPEREGISTRY_HPP_
4 #include "BlockType.hpp"
13 class BlockTypeRegistry {
16 using size_type = std::vector<BlockType>::size_type;
17 using reference = std::vector<BlockType>::reference;
18 using const_reference = std::vector<BlockType>::const_reference;
19 using iterator = std::vector<BlockType>::iterator;
20 using const_iterator = std::vector<BlockType>::const_iterator;
25 /// register a new block type
26 /// this may throw if the name is already taken (names must be unique)
27 Block::Type Add(BlockType &&);
29 size_t size() const noexcept { return types.size(); }
31 iterator begin() noexcept { return types.begin(); }
32 const_iterator begin() const noexcept { return types.begin(); }
33 iterator end() noexcept { return types.end(); }
34 const_iterator end() const noexcept { return types.end(); }
37 BlockType &operator [](Block::Type id) noexcept { return types[id]; }
38 const BlockType &operator [](Block::Type id) const noexcept { return types[id]; }
40 BlockType &Get(Block::Type id) noexcept { return types[id]; }
41 const BlockType &Get(Block::Type id) const noexcept { return types[id]; }
44 BlockType &Get(const std::string &name);
45 const BlockType &Get(const std::string &name) const;
48 std::vector<BlockType> types;
49 std::map<std::string, Block::Type> names;