Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- namespace Nio
- {
- namespace Managers
- {
- template<class Type> class Manager
- {
- protected:
- std::vector<Type> objects;
- std::function<Type(const std::string&)> construct;
- public:
- inline Manager(const std::function<Type(const std::string&)> &construct = [](const std::string &name) -> Type { return Type(name); }) :
- construct(construct)
- {
- }
- inline ~Manager()
- {
- }
- inline Type& add(const std::string &name)
- {
- this->objects.push_back(this->construct(name));
- return *(this->objects.back());
- }
- inline Type& get(const std::string &name)
- {
- typename std::vector<Type>::iterator index = std::find_if(this->objects.begin(), this->objects.end(), [name](const Type &object)
- {
- if (object.getName() == name) return true;
- return false;
- });
- if (index == this->objects.end()) return this->add(name);
- return *index;
- }
- };
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement