Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
Executable
+120
@@ -0,0 +1,120 @@
|
||||
/**
|
||||
**
|
||||
** @RDE_HEADER@
|
||||
** Simple Id Handler
|
||||
** $Id$
|
||||
** $HeadURL$
|
||||
** $Author$
|
||||
**
|
||||
** -----------------------------------------------------------------------------------------------
|
||||
**
|
||||
** Hardware-Environment: Intel-PC
|
||||
** Software-Environment: Linux, Windows 7, Qt 5.4. ArcGIS 10.2.5
|
||||
**
|
||||
** Language ........: C++ 11
|
||||
**
|
||||
** -----------------------------------------------------------------------------------------------
|
||||
**
|
||||
** Author ...........: Jörg Turla, SPD G, Tel. 3132
|
||||
**
|
||||
** -----------------------------------------------------------------------------------------------
|
||||
**
|
||||
** Notes .........:
|
||||
**
|
||||
** ??.??.1994, JT : First edition for use with Tcl/Tk in START Feature Editor fe
|
||||
** 16.08.2004, JT : Refactoring for use in Geo-Map Library GeISiR
|
||||
** 11.05.2015, JT : Refactoring for use with Qt5
|
||||
**
|
||||
** -----------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
//#include <Map/situation_map_types.h>
|
||||
#include "referenced.h"
|
||||
#include "ref_pointer.h"
|
||||
#include "situation_map_logging.h"
|
||||
|
||||
#include "situation_map_common_export.h"
|
||||
#include <QVector>
|
||||
|
||||
namespace SituationMap
|
||||
{
|
||||
|
||||
/**
|
||||
@class IdHandler id_handler.h
|
||||
@brief Simple IdHandler to map id's to data pointers
|
||||
|
||||
IdHandler is a class to manage integer ids and map them to data pointers. The IdHandler stores
|
||||
the data pointer in a vector container. The index of the data pointer in this vector is used as
|
||||
id value. If the vector gets out of size new vector elements will be added automaticaly. This
|
||||
will be done blockwises. The initial size of the vector and the block size can be set as
|
||||
parameter of IdHandler ctor. The default values are 10000 for the initial vector size and 1000
|
||||
for the block size.
|
||||
*/
|
||||
class SITUATIONMAPCOMMON_EXPORT IdHandler
|
||||
{
|
||||
public:
|
||||
|
||||
using AccessableId = Referenced;
|
||||
using UniqueId = quint32; // see UniqueMapId @ situation_map_types.h
|
||||
|
||||
static const UniqueId BadId;
|
||||
|
||||
static bool isIdValid(const UniqueId &id); //!< Checks if the \c id is not a BadId
|
||||
|
||||
IdHandler(const IdHandler &) = delete;
|
||||
IdHandler &operator = (const IdHandler &) = delete;
|
||||
|
||||
/**
|
||||
@brief Construction of IdHandler
|
||||
|
||||
Initialize IdHandler instances. The vector container to store data pointers is
|
||||
reserved with \c maxItems. If the vector gets out of size new vector elements
|
||||
will be added automaticaly
|
||||
|
||||
@param maxItems Initial size of the vector container to store the data pointer.
|
||||
@param blockS Block size is used when the vector container will be extended.
|
||||
*/
|
||||
IdHandler(unsigned int maxItems = 10000, unsigned int blockS = 1000);
|
||||
|
||||
/**
|
||||
@brief Destruction of IdHandler
|
||||
*/
|
||||
virtual ~IdHandler();
|
||||
|
||||
bool valid() const; //!< Checks if IdHandler is valid
|
||||
|
||||
quint32 countReservedIds() const; //!< Returns count of reserved ids.
|
||||
quint32 countUsedIds() const; //!< Returns count of used ids.
|
||||
quint32 countFreeIds() const; //!< Returnes count of free ids
|
||||
|
||||
bool resize(quint32 maxItems); //!< Resize idMem to store now maxItems ids. Returns true on success.
|
||||
|
||||
UniqueId createId(AccessableId *); //!< Create new \c id and returns this new id.
|
||||
bool reserveId(UniqueId id, AccessableId *); //!< Reserve \c id if the id is unused. Returns true if \c id is not already in use and reservation of \c id is successful elsewise false.
|
||||
bool freeId(UniqueId id); //!< Frees \c id. Returns true on success elsewise false.
|
||||
|
||||
AccessableId *accessId(UniqueId id) const; //!< Returns pointer to object for \c id. Returns pointer on success elsewise \c nullptr.
|
||||
bool isIdInUse(UniqueId id) const; //!< Checks if a id is already in use.
|
||||
|
||||
protected:
|
||||
|
||||
quint32 _blockSize;
|
||||
quint32 _maxIds;
|
||||
quint32 _freeIds;
|
||||
UniqueId _firstFree;
|
||||
UniqueId _lastAlloc;
|
||||
LOGGER_T _notify;
|
||||
|
||||
mutable QVector<RefPointer<AccessableId>> _idVector;
|
||||
|
||||
private:
|
||||
|
||||
bool initMemHandler();
|
||||
void lookForNextFreeId();
|
||||
|
||||
}; /* IdHandler */
|
||||
|
||||
} /* SituationMap */
|
||||
|
||||
Reference in new issue
Block a user