283 lines
6.8 KiB
C++
283 lines
6.8 KiB
C++
/**
|
|
* @file include/ActivOneApi/TopicId.h
|
|
*
|
|
* @brief Header for the TopicId class.
|
|
*/
|
|
|
|
#if (!defined ACTIV_ONE_API_TOPIC_ID_H)
|
|
#define ACTIV_ONE_API_TOPIC_ID_H
|
|
|
|
#include "ActivOneApi/External.h"
|
|
|
|
#include "ActivOneApi/TypeDefinitions.h"
|
|
#include "ActivOneApi/Constants/DataSourceIds.h"
|
|
|
|
#include "ActivMiddleware/CxxYZ/functional.h"
|
|
|
|
//! Activ namespace.
|
|
namespace Activ
|
|
{
|
|
|
|
//! OneApi namespace.
|
|
namespace OneApi
|
|
{
|
|
|
|
//! Topic id class.
|
|
class TopicId
|
|
{
|
|
public:
|
|
//! Default constructor.
|
|
TopicId();
|
|
|
|
/**
|
|
* @brief Constructor.
|
|
*
|
|
* @param fullyQualifiedSymbol a fully qualified symbol with or without table number. Valid formats are:
|
|
* - 1:MSFT.Q
|
|
* - 1/0:MSFT.Q
|
|
*
|
|
* @throw Exception
|
|
*/
|
|
explicit ACTIV_ONE_API TopicId(const String &fullyQualifiedSymbol);
|
|
|
|
/**
|
|
* @brief Constructor.
|
|
*
|
|
* Table number is set to TABLE_NO_UNDEFINED.
|
|
*
|
|
* @param dataSourceId the data source this topic belongs to.
|
|
* @param symbol the symbol.
|
|
*/
|
|
TopicId(const DataSourceId dataSourceId, const String &symbol);
|
|
|
|
/**
|
|
* @brief Constructor.
|
|
*
|
|
* @param dataSourceId the data source this topic belongs to.
|
|
* @param tableNumber the TableNo of this topic.
|
|
* @param symbol the symbol.
|
|
*/
|
|
TopicId(const DataSourceId dataSourceId, const TableNo tableNumber, const String &symbol);
|
|
|
|
//! Reset the TopicId
|
|
void Reset();
|
|
|
|
/**
|
|
* @brief Is the TopicId valid?
|
|
*
|
|
* @return Boolean
|
|
*/
|
|
bool IsValid() const;
|
|
|
|
/**
|
|
* @brief Equality operator.
|
|
*
|
|
* @param rhs
|
|
*
|
|
* @return Boolean
|
|
*/
|
|
bool operator==(const TopicId &rhs) const;
|
|
|
|
/**
|
|
* @brief Inequality operator.
|
|
*
|
|
* @param rhs
|
|
*
|
|
* @return Boolean
|
|
*/
|
|
bool operator!=(const TopicId &rhs) const;
|
|
|
|
/**
|
|
* @brief Less than operator.
|
|
*
|
|
* @param rhs
|
|
*
|
|
* @return Boolean
|
|
*/
|
|
bool operator<(const TopicId &rhs) const;
|
|
|
|
/**
|
|
* @brief Less than or equal operator.
|
|
*
|
|
* @param rhs
|
|
*
|
|
* @return Boolean
|
|
*/
|
|
bool operator<=(const TopicId &rhs) const;
|
|
|
|
/**
|
|
* @brief More than operator.
|
|
*
|
|
* @param rhs
|
|
*
|
|
* @return Boolean
|
|
*/
|
|
bool operator>(const TopicId &rhs) const;
|
|
|
|
/**
|
|
* @brief More than or equal operator.
|
|
*
|
|
* @param rhs
|
|
*
|
|
* @return Boolean
|
|
*/
|
|
bool operator>=(const TopicId &rhs) const;
|
|
|
|
/**
|
|
* @brief Convert TopicId to a string representation.
|
|
*
|
|
* @return The fully qualified string representation of the TopicId.
|
|
*
|
|
* @throw Exception
|
|
*/
|
|
ACTIV_ONE_API String ToString() const;
|
|
|
|
DataSourceId m_dataSourceId; ///< The data source this topic belongs to.
|
|
TableNo m_tableNumber; ///< The TableNo of this topic.
|
|
String m_symbol; ///< The symbol.
|
|
|
|
friend struct CxxYZ::hash<TopicId>;
|
|
};
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline TopicId::TopicId() :
|
|
m_dataSourceId(DATA_SOURCE_UNDEFINED),
|
|
m_tableNumber(TABLE_NO_UNDEFINED)
|
|
{
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline TopicId::TopicId(const DataSourceId dataSourceId, const String &symbol) :
|
|
m_dataSourceId(dataSourceId),
|
|
m_tableNumber(TABLE_NO_UNDEFINED),
|
|
m_symbol(symbol)
|
|
{
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline TopicId::TopicId(const DataSourceId dataSourceId, const TableNo tableNumber, const String &symbol) :
|
|
m_dataSourceId(dataSourceId),
|
|
m_tableNumber(tableNumber),
|
|
m_symbol(symbol)
|
|
{
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline void TopicId::Reset()
|
|
{
|
|
m_dataSourceId = DATA_SOURCE_UNDEFINED;
|
|
m_tableNumber = TABLE_NO_UNDEFINED;
|
|
m_symbol.clear();
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline bool TopicId::IsValid() const
|
|
{
|
|
return (m_dataSourceId != DATA_SOURCE_UNDEFINED) && (!m_symbol.empty());
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline bool TopicId::operator==(const TopicId &rhs) const
|
|
{
|
|
return (rhs.m_dataSourceId == m_dataSourceId) && (rhs.m_tableNumber == m_tableNumber) && (rhs.m_symbol == m_symbol);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline bool TopicId::operator!=(const TopicId &rhs) const
|
|
{
|
|
return !(*this == rhs);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline bool TopicId::operator<(const TopicId &rhs) const
|
|
{
|
|
if ((m_dataSourceId == rhs.m_dataSourceId) && (m_tableNumber == rhs.m_tableNumber))
|
|
return (m_symbol < rhs.m_symbol);
|
|
|
|
if (m_dataSourceId < rhs.m_dataSourceId)
|
|
return true;
|
|
|
|
if (m_dataSourceId > rhs.m_dataSourceId)
|
|
return false;
|
|
|
|
return (m_tableNumber < rhs.m_tableNumber);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline bool TopicId::operator<=(const TopicId &rhs) const
|
|
{
|
|
if ((m_dataSourceId == rhs.m_dataSourceId) && (m_tableNumber == rhs.m_tableNumber))
|
|
return (m_symbol <= rhs.m_symbol);
|
|
|
|
if (m_dataSourceId < rhs.m_dataSourceId)
|
|
return true;
|
|
|
|
if (m_dataSourceId > rhs.m_dataSourceId)
|
|
return false;
|
|
|
|
return (m_tableNumber <= rhs.m_tableNumber);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline bool TopicId::operator>(const TopicId &rhs) const
|
|
{
|
|
return !(*this <= rhs);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline bool TopicId::operator>=(const TopicId &rhs) const
|
|
{
|
|
return !(*this < rhs);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
* @brief hash_value
|
|
*
|
|
* @param topicId
|
|
*
|
|
* @return The hashed value of @a topicId
|
|
*/
|
|
inline std::size_t hash_value(const TopicId &topicId)
|
|
{
|
|
size_t seed = 0;
|
|
Boost::hash_combine(seed, topicId.m_dataSourceId);
|
|
Boost::hash_combine(seed, topicId.m_symbol);
|
|
return seed;
|
|
}
|
|
|
|
} // namespace OneApi
|
|
|
|
} // namespace Activ
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
namespace ACTIV_CXXYZ_HASH_NAMESPACE
|
|
{
|
|
|
|
template<>
|
|
struct hash<Activ::OneApi::TopicId>
|
|
{
|
|
inline size_t operator()(const Activ::OneApi::TopicId &topicId) const
|
|
{
|
|
return hash_value(topicId);
|
|
}
|
|
};
|
|
|
|
} // namespace ACTIV_CXXYZ_HASH_NAMESPACE
|
|
|
|
#endif // (!defined ACTIV_ONE_API_TOPIC_ID_H)
|