diff options
Diffstat (limited to 'src/stable/archive.cpp')
-rw-r--r-- | src/stable/archive.cpp | 200 |
1 files changed, 149 insertions, 51 deletions
diff --git a/src/stable/archive.cpp b/src/stable/archive.cpp index 69447fb..df9b1ff 100644 --- a/src/stable/archive.cpp +++ b/src/stable/archive.cpp | |||
@@ -6,15 +6,8 @@ | |||
6 | */ | 6 | */ |
7 | 7 | ||
8 | #include "bu/archive.h" | 8 | #include "bu/archive.h" |
9 | #include "bu/stream.h" | ||
10 | #include "bu/archival.h" | ||
11 | 9 | ||
12 | #include "bu/sio.h" | 10 | Bu::Archive::Archive() |
13 | |||
14 | Bu::Archive::Archive( Stream &rStream, bool bLoading ) : | ||
15 | bLoading( bLoading ), | ||
16 | rStream( rStream ), | ||
17 | nNextID( 1 ) | ||
18 | { | 11 | { |
19 | } | 12 | } |
20 | 13 | ||
@@ -22,78 +15,183 @@ Bu::Archive::~Archive() | |||
22 | { | 15 | { |
23 | } | 16 | } |
24 | 17 | ||
25 | void Bu::Archive::write( const void *pData, size_t nSize ) | 18 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, bool p) |
19 | { | ||
20 | ar.write( &p, sizeof(p) ); | ||
21 | return ar; | ||
22 | } | ||
23 | |||
24 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, char p) | ||
25 | { | ||
26 | ar.write( &p, sizeof(p) ); | ||
27 | return ar; | ||
28 | } | ||
29 | |||
30 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, signed char p) | ||
31 | { | ||
32 | ar.write( &p, sizeof(p) ); | ||
33 | return ar; | ||
34 | } | ||
35 | |||
36 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, unsigned char p) | ||
37 | { | ||
38 | ar.write( &p, sizeof(p) ); | ||
39 | return ar; | ||
40 | } | ||
41 | |||
42 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, signed short p) | ||
43 | { | ||
44 | ar.write( &p, sizeof(p) ); | ||
45 | return ar; | ||
46 | } | ||
47 | |||
48 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, unsigned short p) | ||
26 | { | 49 | { |
27 | if( nSize == 0 || pData == NULL ) | 50 | ar.write( &p, sizeof(p) ); |
28 | return; | 51 | return ar; |
52 | } | ||
29 | 53 | ||
30 | rStream.write( (const char *)pData, nSize ); | 54 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, signed int p) |
55 | { | ||
56 | ar.write( &p, sizeof(p) ); | ||
57 | return ar; | ||
31 | } | 58 | } |
32 | 59 | ||
33 | void Bu::Archive::read( void *pData, size_t nSize ) | 60 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, unsigned int p) |
34 | { | 61 | { |
35 | if( nSize == 0 || pData == NULL ) | 62 | ar.write( &p, sizeof(p) ); |
36 | return; | 63 | return ar; |
64 | } | ||
37 | 65 | ||
38 | if( (size_t)rStream.read( (char *)pData, nSize ) < nSize ) | 66 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, signed long p) |
39 | throw Bu::ExceptionBase("Insufficient data to unarchive object."); | 67 | { |
68 | ar.write( &p, sizeof(p) ); | ||
69 | return ar; | ||
40 | } | 70 | } |
41 | 71 | ||
42 | void Bu::Archive::close() | 72 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, unsigned long p) |
43 | { | 73 | { |
44 | rStream.close(); | 74 | ar.write( &p, sizeof(p) ); |
75 | return ar; | ||
45 | } | 76 | } |
46 | 77 | ||
47 | bool Bu::Archive::isLoading() | 78 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, signed long long p) |
48 | { | 79 | { |
49 | return bLoading; | 80 | ar.write( &p, sizeof(p) ); |
81 | return ar; | ||
50 | } | 82 | } |
51 | 83 | ||
52 | uint32_t Bu::Archive::getID( const void *ptr ) | 84 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, unsigned long long p) |
53 | { | 85 | { |
54 | if( hPtrID.has( (ptrdiff_t)ptr ) ) | 86 | ar.write( &p, sizeof(p) ); |
55 | return hPtrID.get( (ptrdiff_t)ptr ); | 87 | return ar; |
56 | hPtrID.insert( (ptrdiff_t)ptr, nNextID ); | ||
57 | return nNextID++; | ||
58 | } | 88 | } |
59 | 89 | ||
60 | void Bu::Archive::assocPtrID( void **ptr, uint32_t id ) | 90 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, float p) |
61 | { | 91 | { |
62 | if( hPtrID.has( id ) ) | 92 | ar.write( &p, sizeof(p) ); |
63 | { | 93 | return ar; |
64 | *ptr = (void *)hPtrID.get( id ); | 94 | } |
65 | return; | ||
66 | } | ||
67 | 95 | ||
68 | if( !hPtrDest.has( id ) ) | 96 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, double p) |
69 | hPtrDest.insert( id, List<void **>() ); | 97 | { |
70 | 98 | ar.write( &p, sizeof(p) ); | |
71 | hPtrDest[id].getValue().append( ptr ); | 99 | return ar; |
72 | } | 100 | } |
73 | 101 | ||
74 | void Bu::Archive::readID( const void *ptr, uint32_t id ) | 102 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, long double p) |
75 | { | 103 | { |
76 | hPtrID.insert( id, (ptrdiff_t)ptr ); | 104 | ar.write( &p, sizeof(p) ); |
105 | return ar; | ||
106 | } | ||
77 | 107 | ||
78 | if( hPtrDest.has( id ) ) | 108 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, bool &p) |
79 | { | 109 | { |
80 | Bu::List<void **> &l = hPtrDest.get( id ); | 110 | ar.read( &p, sizeof(p) ); |
81 | for( Bu::List<void **>::iterator i = l.begin(); i != l.end(); i++ ) | 111 | return ar; |
82 | { | 112 | } |
83 | *(*i) = (void *)ptr; | ||
84 | } | ||
85 | 113 | ||
86 | hPtrDest.erase( id ); | 114 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, char &p) |
87 | } | 115 | { |
116 | ar.read( &p, sizeof(p) ); | ||
117 | return ar; | ||
118 | } | ||
119 | |||
120 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, signed char &p) | ||
121 | { | ||
122 | ar.read( &p, sizeof(p) ); | ||
123 | return ar; | ||
124 | } | ||
125 | |||
126 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, unsigned char &p) | ||
127 | { | ||
128 | ar.read( &p, sizeof(p) ); | ||
129 | return ar; | ||
130 | } | ||
131 | |||
132 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, signed short &p) | ||
133 | { | ||
134 | ar.read( &p, sizeof(p) ); | ||
135 | return ar; | ||
136 | } | ||
137 | |||
138 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, unsigned short &p) | ||
139 | { | ||
140 | ar.read( &p, sizeof(p) ); | ||
141 | return ar; | ||
142 | } | ||
143 | |||
144 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, signed int &p) | ||
145 | { | ||
146 | ar.read( &p, sizeof(p) ); | ||
147 | return ar; | ||
148 | } | ||
149 | |||
150 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, unsigned int &p) | ||
151 | { | ||
152 | ar.read( &p, sizeof(p) ); | ||
153 | return ar; | ||
154 | } | ||
155 | |||
156 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, signed long &p) | ||
157 | { | ||
158 | ar.read( &p, sizeof(p) ); | ||
159 | return ar; | ||
160 | } | ||
161 | |||
162 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, unsigned long &p) | ||
163 | { | ||
164 | ar.read( &p, sizeof(p) ); | ||
165 | return ar; | ||
166 | } | ||
167 | |||
168 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, signed long long &p) | ||
169 | { | ||
170 | ar.read( &p, sizeof(p) ); | ||
171 | return ar; | ||
172 | } | ||
173 | |||
174 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, unsigned long long &p) | ||
175 | { | ||
176 | ar.read( &p, sizeof(p) ); | ||
177 | return ar; | ||
178 | } | ||
179 | |||
180 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, float &p) | ||
181 | { | ||
182 | ar.read( &p, sizeof(p) ); | ||
183 | return ar; | ||
88 | } | 184 | } |
89 | 185 | ||
90 | void Bu::Archive::setProperty( const Bu::Blob &rKey, const Bu::Variant &rValue ) | 186 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, double &p) |
91 | { | 187 | { |
92 | hProps.insert( rKey, rValue ); | 188 | ar.read( &p, sizeof(p) ); |
189 | return ar; | ||
93 | } | 190 | } |
94 | 191 | ||
95 | Bu::Variant Bu::Archive::getProperty( const Bu::Blob &rKey ) const | 192 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, long double &p) |
96 | { | 193 | { |
97 | return hProps.get( rKey ); | 194 | ar.read( &p, sizeof(p) ); |
195 | return ar; | ||
98 | } | 196 | } |
99 | 197 | ||