oculus1

diff libovr/Src/Kernel/OVR_StringHash.h @ 3:b069a5c27388

added a couple more stuff, fixed all the LibOVR line endings
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 15 Sep 2013 04:10:05 +0300
parents e2f9e4603129
children
line diff
     1.1 --- a/libovr/Src/Kernel/OVR_StringHash.h	Sat Sep 14 17:51:03 2013 +0300
     1.2 +++ b/libovr/Src/Kernel/OVR_StringHash.h	Sun Sep 15 04:10:05 2013 +0300
     1.3 @@ -1,1 +1,89 @@
     1.4 -/************************************************************************************
     1.5 
     1.6 PublicHeader:   None
     1.7 Filename    :   OVR_StringHash.h
     1.8 Content     :   String hash table used when optional case-insensitive
     1.9                 lookup is required.
    1.10 Created     :   September 19, 2012
    1.11 Notes       : 
    1.12 
    1.13 Copyright   :   Copyright 2012 Oculus VR, Inc. All Rights reserved.
    1.14 
    1.15 Use of this software is subject to the terms of the Oculus license
    1.16 agreement provided at the time of installation or download, or which
    1.17 otherwise accompanies this software in either electronic or hard copy form.
    1.18 
    1.19 ************************************************************************************/
    1.20 
    1.21 #ifndef OVR_StringHash_h
    1.22 #define OVR_StringHash_h
    1.23 
    1.24 #include "OVR_String.h"
    1.25 #include "OVR_Hash.h"
    1.26 
    1.27 namespace OVR {
    1.28 
    1.29 //-----------------------------------------------------------------------------------
    1.30 // *** StringHash
    1.31 
    1.32 // This is a custom string hash table that supports case-insensitive
    1.33 // searches through special functions such as GetCaseInsensitive, etc.
    1.34 // This class is used for Flash labels, exports and other case-insensitive tables.
    1.35 
    1.36 template<class U, class Allocator = ContainerAllocator<U> >
    1.37 class StringHash : public Hash<String, U, String::NoCaseHashFunctor, Allocator>
    1.38 {
    1.39 public:
    1.40     typedef U                                                        ValueType;
    1.41     typedef StringHash<U, Allocator>                                 SelfType;
    1.42     typedef Hash<String, U, String::NoCaseHashFunctor, Allocator>    BaseType;
    1.43 
    1.44 public:    
    1.45 
    1.46     void    operator = (const SelfType& src) { BaseType::operator = (src); }
    1.47 
    1.48     bool    GetCaseInsensitive(const String& key, U* pvalue) const
    1.49     {
    1.50         String::NoCaseKey ikey(key);
    1.51         return BaseType::GetAlt(ikey, pvalue);
    1.52     }
    1.53     // Pointer-returning get variety.
    1.54     const U* GetCaseInsensitive(const String& key) const   
    1.55     {
    1.56         String::NoCaseKey ikey(key);
    1.57         return BaseType::GetAlt(ikey);
    1.58     }
    1.59     U*  GetCaseInsensitive(const String& key)
    1.60     {
    1.61         String::NoCaseKey ikey(key);
    1.62         return BaseType::GetAlt(ikey);
    1.63     }
    1.64 
    1.65     
    1.66     typedef typename BaseType::Iterator base_iterator;
    1.67 
    1.68     base_iterator    FindCaseInsensitive(const String& key)
    1.69     {
    1.70         String::NoCaseKey ikey(key);
    1.71         return BaseType::FindAlt(ikey);
    1.72     }
    1.73 
    1.74     // Set just uses a find and assigns value if found. The key is not modified;
    1.75     // this behavior is identical to Flash string variable assignment.    
    1.76     void    SetCaseInsensitive(const String& key, const U& value)
    1.77     {
    1.78         base_iterator it = FindCaseInsensitive(key);
    1.79         if (it != BaseType::End())
    1.80         {
    1.81             it->Second = value;
    1.82         }
    1.83         else
    1.84         {
    1.85             BaseType::Add(key, value);
    1.86         }
    1.87     } 
    1.88 };
    1.89 
    1.90 } // OVR 
    1.91 
    1.92 #endif
    1.93 \ No newline at end of file
    1.94 +/************************************************************************************
    1.95 +
    1.96 +PublicHeader:   None
    1.97 +Filename    :   OVR_StringHash.h
    1.98 +Content     :   String hash table used when optional case-insensitive
    1.99 +                lookup is required.
   1.100 +Created     :   September 19, 2012
   1.101 +Notes       : 
   1.102 +
   1.103 +Copyright   :   Copyright 2012 Oculus VR, Inc. All Rights reserved.
   1.104 +
   1.105 +Use of this software is subject to the terms of the Oculus license
   1.106 +agreement provided at the time of installation or download, or which
   1.107 +otherwise accompanies this software in either electronic or hard copy form.
   1.108 +
   1.109 +************************************************************************************/
   1.110 +
   1.111 +#ifndef OVR_StringHash_h
   1.112 +#define OVR_StringHash_h
   1.113 +
   1.114 +#include "OVR_String.h"
   1.115 +#include "OVR_Hash.h"
   1.116 +
   1.117 +namespace OVR {
   1.118 +
   1.119 +//-----------------------------------------------------------------------------------
   1.120 +// *** StringHash
   1.121 +
   1.122 +// This is a custom string hash table that supports case-insensitive
   1.123 +// searches through special functions such as GetCaseInsensitive, etc.
   1.124 +// This class is used for Flash labels, exports and other case-insensitive tables.
   1.125 +
   1.126 +template<class U, class Allocator = ContainerAllocator<U> >
   1.127 +class StringHash : public Hash<String, U, String::NoCaseHashFunctor, Allocator>
   1.128 +{
   1.129 +public:
   1.130 +    typedef U                                                        ValueType;
   1.131 +    typedef StringHash<U, Allocator>                                 SelfType;
   1.132 +    typedef Hash<String, U, String::NoCaseHashFunctor, Allocator>    BaseType;
   1.133 +
   1.134 +public:    
   1.135 +
   1.136 +    void    operator = (const SelfType& src) { BaseType::operator = (src); }
   1.137 +
   1.138 +    bool    GetCaseInsensitive(const String& key, U* pvalue) const
   1.139 +    {
   1.140 +        String::NoCaseKey ikey(key);
   1.141 +        return BaseType::GetAlt(ikey, pvalue);
   1.142 +    }
   1.143 +    // Pointer-returning get variety.
   1.144 +    const U* GetCaseInsensitive(const String& key) const   
   1.145 +    {
   1.146 +        String::NoCaseKey ikey(key);
   1.147 +        return BaseType::GetAlt(ikey);
   1.148 +    }
   1.149 +    U*  GetCaseInsensitive(const String& key)
   1.150 +    {
   1.151 +        String::NoCaseKey ikey(key);
   1.152 +        return BaseType::GetAlt(ikey);
   1.153 +    }
   1.154 +
   1.155 +    
   1.156 +    typedef typename BaseType::Iterator base_iterator;
   1.157 +
   1.158 +    base_iterator    FindCaseInsensitive(const String& key)
   1.159 +    {
   1.160 +        String::NoCaseKey ikey(key);
   1.161 +        return BaseType::FindAlt(ikey);
   1.162 +    }
   1.163 +
   1.164 +    // Set just uses a find and assigns value if found. The key is not modified;
   1.165 +    // this behavior is identical to Flash string variable assignment.    
   1.166 +    void    SetCaseInsensitive(const String& key, const U& value)
   1.167 +    {
   1.168 +        base_iterator it = FindCaseInsensitive(key);
   1.169 +        if (it != BaseType::End())
   1.170 +        {
   1.171 +            it->Second = value;
   1.172 +        }
   1.173 +        else
   1.174 +        {
   1.175 +            BaseType::Add(key, value);
   1.176 +        }
   1.177 +    } 
   1.178 +};
   1.179 +
   1.180 +} // OVR 
   1.181 +
   1.182 +#endif