ovr_sdk

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