diff options
author | Mike Buland <eichlan@xagasoft.com> | 2008-12-01 17:20:26 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2008-12-01 17:20:26 +0000 |
commit | 350b052cfd866e3b3c7c4626551b49f8b75e55a1 (patch) | |
tree | b957f0dea70a7a2527ec78b32cdfc3e00712ff4d /src/tests | |
parent | c1229c50baa4816924e1914f3b4c78177749b73d (diff) | |
download | libbu++-350b052cfd866e3b3c7c4626551b49f8b75e55a1.tar.gz libbu++-350b052cfd866e3b3c7c4626551b49f8b75e55a1.tar.bz2 libbu++-350b052cfd866e3b3c7c4626551b49f8b75e55a1.tar.xz libbu++-350b052cfd866e3b3c7c4626551b49f8b75e55a1.zip |
Woo! Very nearly there cache-wise, I'm about to change the name of the handler,
do a few more tests, and hopefully get something loading/saving.
Diffstat (limited to 'src/tests')
-rw-r--r-- | src/tests/cache.cpp | 52 |
1 files changed, 41 insertions, 11 deletions
diff --git a/src/tests/cache.cpp b/src/tests/cache.cpp index f05de57..55ec5be 100644 --- a/src/tests/cache.cpp +++ b/src/tests/cache.cpp | |||
@@ -1,9 +1,8 @@ | |||
1 | #include <stdio.h> | 1 | #include <stdio.h> |
2 | 2 | ||
3 | #include "bu/cache.h" | 3 | #include "bu/cache.h" |
4 | #include "bu/cachable.h" | ||
5 | 4 | ||
6 | class Bob : public Bu::Cachable | 5 | class Bob |
7 | { | 6 | { |
8 | public: | 7 | public: |
9 | Bob() | 8 | Bob() |
@@ -36,24 +35,55 @@ public: | |||
36 | int iInt; | 35 | int iInt; |
37 | }; | 36 | }; |
38 | 37 | ||
39 | DECL_CACHABLE( Bob ); | 38 | class BobHandler : public Bu::CacheHandler<Bob> |
40 | DEF_CACHABLE( Bob ); | 39 | { |
40 | public: | ||
41 | BobHandler() : | ||
42 | cLastId( 0 ) | ||
43 | { | ||
44 | } | ||
45 | |||
46 | ~BobHandler() | ||
47 | { | ||
48 | } | ||
49 | |||
50 | virtual Bu::CPtr<Bob> load() | ||
51 | { | ||
52 | } | ||
53 | |||
54 | virtual void unload( Bu::CPtr<Bob> pObj ) | ||
55 | { | ||
56 | } | ||
57 | |||
58 | virtual Bu::CPtr<Bob> create() | ||
59 | { | ||
60 | } | ||
61 | |||
62 | virtual Bu::CPtr<Bob> create( Bob &rSrc ) | ||
63 | { | ||
64 | } | ||
65 | |||
66 | virtual void destroy( Bu::CPtr<Bob> pObj ) | ||
67 | { | ||
68 | } | ||
69 | |||
70 | private: | ||
71 | Bu::Cache<Bob>::cid_t cLastId; | ||
72 | }; | ||
41 | 73 | ||
42 | int main() | 74 | int main() |
43 | { | 75 | { |
44 | Bu::Cache<Bob> bobCache; | 76 | typedef Bu::Cache<Bob> BobCache; |
77 | typedef Bu::CPtr<Bob> BobPtr; | ||
45 | 78 | ||
46 | Bu::CPtr<Bob> pB1 = bobCache.insert( new Bob() ); | 79 | BobCache bobCache; |
47 | 80 | ||
81 | BobPtr pB1 = bobCache.insert( new Bob() ); | ||
48 | (*pB1).setInt( 44 ); | 82 | (*pB1).setInt( 44 ); |
49 | |||
50 | printf("RefCnt = %d\n", bobCache.getRefCnt( 0 ) ); | 83 | printf("RefCnt = %d\n", bobCache.getRefCnt( 0 ) ); |
51 | 84 | ||
52 | Bu::CPtr<Bob> pB2 = bobCache.get( 0 ); | 85 | BobPtr pB2 = bobCache.get( 0 ); |
53 | |||
54 | printf("RefCnt = %d\n", bobCache.getRefCnt( 0 ) ); | 86 | printf("RefCnt = %d\n", bobCache.getRefCnt( 0 ) ); |
55 | |||
56 | printf("Int = %d\n", pB2->getInt() ); | 87 | printf("Int = %d\n", pB2->getInt() ); |
57 | |||
58 | } | 88 | } |
59 | 89 | ||