nuclear@0: /************************************************************************************ nuclear@0: nuclear@0: PublicHeader: None nuclear@0: Filename : OVR_StringHash.h nuclear@0: Content : String hash table used when optional case-insensitive nuclear@0: lookup is required. nuclear@0: Created : September 19, 2012 nuclear@0: Notes : nuclear@0: nuclear@0: Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved. nuclear@0: nuclear@0: Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); nuclear@0: you may not use the Oculus VR Rift SDK except in compliance with the License, nuclear@0: which is provided at the time of installation or download, or which nuclear@0: otherwise accompanies this software in either electronic or hard copy form. nuclear@0: nuclear@0: You may obtain a copy of the License at nuclear@0: nuclear@0: http://www.oculusvr.com/licenses/LICENSE-3.2 nuclear@0: nuclear@0: Unless required by applicable law or agreed to in writing, the Oculus VR SDK nuclear@0: distributed under the License is distributed on an "AS IS" BASIS, nuclear@0: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. nuclear@0: See the License for the specific language governing permissions and nuclear@0: limitations under the License. nuclear@0: nuclear@0: ************************************************************************************/ nuclear@0: nuclear@0: #ifndef OVR_StringHash_h nuclear@0: #define OVR_StringHash_h nuclear@0: nuclear@0: #include "OVR_String.h" nuclear@0: #include "OVR_Hash.h" nuclear@0: nuclear@0: namespace OVR { nuclear@0: nuclear@0: //----------------------------------------------------------------------------------- nuclear@0: // *** StringHash nuclear@0: nuclear@0: // This is a custom string hash table that supports case-insensitive nuclear@0: // searches through special functions such as GetCaseInsensitive, etc. nuclear@0: // This class is used for Flash labels, exports and other case-insensitive tables. nuclear@0: nuclear@0: template > nuclear@0: class StringHash : public Hash nuclear@0: { nuclear@0: public: nuclear@0: typedef U ValueType; nuclear@0: typedef StringHash SelfType; nuclear@0: typedef Hash BaseType; nuclear@0: nuclear@0: public: nuclear@0: nuclear@0: void operator = (const SelfType& src) { BaseType::operator = (src); } nuclear@0: nuclear@0: bool GetCaseInsensitive(const String& key, U* pvalue) const nuclear@0: { nuclear@0: String::NoCaseKey ikey(key); nuclear@0: return BaseType::GetAlt(ikey, pvalue); nuclear@0: } nuclear@0: // Pointer-returning get variety. nuclear@0: const U* GetCaseInsensitive(const String& key) const nuclear@0: { nuclear@0: String::NoCaseKey ikey(key); nuclear@0: return BaseType::GetAlt(ikey); nuclear@0: } nuclear@0: U* GetCaseInsensitive(const String& key) nuclear@0: { nuclear@0: String::NoCaseKey ikey(key); nuclear@0: return BaseType::GetAlt(ikey); nuclear@0: } nuclear@0: nuclear@0: nuclear@0: typedef typename BaseType::Iterator base_iterator; nuclear@0: nuclear@0: base_iterator FindCaseInsensitive(const String& key) nuclear@0: { nuclear@0: String::NoCaseKey ikey(key); nuclear@0: return BaseType::FindAlt(ikey); nuclear@0: } nuclear@0: nuclear@0: // Set just uses a find and assigns value if found. The key is not modified; nuclear@0: // this behavior is identical to Flash string variable assignment. nuclear@0: void SetCaseInsensitive(const String& key, const U& value) nuclear@0: { nuclear@0: base_iterator it = FindCaseInsensitive(key); nuclear@0: if (it != BaseType::End()) nuclear@0: { nuclear@0: it->Second = value; nuclear@0: } nuclear@0: else nuclear@0: { nuclear@0: BaseType::Add(key, value); nuclear@0: } nuclear@0: } nuclear@0: }; nuclear@0: nuclear@0: } // OVR nuclear@0: nuclear@0: #endif