OVR_StringHash.h
Go to the documentation of this file.
00001 /************************************************************************************
00002 
00003 PublicHeader:   None
00004 Filename    :   OVR_StringHash.h
00005 Content     :   String hash table used when optional case-insensitive
00006                 lookup is required.
00007 Created     :   September 19, 2012
00008 Notes       : 
00009 
00010 Copyright   :   Copyright 2012 Oculus VR, Inc. All Rights reserved.
00011 
00012 Use of this software is subject to the terms of the Oculus license
00013 agreement provided at the time of installation or download, or which
00014 otherwise accompanies this software in either electronic or hard copy form.
00015 
00016 ************************************************************************************/
00017 
00018 #ifndef OVR_StringHash_h
00019 #define OVR_StringHash_h
00020 
00021 #include "OVR_String.h"
00022 #include "OVR_Hash.h"
00023 
00024 namespace OVR {
00025 
00026 //-----------------------------------------------------------------------------------
00027 // *** StringHash
00028 
00029 // This is a custom string hash table that supports case-insensitive
00030 // searches through special functions such as GetCaseInsensitive, etc.
00031 // This class is used for Flash labels, exports and other case-insensitive tables.
00032 
00033 template<class U, class Allocator = ContainerAllocator<U> >
00034 class StringHash : public Hash<String, U, String::NoCaseHashFunctor, Allocator>
00035 {
00036 public:
00037     typedef U                                                        ValueType;
00038     typedef StringHash<U, Allocator>                                 SelfType;
00039     typedef Hash<String, U, String::NoCaseHashFunctor, Allocator>    BaseType;
00040 
00041 public:    
00042 
00043     void    operator = (const SelfType& src) { BaseType::operator = (src); }
00044 
00045     bool    GetCaseInsensitive(const String& key, U* pvalue) const
00046     {
00047         String::NoCaseKey ikey(key);
00048         return BaseType::GetAlt(ikey, pvalue);
00049     }
00050     // Pointer-returning get variety.
00051     const U* GetCaseInsensitive(const String& key) const   
00052     {
00053         String::NoCaseKey ikey(key);
00054         return BaseType::GetAlt(ikey);
00055     }
00056     U*  GetCaseInsensitive(const String& key)
00057     {
00058         String::NoCaseKey ikey(key);
00059         return BaseType::GetAlt(ikey);
00060     }
00061 
00062     
00063     typedef typename BaseType::Iterator base_iterator;
00064 
00065     base_iterator    FindCaseInsensitive(const String& key)
00066     {
00067         String::NoCaseKey ikey(key);
00068         return BaseType::FindAlt(ikey);
00069     }
00070 
00071     // Set just uses a find and assigns value if found. The key is not modified;
00072     // this behavior is identical to Flash string variable assignment.    
00073     void    SetCaseInsensitive(const String& key, const U& value)
00074     {
00075         base_iterator it = FindCaseInsensitive(key);
00076         if (it != BaseType::End())
00077         {
00078             it->Second = value;
00079         }
00080         else
00081         {
00082             BaseType::Add(key, value);
00083         }
00084     } 
00085 };
00086 
00087 } // OVR 
00088 
00089 #endif


oculus_sdk
Author(s):
autogenerated on Mon Oct 6 2014 03:01:19