ovr_sdk

diff LibOVR/Src/Kernel/OVR_StringHash.h @ 0:1b39a1b46319

initial 0.4.4
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 14 Jan 2015 06:51:16 +0200
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/LibOVR/Src/Kernel/OVR_StringHash.h	Wed Jan 14 06:51:16 2015 +0200
     1.3 @@ -0,0 +1,100 @@
     1.4 +/************************************************************************************
     1.5 +
     1.6 +PublicHeader:   None
     1.7 +Filename    :   OVR_StringHash.h
     1.8 +Content     :   String hash table used when optional case-insensitive
     1.9 +                lookup is required.
    1.10 +Created     :   September 19, 2012
    1.11 +Notes       : 
    1.12 +
    1.13 +Copyright   :   Copyright 2014 Oculus VR, LLC All Rights reserved.
    1.14 +
    1.15 +Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); 
    1.16 +you may not use the Oculus VR Rift SDK except in compliance with the License, 
    1.17 +which is provided at the time of installation or download, or which 
    1.18 +otherwise accompanies this software in either electronic or hard copy form.
    1.19 +
    1.20 +You may obtain a copy of the License at
    1.21 +
    1.22 +http://www.oculusvr.com/licenses/LICENSE-3.2 
    1.23 +
    1.24 +Unless required by applicable law or agreed to in writing, the Oculus VR SDK 
    1.25 +distributed under the License is distributed on an "AS IS" BASIS,
    1.26 +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    1.27 +See the License for the specific language governing permissions and
    1.28 +limitations under the License.
    1.29 +
    1.30 +************************************************************************************/
    1.31 +
    1.32 +#ifndef OVR_StringHash_h
    1.33 +#define OVR_StringHash_h
    1.34 +
    1.35 +#include "OVR_String.h"
    1.36 +#include "OVR_Hash.h"
    1.37 +
    1.38 +namespace OVR {
    1.39 +
    1.40 +//-----------------------------------------------------------------------------------
    1.41 +// *** StringHash
    1.42 +
    1.43 +// This is a custom string hash table that supports case-insensitive
    1.44 +// searches through special functions such as GetCaseInsensitive, etc.
    1.45 +// This class is used for Flash labels, exports and other case-insensitive tables.
    1.46 +
    1.47 +template<class U, class Allocator = ContainerAllocator<U> >
    1.48 +class StringHash : public Hash<String, U, String::NoCaseHashFunctor, Allocator>
    1.49 +{
    1.50 +public:
    1.51 +    typedef U                                                        ValueType;
    1.52 +    typedef StringHash<U, Allocator>                                 SelfType;
    1.53 +    typedef Hash<String, U, String::NoCaseHashFunctor, Allocator>    BaseType;
    1.54 +
    1.55 +public:    
    1.56 +
    1.57 +    void    operator = (const SelfType& src) { BaseType::operator = (src); }
    1.58 +
    1.59 +    bool    GetCaseInsensitive(const String& key, U* pvalue) const
    1.60 +    {
    1.61 +        String::NoCaseKey ikey(key);
    1.62 +        return BaseType::GetAlt(ikey, pvalue);
    1.63 +    }
    1.64 +    // Pointer-returning get variety.
    1.65 +    const U* GetCaseInsensitive(const String& key) const   
    1.66 +    {
    1.67 +        String::NoCaseKey ikey(key);
    1.68 +        return BaseType::GetAlt(ikey);
    1.69 +    }
    1.70 +    U*  GetCaseInsensitive(const String& key)
    1.71 +    {
    1.72 +        String::NoCaseKey ikey(key);
    1.73 +        return BaseType::GetAlt(ikey);
    1.74 +    }
    1.75 +
    1.76 +    
    1.77 +    typedef typename BaseType::Iterator base_iterator;
    1.78 +
    1.79 +    base_iterator    FindCaseInsensitive(const String& key)
    1.80 +    {
    1.81 +        String::NoCaseKey ikey(key);
    1.82 +        return BaseType::FindAlt(ikey);
    1.83 +    }
    1.84 +
    1.85 +    // Set just uses a find and assigns value if found. The key is not modified;
    1.86 +    // this behavior is identical to Flash string variable assignment.    
    1.87 +    void    SetCaseInsensitive(const String& key, const U& value)
    1.88 +    {
    1.89 +        base_iterator it = FindCaseInsensitive(key);
    1.90 +        if (it != BaseType::End())
    1.91 +        {
    1.92 +            it->Second = value;
    1.93 +        }
    1.94 +        else
    1.95 +        {
    1.96 +            BaseType::Add(key, value);
    1.97 +        }
    1.98 +    } 
    1.99 +};
   1.100 +
   1.101 +} // OVR 
   1.102 +
   1.103 +#endif