837 lines
22 KiB
C++
837 lines
22 KiB
C++
/**
|
|
* @file include/ActivOneApi/Detail/FieldListValidatorDetail.h
|
|
*
|
|
* @brief Header file for the field list validator detail classes.
|
|
*/
|
|
|
|
#if (!defined ACTIV_ONE_API_DETAIL_FIELD_LIST_VALIDATOR_DETAIL_H)
|
|
#define ACTIV_ONE_API_DETAIL_FIELD_LIST_VALIDATOR_DETAIL_H
|
|
|
|
#include "ActivOneApi/External.h"
|
|
|
|
#include "ActivOneApi/TypeDefinitions.h"
|
|
|
|
#include "ActivMiddleware/ActivBase/FieldTypes/All.h"
|
|
#include "ActivMiddleware/ActivBase/FieldTypes/FieldTypeFactory.h"
|
|
#include "ActivMiddleware/ActivBase/FieldTypes/IFieldType.h"
|
|
#include "ActivMiddleware/CxxYZ/memory.h"
|
|
#include "ActivMiddleware/CxxYZ/vector.h"
|
|
|
|
#include ACTIV_BOOST_INCLUDE(dynamic_bitset.hpp)
|
|
#include ACTIV_BOOST_INCLUDE(multi_index_container.hpp)
|
|
#include ACTIV_BOOST_INCLUDE(multi_index/hashed_index.hpp)
|
|
#include ACTIV_BOOST_INCLUDE(multi_index/ordered_index.hpp)
|
|
#include ACTIV_BOOST_INCLUDE(multi_index/mem_fun.hpp)
|
|
|
|
//! Activ namespace.
|
|
namespace Activ
|
|
{
|
|
|
|
//! OneApi namespace.
|
|
namespace OneApi
|
|
{
|
|
|
|
template<typename FIELD_STORAGE>
|
|
class FieldListValidatorT;
|
|
class FieldListValidatorImpl;
|
|
class FieldListValidatorImplTemplateUpdate;
|
|
|
|
//! FlvDetail namespace.
|
|
namespace FlvDetail
|
|
{
|
|
|
|
class CachedField;
|
|
|
|
//! Field class.
|
|
class Field
|
|
{
|
|
public:
|
|
//! Get the field id.
|
|
FieldId GetId() const
|
|
{
|
|
return m_fieldId;
|
|
}
|
|
|
|
//! Is defined.
|
|
bool IsDefined() const
|
|
{
|
|
return m_isDefined;
|
|
}
|
|
|
|
//! Get the IFieldType of this field.
|
|
FieldType GetType() const
|
|
{
|
|
return IsDefined() ? m_pIFieldType->GetType() : FIELD_TYPE_UNKNOWN;
|
|
}
|
|
|
|
/**
|
|
* @brief Does this field update the last cached value for the field?
|
|
*
|
|
* An example of a field that would return false here is one from a late trade.
|
|
*
|
|
* @return true if the field would be updated.
|
|
*/
|
|
bool DoesUpdateLastValue() const
|
|
{
|
|
return m_doesUpdateLastValue;
|
|
}
|
|
|
|
/**
|
|
* @brief Get the ACTIV field type as a base IFieldType pointer.
|
|
*
|
|
* @return IFieldType pointer to a const or nullptr if the field is undefined.
|
|
*/
|
|
const IFieldType * GetIFieldType() const
|
|
{
|
|
return IsDefined() ? m_pIFieldType.get() : ACTIV_NULLPTR;
|
|
}
|
|
|
|
/**
|
|
* @brief Get ACTIV field type.
|
|
*
|
|
* @deprecated This method will be removed in future release.
|
|
*
|
|
* @param pFieldType reference to a const pointer to a concrete ACTIV field type object.
|
|
*
|
|
* @retval STATUS_CODE_SUCCESS field is defined and pFieldType is set
|
|
* @retval STATUS_CODE_UNDEFINED_FIELD field is undefined
|
|
* @retval STATUS_CODE_INVALID_FIELD_TYPE template type @a T does not match the type of the field
|
|
*/
|
|
template<typename T>
|
|
StatusCode GetActivFieldType(const T* &pFieldType) const
|
|
{
|
|
if (!IsDefined())
|
|
return STATUS_CODE_UNDEFINED_FIELD;
|
|
|
|
if (ACTIV_LIKELY(T::FIELD_TYPE == m_pIFieldType->GetType()))
|
|
{
|
|
pFieldType = static_cast<T *>(m_pIFieldType.get());
|
|
return STATUS_CODE_SUCCESS;
|
|
}
|
|
|
|
return STATUS_CODE_INVALID_FIELD_TYPE;
|
|
}
|
|
|
|
/**
|
|
* @brief Get ACTIV field type.
|
|
*
|
|
* @deprecated This method will be removed in future release.
|
|
*
|
|
* @return Const pointer to a concrete ACTIV field type object.
|
|
*
|
|
* @throw StatusCodeException, where m_errorCode is:
|
|
* STATUS_CODE_UNDEFINED_FIELD field is undefined
|
|
* STATUS_CODE_NOT_FOUND field not present in record
|
|
* STATUS_CODE_INVALID_FIELD_TYPE template type T does not match the type of the field
|
|
*/
|
|
template<typename T>
|
|
const T *GetActivFieldType() const
|
|
{
|
|
const T *pFieldType;
|
|
|
|
ACTIV_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, GetActivFieldType(pFieldType));
|
|
|
|
return pFieldType;
|
|
}
|
|
|
|
/**
|
|
* @brief Get a pointer to the ACTIV field type object.
|
|
*
|
|
* @tparam concrete ACTIV field type
|
|
*
|
|
* @param pFieldValue const pointer reference to a concrete ACTIV field type object.
|
|
*
|
|
* @retval STATUS_CODE_SUCCESS field is defined and pFieldValue is set
|
|
* @retval STATUS_CODE_UNDEFINED_FIELD field is undefined
|
|
* @retval STATUS_CODE_INVALID_FIELD_TYPE template type @a T does not match the type of the field
|
|
*/
|
|
template<typename T>
|
|
typename Boost::enable_if<IsFieldType<T>, StatusCode>::type
|
|
GetValue(const T* &pFieldValue) const
|
|
{
|
|
return GetActivFieldType<T>(pFieldValue);
|
|
}
|
|
|
|
/**
|
|
* @brief Get the value as a String.
|
|
*
|
|
* @param fieldValue reference to a String.
|
|
*
|
|
* @retval STATUS_CODE_SUCCESS field is defined and fieldValue is set
|
|
* @retval STATUS_CODE_UNDEFINED_FIELD field is undefined
|
|
*/
|
|
template<typename T>
|
|
typename Boost::enable_if<Boost::is_same<String, T>, StatusCode>::type
|
|
GetValue(T &fieldValue) const
|
|
{
|
|
if (!IsDefined())
|
|
return STATUS_CODE_UNDEFINED_FIELD;
|
|
|
|
fieldValue = m_pIFieldType->ToString();
|
|
return STATUS_CODE_SUCCESS;
|
|
}
|
|
|
|
/**
|
|
* @brief Get the value as an unsigned integral.
|
|
*
|
|
* @tparam the basic unsigned int type (uint8_t, uint16_t, uint32_t, uint64_t)
|
|
*
|
|
* @param fieldValue reference to an unsigned integral.
|
|
*
|
|
* @retval STATUS_CODE_SUCCESS field is defined and fieldValue is set
|
|
* @retval STATUS_CODE_UNDEFINED_FIELD field is undefined
|
|
* @retval STATUS_CODE_INVALID_FIELD_TYPE template type @a T does not match the type of the field
|
|
* @retval STATUS_CODE_OUT_OF_RANGE template type @a T too short to store the value
|
|
*/
|
|
template<typename T>
|
|
typename Boost::enable_if_c<Boost::is_unsigned<T>::value && !Boost::is_same<bool, T>::value, StatusCode>::type
|
|
GetValue(T &fieldValue) const
|
|
{
|
|
const UInt *pFieldType;
|
|
ACTIV_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, GetActivFieldType(pFieldType));
|
|
|
|
const uint64_t value = pFieldType->Get();
|
|
fieldValue = static_cast<T>(value);
|
|
|
|
if (ACTIV_UNLIKELY(value != static_cast<uint64_t>(fieldValue)))
|
|
return STATUS_CODE_OUT_OF_RANGE;
|
|
|
|
return STATUS_CODE_SUCCESS;
|
|
}
|
|
|
|
/**
|
|
* @brief Get the value as a signed integral.
|
|
*
|
|
* @tparam the basic signed integral type (int8_t, int16_t, int32_t, int64_t)
|
|
*
|
|
* @param fieldValue reference to the basic signed integral.
|
|
*
|
|
* @retval STATUS_CODE_SUCCESS field is defined and pFieldType is set
|
|
* @retval STATUS_CODE_UNDEFINED_FIELD field is undefined
|
|
* @retval STATUS_CODE_INVALID_FIELD_TYPE template type @a T does not match the type of the field
|
|
* @retval STATUS_CODE_OUT_OF_RANGE template type @a T too short to store the value
|
|
*/
|
|
template<typename T>
|
|
typename Boost::enable_if<Boost::is_signed<T>, StatusCode>::type
|
|
GetValue(T &fieldValue) const
|
|
{
|
|
const SInt *pFieldType;
|
|
ACTIV_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, GetActivFieldType(pFieldType));
|
|
|
|
const int64_t value = pFieldType->Get();
|
|
fieldValue = static_cast<T>(value);
|
|
|
|
if (ACTIV_UNLIKELY(value != static_cast<int64_t>(fieldValue)))
|
|
return STATUS_CODE_OUT_OF_RANGE;
|
|
|
|
return STATUS_CODE_SUCCESS;
|
|
}
|
|
|
|
/**
|
|
* @brief Get the value as a floating-point.
|
|
*
|
|
* @tparam the floating-point type (float, double, long double)
|
|
*
|
|
* @param fieldValue reference to a floating-point.
|
|
*
|
|
* @retval STATUS_CODE_SUCCESS field is defined and pFieldType is set
|
|
* @retval STATUS_CODE_UNDEFINED_FIELD field is undefined
|
|
* @retval STATUS_CODE_INVALID_FIELD_TYPE template type @a T does not match the type of the field
|
|
* @retval STATUS_CODE_OUT_OF_RANGE template type @a T too short to store the value
|
|
*/
|
|
template<typename T>
|
|
typename Boost::enable_if<Boost::is_floating_point<T>, StatusCode>::type
|
|
GetValue(T &fieldValue) const
|
|
{
|
|
if (!IsDefined())
|
|
return STATUS_CODE_UNDEFINED_FIELD;
|
|
|
|
switch (GetType())
|
|
{
|
|
case Rational::FIELD_TYPE:
|
|
case TRational::FIELD_TYPE:
|
|
{
|
|
const Rational *pFieldValue;
|
|
ACTIV_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, GetValue<Rational>(pFieldValue));
|
|
fieldValue = static_cast<T>(pFieldValue->Get());
|
|
}
|
|
break;
|
|
|
|
case Double::FIELD_TYPE:
|
|
{
|
|
const Double *pFieldValue;
|
|
ACTIV_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, GetValue<Double>(pFieldValue));
|
|
fieldValue = static_cast<T>(pFieldValue->Get());
|
|
}
|
|
break;
|
|
|
|
default:
|
|
return STATUS_CODE_INVALID_FIELD_TYPE;
|
|
}
|
|
|
|
return STATUS_CODE_SUCCESS;
|
|
}
|
|
|
|
/**
|
|
* @brief Get the value as a boolean.
|
|
*
|
|
* @tparam the basic bool type
|
|
*
|
|
* @param fieldValue reference to a boolean.
|
|
*
|
|
* @retval STATUS_CODE_SUCCESS field is defined and pFieldType is set
|
|
* @retval STATUS_CODE_UNDEFINED_FIELD field is undefined
|
|
* @retval STATUS_CODE_INVALID_FIELD_TYPE template type @a T does not match the type of the field
|
|
* @retval STATUS_CODE_OUT_OF_RANGE template type @a T too short to store the value
|
|
*/
|
|
template<typename T>
|
|
typename Boost::enable_if<Boost::is_same<bool, T>, StatusCode>::type
|
|
GetValue(bool &fieldValue) const
|
|
{
|
|
const Boolean *pFieldType;
|
|
ACTIV_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, GetActivFieldType(pFieldType));
|
|
|
|
fieldValue = pFieldType->Get();
|
|
|
|
return STATUS_CODE_SUCCESS;
|
|
}
|
|
|
|
/**
|
|
* @brief Get the value as a ACTIV field type reference.
|
|
*
|
|
* @return const concrete ACTIV field type reference.
|
|
*
|
|
* @throw StatusCodeException, where m_errorCode is:
|
|
* STATUS_CODE_UNDEFINED_FIELD field is undefined
|
|
* STATUS_CODE_NOT_FOUND field not present in record
|
|
* STATUS_CODE_INVALID_FIELD_TYPE template type T does not match the type of the field
|
|
*/
|
|
template<typename T>
|
|
typename Boost::enable_if<IsFieldType<T>, const T&>::type
|
|
GetValue() const
|
|
{
|
|
return *GetActivFieldType<T>();
|
|
}
|
|
|
|
/**
|
|
* @brief Get the value.
|
|
*
|
|
* @return the value as type (uint*_t, int*_t, bool, double, String, ...)
|
|
*
|
|
* @throw StatusCodeException, where m_errorCode is:
|
|
* STATUS_CODE_UNDEFINED_FIELD field is undefined
|
|
* STATUS_CODE_NOT_FOUND field not present in record
|
|
* STATUS_CODE_INVALID_FIELD_TYPE template type T does not match the UInt type of the field
|
|
* STATUS_CODE_OUT_OF_RANGE template type @a T too short to store the value
|
|
*/
|
|
template<typename T>
|
|
typename Boost::enable_if_c<!IsFieldType<T>::value, T>::type
|
|
GetValue() const
|
|
{
|
|
T fieldValue;
|
|
ACTIV_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, GetValue<T>(fieldValue));
|
|
return fieldValue;
|
|
}
|
|
|
|
/**
|
|
* @brief Get the value as a vector of bytes.
|
|
*
|
|
* @param fieldValue reference to a vector of bytes.
|
|
*
|
|
* @retval STATUS_CODE_SUCCESS field is defined and pFieldType is set
|
|
* @retval STATUS_CODE_UNDEFINED_FIELD field is undefined
|
|
* @retval STATUS_CODE_INVALID_FIELD_TYPE field type does not return vector of bytes
|
|
*/
|
|
template<typename T>
|
|
typename Boost::enable_if<Boost::is_same<std::vector<uint8_t>, T>, StatusCode>::type
|
|
GetValue(T &fieldValue) const
|
|
{
|
|
if (!IsDefined())
|
|
return STATUS_CODE_UNDEFINED_FIELD;
|
|
|
|
switch (m_pIFieldType->GetType())
|
|
{
|
|
case FIELD_TYPE_TEXT_STRING:
|
|
AssignValue<TextString>(fieldValue);
|
|
break;
|
|
|
|
case FIELD_TYPE_TEXT_ARRAY:
|
|
AssignValue<TextArray>(fieldValue);
|
|
break;
|
|
|
|
case FIELD_TYPE_BINARY_STRING:
|
|
AssignValue<BinaryString>(fieldValue);
|
|
break;
|
|
|
|
case FIELD_TYPE_BINARY_ARRAY:
|
|
AssignValue<BinaryArray>(fieldValue);
|
|
break;
|
|
|
|
case FIELD_TYPE_BLOB:
|
|
AssignValue<Blob>(fieldValue);
|
|
break;
|
|
|
|
case FIELD_TYPE_CRC_BLOB:
|
|
AssignValue<CrcBlob>(fieldValue);
|
|
break;
|
|
|
|
default:
|
|
return STATUS_CODE_INVALID_FIELD_TYPE;
|
|
}
|
|
|
|
return STATUS_CODE_SUCCESS;
|
|
}
|
|
|
|
private:
|
|
ACTIV_BOOST_MOVABLE_BUT_NOT_COPYABLE(Field)
|
|
|
|
explicit Field(const FieldId fieldId) :
|
|
m_fieldId(fieldId)
|
|
{
|
|
// In class declaration for GCC.
|
|
}
|
|
|
|
explicit Field(ACTIV_BOOST_RV_REF(Field) rhs) :
|
|
m_fieldId(rhs.m_fieldId),
|
|
m_isDefined(rhs.m_isDefined),
|
|
m_doesUpdateLastValue(rhs.m_doesUpdateLastValue),
|
|
m_pIFieldType(CxxYZ::move(rhs.m_pIFieldType))
|
|
{
|
|
// In class declaration for GCC.
|
|
}
|
|
|
|
template<typename T>
|
|
void AssignValue(std::vector<uint8_t> &fieldValue) const
|
|
{
|
|
const T *pValue;
|
|
pValue = static_cast<T *>(m_pIFieldType.get());
|
|
fieldValue.assign(pValue->GetData(), pValue->GetData() + pValue->GetSize());
|
|
}
|
|
|
|
const FieldId m_fieldId; ///< Id of this field.
|
|
bool m_isDefined; ///< Is @a m_pIFieldType defined.
|
|
bool m_doesUpdateLastValue; ///< Does this field update the last cached value.
|
|
CxxYZ::unique_ptr<IFieldType> m_pIFieldType; ///< Field data.
|
|
|
|
friend class CachedField;
|
|
|
|
template<typename>
|
|
friend class OneApi::FieldListValidatorT;
|
|
friend class OneApi::FieldListValidatorImpl;
|
|
friend class OneApi::FieldListValidatorImplTemplateUpdate;
|
|
};
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
template<> ACTIV_TEMPLATE_API(ACTIV_ONE_API)
|
|
StatusCode Field::GetActivFieldType<Rational>(const Rational* &pFieldType) const;
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
//! Cached field.
|
|
class CachedField
|
|
{
|
|
public:
|
|
explicit CachedField(const FieldId fieldId) :
|
|
m_field(fieldId),
|
|
m_isPresent(false),
|
|
m_fieldType(FIELD_TYPE_UNKNOWN)
|
|
{
|
|
}
|
|
|
|
explicit CachedField(ACTIV_BOOST_RV_REF(CachedField) rhs) :
|
|
m_field(CxxYZ::move(rhs.m_field)),
|
|
m_isPresent(rhs.m_isPresent),
|
|
m_fieldType(rhs.m_fieldType)
|
|
{
|
|
}
|
|
|
|
~CachedField()
|
|
{
|
|
}
|
|
|
|
//! Does this object have an IFieldType object and is it the correct type?
|
|
bool IsValid(const FieldType fieldType) const
|
|
{
|
|
// m_fieldType only set to !FIELD_TYPE_UNKNOWN when m_field.m_pIFieldType is non-null.
|
|
return (fieldType == m_fieldType);
|
|
}
|
|
|
|
//! Create and store IFieldType object.
|
|
StatusCode Create(const FieldType fieldType)
|
|
{
|
|
assert(!IsValid(fieldType));
|
|
|
|
CxxYZ::unique_ptr<IFieldType> pNewIFieldType(FieldTypeFactory::GetInstance().Create(fieldType));
|
|
if (ACTIV_UNLIKELY(!pNewIFieldType))
|
|
return STATUS_CODE_HEAP_EMPTY;
|
|
|
|
m_field.m_pIFieldType = CxxYZ::move(pNewIFieldType);
|
|
m_fieldType = fieldType;
|
|
|
|
return STATUS_CODE_SUCCESS;
|
|
}
|
|
|
|
//! Clone an existing CachedField object.
|
|
StatusCode Clone(const CachedField &sourceCachedField)
|
|
{
|
|
CxxYZ::unique_ptr<IFieldType> pIFieldType(FieldTypeFactory::GetInstance().Clone(*sourceCachedField.m_field.m_pIFieldType));
|
|
if (ACTIV_UNLIKELY(!pIFieldType))
|
|
return STATUS_CODE_HEAP_EMPTY;
|
|
|
|
// Update the cache with this new IFieldType.
|
|
m_field.m_pIFieldType = CxxYZ::move(pIFieldType);
|
|
m_fieldType = m_field.m_pIFieldType->GetType();
|
|
|
|
return STATUS_CODE_SUCCESS;
|
|
}
|
|
|
|
FieldId GetFieldId() const
|
|
{
|
|
return m_field.m_fieldId;
|
|
}
|
|
|
|
Field m_field;
|
|
bool m_isPresent;
|
|
FieldType m_fieldType;
|
|
|
|
private:
|
|
ACTIV_BOOST_MOVABLE_BUT_NOT_COPYABLE(CachedField)
|
|
};
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
typedef CxxYZ::vector<CachedField *> PresentFieldList;
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
//! Const iterator class.
|
|
class ConstIterator
|
|
{
|
|
public:
|
|
//! Default constructor.
|
|
ConstIterator()
|
|
{
|
|
}
|
|
|
|
/**
|
|
* @brief Prefix increment operator.
|
|
*
|
|
* @return a reference to the updated object.
|
|
*/
|
|
ConstIterator &operator++()
|
|
{
|
|
++m_iterator;
|
|
|
|
return *this;
|
|
}
|
|
|
|
/**
|
|
* @brief Postfix increment operator.
|
|
*
|
|
* @return a copy of the original object.
|
|
*/
|
|
const ConstIterator operator++(int)
|
|
{
|
|
ConstIterator oldValue = *this;
|
|
|
|
++(*this);
|
|
|
|
return oldValue;
|
|
}
|
|
|
|
/**
|
|
* @brief Equality operator.
|
|
*
|
|
* @param rhs the object to test against.
|
|
*
|
|
* @return whether the two objects are equal.
|
|
*/
|
|
bool operator==(const ConstIterator &rhs) const
|
|
{
|
|
return (m_iterator == rhs.m_iterator);
|
|
}
|
|
|
|
/**
|
|
* @brief Inequality operator.
|
|
*
|
|
* @param rhs the object to test against.
|
|
*
|
|
* @return whether the two objects are not equal.
|
|
*/
|
|
bool operator!=(const ConstIterator &rhs) const
|
|
{
|
|
return !(*this == rhs);
|
|
}
|
|
|
|
//! Dereference the iterator and get a field reference.
|
|
const Field &operator*() const
|
|
{
|
|
return (*m_iterator)->m_field;
|
|
}
|
|
|
|
//! Dereference the iterator and get a field pointer.
|
|
const Field *operator->() const
|
|
{
|
|
return &((*m_iterator)->m_field);
|
|
}
|
|
|
|
private:
|
|
/**
|
|
* @brief Constructor.
|
|
*
|
|
* @param iterator to the CachedField.
|
|
*/
|
|
ConstIterator(const PresentFieldList::const_iterator &iterator) :
|
|
m_iterator(iterator)
|
|
{
|
|
}
|
|
|
|
PresentFieldList::const_iterator m_iterator; ///< The iterator.
|
|
|
|
template<typename>
|
|
friend class OneApi::FieldListValidatorT;
|
|
};
|
|
|
|
} // namespace FlvDetail
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
//! FlvTypes namespace.
|
|
namespace FlvTypes
|
|
{
|
|
|
|
//! Flat vector storage for CachedField.
|
|
class FlatVectorFieldStorage : private Boost::noncopyable
|
|
{
|
|
private:
|
|
typedef FlvDetail::Field Field;
|
|
typedef FlvDetail::CachedField CachedField;
|
|
typedef CxxYZ::unique_ptr<CachedField> CachedFieldPtr;
|
|
typedef CxxYZ::vector<CachedFieldPtr> CachedFieldList;
|
|
|
|
public:
|
|
StatusCode GetField(const FieldId fieldId, const Field* &pField) const
|
|
{
|
|
assert(fieldId < m_cachedFieldList.size());
|
|
|
|
const CachedField * const pCachedField = m_cachedFieldList[fieldId].get();
|
|
assert(ACTIV_NULLPTR != pCachedField);
|
|
|
|
pField = &(pCachedField->m_field);
|
|
|
|
return STATUS_CODE_SUCCESS;
|
|
}
|
|
|
|
CachedField &GetCachedField(const FieldId fieldId)
|
|
{
|
|
if (ACTIV_LIKELY(fieldId < m_cachedFieldList.size()))
|
|
{
|
|
CachedField * const pCachedField = m_cachedFieldList[fieldId].get();
|
|
if (ACTIV_LIKELY(ACTIV_NULLPTR != pCachedField))
|
|
return *pCachedField;
|
|
}
|
|
|
|
if (fieldId >= m_cachedFieldList.size())
|
|
m_cachedFieldList.resize(fieldId + 1);
|
|
|
|
CxxYZ::unique_ptr<CachedField> &pCachedField = m_cachedFieldList[fieldId];
|
|
|
|
// Should only get here when it's a new field.
|
|
assert(!pCachedField);
|
|
|
|
if (ACTIV_LIKELY(!pCachedField))
|
|
pCachedField.reset(new CachedField(fieldId));
|
|
|
|
return *pCachedField;
|
|
}
|
|
|
|
void SetFieldPresent(const FieldId fieldId)
|
|
{
|
|
}
|
|
|
|
bool IsFieldPresent(const FieldId fieldId) const
|
|
{
|
|
if (ACTIV_LIKELY(fieldId < m_cachedFieldList.size()))
|
|
{
|
|
const CachedFieldPtr &pCachedField(m_cachedFieldList[fieldId]);
|
|
|
|
if (ACTIV_LIKELY(pCachedField))
|
|
return pCachedField->m_isPresent;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
bool IsFieldDefined(const FieldId fieldId) const
|
|
{
|
|
if (ACTIV_LIKELY(fieldId < m_cachedFieldList.size()))
|
|
{
|
|
const CachedFieldPtr &pCachedField(m_cachedFieldList[fieldId]);
|
|
|
|
if (ACTIV_LIKELY(pCachedField))
|
|
return pCachedField->m_isPresent && pCachedField->m_field.IsDefined();
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
void Reset()
|
|
{
|
|
}
|
|
|
|
void Clear()
|
|
{
|
|
m_cachedFieldList.clear();
|
|
m_cachedFieldList.shrink_to_fit();
|
|
}
|
|
|
|
size_t GetMemoryUsage() const
|
|
{
|
|
size_t memoryUsage = m_cachedFieldList.capacity() * sizeof(CachedFieldList::value_type);
|
|
|
|
// ACTIV_BOOST_FOREACH not happy with a Boost::container::vector of Boost::interprocess::unique_ptr, it seems...
|
|
for (CachedFieldList::const_iterator iter = m_cachedFieldList.begin(), iterEnd = m_cachedFieldList.end();
|
|
iter != iterEnd; ++iter)
|
|
{
|
|
const CachedFieldPtr &pCachedField(*iter);
|
|
|
|
if (pCachedField)
|
|
{
|
|
memoryUsage += sizeof(*pCachedField);
|
|
|
|
if (0 != pCachedField->m_field.GetIFieldType())
|
|
memoryUsage += pCachedField->m_field.GetIFieldType()->GetMemoryUsage();
|
|
}
|
|
}
|
|
|
|
return memoryUsage;
|
|
}
|
|
|
|
private:
|
|
CachedFieldList m_cachedFieldList; ///< Indexed by field id.
|
|
};
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
//! Hash storage for CachedField.
|
|
class HashFieldStorage : private Boost::noncopyable
|
|
{
|
|
private:
|
|
typedef FlvDetail::Field Field;
|
|
typedef FlvDetail::CachedField CachedField;
|
|
class FieldIdIndex;
|
|
|
|
typedef Boost::multi_index::multi_index_container
|
|
<
|
|
CachedField,
|
|
|
|
Boost::multi_index::indexed_by
|
|
<
|
|
Boost::multi_index::hashed_unique
|
|
<
|
|
Boost::multi_index::tag<FieldIdIndex>,
|
|
Boost::multi_index::const_mem_fun<CachedField, FieldId, &CachedField::GetFieldId>
|
|
>
|
|
>
|
|
> CachedFieldContainer;
|
|
|
|
public:
|
|
StatusCode GetField(const FieldId fieldId, const Field* &pField) const
|
|
{
|
|
CachedFieldContainer::const_iterator iter = m_cachedFieldContainer.find(fieldId);
|
|
if (ACTIV_UNLIKELY(iter == m_cachedFieldContainer.end()))
|
|
{
|
|
assert(false);
|
|
return STATUS_CODE_NOT_FOUND;
|
|
}
|
|
|
|
pField = &(iter->m_field);
|
|
return STATUS_CODE_SUCCESS;
|
|
}
|
|
|
|
CachedField &GetCachedField(const FieldId fieldId)
|
|
{
|
|
CachedFieldContainer::iterator iter = m_cachedFieldContainer.find(fieldId);
|
|
if (ACTIV_LIKELY(iter != m_cachedFieldContainer.end()))
|
|
return const_cast<CachedField &>(*iter);
|
|
|
|
return const_cast<CachedField &>(*m_cachedFieldContainer.emplace(fieldId).first);
|
|
}
|
|
|
|
void SetFieldPresent(const FieldId fieldId)
|
|
{
|
|
if (fieldId >= m_fieldIdPresentBitmap.size())
|
|
m_fieldIdPresentBitmap.resize(fieldId + 1, false);
|
|
|
|
m_fieldIdPresentBitmap.set(fieldId, true);
|
|
}
|
|
|
|
bool IsFieldPresent(const FieldId fieldId) const
|
|
{
|
|
return ((m_fieldIdPresentBitmap.size() > fieldId) && m_fieldIdPresentBitmap.test(fieldId));
|
|
}
|
|
|
|
bool IsFieldDefined(const FieldId fieldId) const
|
|
{
|
|
CachedFieldContainer::iterator iter = m_cachedFieldContainer.find(fieldId);
|
|
if (ACTIV_LIKELY(iter != m_cachedFieldContainer.end()))
|
|
{
|
|
const CachedField &cachedField = *iter;
|
|
|
|
return cachedField.m_isPresent && cachedField.m_field.IsDefined();
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
void Reset()
|
|
{
|
|
m_fieldIdPresentBitmap.clear();
|
|
}
|
|
|
|
void Clear()
|
|
{
|
|
m_fieldIdPresentBitmap.clear();
|
|
m_fieldIdPresentBitmap.shrink_to_fit();
|
|
m_cachedFieldContainer.clear();
|
|
}
|
|
|
|
size_t GetMemoryUsage() const
|
|
{
|
|
size_t memoryUsage = 0;
|
|
|
|
memoryUsage += m_fieldIdPresentBitmap.num_blocks() * sizeof(FieldIdPresentBitmap::block_type);
|
|
|
|
ACTIV_FOREACH (const CachedField &cachedField, m_cachedFieldContainer)
|
|
{
|
|
memoryUsage += sizeof(cachedField);
|
|
|
|
if (cachedField.m_field.GetIFieldType())
|
|
memoryUsage += cachedField.m_field.GetIFieldType()->GetMemoryUsage();
|
|
}
|
|
|
|
// TODO the map nodes/buckets.
|
|
|
|
return memoryUsage;
|
|
}
|
|
|
|
private:
|
|
typedef Boost::dynamic_bitset<uint64_t> FieldIdPresentBitmap; ///< The present field id bitmap type definition.
|
|
|
|
CachedFieldContainer m_cachedFieldContainer; ///< Indexed by field id.
|
|
FieldIdPresentBitmap m_fieldIdPresentBitmap; ///< Bitmap of field ids present in message.
|
|
};
|
|
|
|
} // namespace FlvTypes
|
|
|
|
} // namespace OneApi
|
|
|
|
} // namespace Activ
|
|
|
|
#endif // (!defined ACTIV_ONE_API_DETAIL_FIELD_LIST_VALIDATOR_DETAIL_H)
|