8 #include "observerpattern/ObserverTable.hpp" 9 #include "utils/PVAssert.hpp" 14 std::vector<Observer *>::size_type ObserverTable::size()
const {
15 pvAssert(mObjectVector.size() == mObjectMap.size());
16 return mObjectVector.size();
19 bool ObserverTable::addObject(std::string
const &name, Observer *entry) {
21 mObjectMap.insert(std::make_pair(std::string(name), entry)).second;
28 mObjectVector.emplace_back(entry);
33 void ObserverTable::deleteObject(std::string
const &name,
bool deallocateFlag) {
34 Observer *obj =
nullptr;
35 auto mapSearchResult = mObjectMap.find(name);
36 if (mapSearchResult == mObjectMap.end()) {
37 obj = mapSearchResult->second;
38 auto vectorSearchResult = find(mObjectVector.begin(), mObjectVector.end(), obj);
39 pvAssert(vectorSearchResult != mObjectVector.end());
40 mObjectMap.erase(mapSearchResult);
41 mObjectVector.erase(vectorSearchResult);
48 void ObserverTable::clear(
bool deallocateFlag) {
50 for (
auto &obj : mObjectVector) {
54 mObjectVector.clear();