Branching from Cathaswatch project
https://git.nerdyssey.de/exodus/1NiM-WatingRoom-WatchController
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace spit {
|
||||
|
||||
template <typename T>
|
||||
class SpitRepo {
|
||||
public:
|
||||
bool hasEntry(const string &id) {
|
||||
return mEntries.contains(id);
|
||||
}
|
||||
|
||||
T *getEntry(const string &id) {
|
||||
auto i = mEntries.find(id);
|
||||
if (i == mEntries.end()) {
|
||||
return nullptr;
|
||||
}
|
||||
return i->second.get();
|
||||
}
|
||||
const T &getEntryRef(const string &id) {
|
||||
return *mEntries.at(id);
|
||||
}
|
||||
|
||||
void addEntry(unique_ptr<T> entry) {
|
||||
mEntries[entry->getID()] = move(entry);
|
||||
}
|
||||
bool removeEntry(const T &entry) {
|
||||
return removeEntry(entry.getID());
|
||||
}
|
||||
bool removeEntry(const string &id) {
|
||||
auto i = mEntries.find(id);
|
||||
if (i == mEntries.end()) {
|
||||
return false;
|
||||
}
|
||||
mEntries.erase(i);
|
||||
return true;
|
||||
}
|
||||
int getSize() {
|
||||
return mEntries.size();
|
||||
}
|
||||
|
||||
unordered_map<string, unique_ptr<T>> &getRepo() {
|
||||
return mEntries;
|
||||
}
|
||||
|
||||
void clearEntries() {
|
||||
mEntries.clear();
|
||||
}
|
||||
|
||||
private:
|
||||
unordered_map<string, unique_ptr<T>> mEntries;
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user