/** * @RDE_HEADER@ * Interface for Storing of MapObjects * $Id$ * $HeadURL$ * $Author$ */ #pragma once // Own #include "abstract_map_object.h" #include // Qt #include #include #include //---------------------------------------------------------------------------- namespace SituationMap { //forward template class RefPointer; /** * @brief The IdGenerator class generates a new UniqueMapId in a very simple manner. */ class SITUATIONMAP_EXPORT IdGenerator // final { public: static const UniqueMapId INVALID_ID = SituationMap::INVALID_MAP_ID; IdGenerator(); virtual ~IdGenerator(); // leave virtual to let UnitTestInternal succeed IdGenerator(const IdGenerator &other) = delete; IdGenerator &operator=(IdGenerator &other) = delete; /** * @brief Get next UniqueMapId * @return Next UniqueMapId */ UniqueMapId getNextId() { DEBUG_LOG(m_logger) << LOGFUNCTION << " nextId=" << m_counter; return m_counter++; } /** * @brief Check validity * @param id to be checked * @return True if id is not equal INVALID_ID * @note Prefer SituationMap::isUniqueMapIdValid() due to runtime aspects. */ static bool idIsValid(const UniqueMapId &id) { return isUniqueMapIdValid(id); // same as ( id != INVALID_ID ); } UniqueMapId nextFreeId() const { return m_counter; } protected: LOGGER_T m_logger; ///< Interface of the Logging-Facility UniqueMapId m_counter = 0; }; //---------------------------------------------------------------------------- /** * @brief The ObjectContainer class maps UniqueMapId to MapObjects. * It uses an external IdGenerator to generate a next UniqueMapId returned * while inserting. */ class SITUATIONMAP_EXPORT ObjectContainer { public: using UniqueObjectId = UniqueMapId; using Object = AbstractMapObject; /*! \name Construction, Destruction */ //@{ /** * @brief Constructor of ObjectContainer. * @param idGenerator to be used * (can be shared among different ObjectContainer instances). */ explicit ObjectContainer(const QSharedPointer &idGenerator); /** * @brief Destructor. Will delete the IdGenerator when it goes * out of scope, if no other QSharedPointer objects are referencing it. */ virtual ~ObjectContainer(); ObjectContainer(const ObjectContainer &other) = delete; ObjectContainer &operator=(ObjectContainer &other) = delete; /** * @brief Get current IdGenerator. * @return Current IdGenerator. */ virtual QSharedPointer idGenerator() const; //@} /*! \name Insert, Remove, Clear */ //@{ /** * @brief insertObject. * @param object to be inserted. * @return UniqueId of inserted object. */ virtual UniqueObjectId insertObject(Object *object) = 0; virtual UniqueObjectId insertObject(ObjectContainer::Object *object, const ObjectContainer::UniqueObjectId &uid) = 0; /** * @brief Remove object from the container. * @param id to be removed. * @return True on success, otherwise false. */ virtual bool removeObject(const UniqueObjectId &id) = 0; /** * @brief Clear the container (and remove objects from the view) */ virtual void clear() = 0; //@} /*! \name Access */ //@{ /** * @brief getObject. * @param id to access. * @return Object if found, otherwise null. */ virtual Object *getObject(const UniqueObjectId &id) const = 0; /** * @brief Retrieves all UniqueIds. * @return Get all UniqueIds. */ virtual QList getAllKeys() const = 0; /** * @brief Get all objects of any type. * @return All objects. */ virtual QList getAllObjects() const = 0; /** * @brief Get all objects of a certain type. * @param type requested type. * @return All objects fo requested type */ virtual QList getAllObjects(const std::type_index &type) const = 0; /** * @brief Get mutable Iterator * @return mutable Iterator */ virtual QMutableMapIterator> mutableIterator() = 0; //@} /*! \name Check */ //@{ /** * @brief Check existence. * @param id to be checked. * @return True if exists, otherwise false. */ virtual bool containsObject(const UniqueObjectId &id) const = 0; //@} /*! \name Count */ //@{ virtual qint64 countObjects() const = 0; //@} protected: QSharedPointer m_idGenerator; LOGGER_T m_logger; ///< Interface of the Logging-Facility }; } // namespace SituationMap