/** * @RDE_HEADER@ * Interface-Implementation of ObjectContainer * $Id$ * $HeadURL$ * $Author$ */ // Own #include "object_container_impl.h" namespace SituationMap { ObjectContainerCTC::ObjectContainerCTC(const QSharedPointer &idGenerator) : BaseClass(idGenerator) , m_logger(getLogger("ObjectContainerCTC")) { TRACE_LOG(m_logger) << LOGFUNCTION << " START"; TRACE_LOG(m_logger) << LOGFUNCTION << " END"; } ObjectContainerCTC::~ObjectContainerCTC() { TRACE_LOG(m_logger) << LOGFUNCTION << " START"; TRACE_LOG(m_logger) << LOGFUNCTION << " END"; } ObjectContainer::UniqueObjectId ObjectContainerCTC::insertObject(ObjectContainer::Object *object) { TRACE_LOG(m_logger) << LOGFUNCTION << " START"; UniqueObjectId newId = m_idGenerator->getNextId(); m_map.insert(newId, RefPointer(object)); TRACE_LOG(m_logger) << LOGFUNCTION << " END" << " uniqueId = " << newId; return newId; } ObjectContainer::UniqueObjectId ObjectContainerCTC::insertObject(ObjectContainer::Object *object, const ObjectContainer::UniqueObjectId &uid) { TRACE_LOG(m_logger) << LOGFUNCTION << " START"; if ((uid >= m_idGenerator->nextFreeId()) || (INVALID_MAP_ID == uid) || containsObject(uid)) { // uid is unvalid and can't be used. In this case insert the map object with a new id. return insertObject(object); } m_map.insert(uid, RefPointer(object)); TRACE_LOG(m_logger) << LOGFUNCTION << " END" << " uniqueId = " << uid; return uid; } bool ObjectContainerCTC::removeObject(const ObjectContainer::UniqueObjectId &id) { TRACE_LOG(m_logger) << LOGFUNCTION << " START" << " uniqueId = " << id; bool success = (m_map.remove(id) == 1); TRACE_LOG(m_logger) << LOGFUNCTION << " START" << " uniqueId = " << id << " success = " << success; return success; } void ObjectContainerCTC::clear() { m_map.clear(); } ObjectContainer::Object *ObjectContainerCTC::getObject(const ObjectContainer::UniqueObjectId &id) const { auto it = m_map.constFind(id); if (it == m_map.constEnd()) return nullptr; RefPointer obj = it.value(); return obj.get(); } QList ObjectContainerCTC::getAllObjects() const { QList list; QMapIterator< UniqueObjectId, RefPointer > it(m_map); while (it.hasNext()) { it.next(); const RefPointer &obj = it.value(); if (obj) list.append(const_cast(obj.get())); } // while return list; } QList ObjectContainerCTC::getAllObjects(const std::type_index &type) const { QList list; QMapIterator< UniqueObjectId, RefPointer > it(m_map); while (it.hasNext()) { it.next(); const RefPointer &obj = it.value(); // !!! get typ_index of object, not pointer to object: !!! const Object *objGet = obj.get(); if (type == std::type_index(typeid(*objGet))) list.append(const_cast(objGet)); } // while return list; } QList ObjectContainerCTC::getAllKeys() const { return m_map.keys(); } bool ObjectContainerCTC::containsObject(const ObjectContainer::UniqueObjectId &id) const { return m_map.contains(id); } qint64 ObjectContainerCTC::countObjects() const { return m_map.size(); } } // namespace SituationMap