blob: 1cc008abbad68b3ef76670edee6aa49979e2e8c1 (
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <errno.h>
#include "bu/cache.h"
class Bob
{
public:
Bob()
{
TRACE();
}
virtual ~Bob()
{
TRACE();
}
void setInt( int i )
{
TRACE();
iInt = i;
}
int getInt()
{
return iInt;
}
long getCacheId() const
{
TRACE();
return 0;
}
int iInt;
};
class BobStore : public Bu::CacheStore<Bob, long>
{
public:
BobStore() :
cLastId( 0 )
{
TRACE();
}
~BobStore()
{
TRACE();
}
virtual Bob *load( const long &key )
{
TRACE();
return NULL;
}
virtual void unload( Bob *pObj )
{
TRACE();
delete pObj;
}
virtual long create( Bob *rSrc )
{
TRACE();
return ++cLastId;
}
virtual void destroy( Bob *pObj, const long &key )
{
TRACE();
delete pObj;
}
private:
long cLastId;
};
int main( int argc, char *argv[] )
{
TRACE();
if( argc < 3 )
{
printf("Try: %s [icufd] [<id/value>]\n\n", argv[0] );
return 0;
}
switch( argv[1][0] )
{
case 'i':
mkdir("bobcache", 0755 );
printf("Initialized cache: %s\n", strerror( errno ) );
return 0;
case 'c':
typedef Bu::Cache<Bob, long> BobCache;
typedef BobCache::Ptr BobPtr;
BobCache cBob;
cBob.appendStore( new BobStore() );
return 0;
}
}
|