]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - libs/container/cache.h
Wrap GTK
[xonotic/netradiant.git] / libs / container / cache.h
index 880a7a7a57604dd7f90727a124db3c9b488f1197..047e4ea8f94c77a6e7060bab9584282e60f02e38 100644 (file)
@@ -95,83 +95,83 @@ pointer operator->() const {
 template<typename Key, typename Cached, typename Hasher, typename KeyEqual = std::equal_to<Key>, typename CreationPolicy = DefaultCreationPolicy<Cached, Key> >
 class HashedCache : public CreationPolicy
 {
-typedef SharedValue<Cached> Element;
-typedef HashTable<Key, Element, Hasher, KeyEqual> map_type;
+       typedef SharedValue<Cached> Element;
+       typedef HashTable<Key, Element, Hasher, KeyEqual> map_type;
 
-map_type m_map;
+       map_type m_map;
 
 public:
-explicit HashedCache( const CreationPolicy& creation = CreationPolicy() )
-       : CreationPolicy( creation ), m_map( 256 ){
-}
-~HashedCache(){
-       ASSERT_MESSAGE( empty(), "HashedCache::~HashedCache: not empty" );
-}
+       explicit HashedCache( const CreationPolicy& creation = CreationPolicy() )
+               : CreationPolicy( creation ), m_map( 256 ){
+       }
+       ~HashedCache(){
+               ASSERT_MESSAGE( empty(), "HashedCache::~HashedCache: not empty" );
+       }
 
-typedef typename map_type::iterator iterator;
-typedef typename map_type::value_type value_type;
+       typedef typename map_type::iterator iterator;
+       typedef typename map_type::value_type value_type;
 
-iterator begin(){
-       return m_map.begin();
-}
-iterator end(){
-       return m_map.end();
-}
+       iterator begin(){
+               return m_map.begin();
+       }
+       iterator end(){
+               return m_map.end();
+       }
 
-bool empty() const {
-       return m_map.empty();
-}
+       bool empty() const {
+               return m_map.empty();
+       }
 
-iterator find( const Key& key ){
-       return m_map.find( key );
-}
+       iterator find( const Key& key ){
+               return m_map.find( key );
+       }
 
-void capture( iterator i ){
+       void capture( iterator i ){
        ( *i ).value.increment();
-}
-void release( iterator i ){
+       }
+       void release( iterator i ){
        if ( ( *i ).value.decrement() == 0 ) {
                CreationPolicy::destroy( ( *i ).value.get() );
-               m_map.erase( i );
+                       m_map.erase( i );
+               }
        }
-}
 
 #if 1
-Element& capture( const Key& key ){
+       Element& capture( const Key& key ){
 #if 0
        Element& elem = m_map[key];
-       if ( elem.increment() == 1 ) {
-               elem.set( CreationPolicy::construct( key ) );
-       }
+               if ( elem.increment() == 1 ) {
+                       elem.set( CreationPolicy::construct( key ) );
+               }
        return elem;
 #else
        iterator i = m_map.insert( key, Element() );
        if ( ( *i ).value.increment() == 1 ) {
                ( *i ).value.set( CreationPolicy::construct( ( *i ).key ) );
-       }
+               }
        return ( *i ).value;
 #endif
-}
+       }
 #else
 value_type& capture( const Key& key ){
-       iterator i = m_map.find( key );
-       if ( i == m_map.end() ) {
-               i = m_map.insert( key, Element() );
+               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 ).value.increment();
-       return ( *i );
+               return ( *i );
 }
 #endif
-void release( const Key& key ){
-       iterator i = m_map.find( key );
-       ASSERT_MESSAGE( i != m_map.end(), "releasing a non-existent object\n" );
-       release( i );
-}
+       void release( const Key& key ){
+               iterator i = m_map.find( key );
+               ASSERT_MESSAGE( i != m_map.end(), "releasing a non-existent object\n" );
+               release( i );
+       }
 
-void clear(){
-       m_map.clear();
-}
+       void clear(){
+               m_map.clear();
+       }
 };