diff options
Diffstat (limited to '')
-rw-r--r-- | src/cache.cpp | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/cache.cpp b/src/cache.cpp index 43e69dc..10971b1 100644 --- a/src/cache.cpp +++ b/src/cache.cpp | |||
@@ -1,5 +1,6 @@ | |||
1 | #include "cache.h" | 1 | #include "cache.h" |
2 | #include "serializer.h" | 2 | #include "serializer.h" |
3 | #include "staticstring.h" | ||
3 | 4 | ||
4 | Cache::Cache() | 5 | Cache::Cache() |
5 | { | 6 | { |
@@ -18,6 +19,32 @@ void Cache::serialize( class Serializer &ar ) | |||
18 | { | 19 | { |
19 | if( ar.isLoading() ) | 20 | if( ar.isLoading() ) |
20 | { | 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 | /* | ||
21 | int sCache, sData; | 48 | int sCache, sData; |
22 | ar >> sCache; | 49 | ar >> sCache; |
23 | std::string sTmp; | 50 | std::string sTmp; |
@@ -36,9 +63,52 @@ void Cache::serialize( class Serializer &ar ) | |||
36 | ar >> sTmp; | 63 | ar >> sTmp; |
37 | mCache[sTmp] = e; | 64 | mCache[sTmp] = e; |
38 | } | 65 | } |
66 | */ | ||
39 | } | 67 | } |
40 | else | 68 | else |
41 | { | 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 | /* | ||
42 | ar << mCache.size(); | 112 | ar << mCache.size(); |
43 | for( std::map<std::string, Entry *>::iterator i = mCache.begin(); | 113 | for( std::map<std::string, Entry *>::iterator i = mCache.begin(); |
44 | i != mCache.end(); i++ ) | 114 | i != mCache.end(); i++ ) |
@@ -55,6 +125,7 @@ void Cache::serialize( class Serializer &ar ) | |||
55 | std::string str = (*i).first; | 125 | std::string str = (*i).first; |
56 | ar << str; | 126 | ar << str; |
57 | } | 127 | } |
128 | */ | ||
58 | } | 129 | } |
59 | } | 130 | } |
60 | 131 | ||