oculus1

annotate libovr/Src/Kernel/OVR_StringHash.h @ 12:d797639e0234

moving on to the distortion... not correct yet
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 20 Sep 2013 10:14:29 +0300
parents e2f9e4603129
children
rev   line source
nuclear@3 1 /************************************************************************************
nuclear@3 2
nuclear@3 3 PublicHeader: None
nuclear@3 4 Filename : OVR_StringHash.h
nuclear@3 5 Content : String hash table used when optional case-insensitive
nuclear@3 6 lookup is required.
nuclear@3 7 Created : September 19, 2012
nuclear@3 8 Notes :
nuclear@3 9
nuclear@3 10 Copyright : Copyright 2012 Oculus VR, Inc. All Rights reserved.
nuclear@3 11
nuclear@3 12 Use of this software is subject to the terms of the Oculus license
nuclear@3 13 agreement provided at the time of installation or download, or which
nuclear@3 14 otherwise accompanies this software in either electronic or hard copy form.
nuclear@3 15
nuclear@3 16 ************************************************************************************/
nuclear@3 17
nuclear@3 18 #ifndef OVR_StringHash_h
nuclear@3 19 #define OVR_StringHash_h
nuclear@3 20
nuclear@3 21 #include "OVR_String.h"
nuclear@3 22 #include "OVR_Hash.h"
nuclear@3 23
nuclear@3 24 namespace OVR {
nuclear@3 25
nuclear@3 26 //-----------------------------------------------------------------------------------
nuclear@3 27 // *** StringHash
nuclear@3 28
nuclear@3 29 // This is a custom string hash table that supports case-insensitive
nuclear@3 30 // searches through special functions such as GetCaseInsensitive, etc.
nuclear@3 31 // This class is used for Flash labels, exports and other case-insensitive tables.
nuclear@3 32
nuclear@3 33 template<class U, class Allocator = ContainerAllocator<U> >
nuclear@3 34 class StringHash : public Hash<String, U, String::NoCaseHashFunctor, Allocator>
nuclear@3 35 {
nuclear@3 36 public:
nuclear@3 37 typedef U ValueType;
nuclear@3 38 typedef StringHash<U, Allocator> SelfType;
nuclear@3 39 typedef Hash<String, U, String::NoCaseHashFunctor, Allocator> BaseType;
nuclear@3 40
nuclear@3 41 public:
nuclear@3 42
nuclear@3 43 void operator = (const SelfType& src) { BaseType::operator = (src); }
nuclear@3 44
nuclear@3 45 bool GetCaseInsensitive(const String& key, U* pvalue) const
nuclear@3 46 {
nuclear@3 47 String::NoCaseKey ikey(key);
nuclear@3 48 return BaseType::GetAlt(ikey, pvalue);
nuclear@3 49 }
nuclear@3 50 // Pointer-returning get variety.
nuclear@3 51 const U* GetCaseInsensitive(const String& key) const
nuclear@3 52 {
nuclear@3 53 String::NoCaseKey ikey(key);
nuclear@3 54 return BaseType::GetAlt(ikey);
nuclear@3 55 }
nuclear@3 56 U* GetCaseInsensitive(const String& key)
nuclear@3 57 {
nuclear@3 58 String::NoCaseKey ikey(key);
nuclear@3 59 return BaseType::GetAlt(ikey);
nuclear@3 60 }
nuclear@3 61
nuclear@3 62
nuclear@3 63 typedef typename BaseType::Iterator base_iterator;
nuclear@3 64
nuclear@3 65 base_iterator FindCaseInsensitive(const String& key)
nuclear@3 66 {
nuclear@3 67 String::NoCaseKey ikey(key);
nuclear@3 68 return BaseType::FindAlt(ikey);
nuclear@3 69 }
nuclear@3 70
nuclear@3 71 // Set just uses a find and assigns value if found. The key is not modified;
nuclear@3 72 // this behavior is identical to Flash string variable assignment.
nuclear@3 73 void SetCaseInsensitive(const String& key, const U& value)
nuclear@3 74 {
nuclear@3 75 base_iterator it = FindCaseInsensitive(key);
nuclear@3 76 if (it != BaseType::End())
nuclear@3 77 {
nuclear@3 78 it->Second = value;
nuclear@3 79 }
nuclear@3 80 else
nuclear@3 81 {
nuclear@3 82 BaseType::Add(key, value);
nuclear@3 83 }
nuclear@3 84 }
nuclear@3 85 };
nuclear@3 86
nuclear@3 87 } // OVR
nuclear@3 88
nuclear@3 89 #endif