#include "BlockType.hpp"
+#include <map>
+#include <string>
#include <vector>
class BlockTypeRegistry {
public:
- BlockTypeRegistry();
+ using size_type = std::vector<BlockType>::size_type;
+ using reference = std::vector<BlockType>::reference;
+ using const_reference = std::vector<BlockType>::const_reference;
+ using iterator = std::vector<BlockType>::iterator;
+ using const_iterator = std::vector<BlockType>::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<BlockType> types;
+ std::map<std::string, Block::Type> names;
};