24template<
typename STORAGE = adtf::util::cMemoryBlock,
typename INTERFACE = IHashValueMap>
40 struct tHashValueStorageType
42 static uint8_t GetVersion()
49 uint8_t ui8StorageVersion;
68 tResult Set(
const void* pData,
size_t szSize)
override
76 m_pCurrent->nByteSize =
static_cast<uint8_t
>(szSize);
77 adtf::util::cMemoryBlock::MemCopy(&m_pCurrent->eStorage[0], pData, szSize);
82 const void* Get()
const override
84 return &m_pCurrent->eStorage[0];
86 size_t GetSize()
const override
88 return static_cast<size_t>(m_pCurrent->nByteSize);
92 class cHashedValueGetter :
public IHashValueMapValue
94 tHashValueStorageType* m_pCurrent;
97 explicit cHashedValueGetter(tHashValueStorageType* pCurrent): m_pCurrent(pCurrent)
101 tResult Set(
const IHashValueMapValue& )
override
105 tResult FromRaw(
const IRawMemory& )
110 tResult ToRaw(IRawMemory&& oRawValue)
const
112 return oRawValue.Set(&m_pCurrent->eStorage[0],
static_cast<size_t>(m_pCurrent->nByteSize));
115 tType GetType()
const override
117 return (m_pCurrent->eType);
144 oToCopy.
ToRaw(*
this);
153 oToCopy.
ToRaw(*
this);
163 hash_value_map(
size_t szPreallocateMemorySize,
bool bZeroMemory): m_oStorage()
165 m_oStorage.Alloc(szPreallocateMemorySize);
166 if (szPreallocateMemorySize > 0 && bZeroMemory)
168 adtf::util::cMemoryBlock::MemZero(m_oStorage.GetPtr(), szPreallocateMemorySize);
175 value_type* pValue = GetValueT(oKey,
nullptr);
176 return (pValue !=
nullptr);
188 value_type* pKeyValue =
reinterpret_cast<value_type*
>(m_oStorage.GetPtr());
190 for (
size_t szIdx = 0; szIdx < szCurrentSize; ++szIdx)
192 value_type* pCurrentVal = &pKeyValue[szIdx];
195 cHashedValueGetter oValueGetter(pCurrentVal);
196 RETURN_IF_FAILED(oHashMap.
SetValue(pCurrentVal->oKey, oValueGetter));
209 value_type* pValue = GetValueT(oHashKey,
nullptr);
212 cHashedValueGetter oValueGetter(pValue);
213 return oValue.
Set(oValueGetter);
224 m_oStorage.Alloc(szNewSize);
227 adtf::util::cMemoryBlock::MemZero(m_oStorage.GetPtr(), szNewSize);
233 value_type* pFirstInvalidValue =
nullptr;
234 value_type* pKeyValue = GetValueT(oHashKey, &pFirstInvalidValue);
235 if (pKeyValue !=
nullptr)
242 if (pFirstInvalidValue)
244 pKeyValue = pFirstInvalidValue;
250 RETURN_IF_FAILED(m_oStorage.Resize((szNewLastPos + 1) *
sizeof(value_type)));
251 value_type* pNewFirstValue =
reinterpret_cast<value_type*
>(m_oStorage.GetPtr());
252 pKeyValue = &pNewFirstValue[szNewLastPos];
255 pKeyValue->oKey = oHashKey;
256 pKeyValue->eType = oValue.
GetType();
257 pKeyValue->ui8StorageVersion = value_type::GetVersion();
258 return oValue.
ToRaw(cHashedValueSetter(pKeyValue));
265 return m_oStorage.GetSize() /
sizeof(value_type);
270 value_type* pNewFirstValue =
reinterpret_cast<value_type*
>(m_oStorage.GetPtr());
276 return m_oStorage.Set(oRawValue.
Get(), oRawValue.
GetSize());
281 return oRawValue.Set(m_oStorage.GetPtr(), m_oStorage.GetSize());
285 return value_type::GetVersion();
289 return m_oStorage.GetPtr();
297 *ppFirstInvalid =
nullptr;
299 value_type* pKeyValue =
reinterpret_cast<value_type*
>(m_oStorage.GetPtr());
301 for (
size_t szIdx = 0; szIdx < szCurrentSize; ++szIdx)
305 if (pKeyValue[szIdx].oKey == oKey)
307 return &pKeyValue[szIdx];
312 if (ppFirstInvalid && *ppFirstInvalid ==
nullptr)
314 *ppFirstInvalid = &pKeyValue[szIdx];
332 const adtf::util::cVariant oDefault);
A_UTILS_NS::cResult tResult
For backwards compatibility and to bring latest version into scope.
Definition result.h:736
#define RETURN_NOERROR
Return status ERR_NOERROR, which requires the calling function's return type to be tResult.
Definition result.h:29
#define RETURN_ERROR(code)
Return specific error code, which requires the calling function's return type to be tResult.
Definition result.h:42
Definition hashedvaluemap_intf.h:21
tType
Definition hashedvaluemap_intf.h:30
@ HVT_Invalid
Invalid type.
Definition hashedvaluemap_intf.h:32
virtual tType GetType() const =0
virtual tResult Set(const IHashValueMapValue &oValue)=0
Definition hashedvaluemap_intf.h:80
virtual uint8_t GetRawMemoryLayoutVersion() const =0
adtf::util::cStringUtil::tHashKey32 tHashKey
Type for the HashKey of the Value.
Definition hashedvaluemap_intf.h:87
virtual tResult SetValue(const tHashKey &oHashKey, const IHashValueMapValue &oValue)=0
Definition rawmemory_base.h:23
virtual size_t GetSize() const =0
virtual const void * Get() const =0
virtual tResult ToRaw(IRawMemory &&oRawValue) const =0
virtual tResult FromRaw(const IRawMemory &oRawValue)=0
Template class implementation for the IRawMemory interface.
Definition rawmemory_base.h:216
Definition hashedvaluemap.h:26
void Reset() override
Definition hashedvaluemap.h:221
bool Exists(const IHashValueMap::tHashKey &oKey) const override
Definition hashedvaluemap.h:173
tResult ToRaw(IRawMemory &&oRawValue) const override
Definition hashedvaluemap.h:279
tResult SetValue(const IHashValueMap::tHashKey &oHashKey, const IHashValueMapValue &oValue) override
Definition hashedvaluemap.h:231
bool IsEmpty() const override
Definition hashedvaluemap.h:268
hash_value_map(hash_value_map &&oToCopy)=delete
no move DTOR
virtual ~hash_value_map()
DTOR.
Definition hashedvaluemap.h:135
size_t m_szPreAllocatedKeyValueSize
Value count for preallocation of the memory.
Definition hashedvaluemap.h:32
hash_value_map & operator=(const hash_value_map &oToCopy)
Definition hashedvaluemap.h:150
hash_value_map(const hash_value_map &oToCopy)
Definition hashedvaluemap.h:141
tResult Get(IHashValueMap &oHashMap) const override
Definition hashedvaluemap.h:179
hash_value_map & operator=(hash_value_map &&oToCopy)=delete
no move operator
hash_value_map(size_t szPreAllocatedKeyValueSize)
Definition hashedvaluemap.h:128
hash_value_map()
CTOR.
Definition hashedvaluemap.h:123
uint8_t GetRawMemoryLayoutVersion() const
Definition hashedvaluemap.h:283
tResult GetValue(const IHashValueMap::tHashKey &oHashKey, IHashValueMapValue &oValue) const override
Definition hashedvaluemap.h:207
tResult FromRaw(const IRawMemory &oRawValue) override
Definition hashedvaluemap.h:274
size_t GetCapacity() const
Definition hashedvaluemap.h:263
Namespace for all functionality of the ADTF Base SDK provided since v3.0.
Definition adtf_class_version.h:16
IHashValueMap::tHashKey create_hash_value_key(const char *strToHash)
tResult set_hash_value(IHashValueMap &oMap, const IHashValueMap::tHashKey &oHash, const adtf::util::cVariant oValue)
adtf::util::cVariant get_hash_value(const IHashValueMap &oMap, const IHashValueMap::tHashKey &oHash, const adtf::util::cVariant oDefault)
Namespace for the ADTF Base SDK.
Definition adtf_base_type_traits.h:13
Namespace for all functionality provided by ADTF and its SDKs.
Definition adtf_client_connector.h:14
Definition hashedvaluemap.h:41