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