00001 #ifndef _OP_Cache_
00002 #define _OP_Cache_
00003
00004 #include "OP_API.h"
00005 #ifdef WIN32
00006 #include <sys/utime.h>
00007 #else
00008 #include <time.h>
00009 #endif
00010
00011 #include <UT/UT_Pointers.h>
00012 #include <UT/UT_String.h>
00013 #include "OP_Context.h"
00014
00015 class OP_CacheInfo;
00016
00017 enum OP_CacheOptions
00018 {
00019 OP_CACHE_KEEP
00020 };
00021
00022 typedef void (*OP_Cache_Del_Func)( void *object,
00023 void *data);
00024
00025 typedef void *(*OP_Cache_Copy_Func)( void *object,
00026 void *data);
00027
00028 typedef void (*OP_Cache_Eval_Func)( OP_Context &context,
00029 void *eval_data,
00030 OP_Context &eval_context,
00031 unsigned &score,
00032 unsigned &exact_match);
00033
00034 class OP_API OP_Cache : public UT_Pointers
00035 {
00036 public:
00037 OP_Cache();
00038 OP_Cache( void *client,
00039 const char *cop_name,
00040 const char *cache_name,
00041 OP_Cache_Del_Func del_func);
00042 OP_Cache(const OP_Cache &source);
00043 ~OP_Cache();
00044
00045 void setName(const char *copname, const char *cachename);
00046 void setFunctions( void *client,
00047 OP_Cache_Del_Func del_func);
00048
00049 void setSize(short size);
00050 short getSize(void ) const { return( myMaxSize ); }
00051
00052 void *getData (OP_Context &);
00053 void *getDataEval(OP_Context &, OP_Cache_Eval_Func);
00054
00055 void putData(void *data,
00056 OP_Context &c,
00057 OP_CacheOptions o = OP_CACHE_KEEP);
00058
00059 void *stealData(void *, OP_Cache_Copy_Func);
00060
00061 int ownsData(void *);
00062 void clear();
00063
00064
00065
00066
00067
00068 void print(FILE *);
00069 OP_CacheInfo *getInfo();
00070 const void *getDataPtr(int slot);
00071 const OP_Context *getContextPtr(int slot);
00072
00073 protected:
00074
00075 private:
00076 void init();
00077 int deleteReference(void *);
00078
00079 void *myClient;
00080 UT_String myOpName;
00081 UT_String myCacheName;
00082
00083 short myCurrentSize;
00084 short myMaxSize;
00085
00086 OP_Cache_Del_Func myDeleteFunc;
00087 };
00088
00089 #endif