TuttleOFX  1
TuttleOFX/libraries/tuttle/src/tuttle/host/memory/IMemoryCache.hpp
Go to the documentation of this file.
00001 #ifndef _TUTTLE_HOST_CORE_IMEMORYCACHE_HPP_
00002 #define _TUTTLE_HOST_CORE_IMEMORYCACHE_HPP_
00003 
00004 #include "IMemoryPool.hpp"
00005 
00006 #include <boost/shared_ptr.hpp> ///< @todo temporary solution..
00007 #include <string>
00008 
00009 namespace tuttle {
00010 namespace host {
00011 namespace attribute {
00012 class Image;
00013 }
00014 namespace memory {
00015 
00016 /**
00017  * @brief configure the cache with this element
00018  * CACHE_ELEMENT should be a smart_ptr of some kind
00019  * pointer will be stored in a container so no auto_ptr is allowed
00020  */
00021 typedef ::boost::shared_ptr<tuttle::host::attribute::Image> CACHE_ELEMENT; ///< @todo temporary solution..
00022 
00023 struct Key
00024 {
00025         typedef Key This;
00026         Key( const std::string& identifier, const double& time )
00027                 : _identifier( identifier )
00028                 , _time( time )
00029         {}
00030         bool operator<( const This& ) const;
00031         bool operator==( const This& v ) const;
00032         std::size_t  getHash() const;
00033 
00034         std::string _identifier;
00035         double _time;
00036         friend std::ostream& operator<<( std::ostream& os, const Key& v );
00037 };
00038 
00039 struct KeyHash : std::unary_function<Key, std::size_t>
00040 {
00041         std::size_t operator()( const Key& p ) const
00042         {
00043                 return p.getHash();
00044         }
00045 
00046 };
00047 //typedef IPoolDataPtr CACHE_ELEMENT;
00048 
00049 class IMemoryCache
00050 {
00051 typedef IMemoryCache This;
00052 public:
00053         virtual ~IMemoryCache() = 0;
00054         /// @todo tuttle: use key here, instead of (name, time)
00055         virtual void               put( const std::string& identifier, const double time, CACHE_ELEMENT pData ) = 0;
00056         virtual CACHE_ELEMENT      get( const std::string& identifier, const double time ) const                = 0;
00057         virtual CACHE_ELEMENT      getUnusedWithSize( const std::size_t requestedSize ) const                   = 0;
00058         virtual std::size_t        size() const                                                                 = 0;
00059         virtual bool               empty() const                                                                = 0;
00060         virtual bool               inCache( const CACHE_ELEMENT& ) const                                        = 0;
00061         virtual double             getTime( const CACHE_ELEMENT& ) const                                        = 0;
00062         virtual const std::string& getPluginName( const CACHE_ELEMENT& ) const                                  = 0;
00063         virtual bool               remove( const CACHE_ELEMENT& )                                               = 0;
00064         virtual void               clearUnused()                                                                = 0;
00065         virtual void               clearAll()                                                                   = 0;
00066         virtual std::ostream&      outputStream( std::ostream& os ) const                                       = 0;
00067         friend std::ostream& operator<<( std::ostream& os, const This& v );
00068 };
00069 
00070 }
00071 }
00072 }
00073 
00074 #endif