00001 #ifndef CACHEBASE_H 00002 #define CACHEBASE_H 00003 00004 00005 #include "asset.inc" 00006 #include "linklist.h" 00007 #include "mutex.inc" 00008 #include <stdint.h> 00009 00010 00011 // Store rendered elements from files but not the files. 00012 // Drawing caches must be separate from file caches to avoid 00013 // delaying other file accesses for the drawing routines. 00014 00015 00016 class CacheItemBase : public ListItem<CacheItemBase> 00017 { 00018 public: 00019 CacheItemBase(); 00020 virtual ~CacheItemBase(); 00021 00022 00023 00024 virtual int get_size(); 00025 00026 // asset_id - supplied by user if the cache is not part of a file. 00027 // Used for fast accesses. 00028 int asset_id; 00029 // path is needed since the item may need to be deleted based on file. 00030 // Used for deletion. 00031 char *path; 00032 // Number of last get or put operation involving this object. 00033 int age; 00034 // Starting point of item in asset's native rate. 00035 int64_t position; 00036 }; 00037 00038 00039 00040 class CacheBase : public List<CacheItemBase> 00041 { 00042 public: 00043 CacheBase(); 00044 virtual ~CacheBase(); 00045 00046 int get_age(); 00047 00048 void remove_all(); 00049 00050 // Remove all items with the asset id. 00051 void remove_asset(Asset *asset); 00052 00053 // Insert item in list in ascending position order. 00054 void put_item(CacheItemBase *item); 00055 00056 // Get first item from list with matching position or 0 if none found. 00057 CacheItemBase* get_item(int64_t position); 00058 00059 // Called when done with the item returned by get_. 00060 // Ignore if item was 0. 00061 void unlock(); 00062 00063 // Get ID of oldest member. 00064 // Called by MWindow::age_caches. 00065 int get_oldest(); 00066 00067 // Delete oldest item. Return 0 if successful. Return 1 if nothing to delete. 00068 int delete_oldest(); 00069 00070 // Calculate current size of cache in bytes 00071 int64_t get_memory_usage(); 00072 00073 Mutex *lock; 00074 // Current position of search 00075 CacheItemBase *current_item; 00076 }; 00077 00078 00079 00080 #endif
1.5.5