223 lines
9.3 KiB
C++
Executable File
223 lines
9.3 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* SidcCodec for internal handling of SIDCs
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
*/
|
|
#pragma once
|
|
|
|
// Own
|
|
#include "symbology_type.h"
|
|
#include "advanced_symbology_export.h"
|
|
|
|
#include <SymbologyXML/symbol_types.h>
|
|
|
|
// Qt
|
|
#include <QHash>
|
|
#include <QString>
|
|
#include <QStringRef>
|
|
|
|
namespace AdvancedSymbology
|
|
{
|
|
|
|
/**
|
|
* \brief The SidcCodec namespace enables the encoding and decoding of a (raw) sidc (SymbolIdCode)
|
|
* The BaseSymbolCode describes the base symbol, the *Typ* like 'soldier', 'tank'
|
|
* WITHOUT the affiliation (membership to a party) and so on.
|
|
* Only the complete SIDC (WITH affiliation and so on) describes a concrete instanciation,
|
|
* examples:
|
|
*
|
|
* - APP6D / MIL2525D
|
|
* + M25D|BASE|25271300 - abstract/Typ (Context "template": assign symbol)
|
|
* + M25D|CMPL|10012500002713000000 - concrete (message from Training Area)
|
|
*
|
|
* - APP6C / MIL2525C
|
|
* Here a abstract (Base) and concrete (Complete) are existing also:
|
|
* M25C|BASE|S*A*MFUM--*****
|
|
* M25C|CMPL|SNAAMFUM--AL***
|
|
|
|
* - Extra / Civil / ETS / XML:
|
|
* NONE|CIVE|PlanStelle
|
|
* NONE|CIVX|<Dateiname alter XML-basierter SymbolEditor>
|
|
|
|
* @note This namespace uses a QString (and not QLatin1String) since maybe a chinese operator create a symbol and uses a name in his first language.
|
|
*/
|
|
namespace SidcCodec
|
|
{
|
|
/**
|
|
* Type of SIDC code or symbol
|
|
*/
|
|
enum class SidcType
|
|
{
|
|
None, ///< NONE
|
|
Base, ///< base symbol without frame, modifier or amplifier coded as "BASE"
|
|
Complete, ///< concrete symbol with complete definition coded as "CMPL"
|
|
CivilEts, ///< Civil Ets coded as "CVLE"
|
|
CivilXml ///< Civil XML coded as "CVLX"
|
|
};
|
|
|
|
|
|
/**
|
|
* Check if sidc string is encoded.
|
|
* @param encodedSidc sidc string to check
|
|
* @return Returns true if encoded, otherwise false.
|
|
*/
|
|
ADVANCED_SYMBOLOGY_EXPORT bool isEncoded(const QString &encodedSidc);
|
|
|
|
/**
|
|
* Check if sidc syntax is correct.
|
|
* @param encodedSidc sidc string to check
|
|
* @return Returns true if syntax is correct, otherwise false.
|
|
*/
|
|
ADVANCED_SYMBOLOGY_EXPORT bool checkSidcSyntax(const QString &encodedSidc);
|
|
|
|
|
|
/**
|
|
* Check an encode sidc string if it's a civil symbol.
|
|
* @param encodedSidc Encoded sidc string
|
|
* @return Return value is true in case of civil symbols, otherwise false
|
|
*/
|
|
ADVANCED_SYMBOLOGY_EXPORT bool isCivil(const QString &encodedSidc);
|
|
|
|
/**
|
|
* Check an encode sidc string if the syntax is correctly.
|
|
* @param encodedSidc Encoded sidc string
|
|
* @return Return value is true if \c encodeSidc builded correctly. In case of wrong syntax the return value is false.
|
|
*/
|
|
ADVANCED_SYMBOLOGY_EXPORT bool checkSidcSyntax(const QString &encodedSidc);
|
|
|
|
ADVANCED_SYMBOLOGY_EXPORT unsigned int rawSidcOffset();
|
|
|
|
/**
|
|
* Functions to encode and decode a SIDC from or to raw string codes. These functions are really simple and
|
|
* can not convert between SidcType::Base and SidcType::Complete. This purposes are handled by class \c SidcBuilder.
|
|
* @see SidcBuilder
|
|
* @{
|
|
*/
|
|
ADVANCED_SYMBOLOGY_EXPORT QString encodeBaseSymbolCode(SymbologyType symbologyType, const QString &baseSymboCodeSidc); /**< Encode base symbol. Example: M25D|BASE|25271300 */
|
|
ADVANCED_SYMBOLOGY_EXPORT QString encodeComplete(SymbologyType symbologyType, const QString &completeSidc); /**< Encode comlete symbol. Example: M25D|CMPL|10012500002713000000 */
|
|
ADVANCED_SYMBOLOGY_EXPORT QString encodeCivilEts(const QString &civilSidc); /**< Encode ETS civil symbol. Example: NONE|CVLE|PlanStelle */
|
|
ADVANCED_SYMBOLOGY_EXPORT QString encodeCivilXml(const QString &civilSidc); /**< Encode XML civil symbol. Example: NONE|CVLX|PlanStelle */
|
|
|
|
ADVANCED_SYMBOLOGY_EXPORT QString encodeCivilXmlSymbolId( uint symbolId );
|
|
ADVANCED_SYMBOLOGY_EXPORT QString encodeCivilXmlSymbolId( uint symbolId
|
|
, SymbologyXML::SymbolTypes::t_state state
|
|
, SymbologyXML::SymbolTypes::t_uncertainty uncertainty
|
|
, SymbologyXML::SymbolTypes::t_affil affil
|
|
, SymbologyXML::SymbolTypes::t_mob mob );
|
|
|
|
|
|
ADVANCED_SYMBOLOGY_EXPORT QString extractCivilXmlBaseSidc( const QString &sidc );
|
|
|
|
ADVANCED_SYMBOLOGY_EXPORT SymbologyType decodeSymbologyType(const QString &encodedSidc); /**< Decode symbology type */
|
|
ADVANCED_SYMBOLOGY_EXPORT SidcType decodeSidcType(const QString &encodedSidc); /**< Decode sidc type */
|
|
ADVANCED_SYMBOLOGY_EXPORT QString decodeRawSidc(const QString &encodedSidc); /**< Decode raw sidc */
|
|
ADVANCED_SYMBOLOGY_EXPORT int decodeCivilXml(const QString &civilSidc);
|
|
|
|
/** @} */
|
|
|
|
/**
|
|
* Some convience functions ...
|
|
* @{
|
|
*/
|
|
ADVANCED_SYMBOLOGY_EXPORT QString encodeBaseSymbolCode(SymbologyType symbologyType, const QStringRef &baseSymboCodeSidc);
|
|
ADVANCED_SYMBOLOGY_EXPORT QString encodeComplete(SymbologyType symbologyType, const QStringRef &completeSidc);
|
|
ADVANCED_SYMBOLOGY_EXPORT QString encodeCivilEts(const QStringRef &civilSidc);
|
|
ADVANCED_SYMBOLOGY_EXPORT QString encodeCivilXml(const QStringRef &civilSidc);
|
|
|
|
ADVANCED_SYMBOLOGY_EXPORT QString encodeBaseSymbolCode(SymbologyType symbologyType, const std::string &baseSymboCodeSidc);
|
|
ADVANCED_SYMBOLOGY_EXPORT QString encodeComplete(SymbologyType symbologyType, const std::string &completeSidc);
|
|
ADVANCED_SYMBOLOGY_EXPORT QString encodeCivilEts(const std::string &civilSidc);
|
|
ADVANCED_SYMBOLOGY_EXPORT QString encodeCivilXml(const std::string &civilSidc);
|
|
|
|
ADVANCED_SYMBOLOGY_EXPORT QString encodeBaseSymbolCode(SymbologyType symbologyType, const char *baseSymboCodeSidc);
|
|
ADVANCED_SYMBOLOGY_EXPORT QString encodeComplete(SymbologyType symbologyType, const char *completeSidc);
|
|
ADVANCED_SYMBOLOGY_EXPORT QString encodeCivilEts(const char *civilSidc);
|
|
ADVANCED_SYMBOLOGY_EXPORT QString encodeCivilXml(const char *civilSidc);
|
|
|
|
/** @} */
|
|
|
|
/**
|
|
* @brief Helper class to store information appropriate to a sidc.
|
|
* In symbol dictionary symbols are stored with a key to get access to complete set of symbol's data. This key is
|
|
* equal with base or complete symbol code. The class \c SidcHashTable stores information appropriate to a sidc
|
|
* in a QHashTable. The hash tabke index here is the encoded sidc.
|
|
*/
|
|
template<class Storage> class SidcHashTable
|
|
{
|
|
QHash<QString, Storage> m_hashTable;
|
|
SymbologyType m_symbologyType = SymbologyType::None;
|
|
SidcType m_sidcType = SidcType::None;
|
|
|
|
|
|
QString buildSidc(const QString &key) const
|
|
{
|
|
if (isEncoded(key)) return key;
|
|
|
|
switch (m_sidcType)
|
|
{
|
|
case SidcType::Base : return SidcCodec::encodeBaseSymbolCode(m_symbologyType, key);
|
|
case SidcType::Complete : return SidcCodec::encodeComplete(m_symbologyType, key);
|
|
case SidcType::CivilEts : return SidcCodec::encodeCivilEts(key);
|
|
case SidcType::CivilXml : return SidcCodec::encodeCivilXml(key);
|
|
case SidcType::None :
|
|
default : break;
|
|
}
|
|
return QString();
|
|
} // QString buildSidc(const QString & key) const
|
|
|
|
|
|
public:
|
|
|
|
SidcHashTable() = default;
|
|
explicit SidcHashTable(SymbologyType symbologyType) : m_symbologyType(symbologyType) {}
|
|
explicit SidcHashTable(SymbologyType symbologyType, SidcType sidcType) : m_symbologyType(symbologyType), m_sidcType(sidcType) {}
|
|
|
|
SymbologyType symbologyType() const { return m_symbologyType; }
|
|
SidcType sidcType() const { return m_sidcType; }
|
|
|
|
void clear() { m_hashTable.clear(); }
|
|
bool empty() const { return m_hashTable.empty(); }
|
|
int count() const { return m_hashTable.count(); }
|
|
int size() const { return m_hashTable.size(); }
|
|
|
|
QStringList keys() const { return m_hashTable.keys(); }
|
|
|
|
bool contains(const QString &key) const { return m_hashTable.contains(buildSidc(key)); }
|
|
|
|
bool containsSidc(const QString &sidc) const
|
|
{
|
|
if (decodeSymbologyType(sidc) == m_symbologyType)
|
|
{
|
|
if (decodeSidcType(sidc) == m_sidcType) return m_hashTable.contains(sidc);
|
|
}
|
|
return false;
|
|
} // bool containSidc( const QString & sidc ) const
|
|
|
|
typename QHash<QString, Storage>::iterator find(const QString &key) { return m_hashTable.find(buildSidc(key)); }
|
|
typename QHash<QString, Storage>::iterator begin() { return m_hashTable.begin(); }
|
|
typename QHash<QString, Storage>::iterator end() { return m_hashTable.end(); }
|
|
|
|
typename QHash<QString, Storage>::const_iterator find(const QString &key) const { return m_hashTable.find(buildSidc(key)); }
|
|
typename QHash<QString, Storage>::const_iterator begin() const { return m_hashTable.begin(); }
|
|
typename QHash<QString, Storage>::const_iterator end() const { return m_hashTable.end(); }
|
|
|
|
Storage &operator[](const QString &key) { return m_hashTable[buildSidc(key)]; }
|
|
Storage operator[](const QString &key) const { return m_hashTable[buildSidc(key)]; }
|
|
|
|
void remove(const QString &sidc)
|
|
{
|
|
isEncoded(sidc) ? m_hashTable.remove(sidc) : m_hashTable.remove(buildSidc(sidc));
|
|
} // void remove(const QString & sidc)
|
|
|
|
}; // SidcHashTable
|
|
|
|
|
|
} // namespace SidcCodec
|
|
|
|
|
|
} // namespace AdvancedSymbology
|
|
|
|
// #include "sidc_codec.inl"
|