aboutsummaryrefslogtreecommitdiff
path: root/src/stable/archive.cpp
diff options
context:
space:
mode:
authorMike Buland <mbuland@penny-arcade.com>2022-04-20 11:14:47 -0700
committerMike Buland <mbuland@penny-arcade.com>2022-04-20 11:14:47 -0700
commitd10e6a5ca0905f0ef2836cd98aebfb48e7f1e8a3 (patch)
tree0235e978cc5ffa94d790a4e26b5cf1e5492cab2b /src/stable/archive.cpp
parent819ff3d27012b4ec4a0a21c150c112a4dd28b14d (diff)
downloadlibbu++-d10e6a5ca0905f0ef2836cd98aebfb48e7f1e8a3.tar.gz
libbu++-d10e6a5ca0905f0ef2836cd98aebfb48e7f1e8a3.tar.bz2
libbu++-d10e6a5ca0905f0ef2836cd98aebfb48e7f1e8a3.tar.xz
libbu++-d10e6a5ca0905f0ef2836cd98aebfb48e7f1e8a3.zip
ArchiveBase/Archive renamed. More to come.
Diffstat (limited to 'src/stable/archive.cpp')
-rw-r--r--src/stable/archive.cpp200
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" 10Bu::Archive::Archive()
13
14Bu::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
25void Bu::Archive::write( const void *pData, size_t nSize ) 18Bu::Archive &Bu::operator<<( Bu::Archive &ar, bool p)
19{
20 ar.write( &p, sizeof(p) );
21 return ar;
22}
23
24Bu::Archive &Bu::operator<<( Bu::Archive &ar, char p)
25{
26 ar.write( &p, sizeof(p) );
27 return ar;
28}
29
30Bu::Archive &Bu::operator<<( Bu::Archive &ar, signed char p)
31{
32 ar.write( &p, sizeof(p) );
33 return ar;
34}
35
36Bu::Archive &Bu::operator<<( Bu::Archive &ar, unsigned char p)
37{
38 ar.write( &p, sizeof(p) );
39 return ar;
40}
41
42Bu::Archive &Bu::operator<<( Bu::Archive &ar, signed short p)
43{
44 ar.write( &p, sizeof(p) );
45 return ar;
46}
47
48Bu::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 ); 54Bu::Archive &Bu::operator<<( Bu::Archive &ar, signed int p)
55{
56 ar.write( &p, sizeof(p) );
57 return ar;
31} 58}
32 59
33void Bu::Archive::read( void *pData, size_t nSize ) 60Bu::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 ) 66Bu::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
42void Bu::Archive::close() 72Bu::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
47bool Bu::Archive::isLoading() 78Bu::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
52uint32_t Bu::Archive::getID( const void *ptr ) 84Bu::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
60void Bu::Archive::assocPtrID( void **ptr, uint32_t id ) 90Bu::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 ) ) 96Bu::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
74void Bu::Archive::readID( const void *ptr, uint32_t id ) 102Bu::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 ) ) 108Bu::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 ); 114Bu::Archive &Bu::operator>>( Bu::Archive &ar, char &p)
87 } 115{
116 ar.read( &p, sizeof(p) );
117 return ar;
118}
119
120Bu::Archive &Bu::operator>>( Bu::Archive &ar, signed char &p)
121{
122 ar.read( &p, sizeof(p) );
123 return ar;
124}
125
126Bu::Archive &Bu::operator>>( Bu::Archive &ar, unsigned char &p)
127{
128 ar.read( &p, sizeof(p) );
129 return ar;
130}
131
132Bu::Archive &Bu::operator>>( Bu::Archive &ar, signed short &p)
133{
134 ar.read( &p, sizeof(p) );
135 return ar;
136}
137
138Bu::Archive &Bu::operator>>( Bu::Archive &ar, unsigned short &p)
139{
140 ar.read( &p, sizeof(p) );
141 return ar;
142}
143
144Bu::Archive &Bu::operator>>( Bu::Archive &ar, signed int &p)
145{
146 ar.read( &p, sizeof(p) );
147 return ar;
148}
149
150Bu::Archive &Bu::operator>>( Bu::Archive &ar, unsigned int &p)
151{
152 ar.read( &p, sizeof(p) );
153 return ar;
154}
155
156Bu::Archive &Bu::operator>>( Bu::Archive &ar, signed long &p)
157{
158 ar.read( &p, sizeof(p) );
159 return ar;
160}
161
162Bu::Archive &Bu::operator>>( Bu::Archive &ar, unsigned long &p)
163{
164 ar.read( &p, sizeof(p) );
165 return ar;
166}
167
168Bu::Archive &Bu::operator>>( Bu::Archive &ar, signed long long &p)
169{
170 ar.read( &p, sizeof(p) );
171 return ar;
172}
173
174Bu::Archive &Bu::operator>>( Bu::Archive &ar, unsigned long long &p)
175{
176 ar.read( &p, sizeof(p) );
177 return ar;
178}
179
180Bu::Archive &Bu::operator>>( Bu::Archive &ar, float &p)
181{
182 ar.read( &p, sizeof(p) );
183 return ar;
88} 184}
89 185
90void Bu::Archive::setProperty( const Bu::Blob &rKey, const Bu::Variant &rValue ) 186Bu::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
95Bu::Variant Bu::Archive::getProperty( const Bu::Blob &rKey ) const 192Bu::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