Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
   Copyright (c) 2016 DIVIDE-Studio
   Copyright (c) 2009 Ionut Cava

   This file is part of DIVIDE Framework.

   Permission is hereby granted, free of charge, to any person obtaining a copy
   of this software
   and associated documentation files (the "Software"), to deal in the Software
   without restriction,
   including without limitation the rights to use, copy, modify, merge, publish,
   distribute, sublicense,
   and/or sell copies of the Software, and to permit persons to whom the
   Software is furnished to do so,
   subject to the following conditions:

   The above copyright notice and this permission notice shall be included in
   all copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   IMPLIED,
   INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
   PARTICULAR PURPOSE AND NONINFRINGEMENT.
   IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
   DAMAGES OR OTHER LIABILITY,
   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
   IN CONNECTION WITH THE SOFTWARE
   OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

 */

#ifndef _HASH_MAP_H_
#define _HASH_MAP_H_

#include "TemplateAllocator.h"
#include <algorithm>

template<class T>
struct EnumHash;

template <typename Key>
using HashType = EnumHash<Key>;

#if defined(HASH_MAP_IMP) && HASH_MAP_IMP == BOOST_IMP
#include <boost/Unordered_Map.hpp>
// macros are evil but we need to extend namespaces so aliases don't work as well
#define hashAlg boost
#elif defined(HASH_MAP_IMP) && HASH_MAP_IMP == EASTL_IMP
#include <EASTL/hash_map.h>
#define hashAlg eastl
#else  // defined(HASH_MAP_IMP) && HASH_MAP_IMP == STL_IMP
#include <unordered_map>
#define hashAlg std
#endif


template <typename K, typename V, typename HashFun = HashType<K> >
using hashMapImpl = hashAlg::unordered_map<K,
                                           V,
                                           HashFun,
                                           std::equal_to<K>,
                                           dvd_allocator<std::pair<const K, V>>>;

template <typename K, typename V, typename HashFun = HashType<K> >
using hashMapImplAligned = hashAlg::unordered_map<K,
                                                  V,
                                                  HashFun>;

template <typename K, typename V, typename HashFun = HashType<K> >
using hashPairReturn = std::pair<typename hashMapImpl<K, V, HashFun>::iterator, bool>;

template <typename K, typename V, typename HashFun = HashType<K> >
using hashPairReturnAligned = std::pair<typename hashMapImplAligned<K, V, HashFun>::iterator, bool>;

template<class T, bool>
struct hasher {
    inline size_t operator() (const T& elem) {
        return std::hash<T>()(elem);
    }
};

template<class T>
struct hasher<T, true> {
    inline size_t operator() (const T& elem) {
        typedef typename std::underlying_type<T>::type enumType;
        return std::hash<enumType>()(static_cast<enumType>(elem));
    }
};

template<class T>
struct EnumHash {
    inline size_t operator()(const T& elem) const {
        return hasher<T, std::is_enum<T>::value>()(elem);
    }
};

namespace hashAlg {
#if defined(HASH_MAP_IMP) && HASH_MAP_IMP == EASTL_IMP
template <typename K, typename V, typename HashFun = HashType<K> >
inline hashPairReturn<K, V, HashFun> emplace(hashMapImpl<K, V, HashFun>& map, K key, const V& val) {
    hashMapImpl<K, V, HashFun>::value_type value(key);
    value.second = val;

    auto result = map.insert(value);

    return std::make_pair(result.first, result.second);
}

template <typename K, typename V, typename HashFun = HashType<K> >
inline hashPairReturn<K, V, HashFun> insert(hashMapImpl<K, V, HashFun>& map, const std::pair<K, V>& valuePair) {
    
    auto result = map.insert(eastl::pair<K, V>(valuePair.first, valuePair.second));

    return std::make_pair(result.first, result.second);
}

template <typename K, typename V, typename HashFun = HashType<K> >
inline hashPairReturnAligned<K, V, HashFun> emplace(hashMapImplAligned<K, V, HashFun>& map, K key, const V& val) {
    hashMapImpl<K, V, HashFun>::value_type value(key);
    value.second = val;

    auto result = map.insert(value);

    return std::make_pair(result.first, result.second);
}

template <typename K, typename V, typename HashFun = HashType<K> >
inline hashPairReturnAligned<K, V, HashFun> insert(hashMapImplAligned<K, V, HashFun>& map, const std::pair<K, V>& valuePair) {

    auto result = map.insert(eastl::pair<K, V>(valuePair.first, valuePair.second));

    return std::make_pair(result.first, result.second);
}

#else 
template <typename K, typename V, typename HashFun = HashType<K> >
inline hashPairReturn<K, V, HashFun> emplace(hashMapImpl<K, V, HashFun>& map, K key, const V& val) {
    return map.emplace(key, val);
}

template <typename K, typename V, typename HashFun = HashType<K> >
inline hashPairReturn<K, V, HashFun> insert(hashMapImpl<K, V, HashFun>& map, const typename hashMapImpl<K, V, HashFun>::value_type& valuePair) {
    return map.insert(valuePair);
}

#if defined(USE_CUSTOM_MEMORY_ALLOCATORS)
template <typename K, typename V, typename HashFun = HashType<K> >
inline hashPairReturnAligned<K, V, HashFun> emplace(hashMapImplAligned<K, V, HashFun>& map, K key, const V& val) {
    return map.emplace(key, val);
}

template <typename K, typename V, typename HashFun = HashType<K> >
inline hashPairReturnAligned<K, V, HashFun> insert(hashMapImplAligned<K, V, HashFun>& map, const typename hashMapImpl<K, V, HashFun>::value_type& valuePair) {
    return map.insert(valuePair);
}
#endif //USE_CUSTOM_MEMORY_ALLOCATORS

#endif
}; //namespace hashAlg

#endif

Commits for Divide-Framework/trunk/Source Code/Core/TemplateLibraries/Headers/HashMap.h

Diff revisions: vs.
Revision Author Commited Message
727 Diff Diff IonutCava picture IonutCava Tue 14 Jun, 2016 16:01:38 +0000

[IonutCava]
- Remove node and cmd buffers from GFXDevice and add them as a new BufferData struct to RenderPass class.
— Each render pass holds its own buffers
- Improvements / fixes to the CSM code
- Added a global toggle to enable/disable custom memory allocators

691 Diff Diff IonutCava picture IonutCava Tue 26 Apr, 2016 16:14:43 +0000

[IonutCava]
- Cleanup hash map template code (and allow creation of hash maps using the default allocator)
- Speedup text label multi-line parsing (now done on setText instead of drawText)
- Fix some reflection-related material crashes

648 Diff Diff IonutCava picture IonutCava Sun 21 Feb, 2016 16:32:52 +0000

[IonutCava]
- Update copyright notice
- Move BoundingBox and BoundingSphere to a new BoundsComponent
— Add a temp hack in SceneGraphNode to update these

466 Diff Diff IonutCava picture IonutCava Fri 05 Jun, 2015 15:07:17 +0000

[Ionut]
- Moved EASTL, SimpleINI and Threadpool libraries from Dependencies repo to engine repo
- Disabled EASTL string and vector support as they are really out of date and missing required features.
— EASTL hash map is still usable

458 Diff Diff IonutCava picture IonutCava Tue 02 Jun, 2015 16:26:18 +0000

[Ionut]
- More Linux port work

457 IonutCava picture IonutCava Mon 01 Jun, 2015 21:45:52 +0000

[Ionut]
- Windows build fix for previous commit