summaryrefslogtreecommitdiff
path: root/src/cachecalc.h
blob: dd6add16926436d090870c3968afb2abe986a75c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
 * Copyright (C) 2007-2008 Xagasoft, All rights reserved.
 *
 * This file is part of the libbu++ library and is released under the
 * terms of the license contained in the file LICENSE.
 */

#ifndef BU_CACHE_CALC_H
#define BU_CACHE_CALC_H

#include "bu/trace.h"

#include <time.h>

namespace Bu
{
	template<class obtype, class keytype> class Cache;

	template<class obtype, class keytype>
	class CacheCalc
	{
	friend class Cache<obtype, keytype>;
	private:
		typedef Cache<obtype, keytype> MyCache;
	public:
		CacheCalc() :
			pCache( (MyCache *)0 )
		{
			TRACE();
		}

		virtual ~CacheCalc()
		{
			TRACE();
		}

		virtual void onLoad( obtype *pSrc, const keytype &key )=0;
		virtual void onUnload( obtype *pSrc, const keytype &key )=0;
		virtual bool shouldSync( obtype *pSrc, const keytype &key,
			time_t tLastSync )=0;
		virtual void onTick() { };

	protected:
		MyCache *getCache()
		{
			TRACE();
			return pCache;
		}

	private:
		void setCache( MyCache *pCache )
		{
			TRACE();
			this->pCache = pCache;
		}

		MyCache *pCache;
	};
};

#endif