akonadi
sharedvaluepool_p.h
00001 /* 00002 Copyright (c) 2010 Volker Krause <vkrause@kde.org> 00003 00004 This library is free software; you can redistribute it and/or modify it 00005 under the terms of the GNU Library General Public License as published by 00006 the Free Software Foundation; either version 2 of the License, or (at your 00007 option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, but WITHOUT 00010 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00011 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00012 License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to the 00016 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00017 02110-1301, USA. 00018 */ 00019 00020 #ifndef AKONADI_SHAREDVALUEPOOL_P_H 00021 #define AKONADI_SHAREDVALUEPOOL_P_H 00022 00023 #include <boost/utility/enable_if.hpp> 00024 #include <algorithm> 00025 00026 namespace Akonadi { 00027 namespace Internal { 00028 00029 /*template <typename T> class container_traits 00030 { 00031 private: 00032 typedef char sizeOne; 00033 typedef struct { char a[2]; } sizeTwo; 00034 template <typename C> static sizeOne testForKeyType( typename C::key_type const* ); 00035 template <typename C> static sizeTwo testForKeyType( ... ); 00036 public: 00037 enum { isAssociative = sizeof( container_traits<T>::testForKeyType<T>( 0 ) ) == 1 }; 00038 };*/ 00039 00044 template <typename T, template <typename> class Container> 00045 class SharedValuePool 00046 { 00047 public: 00049 /*template <typename C> 00050 typename boost::enable_if_c<container_traits<Container<C> >::isAssociative, C>::type sharedValue( const C &value, const int* = 0 ) 00051 { 00052 typename Container<T>::const_iterator it = m_pool.constFind( value ); 00053 if ( it != m_pool.constEnd() ) 00054 return *it; 00055 m_pool.insert( value ); 00056 return value; 00057 } 00058 00059 template <typename C> 00060 typename boost::disable_if_c<container_traits<Container<C> >::isAssociative, C>::type sharedValue( const C &value )*/ 00061 T sharedValue( const T &value ) 00062 { 00063 // for small pool sizes this is actually faster than using lower_bound and a sorted vector 00064 typename Container<T>::const_iterator it = std::find( m_pool.constBegin(), m_pool.constEnd(), value ); 00065 if ( it != m_pool.constEnd() ) 00066 return *it; 00067 m_pool.push_back( value ); 00068 return value; 00069 } 00070 00071 private: 00072 Container<T> m_pool; 00073 }; 00074 00075 } 00076 } 00077 00078 #endif
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu Aug 2 2012 15:25:19 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu Aug 2 2012 15:25:19 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.