aboutsummaryrefslogtreecommitdiff
path: root/src/cachecalc.h
blob: c9968dcef05b9a2f6a6d66ed40497c10bd3d3698 (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-2010 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 keytype, class obtype> class Cache;

	template<class keytype, class obtype>
	class CacheCalc
	{
	friend class Cache<keytype, obtype>;
	private:
		typedef Cache<keytype, obtype> 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