XFuStringKey.cpp Source File

Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members File Members Related Pages

# XFuStringKey.cpp

Go to the documentation of this file.

    00001 /*! \file
    00002  * X-Forge Util <br>
    00003  * Copyright 2000-2003 Fathammer Ltd
    00004  *
    00005  * \brief XFuStringKey.cpp is the implementation file for the
    00006  * XFuStringKey class. For more information, see XFuStringKey.h.
    00007  *
    00008  * $Id: XFuStringKey.cpp,v 1.9 2003/09/29 13:47:35 jari Exp $
    00009  * $Date: 2003/09/29 13:47:35 $
    00010  * $Revision: 1.9 $
    00011  */
    00012
    00013 #include <xfcore/XFcCore.h>
    00014 #include <xfutil/XFuStringKey.h>
    00015
    00016
    00017 XFuStringKey::XFuStringKey()
    00018 {
    00019     mKey = NULL;
    00020     mHashCode = 0;
    00021     mUsingData = 0;
    00022 }
    00023
    00024
    00025 XFuStringKey::XFuStringKey(const CHAR *aKey)
    00026 {
    00027     init(aKey);
    00028 }
    00029
    00030
    00031 XFuStringKey::XFuStringKey(const XFuStringKey &aKey)
    00032 {
    00033     init(aKey.mKey);
    00034 }
    00035
    00036
    00037 XFuStringKey & XFuStringKey::operator=(const XFuStringKey &aKey)
    00038 {
    00039     init(aKey.mKey);
    00040     return *this;
    00041 }
    00042
    00043
    00044 void XFuStringKey::init(const CHAR *aKey)
    00045 {
    00046     mKey = NULL;
    00047     mHashCode = 0;
    00048     mUsingData = 0;
    00049
    00050     if (aKey)
    00051     {
    00052         INT32 keyLen = XFcStringToolkit::getLength(aKey);
    00053         if (keyLen < XFUSTRINGKEY_DATASIZE - 1)
    00054             mUsingData = 1;
    00055         if (mUsingData)
    00056         {
    00057             mKey = mData;
    00058             INT a;
    00059             for (a = 0; a < keyLen; ++a)
    00060                 mData[a] = aKey[a];
    00061             mData[keyLen] = 0;
    00062         }
    00063         else
    00064         {
    00065             mKey = XFcStringToolkit::copy(aKey);
    00066         }
    00067         mHashCode = 0;
    00068         INT32 pos;
    00069         for (pos = 0; pos < keyLen; pos++)
    00070             mHashCode = 7 * mHashCode + aKey[pos];
    00071     }
    00072     else
    00073     {
    00074         mKey = NULL;
    00075     }
    00076 }
    00077
    00078
    00079 XFuStringKey::~XFuStringKey()
    00080 {
    00081     if (!mUsingData)
    00082         delete[] mKey;
    00083 }
    00084
    00085
    00086 UINT32 XFcHashtableHash<XFuStringKey>::operator() (const XFuStringKey key) const
    00087 {
    00088     return key.mHashCode;
    00089 }
    00090
    00091
    00092 INT XFcHashtableEQ<XFuStringKey>::operator() (const XFuStringKey key1, const XFuStringKey key2) const
    00093 {
    00094     return !XFcStringToolkit::compare(key1.mKey, key2.mKey);
    00095 }
    00096
    00097

|  | X-Forge Documentation Confidential Copyright © 2002-2003 Fathammer |  | Documentation generated with doxygen by Dimitri van Heesch