X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fworld%2FBlockTypeRegistry.hpp;h=23b183a1b1cf765a390d920bc9b41278f7500fd5;hb=b3c37033944671429f8db22c3754caef7add1695;hp=38afac4b6be98b18a8ad2273d284bf5e7a18f14d;hpb=ad7cf72ed47c39640d5588ba53386e090289b4d1;p=blank.git diff --git a/src/world/BlockTypeRegistry.hpp b/src/world/BlockTypeRegistry.hpp index 38afac4..23b183a 100644 --- a/src/world/BlockTypeRegistry.hpp +++ b/src/world/BlockTypeRegistry.hpp @@ -3,6 +3,8 @@ #include "BlockType.hpp" +#include +#include #include @@ -11,21 +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(); } - size_t Size() const noexcept { return types.size(); } + /// lookup by ID + BlockType &operator [](Block::Type id) noexcept { return types[id]; } + const BlockType &operator [](Block::Type id) const noexcept { return types[id]; } - BlockType &operator [](Block::Type id) { return types[id]; } - const BlockType &operator [](Block::Type id) const { return types[id]; } + BlockType &Get(Block::Type id) noexcept { return types[id]; } + const BlockType &Get(Block::Type id) const noexcept { return types[id]; } - BlockType &Get(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; };