• Main Page
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

XnStringsHash.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002 *                                                                            *
00003 *  OpenNI 1.0 Alpha                                                          *
00004 *  Copyright (C) 2010 PrimeSense Ltd.                                        *
00005 *                                                                            *
00006 *  This file is part of OpenNI.                                              *
00007 *                                                                            *
00008 *  OpenNI is free software: you can redistribute it and/or modify            *
00009 *  it under the terms of the GNU Lesser General Public License as published  *
00010 *  by the Free Software Foundation, either version 3 of the License, or      *
00011 *  (at your option) any later version.                                       *
00012 *                                                                            *
00013 *  OpenNI is distributed in the hope that it will be useful,                 *
00014 *  but WITHOUT ANY WARRANTY; without even the implied warranty of            *
00015 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the              *
00016 *  GNU Lesser General Public License for more details.                       *
00017 *                                                                            *
00018 *  You should have received a copy of the GNU Lesser General Public License  *
00019 *  along with OpenNI. If not, see <http://www.gnu.org/licenses/>.            *
00020 *                                                                            *
00021 *****************************************************************************/
00022 
00023 
00024 
00025 
00026 #ifndef _XN_STRINGS_HASH_H
00027 #define _XN_STRINGS_HASH_H
00028 
00029 //---------------------------------------------------------------------------
00030 // Includes
00031 //---------------------------------------------------------------------------
00032 #include "XnHash.h"
00033 #include <XnOS.h>
00034 
00035 //---------------------------------------------------------------------------
00036 // Types
00037 //---------------------------------------------------------------------------
00038 class XnStringsKeyManager
00039 {
00040 public:
00041     static XnHashValue Hash(const XnChar* const& key)
00042     {
00043         XnUInt32 nCRC = 0;
00044         xnOSStrCRC32(key, &nCRC);
00045 
00046         // convert from UINT32 to XnHashValue
00047         return nCRC % (1 << (sizeof(XnHashValue)*8));
00048     }
00049 
00050     static XnInt32 Compare(const XnChar* const& key1, const XnChar* const& key2)
00051     {
00052         return strcmp(key1, key2);
00053     }
00054 };
00055 
00056 class XnStringsKeyTranslator
00057 {
00058 public:
00059     static XnValue CreateValueCopy(const XnChar* const& orig)
00060     {
00061         // we should copy string, so we can keep the key
00062         XnUInt32 nLen = strlen(orig) + 1; // with null termination
00063         XnChar* pcKey = (XnChar*)xnOSMalloc(nLen);
00064         xnOSStrCopy(pcKey, orig, nLen);
00065         return (pcKey);
00066     }
00067 
00068     static void FreeValue(XnValue& Value)
00069     {
00070         XnChar* pcKey = (XnChar*)Value;
00071         xnOSFree(pcKey);
00072     }
00073 
00074     static XnValue GetAsValue(const XnChar* const& orig)
00075     {
00076         return (XnValue)orig;
00077     }
00078 
00079     static const XnChar* const& GetFromValue(const XnValue& Value)
00080     {
00081         return (const XnChar* const&)Value;
00082     }
00083 
00084     static const XnChar*& GetFromValue(XnValue& Value)
00085     {
00086         return (const XnChar*&)Value;
00087     }
00088 };
00089 
00094 #define XN_DECLARE_STRINGS_HASH_WITH_TRANSLATOR_DECL(decl, ValueType, ClassName, ValueTranslator)                               \
00095     XN_DECLARE_HASH_DECL(decl, const XnChar*, ValueType, ClassName, XnStringsKeyTranslator, ValueTranslator, XnStringsKeyManager)   \
00096 
00097 
00101 #define XN_DECLARE_STRINGS_HASH_WITH_TRANSLATOR(ValueType, ClassName, ValueTranslator)                              \
00102     XN_DECLARE_STRINGS_HASH_WITH_TRANSLATOR_DECL(, ValueType, ClassName, ValueTranslator)
00103 
00108 #define XN_DECLARE_STRINGS_HASH_DECL(decl, ValueType, ClassName)                                                        \
00109     XN_DECLARE_DEFAULT_VALUE_TRANSLATOR_DECL(decl, ValueType, XN_DEFAULT_TRANSLATOR_NAME(ClassName))                    \
00110     XN_DECLARE_STRINGS_HASH_WITH_TRANSLATOR_DECL(decl, ValueType, ClassName, XN_DEFAULT_TRANSLATOR_NAME(ClassName)) \
00111 
00112 
00116 #define XN_DECLARE_STRINGS_HASH(ValueType, ClassName)               \
00117     XN_DECLARE_STRINGS_HASH_DECL(, ValueType, ClassName)
00118 
00119 
00120 XN_DECLARE_STRINGS_HASH(XnValue, XnStringsHash)
00121 
00122 #endif //_XN_STRINGS_HASH_H

Generated on Thu Feb 10 2011 for OpenNI 1.0.0 by  doxygen 1.7.1