ovr_sdk

annotate 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
rev   line source
nuclear@0 1 /************************************************************************************
nuclear@0 2
nuclear@0 3 PublicHeader: None
nuclear@0 4 Filename : OVR_StringHash.h
nuclear@0 5 Content : String hash table used when optional case-insensitive
nuclear@0 6 lookup is required.
nuclear@0 7 Created : September 19, 2012
nuclear@0 8 Notes :
nuclear@0 9
nuclear@0 10 Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved.
nuclear@0 11
nuclear@0 12 Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License");
nuclear@0 13 you may not use the Oculus VR Rift SDK except in compliance with the License,
nuclear@0 14 which is provided at the time of installation or download, or which
nuclear@0 15 otherwise accompanies this software in either electronic or hard copy form.
nuclear@0 16
nuclear@0 17 You may obtain a copy of the License at
nuclear@0 18
nuclear@0 19 http://www.oculusvr.com/licenses/LICENSE-3.2
nuclear@0 20
nuclear@0 21 Unless required by applicable law or agreed to in writing, the Oculus VR SDK
nuclear@0 22 distributed under the License is distributed on an "AS IS" BASIS,
nuclear@0 23 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
nuclear@0 24 See the License for the specific language governing permissions and
nuclear@0 25 limitations under the License.
nuclear@0 26
nuclear@0 27 ************************************************************************************/
nuclear@0 28
nuclear@0 29 #ifndef OVR_StringHash_h
nuclear@0 30 #define OVR_StringHash_h
nuclear@0 31
nuclear@0 32 #include "OVR_String.h"
nuclear@0 33 #include "OVR_Hash.h"
nuclear@0 34
nuclear@0 35 namespace OVR {
nuclear@0 36
nuclear@0 37 //-----------------------------------------------------------------------------------
nuclear@0 38 // *** StringHash
nuclear@0 39
nuclear@0 40 // This is a custom string hash table that supports case-insensitive
nuclear@0 41 // searches through special functions such as GetCaseInsensitive, etc.
nuclear@0 42 // This class is used for Flash labels, exports and other case-insensitive tables.
nuclear@0 43
nuclear@0 44 template<class U, class Allocator = ContainerAllocator<U> >
nuclear@0 45 class StringHash : public Hash<String, U, String::NoCaseHashFunctor, Allocator>
nuclear@0 46 {
nuclear@0 47 public:
nuclear@0 48 typedef U ValueType;
nuclear@0 49 typedef StringHash<U, Allocator> SelfType;
nuclear@0 50 typedef Hash<String, U, String::NoCaseHashFunctor, Allocator> BaseType;
nuclear@0 51
nuclear@0 52 public:
nuclear@0 53
nuclear@0 54 void operator = (const SelfType& src) { BaseType::operator = (src); }
nuclear@0 55
nuclear@0 56 bool GetCaseInsensitive(const String& key, U* pvalue) const
nuclear@0 57 {
nuclear@0 58 String::NoCaseKey ikey(key);
nuclear@0 59 return BaseType::GetAlt(ikey, pvalue);
nuclear@0 60 }
nuclear@0 61 // Pointer-returning get variety.
nuclear@0 62 const U* GetCaseInsensitive(const String& key) const
nuclear@0 63 {
nuclear@0 64 String::NoCaseKey ikey(key);
nuclear@0 65 return BaseType::GetAlt(ikey);
nuclear@0 66 }
nuclear@0 67 U* GetCaseInsensitive(const String& key)
nuclear@0 68 {
nuclear@0 69 String::NoCaseKey ikey(key);
nuclear@0 70 return BaseType::GetAlt(ikey);
nuclear@0 71 }
nuclear@0 72
nuclear@0 73
nuclear@0 74 typedef typename BaseType::Iterator base_iterator;
nuclear@0 75
nuclear@0 76 base_iterator FindCaseInsensitive(const String& key)
nuclear@0 77 {
nuclear@0 78 String::NoCaseKey ikey(key);
nuclear@0 79 return BaseType::FindAlt(ikey);
nuclear@0 80 }
nuclear@0 81
nuclear@0 82 // Set just uses a find and assigns value if found. The key is not modified;
nuclear@0 83 // this behavior is identical to Flash string variable assignment.
nuclear@0 84 void SetCaseInsensitive(const String& key, const U& value)
nuclear@0 85 {
nuclear@0 86 base_iterator it = FindCaseInsensitive(key);
nuclear@0 87 if (it != BaseType::End())
nuclear@0 88 {
nuclear@0 89 it->Second = value;
nuclear@0 90 }
nuclear@0 91 else
nuclear@0 92 {
nuclear@0 93 BaseType::Add(key, value);
nuclear@0 94 }
nuclear@0 95 }
nuclear@0 96 };
nuclear@0 97
nuclear@0 98 } // OVR
nuclear@0 99
nuclear@0 100 #endif