MCPcopy Create free account
hub / github.com/DFHack/dfhack / getByKey

Method getByKey

library/modules/Persistence.cpp:350–364  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

348}
349
350PersistentDataItem Persistence::getByKey(int entity_id, const std::string &key, bool *added) {
351 if (!is_good_entity_id(entity_id) || key.empty() || !Core::getInstance().isWorldLoaded())
352 return PersistentDataItem();
353
354 CoreSuspender suspend;
355
356 bool found = store.contains(entity_id) && store[entity_id].contains(key);
357 if (added)
358 *added = !found;
359 if (found)
360 return PersistentDataItem(store[entity_id].find(key)->second);
361 if (!added)
362 return PersistentDataItem();
363 return addItem(entity_id, key);
364}
365
366bool Persistence::deleteItem(const PersistentDataItem &item) {
367 if (!item.isValid())

Callers

nothing calls this directly

Calls 5

is_good_entity_idFunction · 0.85
PersistentDataItemFunction · 0.85
containsMethod · 0.80
emptyMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected