diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | 114a878c64ce6f8223cfd22d76a20eb16d177e5e (patch) | |
tree | acaf47eb0fa12142d3896416a69e74cbf5a72242 /lib/cppparser/cachemanager.h | |
download | tdevelop-114a878c64ce6f8223cfd22d76a20eb16d177e5e.tar.gz tdevelop-114a878c64ce6f8223cfd22d76a20eb16d177e5e.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdevelop@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'lib/cppparser/cachemanager.h')
-rw-r--r-- | lib/cppparser/cachemanager.h | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/lib/cppparser/cachemanager.h b/lib/cppparser/cachemanager.h new file mode 100644 index 00000000..3804356f --- /dev/null +++ b/lib/cppparser/cachemanager.h @@ -0,0 +1,102 @@ + +/*************************************************************************** + copyright : (C) 2006 by David Nolden + email : david.nolden.kdevelop@art-master.de +***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef CACHEMANAGER_H +#define CACHEMANAGER_H +#include <cstdlib> +#include <set> +#include <limits> + +class CacheManager; + + +class CacheNode { + typedef CacheManager Manager; + public: + CacheNode( Manager* manager ); + + virtual ~CacheNode(); + + void access() const; + + inline uint value() const { + return m_value; + } + + inline void setValue( const uint v ) const { + m_value = v; + } + + inline void addValue( const uint diff ) const { + m_value += diff; + } + + private: + Manager* m_manager; + mutable uint m_value; //This value stands for the priority of the node(higher is better) +}; + +class CacheNodeCompare { + public: + bool operator() ( const CacheNode* lhs, const CacheNode* rhs ) const { + if( lhs->value() != rhs->value() ) + return lhs->value() < rhs->value(); + else + return lhs < rhs; //To be able to identify nodes precisely + } +}; + + +class CacheManager { + typedef std::set< const CacheNode*, CacheNodeCompare > SetType; + public: + CacheManager( int maxNodes = 1000 ) : m_currentFrame(1), m_maxNodes( maxNodes ), m_currentMax(1) { + }; + + inline int currentFrame() const { + return m_currentFrame; + } + + void access( const CacheNode* node ); + + ///Can be used from outside to set the maximum count of nodes to keep. + void setMaxNodes ( int maxNodes ); + + void increaseFrame(); + + ///Can be used on a regular basis(time-triggered) to save memory: Removes half of all triggered + void removeLowerHalf(); + + virtual void saveMemory(); + + int currentMax() const { + return m_currentMax; + } + + ///This triggered function should erase the given node. + virtual void erase( const CacheNode* node ) = 0; + private: + void restart( uint normalizeby ); + friend class CacheNode; + void remove( const CacheNode* node ); + void add( const CacheNode* node ); + int m_currentFrame; + int m_maxNodes; + int m_currentMax; + SetType m_set; +}; + + +#endif |