}
void capture( iterator i ){
- ( *i ).value.increment();
+ ( *i ).second.increment();
}
void release( iterator i ){
- if ( ( *i ).value.decrement() == 0 ) {
- CreationPolicy::destroy( ( *i ).value.get() );
+ if ( ( *i ).second.decrement() == 0 ) {
+ CreationPolicy::destroy( ( *i ).second.get() );
m_map.erase( i );
}
}
}
return elem;
#else
- iterator i = m_map.insert( key, Element() );
- if ( ( *i ).value.increment() == 1 ) {
- ( *i ).value.set( CreationPolicy::construct( ( *i ).key ) );
+ iterator i = m_map.emplace( key, Element() ).first;
+ if ( ( *i ).second.increment() == 1 ) {
+ ( *i ).second.set( CreationPolicy::construct( ( *i ).first ) );
}
- return ( *i ).value;
+ return ( *i ).second;
#endif
}
#else
iterator i = m_map.find( key );
if ( i == m_map.end() ) {
i = m_map.insert( key, Element() );
- ( *i ).value.set( CreationPolicy::construct( ( *i ).key ) );
+ ( *i ).second.set( CreationPolicy::construct( ( *i ).first ) );
}
- ( *i ).value.increment();
+ ( *i ).second.increment();
return ( *i );
}
#endif
for ( MyHashTable::iterator i = hashtable.begin(); i != hashtable.end(); ++i )
{
- if ( ( *i ).key != "bleh" ) {
+ if ( ( *i ).first != "bleh" ) {
++hashtable["count"]; // insertion does not invalidate iterators
}
}
#if !defined( INCLUDED_CONTAINER_HASHTABLE_H )
#define INCLUDED_CONTAINER_HASHTABLE_H
+#include <unordered_map>
+
+template<typename Key, typename Value, typename Hasher, typename KeyEqual = std::equal_to<Key> >
+ using HashTable = std::unordered_map<Key, Value, Hasher, KeyEqual>;
+
+#if 0
#include <cstddef>
#include <algorithm>
#include <functional>
#include "debugging/debugging.h"
-
namespace HashTableDetail
{
inline std::size_t next_power_of_two( std::size_t size ){
return 0;
}
- if ( nodeHash == hash && KeyEqual::operator()( ( *i ).key, key ) ) {
+ if ( nodeHash == hash && KeyEqual::operator()( ( *i ).first, key ) ) {
return i.node();
}
}
};
#endif
+
+#endif
std::size_t pooled = 0;
for ( StringPool::iterator i = pool.begin(); i != pool.end(); ++i )
{
- std::size_t size = string_length( ( *i ).key ) + 1;
- total += size * ( *i ).value;
+ std::size_t size = string_length( ( *i ).first ) + 1;
+ total += size * ( *i ).second;
pooled += size + 20;
- ordered.insert( Ordered::value_type( ( *i ).value, ( *i ).key ) );
+ ordered.insert( Ordered::value_type( ( *i ).second, ( *i ).first ) );
}
globalOutputStream() << "total: " << Unsigned( total ) << " pooled:" << Unsigned( pooled ) << "\n";
for ( Ordered::iterator i = ordered.begin(); i != ordered.end(); ++i )
{
StringPool::iterator m_i;
static StringPool::iterator increment( StringPool::iterator i ){
- ++( *i ).value;
+ ++( *i ).second;
return i;
}
static StringPool::iterator insert( const char* string ){
StringPool::iterator i = PoolContext::instance().find( const_cast<char*>( string ) );
if ( i == PoolContext::instance().end() ) {
- return PoolContext::instance().insert( string_clone( string ), 1 );
+ return PoolContext::instance().emplace( string_clone( string ), 1 ).first;
}
return increment( i );
}
static void erase( StringPool::iterator i ){
- if ( --( *i ).value == 0 ) {
- char* string = ( *i ).key;
+ if ( --( *i ).second == 0 ) {
+ char* string = ( *i ).first;
PoolContext::instance().erase( i );
string_release( string, string_length( string ) );
}
return m_i == other.m_i;
}
const char* c_str() const {
- return ( *m_i ).key;
+ return ( *m_i ).first;
}
};
m_realised = true;
for ( Cache::iterator i = m_cache.begin(); i != m_cache.end(); ++i )
{
- ( *i ).value->realise( ( *i ).key.c_str() );
+ ( *i ).second->realise( ( *i ).first.c_str() );
}
}
void unrealise(){
m_realised = false;
for ( Cache::iterator i = m_cache.begin(); i != m_cache.end(); ++i )
{
- ( *i ).value->unrealise();
+ ( *i ).second->unrealise();
}
g_skins.unrealise();
}
ModelCache::iterator ModelCache_insert( const char* path, const char* name, scene::Node& node ){
if ( g_modelCache_enabled ) {
- return g_modelCache.insert( ModelKey( path, name ), NodeSmartReference( node ) );
+ return g_modelCache.emplace( ModelKey( path, name ), NodeSmartReference( node ) ).first;
}
- return g_modelCache.insert( ModelKey( "", "" ), g_nullModel );
+ return g_modelCache.emplace( ModelKey( "", "" ), g_nullModel ).first;
}
void ModelCache_flush( const char* path, const char* name ){
);
}
- setModel( ( *i ).value );
+ setModel( ( *i ).second );
}
else
{
void setNode( scene::Node* node ){
ModelCache::iterator i = ModelCache_find( m_path.c_str(), m_name.c_str() );
if ( i != g_modelCache.end() ) {
- ( *i ).value = NodeSmartReference( *node );
+ ( *i ).second = NodeSmartReference( *node );
}
setModel( NodeSmartReference( *node ) );
for ( ModelReferencesSnapshot::iterator i = snapshot.begin(); i != snapshot.end(); ++i )
{
ModelReferences::value_type& value = *( *i );
- if ( value.value.count() != 1 ) {
- value.value.get()->realise();
+ if ( value.second.count() != 1 ) {
+ value.second.get()->realise();
}
}
}
for ( ModelReferencesSnapshot::iterator i = snapshot.begin(); i != snapshot.end(); ++i )
{
ModelReferences::value_type& value = *( *i );
- if ( value.value.count() != 1 ) {
- value.value.get()->unrealise();
+ if ( value.second.count() != 1 ) {
+ value.second.get()->unrealise();
}
}
}
ModelReferencesSnapshot snapshot( m_references );
for ( ModelReferencesSnapshot::iterator i = snapshot.begin(); i != snapshot.end(); ++i )
{
- ModelResource* resource = ( *( *i ) ).value.get();
+ ModelResource* resource = ( *( *i ) ).second.get();
if ( !resource->isMap() ) {
resource->refresh();
}
ScopeDisableScreenUpdates disableScreenUpdates( "Processing...", "Saving Map" );
for ( HashtableReferenceCache::iterator i = g_referenceCache.begin(); i != g_referenceCache.end(); ++i )
{
- ( *i ).value->save();
+ ( *i ).second->save();
}
MapChanged();
}
bool References_Saved(){
for ( HashtableReferenceCache::iterator i = g_referenceCache.begin(); i != g_referenceCache.end(); ++i )
{
- scene::Node* node = ( *i ).value->getNode();
+ scene::Node* node = ( *i ).second->getNode();
if ( node != 0 ) {
MapFile* map = Node_getMapFile( *node );
if ( map != 0 && !map->saved() ) {
~OpenGLShaderCache(){
for ( Shaders::iterator i = m_shaders.begin(); i != m_shaders.end(); ++i )
{
- globalOutputStream() << "leaked shader: " << makeQuoted( ( *i ).key.c_str() ) << "\n";
+ globalOutputStream() << "leaked shader: " << makeQuoted( ( *i ).first.c_str() ) << "\n";
}
}
Shader* capture( const char* name ){
for ( Shaders::iterator i = m_shaders.begin(); i != m_shaders.end(); ++i )
{
- if ( !( *i ).value.empty() ) {
- ( *i ).value->realise( i->key );
+ if ( !( *i ).second.empty() ) {
+ ( *i ).second->realise( i->first );
}
}
}
if ( ++m_unrealised == 1 ) {
for ( Shaders::iterator i = m_shaders.begin(); i != m_shaders.end(); ++i )
{
- if ( !( *i ).value.empty() ) {
- ( *i ).value->unrealise();
+ if ( !( *i ).second.empty() ) {
+ ( *i ).second->unrealise();
}
}
if ( GlobalOpenGL().contextValid && lightingSupported() && lightingEnabled() ) {
for ( qtextures_t::iterator i = m_qtextures.begin(); i != m_qtextures.end(); ++i )
{
- if ( !( *i ).value.empty() ) {
- qtexture_realise( *( *i ).value, ( *i ).key );
+ if ( !( *i ).second.empty() ) {
+ qtexture_realise( *( *i ).second, ( *i ).first );
}
}
if ( m_observer != 0 ) {
}
for ( qtextures_t::iterator i = m_qtextures.begin(); i != m_qtextures.end(); ++i )
{
- if ( !( *i ).value.empty() ) {
- qtexture_unrealise( *( *i ).value );
+ if ( !( *i ).second.empty() ) {
+ qtexture_unrealise( *( *i ).second );
}
}
}
for ( TexturesMap::iterator i = g_texturesmap->begin(); i != g_texturesmap->end(); ++i )
{
- glBindTexture( GL_TEXTURE_2D, ( *i ).value->texture_number );
+ glBindTexture( GL_TEXTURE_2D, ( *i ).second->texture_number );
SetTexParameters( g_texture_mode );
}