oculus1
view libovr/Src/Kernel/OVR_StringHash.h @ 17:cfe4979ab3eb
ops, minor error in the last commit
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 21 Sep 2013 07:09:48 +0300 |
parents | e2f9e4603129 |
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 2012 Oculus VR, Inc. All Rights reserved.
12 Use of this software is subject to the terms of the Oculus license
13 agreement provided at the time of installation or download, or which
14 otherwise accompanies this software in either electronic or hard copy form.
16 ************************************************************************************/
18 #ifndef OVR_StringHash_h
19 #define OVR_StringHash_h
21 #include "OVR_String.h"
22 #include "OVR_Hash.h"
24 namespace OVR {
26 //-----------------------------------------------------------------------------------
27 // *** StringHash
29 // This is a custom string hash table that supports case-insensitive
30 // searches through special functions such as GetCaseInsensitive, etc.
31 // This class is used for Flash labels, exports and other case-insensitive tables.
33 template<class U, class Allocator = ContainerAllocator<U> >
34 class StringHash : public Hash<String, U, String::NoCaseHashFunctor, Allocator>
35 {
36 public:
37 typedef U ValueType;
38 typedef StringHash<U, Allocator> SelfType;
39 typedef Hash<String, U, String::NoCaseHashFunctor, Allocator> BaseType;
41 public:
43 void operator = (const SelfType& src) { BaseType::operator = (src); }
45 bool GetCaseInsensitive(const String& key, U* pvalue) const
46 {
47 String::NoCaseKey ikey(key);
48 return BaseType::GetAlt(ikey, pvalue);
49 }
50 // Pointer-returning get variety.
51 const U* GetCaseInsensitive(const String& key) const
52 {
53 String::NoCaseKey ikey(key);
54 return BaseType::GetAlt(ikey);
55 }
56 U* GetCaseInsensitive(const String& key)
57 {
58 String::NoCaseKey ikey(key);
59 return BaseType::GetAlt(ikey);
60 }
63 typedef typename BaseType::Iterator base_iterator;
65 base_iterator FindCaseInsensitive(const String& key)
66 {
67 String::NoCaseKey ikey(key);
68 return BaseType::FindAlt(ikey);
69 }
71 // Set just uses a find and assigns value if found. The key is not modified;
72 // this behavior is identical to Flash string variable assignment.
73 void SetCaseInsensitive(const String& key, const U& value)
74 {
75 base_iterator it = FindCaseInsensitive(key);
76 if (it != BaseType::End())
77 {
78 it->Second = value;
79 }
80 else
81 {
82 BaseType::Add(key, value);
83 }
84 }
85 };
87 } // OVR
89 #endif