* Besides calling the underlying container's insert which checks (and replaces) * for existing elements with the same unique ID (name), this method also check * for elements with the same global address. Such elements are also removed * before adding the new element, since container is not allowed to hold two * ebjects with the same global address. Moreover, @c _addr2global is also * updated.
| 201 | * updated. |
| 202 | */ |
| 203 | std::pair<GlobalVarContainer::iterator,bool> GlobalVarContainer::insert( |
| 204 | const Object& e) |
| 205 | { |
| 206 | assert(e.getStorage().isMemory()); |
| 207 | if (!e.getStorage().isMemory()) |
| 208 | { |
| 209 | return {end(), false}; |
| 210 | } |
| 211 | |
| 212 | auto existing = getObjectByAddress(e.getStorage().getAddress()); |
| 213 | if (existing) |
| 214 | { |
| 215 | erase(*existing); |
| 216 | } |
| 217 | auto fit = find(e.getName()); |
| 218 | if (fit != end()) |
| 219 | { |
| 220 | ObjectSetContainer::erase(fit); |
| 221 | } |
| 222 | |
| 223 | auto retPair = ObjectSetContainer::insert(e); |
| 224 | |
| 225 | const Object* obj = &(*retPair.first); |
| 226 | const auto& addr = e.getStorage().getAddress(); |
| 227 | auto res = _addr2global.emplace(addr,obj); |
| 228 | if (!res.second) |
| 229 | { |
| 230 | // There is already an object on this address, so overwrite it |
| 231 | // to ensure that it is updated. |
| 232 | res.first->second = obj; |
| 233 | } |
| 234 | |
| 235 | return retPair; |
| 236 | } |
| 237 | |
| 238 | std::pair<GlobalVarContainer::iterator,bool> GlobalVarContainer::insert( |
| 239 | GlobalVarContainer::iterator, |