Initial commit

This commit is contained in:
torsten committed 2026-08-13 18:33:10 +02:00
commit b7d90b9afe
16245 files changed
+3396666

No files matched your search

+44
View File
@@ -0,0 +1,44 @@
#
# $Id$
# $HeadURL$
# $Author$
#
# LIBRARY
SET(Common_SRCS
id_handler.cpp
referenced.cpp
resource_path.cpp
situation_map_logging.cpp
)
SET (Common_HDRS
exception.h
id_handler.h
ref_pointer.h
referenced.h
resource_path.h
situation_map_common_export.h
situation_map_logging.h
simple_value.h
)
SOURCE_GROUP(Common FILES ${Common_SRCS} ${Common_HDRS})
NGL_ADD_LIBRARY(WS AAR HLA SV situationMapCommon SHARED ${Common_SRCS} ${Common_HDRS})
NGL_TARGET_LINK_LIBRARIES(situationMapCommon
PRIVATE
ngltools
PUBLIC
NGLLogger
Qt5::Core
)
NGL_TARGET_INCLUDE_DIRECTORIES(situationMapCommon
INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}/..
)
NGL_INSTALL_TARGET(situationMapCommon)
+93
View File
@@ -0,0 +1,93 @@
/**
**
** @RDE_HEADER@
** Implementation of Splines
** $Id$
** $HeadURL$
** $Author$
** -----------------------------------------------------------------------------------------------
**
** Hardware-Environment: Intel-PC
** Software-Environment: Windows 7, Qt 5.4. ArcGIS 10.2.5
**
** Language ........: C++ 11
**
** -----------------------------------------------------------------------------------------------
**
** Author ...........: Joerg Turla, SPD G, Tel. 3132
**
** -----------------------------------------------------------------------------------------------
**
** Notes .........:
**
** 19.06.2012, JT : Urversion for use in VIntel project
** 12.08.2015, JT : adapted to SituationMap
**
** -----------------------------------------------------------------------------------------------
*/
#pragma once
#include <QtCore/QString>
namespace SituationMap
{
/**
\class Exception exception.h
\brief Basisklasse for Exception-Handling
The class Exception defines a very simple exception handler, that will be able to return
a string message when an exception is thrown
*/
class Exception
{
public:
Exception()
: _message(QLatin1String("Error"))
{}
Exception(const Exception &) = default;
explicit Exception(const QString &msg)
: _message(msg)
{}
// explicit is not used here because
// throw SituationMap::Exception(__FILE__, __LINE__, "Message" );
// will become more complicated
Exception(const char *Source
, unsigned int lineNo
, const char *msg)
: Exception(QLatin1String(Source), lineNo, QLatin1String(msg))
{}
Exception(const char *Source
, unsigned int lineNo
, const QString &msg)
: Exception(QLatin1String(Source), lineNo, msg)
{}
Exception(const QString &Source
, unsigned int lineNo
, const QString &msg)
: _message(QStringLiteral("\"%1\" in %2 at %3").arg(msg, Source).arg(lineNo))
{}
~Exception() = default;
Exception &operator = (const Exception &e) = default;
QString getMessage() const { return _message; } //!< returns a specific error message as QString
protected:
QString _message;
};
} // namespace SituationMap
+345
View File
@@ -0,0 +1,345 @@
/**
**
** @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
**
** -----------------------------------------------------------------------------------------------
*/
#include "id_handler.h"
#include <typeinfo>
#include "referenced.h"
namespace SituationMap
{
const IdHandler::UniqueId IdHandler::BadId = static_cast<IdHandler::UniqueId>(-1);
bool IdHandler::isIdValid(const UniqueId &id) { return id != BadId; }
IdHandler::IdHandler(unsigned int maxItems, unsigned int blockS)
: _blockSize(blockS)
, _maxIds(maxItems)
, _freeIds(maxItems)
, _firstFree(BadId)
, _lastAlloc(BadId)
, _notify(getLogger("IdHandler"))
, _idVector()
{
} // IdHandler::IdHandler
IdHandler::~IdHandler()
{
if (!_idVector.isEmpty())
{
if (_lastAlloc != BadId)
{
for (UniqueId i = 0; i <= _lastAlloc; ++i)
_idVector[i] = nullptr;
}
_maxIds = 0;
_freeIds = 0;
_firstFree = BadId;
_lastAlloc = BadId;
}
} // IdHandler::~IdHandler
bool IdHandler::initMemHandler()
{
if (_idVector.empty())
{
_idVector.resize(_maxIds);
_freeIds = _maxIds;
_firstFree = 0;
_lastAlloc = BadId;
return false;
}
return true;
} // IdHandler::initMemHandler
void IdHandler::lookForNextFreeId()
{
++_firstFree;
while (_firstFree < _lastAlloc)
{
if (!_idVector[_firstFree]) break;
++_firstFree;
}
if (_firstFree >= _lastAlloc) _firstFree = _maxIds;
} //IdHandler::lookForNextFreeId
bool IdHandler::valid() const
{
return ((static_cast<quint32>(_idVector.size()) == _maxIds) && (_firstFree != BadId));
} // IdHandler::valid
unsigned int IdHandler::countReservedIds() const { return _maxIds; }
unsigned int IdHandler::countUsedIds() const { return _maxIds - _freeIds; }
unsigned int IdHandler::countFreeIds() const { return _freeIds; }
bool IdHandler::resize(quint32 maxItems)
{
if (initMemHandler())
{
if (maxItems > static_cast<quint32>(_idVector.size()))
{
_freeIds += maxItems - _maxIds;
_maxIds = maxItems;
_idVector.resize(_maxIds);
}
}
return (static_cast<quint32>(_idVector.size()) == _maxIds);
} // IdHandler::resize
IdHandler::UniqueId IdHandler::createId(AccessableId *idPtr)
{
initMemHandler();
UniqueId id((_lastAlloc == BadId) ? 0 : _lastAlloc + 1);
if (id < _maxIds)
{
_idVector[id] = idPtr;
_lastAlloc = id;
if (_firstFree == id) ++_firstFree;
}
else
{
if (_firstFree >= _maxIds)
{
resize(_maxIds + _blockSize);
if (id < _maxIds)
{
_idVector[id] = idPtr;
_lastAlloc = id;
if (_firstFree == id)
++_firstFree;
}
else
{
ERROR_LOG(_notify)
<< LOGFUNCTION
<< QStringLiteral("Id table overflow, object <%1> of type <%2>, reserved Ids %3")
.arg(reinterpret_cast<qulonglong>(idPtr), 0, 16)
.arg(QLatin1String(typeid(idPtr).name()))
.arg(_maxIds);
return BadId;
}
}
else
{
id = _firstFree;
_idVector[id] = idPtr;
lookForNextFreeId();
}
}
_freeIds--;
return (id);
} // IdHandler::createId
bool IdHandler::reserveId(UniqueId id, AccessableId *idPtr)
{
initMemHandler();
if (!valid())
{
ERROR_LOG(_notify)
<< LOGFUNCTION
<< QStringLiteral("IdHandler is not initialzed, object <%1> of type <%2> ")
.arg(reinterpret_cast<qulonglong>(idPtr), 0, 16)
.arg(QLatin1String(typeid(idPtr).name()));
return false;
}
if (id == BadId)
{
ERROR_LOG(_notify)
<< LOGFUNCTION
<< " Requested id is bad id <" << id << ">";
return false;
}
if (id >= _maxIds)
{
if (!resize((((id + 1) / _blockSize) + 1) * _blockSize))
{
ERROR_LOG(_notify)
<< LOGFUNCTION
<< QStringLiteral("Requested id is to large, id <%1> object <%2> of type <%3>.")
.arg(id)
.arg(reinterpret_cast<qulonglong>(idPtr), 0, 16)
.arg(QLatin1String(typeid(idPtr).name()));
return false;
}
}
if (_idVector[id])
{
ERROR_LOG(_notify)
<< LOGFUNCTION
<< QStringLiteral("Requested id is already in use, object <%1> of type <%2>.")
.arg(reinterpret_cast<qulonglong>(idPtr), 0, 16)
.arg(QLatin1String(typeid(idPtr).name()));
return false;
}
_idVector[id] = idPtr;
if ((_lastAlloc == BadId) || (id > _lastAlloc)) _lastAlloc = id;
if (id == _firstFree)
{
++_firstFree;
lookForNextFreeId();
}
_freeIds--;
return true;
} // IdHandler::reserveId
bool IdHandler::freeId(UniqueId id)
{
if (valid() && (_lastAlloc != BadId) && (id != BadId))
{
if (id <= _lastAlloc)
{
if (_idVector[id])
{
_idVector[id] = nullptr;
if (id < _firstFree) _firstFree = id;
if (id == _lastAlloc)
{
/* ---------------------------------------------------------
* Last allocated id is now free. Search new lastAlloc ...
* ---------------------------------------------------------- */
if (_lastAlloc > 0)
{
--_lastAlloc;
while (!_idVector[_lastAlloc])
{
if (_lastAlloc < 1)
{
_lastAlloc = BadId;
break;
}
else --_lastAlloc;
} // while
}
else _lastAlloc = BadId;
}
_freeIds++;
return true;
}
}
else
{
ERROR_LOG(_notify)
<< LOGFUNCTION
<< "Id is not in use, id <" << id << ">";
}
}
else
{
if (id != BadId)
{
ERROR_LOG(_notify)
<< LOGFUNCTION
<< "IdHandler is not initialzed.";
}
else
{
ERROR_LOG(_notify)
<< LOGFUNCTION
<< "Bad id, id <" << id << ">";
}
}
return false;
} // IdHandler::freeId
IdHandler::AccessableId *IdHandler::accessId(UniqueId id) const
{
if (valid())
{
if ((id != BadId) && (id <= _lastAlloc))
return _idVector[id].get();
else
{
ERROR_LOG(_notify)
<< LOGFUNCTION
<< "Bad id or id is not in use, id <" << id << ">";
#ifdef UseDebugBreaks
#ifdef WIN32
#ifdef _DEBUG
__asm int 3
#endif
#endif
#endif
}
}
else
{
ERROR_LOG(_notify)
<< LOGFUNCTION
<< "IdHandler is not initialzed";
}
return nullptr;
} // IdHandler::accessId
bool IdHandler::isIdInUse(UniqueId id) const
{
if (valid())
{
if ((id != BadId) && (id <= _lastAlloc))
return (_idVector[id].get() != nullptr);
}
return false;
} // IdHandler::isIdInUse
} // SituationMap
+120
View File
@@ -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 */
+226
View File
@@ -0,0 +1,226 @@
/**
**
** @RDE_HEADER@
** Base class for reference counted objects
** $Id$
** $HeadURL$
** $Author$
**
** -----------------------------------------------------------------------------------------------
**
** Hardware-Umgebung: Intel-PC
** Software-Umgebung: Linux, Windows 7, Qt 5.4. ArcGIS 10.2.5
**
** Pgrm-Sprache ....: C++ 11
**
** HIER/SACHN ......: P: -- ---- - --- QE
**
** Version .........: $Revision$
** -----------------------------------------------------------------------------------------------
**
** Autor ...........: Nikolaus Hanekamp, SEDG, Tel. 2906
**
** -----------------------------------------------------------------------------------------------
**
** Notizen .........:
**
** 18.08.2004, NH : Urversion
** 13.05.2015, JT : Refactoring for use with Qt5, ArcGIS 10.2.5
** adding methodes according to std::share_ptr like reset
**
** -----------------------------------------------------------------------------------------------
**
** Copyright (C) 2004 Rheinmetall Defence Electronics GmbH, D-28309 BREMEN
**
** -----------------------------------------------------------------------------------------------
*/
#pragma once
#include "referenced.h"
namespace SituationMap
{
/**
@class RefPointer ref_pointer.h
@brief Smart pointer for handling referenced counted objects
Simple class template to implement reference counted pointers or smart pointers. The RefPointer class controls the
reference counter of the object \c T the pointer points to. The class \c T have to be derived from class \c Referenced,
where the reference counter member variable is located. In case of this reference counter gets zero delete will be called
automatically.
@see Referenced
*/
template<class T> class RefPointer
{
public:
using ElementType = T;
/**
@name Construction and Destruction
@{
*/
RefPointer() : RefPointer(nullptr) {}
RefPointer(const RefPointer &rp) : RefPointer(rp._ptr) {}
explicit RefPointer(ElementType *t)
: _ptr(t)
{
static_assert(std::is_base_of<Referenced, T>::value
, "Class of template SituationMap::RefPointer have to be derived from class SituationMap::Referenced");
if (_ptr) _ptr->ref();
} /* RefPointer */
~RefPointer()
{
if (_ptr) _ptr->unref();
_ptr = nullptr;
} /* ~RefPointer */
/** @} */
/**
Checks if pointer is valid.
*/
explicit inline operator bool() const { return (_ptr != nullptr); }
/**
@name Casting
@{
*/
/**
To create reference pointer from a derived class directly this contructor template can be used.
How to use it is shown in the following example:
\code
RefPointer<AbstractMapObject> objPtr = getAbstractMapObject();
RefPointer<Participant> participantObj( objPtr );
if (participantObj != NULL)
{
...
}
\endcode
Alternatively it is posible to create \b participantObj from example above as follows:
\code
RefPointer<Participant> participantObj = RefPointer<Participant>(dynamic_cast<Participant*>(objPtr.get()));
\endcode
*/
template<class Y> explicit RefPointer(RefPointer<Y> assignPtr)
{
_ptr = dynamic_cast<T *>(assignPtr.get());
if (_ptr) _ptr->ref();
}
template<class Y> explicit RefPointer(Y *assignPtr)
{
_ptr = dynamic_cast<T *>(assignPtr);
if (_ptr) _ptr->ref();
}
/** @} */
inline RefPointer &operator = (const RefPointer &rp)
{
if (_ptr == rp._ptr) return *this;
T *tmp_ptr = _ptr;
_ptr = rp._ptr;
if (_ptr) _ptr->ref();
// unref second to prevent any deletion of any object which might
// be referenced by the other object. i.e rp is child of the
// original _ptr.
if (tmp_ptr) tmp_ptr->unref();
return *this;
}
inline RefPointer &operator = (ElementType *ptr)
{
if (_ptr == ptr) return *this;
T *tmp_ptr = _ptr;
_ptr = ptr;
if (_ptr) _ptr->ref();
// unref second to prevent any deletion of any object which might
// be referenced by the other object. i.e rp is child of the
// original _ptr.
if (tmp_ptr) tmp_ptr->unref();
return *this;
}
inline void reset() { *this = nullptr; }
inline void reset(T *ptr) { *this = ptr; }
/**
@name Comparison Operators
Compares the pointer element \c _ptr with other pointers.
@{
*/
inline bool operator == (const RefPointer &rp) const { return (_ptr == rp._ptr); }
inline bool operator != (const RefPointer &rp) const { return (_ptr != rp._ptr); }
inline bool operator < (const RefPointer &rp) const { return (_ptr < rp._ptr); }
inline bool operator > (const RefPointer &rp) const { return (_ptr > rp._ptr); }
inline bool operator == (const ElementType *ptr) const { return (_ptr == ptr); }
inline bool operator != (const ElementType *ptr) const { return (_ptr != ptr); }
inline bool operator < (const ElementType *ptr) const { return (_ptr < ptr); }
inline bool operator > (const ElementType *ptr) const { return (_ptr > ptr); }
/** @} */
/**
@name Access Operators
Get access to the pointer or the object it points to.
@{
*/
inline ElementType &operator*() { return *_ptr; }
inline const ElementType &operator*() const { return *_ptr; }
inline ElementType *operator->() { return _ptr; }
inline const ElementType *operator->() const { return _ptr; }
inline ElementType *get() { return _ptr; }
inline const ElementType *get() const { return _ptr; }
/** @} */
/**
@name Checks if the pointer is valid.
@{
*/
inline bool valid() const { return _ptr != nullptr; }
inline bool operator!() const { return _ptr == nullptr; }
/** @} */
/**
* @name Control Over Object Pointer
* Take control over the object pointed to by RefPointer, unreference but do not delete even if ref count goes to 0,
* return the pointer to the object.
* Note, do not use this unless you are 100% sure your code handles the deletion of the object correctly, and
* only use when absolutely required.
@{
*/
inline ElementType *take() { return release();}
inline ElementType *release() { T *tmp = _ptr; if (_ptr) _ptr->unref_nodelete(); _ptr = nullptr; return tmp;}
/** @} */
private:
ElementType *_ptr;
};
} // SituationMap
+76
View File
@@ -0,0 +1,76 @@
/**
**
** @RDE_HEADER@
** Base class for reference counted objects
** $Id$
** $HeadURL$
** $Author$
**
** -----------------------------------------------------------------------------------------------
**
** Hardware-Umgebung: Intel-PC
** Software-Umgebung: Linux, Windows 7, Qt 5.4. ArcGIS 10.2.5
**
** Pgrm-Sprache ....: C++ 11
**
** HIER/SACHN ......: P: -- ---- - --- QE
**
** Version .........: $Revision$
** -----------------------------------------------------------------------------------------------
**
** Autor ...........: Nikolaus Hanekamp, SEDG, Tel. 2906
** Joerg Turla, SPD G, Tel. 3132
**
** -----------------------------------------------------------------------------------------------
**
** Notizen .........:
**
** 18.08.2004, NH : Urversion
** 13.05.2015, JT : Refactoring for use with Qt5, ArcGIS 10.2.5
**
** -----------------------------------------------------------------------------------------------
*/
#include "referenced.h"
#include <QDebug>
#include <typeinfo>
#include <memory>
namespace SituationMap
{
std::shared_ptr<DeleteHandler> & s_deleteHandler()
{
static std::shared_ptr<DeleteHandler> deleteHandler(nullptr);
return deleteHandler;
} // std::shared_ptr<DeleteHandler> & s_deleteHandler()
void Referenced::setDeleteHandler(DeleteHandler *handler)
{
s_deleteHandler().reset(handler);
} // Referenced::setDeleteHandler
DeleteHandler *Referenced::getDeleteHandler() { return s_deleteHandler().get(); }
Referenced::~Referenced()
{
if (_refCount > 0)
{
qCritical() << "Deleting still referenced object < " << QString::number((qint64)this, 0, 16) << ">"
<< "of type <" << typeid(this).name() << ">"
<< "refCnt: <" << _refCount;
}
} // Referenced::~Referenced
} // end of namespace SituationMap
+157
View File
@@ -0,0 +1,157 @@
/**
**
** @RDE_HEADER@
** Base class for reference counted objects
** $Id$
** $HeadURL$
** $Author$
**
** -----------------------------------------------------------------------------------------------
**
** Hardware-Umgebung: Intel-PC
** Software-Umgebung: Linux, Windows 7, Qt 5.4. ArcGIS 10.2.5
**
** Pgrm-Sprache ....: C++ 11
**
** HIER/SACHN ......: P: -- ---- - --- QE
**
** Version .........: $Revision$
** -----------------------------------------------------------------------------------------------
**
** Autor ...........: Nikolaus Hanekamp, SEDG, Tel. 2906
** Joerg Turla, SPD G, Tel. 3132
**
** -----------------------------------------------------------------------------------------------
**
** Notizen .........:
**
** 18.08.2004, NH : Urversion
** 13.05.2015, JT : Refactoring for use with Qt5, ArcGIS 10.2.5
**
** -----------------------------------------------------------------------------------------------
*/
#pragma once
#include "situation_map_common_export.h"
namespace SituationMap
{
// forward declar, declared after Refenced below.
class DeleteHandler;
/**
@class Referenced referenced.h
@brief Base class for referenced counted object classes
Base class from providing referencing counted objects. Objects from type "Referenced" should
be used in combination with the class "RefPointer" for memory handling. In this case calling
delete direcly for those objects will result in an error at runtime. Unfortunately there is
no way to check this at compile time - to declare delete operator protected does not work.
@sa RefPointer
*/
class SITUATIONMAPCOMMON_EXPORT Referenced
{
public:
/**
@name Construction
@{
*/
Referenced() { _refCount = 0; }
Referenced(const Referenced &) { _refCount = 0; }
/** @} */
/**
Assign operator has to do nothing because is is permitted to change _refCount during assignment operation.
*/
inline Referenced &operator = (const Referenced &) { return *this; }
friend class DeleteHandler;
/** Set a DeleteHandler to which deletion of all referenced counted objects
* will be delegated to.*/
static void setDeleteHandler(DeleteHandler *handler);
/** Get a DeleteHandler.*/
static DeleteHandler *getDeleteHandler();
/** Increment the reference count by one, indicating that
this object has another pointer which is referencing it.*/
inline void ref() const { ++_refCount; }
/** Decrement the reference count by one, indicating that
a pointer to this object is referencing it. If the
reference count goes to zero, it is assumed that this object
is no longer referenced and is automatically deleted.*/
inline void unref() const;
/** Decrement the reference count by one, indicating that
a pointer to this object is referencing it. However, do
not delete it, even if ref count goes to 0. Warning, unref_nodelete()
should only be called if the user knows exactly who will
be resonsible for, one should prefer unref() over unref_nodelete()
as the later can lead to memory leaks.*/
inline void unref_nodelete() const { --_refCount; }
/** Return the number pointers currently referencing this object. */
inline int referenceCount() const { return _refCount; }
protected:
/**
Declaration of destructor is protected because only methode unref() or the delete
handler itself are allowed to destroy referenced objects.
*/
virtual ~Referenced();
mutable int _refCount;
};
/** Class for override the default delete behavior so that users can implement their own object
* deletion schemes. This might be done to help implement protection of multiple threads from deleting
* objects unintentionally.
* Note, the DeleteHandler cannot itself be reference counted, otherwise it
* would be responsible for deleting itself!
* An static auto_ptr<> is used internally in Referenced.cpp to manage the
* DeleteHandler's memory.*/
class SITUATIONMAPCOMMON_EXPORT DeleteHandler
{
public:
DeleteHandler() = default;
virtual ~DeleteHandler() = default;
/** Flush any cache of objects that need to be deleted by doing an actual delete.*/
virtual void flush() {}
static inline void doDelete(const Referenced *object) { delete object; }
/** Request the deletion of an object.
* Depending on users implementation of DeleteHandler, the delete of the object may occur
* straight away or be delayed until doDelete is called.
* The default implementation does a delete straight away.*/
virtual void requestDelete(const Referenced *object) { doDelete(object); }
}; /* DeleteHandler */
inline void Referenced::unref() const
{
--_refCount;
if (_refCount == 0)
{
if (getDeleteHandler()) getDeleteHandler()->requestDelete(this);
else delete this;
}
else if (_refCount < 0)
throw 2325;
} /* Referenced::unref */
} // SituationMap
+51
View File
@@ -0,0 +1,51 @@
/**
* @RDE_HEADER@
* Helper function to get the resource path
* $Id$
* $HeadURL$
* $Author$
*/
#include "resource_path.h"
#include <ngltools/ngltools_filesystem.h> // for NGL::directories
// Qt
#include <QDir>
#include <QVector>
//----------------------------------------------------------------------------
namespace SituationMap
{
QString getResourcePath()
{
const QString resDir = NGL::directory(NGL::FileType::ConfigFile, QLatin1String("resources"));
if (!resDir.isEmpty())
return resDir;
QVector<QString> pathsToSearch;
// for old systems
#ifdef Q_OS_WIN
pathsToSearch += QLatin1String("C:/ExtFw/resources/");
#else
pathsToSearch += QLatin1String("/usr/share/arcgis/resources");
#endif
for (const QString &path : qAsConst(pathsToSearch))
{
if (QDir(path).exists())
return path + QLatin1Char('/');
}
return QString();
}
} // namespace SituationMap
+24
View File
@@ -0,0 +1,24 @@
/**
* @RDE_HEADER@
* Helper function to get the resource path
* $Id$
* $HeadURL$
* $Author$
*/
#pragma once
#include "situation_map_common_export.h"
// Qt
#include <QString>
//----------------------------------------------------------------------------
namespace SituationMap
{
QString SITUATIONMAPCOMMON_EXPORT getResourcePath();
} // namespace SituationMap
+96
View File
@@ -0,0 +1,96 @@
/**
* @RDE_HEADER@
* Helper class for storing a simple value and an implizit changed flag
* $Id$
* $HeadURL$
* $Author$
*/
#pragma once
// Qt
#include <sstream>
//----------------------------------------------------------------------------
namespace SituationMap
{
/*! \class SimpleValue
\brief Simple storing fo values
*/
template <class TYPE> class SimpleValue
{
protected:
TYPE m_value = TYPE(); // '{}' to initialize the member (and avoid unconditional jumps@valgrind)
bool m_changed = true;
public:
SimpleValue() = default;
// cppcheck-suppress noExplicitConstructor
SimpleValue(const TYPE &value) // should not be declared explicit to avoid additional writing stuff to cast values
: m_value(value)
{}
SimpleValue<TYPE> &operator=(const TYPE &newValue)
{
if (this->m_value != newValue)
{
this->m_value = newValue;
m_changed = true;
}
return *this;
}
const TYPE &operator()() const
{
return this->m_value;
}
const TYPE &value() const
{
return this->m_value;
}
TYPE &refValue()
{
m_changed = true;
return this->m_value;
}
const TYPE &refValue() const
{
return this->m_value;
}
bool changed() const
{
return m_changed;
}
void reset()
{
m_changed = false;
}
void setChanged()
{
m_changed = true;
}
friend std::ostream &operator<<(std::ostream &stream,
const SimpleValue &simpleVal)
{
stream << simpleVal.value();
return stream;
}
};
} // namespace SituationMap
@@ -0,0 +1,21 @@
/**
* Export definitions
* $Id$
* $HeadURL$
* $Author$
*/
#pragma once
#include <qglobal.h>
#ifndef SITUATIONMAPCOMMON_EXPORT
# ifdef BUILD_STATIC_LIBRARIES
# define SITUATIONMAPCOMMON_EXPORT
# else
# if defined(MAKE_SITUATIONMAPCOMMON_LIB)
# define SITUATIONMAPCOMMON_EXPORT Q_DECL_EXPORT
# else
# define SITUATIONMAPCOMMON_EXPORT Q_DECL_IMPORT
# endif
# endif
#endif
+51
View File
@@ -0,0 +1,51 @@
/**
* @RDE_HEADER@
* Logging within SituationMap
* $Id$
* $HeadURL$
* $Author$
*/
#include "situation_map_logging.h"
#include <NGLLogger/NGLLoggerBootstrap.h>
#include <QUuid>
namespace SituationMap
{
LOGGER_T getLogger(const char *name, int id)
{
static const QLatin1String prefix("SituationMap.");
std::string loggerName;
const size_t len = strlen(name);
loggerName.reserve(prefix.size() + len);
loggerName.append(prefix.data(), prefix.size());
loggerName.append(name, len);
if (id > 0)
{
std::stringstream loggerStream;
loggerStream << loggerName << "." << id;
loggerName = loggerStream.str();
}
try
{
return NGL::NGLLoggerBootstrap::getNGLRootLogger().
getNGLLogger(loggerName);
}
catch (const std::exception &ex)
{
fprintf(stderr, "Error retrieving logger: %s", ex.what());
abort();
}
}
} // namespace SituationMap
std::ostream &operator<< (std::ostream &stream,
const QUuid &value)
{
stream << "QUuid(" << value.toString() << ")";
return stream;
}
+38
View File
@@ -0,0 +1,38 @@
/**
* @RDE_HEADER@
* Logging within SituationMap
* $Id$
* $HeadURL$
* $Author$
*/
#pragma once
#include <NGLLogger/INGLLogger.h>
#include "situation_map_common_export.h"
class QUuid;
namespace SituationMap
{
using LOGGER_T = NGL::INGLLogger&;
// export for executables within 'Tests'
LOGGER_T SITUATIONMAPCOMMON_EXPORT getLogger(const char *name, int id = -1);
} // namespace SituationMap
SITUATIONMAPCOMMON_EXPORT std::ostream &operator<< (std::ostream &stream,
const QUuid &value);