453 lines
11 KiB
C++
453 lines
11 KiB
C++
/**
|
|
* @file include/ActivOneApi/Metadata.h
|
|
*
|
|
* @brief Header for Metadata definition.
|
|
*/
|
|
|
|
#if (!defined ACTIV_ONE_API_METADATA_H)
|
|
#define ACTIV_ONE_API_METADATA_H
|
|
|
|
#include "ActivOneApi/External.h"
|
|
|
|
#include "ActivOneApi/TypeDefinitions.h"
|
|
|
|
#include "ActivMiddleware/ActivBase/StatusCodeException.h"
|
|
#include "ActivMiddleware/ActivBase/StringConversion.h"
|
|
#include "ActivMiddleware/ActivBase/FieldTypes/ActivFieldTypes.h"
|
|
#include "ActivMiddleware/CxxYZ/map.h"
|
|
|
|
//! Activ namespace.
|
|
namespace Activ
|
|
{
|
|
|
|
//! OneApi namespace.
|
|
namespace OneApi
|
|
{
|
|
|
|
/**
|
|
* @brief Provides access to platform metadata.
|
|
*
|
|
* Metadata will only be fully populated when connecting into a R9 gateway.
|
|
*
|
|
* When connecting to a gateway version R8 or lower only the field maps will be populated for dictionaries present at the time of
|
|
* login.
|
|
*/
|
|
class Metadata
|
|
{
|
|
public:
|
|
//! Stores information about a field in a dictionary.
|
|
class Field
|
|
{
|
|
public:
|
|
//! Default constructor.
|
|
Field() :
|
|
m_fieldId(FIELD_ID_UNDEFINED),
|
|
m_type(FIELD_TYPE_UNKNOWN)
|
|
{
|
|
}
|
|
|
|
FieldId m_fieldId; ///< The field id.
|
|
FieldType m_type; ///< The field type.
|
|
String m_name; ///< The field name.
|
|
};
|
|
|
|
//! Map from field id to field metadata.
|
|
typedef CxxYZ::map<FieldId, Field> FieldMap;
|
|
|
|
//! Map from field name to field metadata.
|
|
typedef CxxYZ::map<String, Field> FieldNameMap;
|
|
|
|
//! Stores information about a configured data source.
|
|
class DataSource
|
|
{
|
|
public:
|
|
//! Default constructor.
|
|
DataSource() :
|
|
m_id(DATA_SOURCE_UNDEFINED),
|
|
m_symbologyId(SYMBOLOGY_UNDEFINED),
|
|
m_dictionaryId(DICTIONARY_UNDEFINED)
|
|
{
|
|
}
|
|
|
|
DataSourceId m_id; ///< The data source id.
|
|
String m_name; ///< The name of the data source.
|
|
SymbologyId m_symbologyId; ///< The symbology that the data source uses.
|
|
DictionaryId m_dictionaryId; ///< The dictionary that the data source uses.
|
|
};
|
|
|
|
//! Stores information about a configured symbology.
|
|
class Symbology
|
|
{
|
|
public:
|
|
//! Default constructor.
|
|
Symbology() :
|
|
m_id(SYMBOLOGY_UNDEFINED)
|
|
{
|
|
}
|
|
|
|
SymbologyId m_id; ///< The symbology id.
|
|
String m_name; ///< The name if the symbology.
|
|
};
|
|
|
|
//! Stores information about a configured dictionary.
|
|
class Dictionary
|
|
{
|
|
public:
|
|
//! Default constructor.
|
|
Dictionary() :
|
|
m_id(DICTIONARY_UNDEFINED)
|
|
{
|
|
}
|
|
|
|
/**
|
|
* @brief Copy constructor.
|
|
*
|
|
* @param rhs
|
|
*/
|
|
ACTIV_ONE_API Dictionary(const Dictionary &rhs);
|
|
|
|
/**
|
|
* @brief Assignment operator.
|
|
*
|
|
* @param rhs
|
|
*
|
|
* @return *this
|
|
*/
|
|
ACTIV_ONE_API Dictionary &operator=(const Dictionary &rhs);
|
|
|
|
/**
|
|
* @brief Get a field from the dictionary by field id.
|
|
*
|
|
* @param fieldId
|
|
*
|
|
* @return a reference to the field metadata.
|
|
*
|
|
* @throw Exception
|
|
*/
|
|
const Field &GetField(const FieldId fieldId) const;
|
|
|
|
/**
|
|
* @brief Get a field from the dictionary by field id.
|
|
*
|
|
* @param fieldId
|
|
* @param pField a reference to receive a pointer to the field.
|
|
*
|
|
* @retval STATUS_CODE_SUCCESS
|
|
* @retval STATUS_CODE_NOT_FOUND
|
|
*/
|
|
StatusCode GetField(const FieldId fieldId, const Field *&pField) const;
|
|
|
|
/**
|
|
* @brief Get a field from the dictionary by field name.
|
|
*
|
|
* @param fieldName
|
|
*
|
|
* @return a reference to the field metadata.
|
|
*
|
|
* @throw Exception
|
|
*/
|
|
const Field &GetField(const String &fieldName) const;
|
|
|
|
/**
|
|
* @brief Get a field from the dictionary by field name.
|
|
*
|
|
* @param fieldName
|
|
* @param pField a reference to receive a pointer to the field.
|
|
*
|
|
* @retval STATUS_CODE_SUCCESS
|
|
* @retval STATUS_CODE_NOT_FOUND
|
|
*/
|
|
StatusCode GetField(const String &fieldName, const Field *&pField) const;
|
|
|
|
/**
|
|
* @brief Get the name of a field.
|
|
*
|
|
* @param fieldId
|
|
*
|
|
* @return the field name, or the id converted to a string if not found.
|
|
*/
|
|
String GetFieldName(const FieldId fieldId) const;
|
|
|
|
DictionaryId m_id; ///< The dictionary id.
|
|
String m_name; ///< The name of the dictionary.
|
|
FieldMap m_fieldMap; ///< A map from field id to field.
|
|
FieldNameMap m_fieldNameMap; ///< A map from field name to field.
|
|
};
|
|
|
|
//! Map from data source id to data source.
|
|
typedef CxxYZ::map<DataSourceId, DataSource> DataSourceMap;
|
|
|
|
//! Map from symbology id to symbology.
|
|
typedef CxxYZ::map<SymbologyId, Symbology> SymbologyMap;
|
|
|
|
//! Map from dictionary id to dictionary.
|
|
typedef CxxYZ::map<DictionaryId, Dictionary> DictionaryMap;
|
|
|
|
/**
|
|
* @brief Get a data source name from id.
|
|
*
|
|
* @param dataSourceId
|
|
*
|
|
* @return the data source name, or the id converted to a string if not found.
|
|
*/
|
|
ACTIV_ONE_API String GetDataSourceName(const DataSourceId dataSourceId) const;
|
|
|
|
/**
|
|
* @brief Get a symbology name from id.
|
|
*
|
|
* @param symbologyId
|
|
*
|
|
* @return the symbology name, or the id converted to a string if not found.
|
|
*/
|
|
ACTIV_ONE_API String GetSymbologyName(const SymbologyId symbologyId) const;
|
|
|
|
/**
|
|
* @brief Get a dictionary name from id.
|
|
*
|
|
* @param dictionaryId
|
|
*
|
|
* @return the dictionary name, or the id converted to a string if not found.
|
|
*/
|
|
ACTIV_ONE_API String GetDictionaryName(const DictionaryId dictionaryId) const;
|
|
|
|
/**
|
|
* @brief Get a data source id from a name.
|
|
*
|
|
* @param dataSourceName
|
|
*
|
|
* @return the data source id.
|
|
*
|
|
* @throw Exeption
|
|
*/
|
|
ACTIV_ONE_API DataSourceId GetDataSourceId(const String &dataSourceName) const;
|
|
|
|
/**
|
|
* @brief Get a symbology id from a name.
|
|
*
|
|
* @param symbologyName
|
|
*
|
|
* @return the symbology id.
|
|
*
|
|
* @throw Exeption
|
|
*/
|
|
ACTIV_ONE_API SymbologyId GetSymbologyId(const String &symbologyName) const;
|
|
|
|
/**
|
|
* @brief Get a dictionary id from a name.
|
|
*
|
|
* @param dictionaryName
|
|
*
|
|
* @return the dictionary id.
|
|
*
|
|
* @throw Exeption
|
|
*/
|
|
ACTIV_ONE_API DictionaryId GetDictionaryId(const String &dictionaryName) const;
|
|
|
|
/**
|
|
* @brief Get a data source.
|
|
*
|
|
* @param dataSourceId
|
|
*
|
|
* @return a reference to the data source.
|
|
*
|
|
* @throw Exception
|
|
*/
|
|
ACTIV_ONE_API const DataSource &GetDataSource(const DataSourceId dataSourceId) const;
|
|
|
|
/**
|
|
* @brief Get a symbology.
|
|
*
|
|
* @param symbologyId
|
|
*
|
|
* @return a reference to the symbology.
|
|
*
|
|
* @throw Exception
|
|
*/
|
|
ACTIV_ONE_API const Symbology &GetSymbology(const SymbologyId symbologyId) const;
|
|
|
|
/**
|
|
* @brief Get a dictionary.
|
|
*
|
|
* @param dictionaryId
|
|
*
|
|
* @return a reference to the dictionary.
|
|
*
|
|
* @throw Exception
|
|
*/
|
|
ACTIV_ONE_API const Dictionary &GetDictionary(const DictionaryId dictionaryId) const;
|
|
|
|
/**
|
|
* @brief Get a data source.
|
|
*
|
|
* @param dataSourceId
|
|
* @param pDataSource a reference to recieve a pointer to the data source.
|
|
*
|
|
* @retval STATUS_CODE_SUCCESS
|
|
* @retval STATUS_CODE_NOT_FOUND
|
|
*/
|
|
ACTIV_ONE_API StatusCode GetDataSource(const DataSourceId dataSourceId, const DataSource *&pDataSource) const;
|
|
|
|
/**
|
|
* @brief Get a symbology.
|
|
*
|
|
* @param symbologyId
|
|
* @param pSymbology a reference to recieve a pointer to the symbology.
|
|
*
|
|
* @retval STATUS_CODE_SUCCESS
|
|
* @retval STATUS_CODE_NOT_FOUND
|
|
*/
|
|
ACTIV_ONE_API StatusCode GetSymbology(const SymbologyId symbologyId, const Symbology *&pSymbology) const;
|
|
|
|
/**
|
|
* @brief Get a dictionary.
|
|
*
|
|
* @param dictionaryId
|
|
* @param pDictionary a reference to recieve a pointer to the dictionary.
|
|
*
|
|
* @retval STATUS_CODE_SUCCESS
|
|
* @retval STATUS_CODE_NOT_FOUND
|
|
*/
|
|
ACTIV_ONE_API StatusCode GetDictionary(const DictionaryId dictionaryId, const Dictionary *&pDictionary) const;
|
|
|
|
/**
|
|
* @brief Get the dictionary for a data source.
|
|
*
|
|
* @param dataSourceId
|
|
*
|
|
* @return a reference to the dictionary.
|
|
*
|
|
* @throw Exception
|
|
*/
|
|
ACTIV_ONE_API const Dictionary &GetDataSourceDictionary(const DataSourceId dataSourceId) const;
|
|
|
|
/**
|
|
* @brief Get the dictionary for a data source.
|
|
*
|
|
* @param dataSourceId
|
|
* @param pDictionary a reference to recieve a pointer to the dictionary.
|
|
*
|
|
* @retval STATUS_CODE_SUCCESS
|
|
* @retval STATUS_CODE_NOT_FOUND
|
|
*/
|
|
ACTIV_ONE_API StatusCode GetDataSourceDictionary(const DataSourceId dataSourceId, const Dictionary *&pDictionary) const;
|
|
|
|
/**
|
|
* @brief Get the data source map.
|
|
*
|
|
* @return A reference to the data source map.
|
|
*/
|
|
const DataSourceMap &GetDataSourceMap() const;
|
|
|
|
/**
|
|
* @brief Get the symbology map.
|
|
*
|
|
* @return A reference to the symbology map.
|
|
*/
|
|
const SymbologyMap &GetSymbologyMap() const;
|
|
|
|
/**
|
|
* @brief Get the dictionary map.
|
|
*
|
|
* @return A reference to the dictionary map.
|
|
*/
|
|
const DictionaryMap &GetDictionaryMap() const;
|
|
|
|
private:
|
|
friend class MetadataManager;
|
|
|
|
DataSourceMap m_dataSourceMap;
|
|
SymbologyMap m_symbologyMap;
|
|
DictionaryMap m_dictionaryMap;
|
|
};
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline const Metadata::DataSourceMap &Metadata::GetDataSourceMap() const
|
|
{
|
|
return m_dataSourceMap;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline const Metadata::SymbologyMap &Metadata::GetSymbologyMap() const
|
|
{
|
|
return m_symbologyMap;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline const Metadata::DictionaryMap &Metadata::GetDictionaryMap() const
|
|
{
|
|
return m_dictionaryMap;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline const Metadata::Field &Metadata::Dictionary::GetField(const FieldId fieldId) const
|
|
{
|
|
const Field *pField;
|
|
|
|
ACTIV_THROW_RESULT_WITH_MESSAGE_IF(STATUS_CODE_SUCCESS, !=,
|
|
GetField(fieldId, pField),
|
|
"field id " + TypeToString(fieldId));
|
|
|
|
return *pField;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline StatusCode Metadata::Dictionary::GetField(const FieldId fieldId, const Field *&pField) const
|
|
{
|
|
const FieldMap::const_iterator iter = m_fieldMap.find(fieldId);
|
|
|
|
if (m_fieldMap.end() != iter)
|
|
{
|
|
pField = &iter->second;
|
|
return STATUS_CODE_SUCCESS;
|
|
}
|
|
|
|
return STATUS_CODE_NOT_FOUND;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline const Metadata::Field &Metadata::Dictionary::GetField(const String &fieldName) const
|
|
{
|
|
const Field *pField;
|
|
ACTIV_THROW_RESULT_WITH_MESSAGE_IF(STATUS_CODE_SUCCESS, !=, GetField(fieldName, pField), "field name " + fieldName);
|
|
return *pField;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline StatusCode Metadata::Dictionary::GetField(const String &fieldName, const Field *&pField) const
|
|
{
|
|
const FieldNameMap::const_iterator iter = m_fieldNameMap.find(fieldName);
|
|
|
|
if (m_fieldNameMap.end() != iter)
|
|
{
|
|
pField = &iter->second;
|
|
return STATUS_CODE_SUCCESS;
|
|
}
|
|
|
|
return STATUS_CODE_NOT_FOUND;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline String Metadata::Dictionary::GetFieldName(const FieldId fieldId) const
|
|
{
|
|
const Field *pField;
|
|
if (STATUS_CODE_SUCCESS == GetField(fieldId, pField))
|
|
return pField->m_name;
|
|
else
|
|
return TypeToString(fieldId);
|
|
}
|
|
|
|
} // namespace OneApi
|
|
|
|
} // namespace Activ
|
|
|
|
#endif // (!defined ACTIV_ONE_API_METADATA_H)
|