XnStringsHashT.h
Go to the documentation of this file.
#ifndef _XN_STRINGS_HASH_T_H_
#define _XN_STRINGS_HASH_T_H_
//---------------------------------------------------------------------------
// Includes
//---------------------------------------------------------------------------
#include "XnHashT.h"
//---------------------------------------------------------------------------
// Code
//---------------------------------------------------------------------------
class XnStringsHashKeyManager
{
public:
static XnHashCode Hash(const XnChar* const& key)
{
XnUInt32 nCRC = 0;
xnOSStrCRC32(key, &nCRC);
// convert from UINT32 to XnHashValue
return nCRC % (1 << (sizeof(XnHashCode)*8));
}
static XnInt32 Compare(const XnChar* const& key1, const XnChar* const& key2)
{
return strcmp(key1, key2);
}
};
template<class TValue>
class XnStringsNodeAllocator
{
public:
typedef XnKeyValuePair<const XnChar*, TValue> TPair;
typedef XnLinkedNodeT<TPair> TLinkedNode;
static TLinkedNode* Allocate(TPair const& pair)
{
XnChar* pKeyCopy = xnOSStrDup(pair.Key());
if (pKeyCopy == NULL)
{
return NULL;
}
return XN_NEW(TLinkedNode, TPair(pKeyCopy, pair.Value()));
}
static void Deallocate(TLinkedNode* pNode)
{
XN_ASSERT(pNode != NULL);
XN_ASSERT(pNode->value.Key() != NULL);
xnOSFree(pNode->value.Key());
XN_DELETE(pNode);
}
};
template<class TValue>
class XnStringsHashT : public XnHashT<const XnChar*, TValue, XnStringsHashKeyManager, XnStringsNodeAllocator<TValue> >
{
typedef XnHashT<const XnChar*, TValue, XnStringsHashKeyManager, XnStringsNodeAllocator<TValue> > Base;
public:
XnStringsHashT() : Base() {}
XnStringsHashT(const XnStringsHashT& other) : Base()
{
*this = other;
}
XnStringsHashT& operator=(const XnStringsHashT& other)
{
Base::operator=(other);
// no other members
return *this;
}
};
class XnStringsSet : public XnStringsHashT<void*>
{
typedef XnStringsHashT<void*> Base;
public:
XnStatus Set(const XnChar* key)
{
return Base::Set(key, NULL);
}
};
#endif // _XN_STRINGS_HASH_T_H_
XnHashT.h
XnHashCode
XnUInt8 XnHashCode
Definition XnHashT.h:13
XN_DELETE
#define XN_DELETE(p)
Definition XnOS.h:336
XN_NEW
#define XN_NEW(type,...)
Definition XnOS.h:326
xnOSFree
XN_C_API void XN_C_DECL xnOSFree(const void *pMemBlock)
xnOSStrDup
XN_C_API XnChar *XN_C_DECL xnOSStrDup(const XnChar *strSource)
xnOSStrCRC32
XN_C_API XnStatus XN_C_DECL xnOSStrCRC32(const XnChar *cpString, XnUInt32 *nCRC32)
XnStatus
XnUInt32 XnStatus
Definition XnStatus.h:34
XnHashT< const XnChar *, TValue, XnStringsHashKeyManager, XnStringsNodeAllocator< TValue > >::operator=
XnHashT & operator=(const XnHashT &other)
Definition XnHashT.h:297
XnHashT::Set
XnStatus Set(const TKey &key, const TValue &value)
Definition XnHashT.h:362
XnHashT< const XnChar *, TValue, XnStringsHashKeyManager, XnStringsNodeAllocator< TValue > >::XnHashT
XnHashT()
Definition XnHashT.h:286
XnStringsHashKeyManager
Definition XnStringsHashT.h:13
XnStringsHashKeyManager::Compare
static XnInt32 Compare(const XnChar *const &key1, const XnChar *const &key2)
Definition XnStringsHashT.h:24
XnStringsHashKeyManager::Hash
static XnHashCode Hash(const XnChar *const &key)
Definition XnStringsHashT.h:15
XnStringsHashT::operator=
XnStringsHashT & operator=(const XnStringsHashT &other)
Definition XnStringsHashT.h:71
XnStringsHashT::XnStringsHashT
XnStringsHashT()
Definition XnStringsHashT.h:64
XnStringsHashT::XnStringsHashT
XnStringsHashT(const XnStringsHashT &other)
Definition XnStringsHashT.h:66
XnStringsNodeAllocator
Definition XnStringsHashT.h:32
XnStringsNodeAllocator::Deallocate
static void Deallocate(TLinkedNode *pNode)
Definition XnStringsHashT.h:48
XnStringsNodeAllocator::TLinkedNode
XnLinkedNodeT< TPair > TLinkedNode
Definition XnStringsHashT.h:35
XnStringsNodeAllocator::TPair
XnKeyValuePair< const XnChar *, TValue > TPair
Definition XnStringsHashT.h:34
XnStringsNodeAllocator::Allocate
static TLinkedNode * Allocate(TPair const &pair)
Definition XnStringsHashT.h:37
XnStringsSet
Definition XnStringsHashT.h:80
XnStringsSet::Set
XnStatus Set(const XnChar *key)
Definition XnStringsHashT.h:84
XnKeyValuePair
Definition XnHashT.h:20
XnKeyValuePair::Value
TValue const & Value() const
Definition XnHashT.h:30
XnKeyValuePair::Key
TKey const & Key() const
Definition XnHashT.h:29
XnLinkedNodeT
Definition XnListT.h:22
XnLinkedNodeT::value
T value
Definition XnListT.h:28