Daniele Bartolini 10 лет назад
Родитель
Сommit
6dfb2333bd

+ 11 - 4
src/core/containers/container_types.h

@@ -162,8 +162,9 @@ struct Map
 	ALLOCATOR_AWARE;
 };
 
-/// Sorted map from key to POD items.
-/// Items are not automatically sorted, you have to call sort_map::sort().
+/// Vector of sorted items.
+/// Items are not automatically sorted, you have to call sort_map::sort()
+/// whenever you are done inserting items.
 /// @ingroup Containers.
 template <typename TKey, typename TValue, class Compare = less<TKey> >
 struct SortMap
@@ -172,8 +173,14 @@ struct SortMap
 
 	struct Entry
 	{
-		TKey key;
-		TValue value;
+		Entry(Allocator& a)
+			: pair(a)
+		{
+		}
+
+		PAIR(TKey, TValue) pair;
+
+		ALLOCATOR_AWARE;
 	};
 
 	Vector<Entry> _data;

+ 8 - 8
src/core/containers/sort_map.h

@@ -59,13 +59,13 @@ namespace sort_map_internal
 		bool operator()(const typename SortMap<TKey, TValue, Compare>::Entry& a,
 			const typename SortMap<TKey, TValue, Compare>::Entry& b) const
 		{
-			return comp(a.key, b.key);
+			return comp(a.pair.first, b.pair.first);
 		}
 
 		bool operator()(const typename SortMap<TKey, TValue, Compare>::Entry& a,
 			const TKey& key) const
 		{
-			return comp(a.key, key);
+			return comp(a.pair.first, key);
 		}
 
 		Compare comp;
@@ -83,7 +83,7 @@ namespace sort_map_internal
 			std::lower_bound(vector::begin(m._data), vector::end(m._data), key,
 			sort_map_internal::CompareEntry<TKey, TValue, Compare>());
 
-		if (first != vector::end(m._data) && !(key < first->key))
+		if (first != vector::end(m._data) && !(key < first->pair.first))
 		 	result.item_i = first - vector::begin(m._data);
 
 		return result;
@@ -106,7 +106,7 @@ namespace sort_map
 		if (result.item_i == sort_map_internal::END_OF_LIST)
 			return deffault;
 
-		return m._data[result.item_i].value;
+		return m._data[result.item_i].pair.second;
 	}
 
 	template <typename TKey, typename TValue, typename Compare>
@@ -132,14 +132,14 @@ namespace sort_map
 
 		if (result.item_i == sort_map_internal::END_OF_LIST)
 		{
-			typename SortMap<TKey, TValue, Compare>::Entry e;
-			e.key = key;
-			e.value = val;
+			typename SortMap<TKey, TValue, Compare>::Entry e(*m._data._allocator);
+			e.pair.first = key;
+			e.pair.second = val;
 			vector::push_back(m._data, e);
 		}
 		else
 		{
-			m._data[result.item_i].value = val;
+			m._data[result.item_i].pair.second = val;
 		}
 #if CROWN_DEBUG
 		m._is_sorted = false;

+ 2 - 2
src/resource/resource_manager.cpp

@@ -29,8 +29,8 @@ ResourceManager::~ResourceManager()
 
 	for (; begin != end; begin++)
 	{
-		resource_on_offline(begin->key.type, begin->key.name, *this);
-		resource_on_unload(begin->key.type, _resource_heap, begin->value.data);
+		resource_on_offline(begin->pair.first.type, begin->pair.first.name, *this);
+		resource_on_unload(begin->pair.first.type, _resource_heap, begin->pair.second.data);
 	}
 }