aboutsummaryrefslogtreecommitdiff
path: root/src/cache.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-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 10971b1..0000000
--- a/src/cache.cpp
+++ /dev/null
@@ -1,149 +0,0 @@
1#include "cache.h"
2#include "serializer.h"
3#include "staticstring.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::serialize( class Serializer &ar )
19{
20 if( ar.isLoading() )
21 {
22 int sCache, sData, sIndex;
23
24 ar >> sIndex;
25 StaticString *Index = new StaticString[sIndex];
26 for( int i = 0; i < sIndex; i++ )
27 {
28 ar >> Index[i];
29 }
30
31 ar >> sCache;
32 int nTmp;
33 for( int 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( int j = 0; j < sData; j++ )
40 {
41 ar >> nTmp;
42 lData.push_back( Index[nTmp].getString() );
43 }
44 ar >> nTmp;
45 mCache[Index[nTmp].getString()] = e;
46 }
47 /*
48 int sCache, sData;
49 ar >> sCache;
50 std::string sTmp;
51
52 for( int 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( int 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, int> 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 << mIndex.size();
84 int cnt = 0;
85 for( std::map<std::string, int>::iterator i = mIndex.begin();
86 i != mIndex.end(); i++ )
87 {
88 (*i).second = cnt;
89 cnt++;
90 std::string s = ((*i).first);
91 ar << s;
92 }
93
94 ar << 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 << 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