aboutsummaryrefslogtreecommitdiff
path: root/src/cache.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/cache.cpp')
-rw-r--r--src/cache.cpp149
1 files changed, 0 insertions, 149 deletions
diff --git a/src/cache.cpp b/src/cache.cpp
deleted file mode 100644
index d2bf537..0000000
--- a/src/cache.cpp
+++ /dev/null
@@ -1,149 +0,0 @@
1#include "cache.h"
2#include "bu/fstring.h"
3#include "bu/archive.h"
4
5Cache::Cache()
6{
7}
8
9Cache::~Cache()
10{
11 for( std::map<std::string, Entry *>::iterator i = mCache.begin();
12 i != mCache.end(); i++ )
13 {
14 delete (*i).second;
15 }
16}
17
18void Cache::archive( class Bu::ArchiveBase &ar )
19{
20 if( ar.isLoading() )
21 {
22 uint32_t sCache, sData, sIndex;
23
24 ar >> sIndex;
25 Bu::FString *Index = new Bu::FString[sIndex];
26 for( uint32_t i = 0; i < sIndex; i++ )
27 {
28 ar >> Index[i];
29 }
30
31 ar >> sCache;
32 uint32_t nTmp;
33 for( uint32_t i = 0; i < sCache; i++ )
34 {
35 Entry *e = new Entry;
36 ar >> e->tCreated;
37 ar >> sData;
38 std::list<std::string> &lData = e->lData;
39 for( uint32_t j = 0; j < sData; j++ )
40 {
41 ar >> nTmp;
42 lData.push_back( Index[nTmp].getStr() );
43 }
44 ar >> nTmp;
45 mCache[Index[nTmp].getStr()] = e;
46 }
47 /*
48 uint32_t sCache, sData;
49 ar >> sCache;
50 std::string sTmp;
51
52 for( uint32_t i = 0; i < sCache; i++ )
53 {
54 Entry *e = new Entry;
55 ar >> e->tCreated;
56 ar >> sData;
57 std::list<std::string> &lData = e->lData;
58 for( uint32_t j = 0; j < sData; j++ )
59 {
60 ar >> sTmp;
61 lData.push_back( sTmp );
62 }
63 ar >> sTmp;
64 mCache[sTmp] = e;
65 }
66 */
67 }
68 else
69 {
70 std::map<std::string, uint32_t> mIndex;
71 for( std::map<std::string, Entry *>::iterator i = mCache.begin();
72 i != mCache.end(); i++ )
73 {
74 mIndex[(*i).first] = 0;
75 std::list<std::string> &lData = (*i).second->lData;
76 for( std::list<std::string>::iterator j = lData.begin();
77 j != lData.end(); j++ )
78 {
79 mIndex[(*j)] = 0;
80 }
81 }
82
83 ar << (uint32_t)mIndex.size();
84 uint32_t cnt = 0;
85 for( std::map<std::string, uint32_t>::iterator i = mIndex.begin();
86 i != mIndex.end(); i++ )
87 {
88 (*i).second = cnt;
89 cnt++;
90 Bu::FString s( ((*i).first).c_str(), ((*i).first).size() );
91 ar << s;
92 }
93
94 ar << (uint32_t)mCache.size();
95 for( std::map<std::string, Entry *>::iterator i = mCache.begin();
96 i != mCache.end(); i++ )
97 {
98 ar << (*i).second->tCreated;
99 std::list<std::string> &lData = (*i).second->lData;
100 ar << (uint32_t)lData.size();
101 for( std::list<std::string>::iterator j = lData.begin();
102 j != lData.end(); j++ )
103 {
104 ar << mIndex[(*j)];
105 }
106
107 ar << mIndex[(*i).first];
108 }
109
110
111 /*
112 ar << mCache.size();
113 for( std::map<std::string, Entry *>::iterator i = mCache.begin();
114 i != mCache.end(); i++ )
115 {
116 ar << (*i).second->tCreated;
117 std::list<std::string> &lData = (*i).second->lData;
118 ar << lData.size();
119 for( std::list<std::string>::iterator j = lData.begin();
120 j != lData.end(); j++ )
121 {
122 ar << (*j);
123 }
124
125 std::string str = (*i).first;
126 ar << str;
127 }
128 */
129 }
130}
131
132Cache::Entry *Cache::get( const std::string &id )
133{
134 std::map<std::string, Entry *>::iterator i = mCache.find( id );
135 if( i != mCache.end() )
136 return (*i).second;
137
138 return NULL;
139}
140
141void Cache::put( const std::string &id, Entry *data )
142{
143 std::map<std::string, Entry *>::iterator i = mCache.find( id );
144 if( i != mCache.end() )
145 delete (*i).second;
146
147 mCache[id] = data;
148}
149