oculus1

annotate libovr/Src/Kernel/OVR_StringHash.h @ 1:e2f9e4603129

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