X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fworld%2FBlockTypeRegistry.hpp;h=23b183a1b1cf765a390d920bc9b41278f7500fd5;hb=b94a7dc7daad9ae9be90a39d723e332dae375325;hp=0a1ebf0ebc4f31a369fdc5eada961d12eef4d093;hpb=b7d09e1e35ef90282c97509e0020b20db3c7ea9f;p=blank.git diff --git a/src/world/BlockTypeRegistry.hpp b/src/world/BlockTypeRegistry.hpp index 0a1ebf0..23b183a 100644 --- a/src/world/BlockTypeRegistry.hpp +++ b/src/world/BlockTypeRegistry.hpp @@ -3,6 +3,8 @@ #include "BlockType.hpp" +#include +#include #include @@ -11,18 +13,40 @@ namespace blank { class BlockTypeRegistry { public: - BlockTypeRegistry(); + using size_type = std::vector::size_type; + using reference = std::vector::reference; + using const_reference = std::vector::const_reference; + using iterator = std::vector::iterator; + using const_iterator = std::vector::const_iterator; public: - Block::Type Add(const BlockType &); + BlockTypeRegistry(); + + /// register a new block type + /// this may throw if the name is already taken (names must be unique) + Block::Type Add(BlockType &&); + + size_t size() const noexcept { return types.size(); } + + iterator begin() noexcept { return types.begin(); } + const_iterator begin() const noexcept { return types.begin(); } + iterator end() noexcept { return types.end(); } + const_iterator end() const noexcept { return types.end(); } + + /// lookup by ID + BlockType &operator [](Block::Type id) noexcept { return types[id]; } + const BlockType &operator [](Block::Type id) const noexcept { return types[id]; } - size_t Size() const noexcept { return types.size(); } + BlockType &Get(Block::Type id) noexcept { return types[id]; } + const BlockType &Get(Block::Type id) const noexcept { return types[id]; } - BlockType &operator [](Block::Type id) { return types[id]; } - const BlockType &Get(Block::Type id) const { return types[id]; } + /// lookup by name + BlockType &Get(const std::string &name); + const BlockType &Get(const std::string &name) const; private: std::vector types; + std::map names; };