Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
+134
@@ -0,0 +1,134 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Interface-Implementation of ObjectContainer
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
|
||||
// Own
|
||||
#include "object_container_impl.h"
|
||||
|
||||
namespace SituationMap
|
||||
{
|
||||
|
||||
ObjectContainerCTC::ObjectContainerCTC(const QSharedPointer<IdGenerator> &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>(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>(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<Object> obj = it.value();
|
||||
return obj.get();
|
||||
}
|
||||
|
||||
QList<ObjectContainer::Object *> ObjectContainerCTC::getAllObjects() const
|
||||
{
|
||||
QList<ObjectContainer::Object *> list;
|
||||
|
||||
QMapIterator< UniqueObjectId, RefPointer<Object> > it(m_map);
|
||||
while (it.hasNext())
|
||||
{
|
||||
it.next();
|
||||
const RefPointer<Object> &obj = it.value();
|
||||
if (obj)
|
||||
list.append(const_cast<ObjectContainer::Object *>(obj.get()));
|
||||
} // while
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
QList<ObjectContainer::Object *> ObjectContainerCTC::getAllObjects(const std::type_index &type) const
|
||||
{
|
||||
QList<ObjectContainer::Object *> list;
|
||||
|
||||
QMapIterator< UniqueObjectId, RefPointer<Object> > it(m_map);
|
||||
while (it.hasNext())
|
||||
{
|
||||
it.next();
|
||||
const RefPointer<Object> &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<ObjectContainer::Object *>(objGet));
|
||||
} // while
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
QList<ObjectContainer::UniqueObjectId> 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
|
||||
Reference in new issue
Block a user