]> git.localhorst.tv Git - blank.git/blob - src/model/ModelRegistry.hpp
new gcc version
[blank.git] / src / model / ModelRegistry.hpp
1 #ifndef BLANK_MODEL_MODELREGISTRY_HPP_
2 #define BLANK_MODEL_MODELREGISTRY_HPP_
3
4 #include "Model.hpp"
5
6 #include <cstdint>
7 #include <map>
8 #include <memory>
9 #include <string>
10 #include <vector>
11
12
13 namespace blank {
14
15 class ModelRegistry {
16
17 public:
18         using size_type = std::size_t;
19         using reference = Model &;
20         using const_reference = const Model &;
21
22 public:
23         ModelRegistry();
24
25         reference Add(const std::string &);
26
27         size_type size() const noexcept { return models.size(); }
28
29         // by offset
30         reference operator[](size_type i) noexcept { return *models[i]; }
31         const_reference operator[](size_type i) const noexcept { return *models[i]; }
32         // by ID
33         reference Get(std::uint16_t i) { return *models[i - 1]; }
34         const_reference Get(std::uint16_t i) const { return *models[i - 1]; }
35         // by name
36         reference Get(const std::string &);
37         const_reference Get(const std::string &) const;
38
39 private:
40         std::vector<std::unique_ptr<Model>> models;
41         std::map<std::string, Model *> name_index;
42
43 };
44
45 }
46
47 #endif