viewing paste Unknown #1224 | C

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
/*  This file is part of YA3DE.
 
    YA3DE is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
 
    Foobar is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
    along with YA3DE.  If not, see <http://www.gnu.org/licenses/>. */
 
#ifndef _CONTENTNAME_H_
#define _CONTENTNAME_H_
 
#include <string>
#include <unordered_map>
 
namespace YA3DE
{
    namespace Content
    {
        class ContentName
        {
        public:
            ContentName(const char *name)
            {
                _Name = name;
                _Hash = MakeHash(name);
            }
 
            ContentName(const std::string &name)
            {
                _Name = name;
                _Hash = MakeHash(name);
            }
 
            const std::string &GetName()
            {
                return _Name;
            }
 
            bool operator==(const ContentName &other)
            {
                return other._Hash == _Hash;
            }
            
            DEFPROP_RO(public, unsigned int, Hash);
            DEFPROP_I_RO(public, const std::string &, Name, GetName);
 
        private:
            static unsigned int MakeHash(const std::string &s)
            {
                unsigned int hash = 0x1505;
 
                for (int i = s.size() - 1; i > 0; i--)
                {
                    char c = (char)tolower((int)s[i]);
 
                    if (c == '/')
                        c = '\\';
 
                    hash = hash * 0x21 + c;
                }
 
                return hash;
            }
 
            std::string _Name;
        };
 
        template<typename T>
        struct ContentMapTraits
        {
            typedef std::unordered_map<ContentName, T> unordered_map_type;
        };
 
        template<typename T>
        using ContentNameHashTable = typename ContentMapTraits<T>::unordered_map_type;
    }
}
 
#endif
Viewed 764 times, submitted by greenboxal.