refactor repo
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
|
||||
#include "SPITType.h"
|
||||
#include "spit_message.hpp"
|
||||
#include "SpitRepo.hpp"
|
||||
#include "spit_repo.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace spit;
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
#include "SPITSocket.h"
|
||||
#include "spit_message.hpp"
|
||||
#include "SpitRepo.hpp"
|
||||
#include "spit_repo.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace spit;
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include "SPITSocket.h"
|
||||
#include "SPITType.h"
|
||||
#include "spit_message.hpp"
|
||||
#include "SpitRepo.hpp"
|
||||
#include "spit_repo.hpp"
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
|
||||
@@ -3,6 +3,10 @@
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace spit {
|
||||
|
||||
template <typename T>
|
||||
class SpitRepo {
|
||||
public:
|
||||
@@ -10,33 +14,17 @@ class SpitRepo {
|
||||
return mEntries.contains(id);
|
||||
}
|
||||
|
||||
T *getEntry(const string &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);
|
||||
}
|
||||
|
||||
T *getEntry(int index) {
|
||||
if (index >= 0 && index < mEntries.size()) {
|
||||
return next(mEntries.begin(), index)->second.get();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
const T &getEntryRef(int index) {
|
||||
if (index >= 0 && index < mEntries.size()) {
|
||||
auto i = next(mEntries.begin(), index);
|
||||
return *i->second;
|
||||
} else {
|
||||
throw "SPITObject index out of range";
|
||||
}
|
||||
}
|
||||
|
||||
void addEntry(unique_ptr<T> entry) {
|
||||
mEntries[entry->getID()] = move(entry);
|
||||
}
|
||||
@@ -51,7 +39,7 @@ class SpitRepo {
|
||||
mEntries.erase(i);
|
||||
return true;
|
||||
}
|
||||
int getEntryCount() {
|
||||
int getSize() {
|
||||
return mEntries.size();
|
||||
}
|
||||
|
||||
@@ -66,3 +54,5 @@ class SpitRepo {
|
||||
private:
|
||||
unordered_map<string, unique_ptr<T>> mEntries;
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user