TuttleOFX  1
MemoryCache.hpp
Go to the documentation of this file.
00001 #ifndef _TUTTLE_HOST_CORE_MEMORYCACHE_HPP_
00002 #define _TUTTLE_HOST_CORE_MEMORYCACHE_HPP_
00003 
00004 #include "IMemoryCache.hpp"
00005 #include "IMemoryPool.hpp"
00006 
00007 //#include <boost/ptr_container/ptr_map.hpp>
00008 #include <boost/unordered_map.hpp>
00009 #include <boost/thread.hpp>
00010 //#include <map>
00011 
00012 namespace tuttle {
00013 namespace host {
00014 namespace memory {
00015 
00016 class MemoryCache : public IMemoryCache
00017 {
00018 typedef MemoryCache This;
00019 
00020 public:
00021         MemoryCache( const MemoryCache& other )
00022         {
00023                 *this = other;
00024         }
00025         MemoryCache() {}
00026         ~MemoryCache() {}
00027 
00028         MemoryCache& operator=( const MemoryCache& cache );
00029 
00030 private:
00031         typedef boost::unordered_map<Key, CACHE_ELEMENT, KeyHash> MAP;
00032         //      typedef std::map<Key, CACHE_ELEMENT> MAP;
00033         MAP _map;
00034         mutable boost::mutex _mutexMap;  ///< Mutex for cache data map.
00035 
00036         MAP::const_iterator getIteratorForValue( const CACHE_ELEMENT& ) const;
00037         MAP::iterator       getIteratorForValue( const CACHE_ELEMENT& );
00038 
00039 public:
00040         void               put( const std::string& identifier, const double time, CACHE_ELEMENT pData );
00041         CACHE_ELEMENT      get( const std::string& identifier, const double time ) const;
00042         CACHE_ELEMENT      get( const std::size_t& i ) const;
00043         std::size_t        size() const;
00044         bool               empty() const;
00045         bool               inCache( const CACHE_ELEMENT& ) const;
00046         double             getTime( const CACHE_ELEMENT& ) const;
00047         const std::string& getPluginName( const CACHE_ELEMENT& ) const;
00048         bool               remove( const CACHE_ELEMENT& );
00049         void               clearUnused();
00050         void               clearAll();
00051         std::ostream& outputStream( std::ostream& os ) const
00052         {
00053                 os << *this;
00054                 return os;
00055         }
00056         friend std::ostream& operator<<( std::ostream& os, const MemoryCache& v );
00057 };
00058 
00059 }
00060 }
00061 }
00062 
00063 #endif
00064