aboutsummaryrefslogtreecommitdiff
path: root/src/stable/archivebinary.cpp
blob: f46bd28238e539daa36dcd610f352efd07e62226 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
/*
 * Copyright (C) 2007-2019 Xagasoft, All rights reserved.
 *
 * This file is part of the libbu++ library and is released under the
 * terms of the license contained in the file LICENSE.
 */

#include "bu/archivebinary.h"
#include "bu/stream.h"

#include "bu/sio.h"
#include "bu/text.h"

Bu::ArchiveBinary::ArchiveBinary( Stream &rStream, bool bLoading ) :
    bLoading( bLoading ),
    rStream( rStream )
{
}

Bu::ArchiveBinary::~ArchiveBinary()
{
}
/*
void Bu::ArchiveBinary::write( const void *pData, size_t nSize )
{
    if( nSize == 0 || pData == NULL )
        return;

    rStream.write( (const char *)pData, nSize );
}

void Bu::ArchiveBinary::read( void *pData, size_t nSize )
{
    if( nSize == 0 || pData == NULL )
        return;

    if( (size_t)rStream.read( (char *)pData, nSize ) < nSize )
        throw Bu::ExceptionBase("Insufficient data to unarchive object.");
}*/

void Bu::ArchiveBinary::write(                 bool        rData )
{
    rStream.write( &rData, sizeof(rData) );
}

void Bu::ArchiveBinary::write( const unsigned  char        rData )
{
    rStream.write( &rData, sizeof(rData) );
}

void Bu::ArchiveBinary::write(                 char        rData )
{
    rStream.write( &rData, sizeof(rData) );
}

void Bu::ArchiveBinary::write(       signed    char        rData )
{
    rStream.write( &rData, sizeof(rData) );
}

void Bu::ArchiveBinary::write(       unsigned  short       rData )
{
    rStream.write( &rData, sizeof(rData) );
}

void Bu::ArchiveBinary::write(       signed    short       rData )
{
    rStream.write( &rData, sizeof(rData) );
}

void Bu::ArchiveBinary::write(       unsigned  int         rData )
{
    rStream.write( &rData, sizeof(rData) );
}

void Bu::ArchiveBinary::write(       signed    int         rData )
{
    rStream.write( &rData, sizeof(rData) );
}

void Bu::ArchiveBinary::write(       unsigned  long        rData )
{
    rStream.write( &rData, sizeof(rData) );
}

void Bu::ArchiveBinary::write(       signed    long        rData )
{
    rStream.write( &rData, sizeof(rData) );
}

void Bu::ArchiveBinary::write(       unsigned  long long   rData )
{
    rStream.write( &rData, sizeof(rData) );
}

void Bu::ArchiveBinary::write(       signed    long long   rData )
{
    rStream.write( &rData, sizeof(rData) );
}

void Bu::ArchiveBinary::write(                 float       rData )
{
    rStream.write( &rData, sizeof(rData) );
}

void Bu::ArchiveBinary::write(                 double      rData )
{
    rStream.write( &rData, sizeof(rData) );
}

void Bu::ArchiveBinary::write(                 long double rData )
{
    rStream.write( &rData, sizeof(rData) );
}

void Bu::ArchiveBinary::write( const           Bu::Blob    &rData )
{
    int32_t iSize = rData.getSize();
    write( iSize );
    rStream.write( rData.getData(), iSize );
}

void Bu::ArchiveBinary::write( const           Bu::Text    &rData )
{
    int32_t iSize = rData.getSize();
    write( iSize );
    rStream.write( rData.getData(), iSize );
}

void Bu::ArchiveBinary::read(           bool        &rData )
{
    rStream.read( &rData, sizeof(rData) );
}

void Bu::ArchiveBinary::read( unsigned  char        &rData )
{
    rStream.read( &rData, sizeof(rData) );
}

void Bu::ArchiveBinary::read(           char        &rData )
{
    rStream.read( &rData, sizeof(rData) );
}

void Bu::ArchiveBinary::read( signed    char        &rData )
{
    rStream.read( &rData, sizeof(rData) );
}

void Bu::ArchiveBinary::read( unsigned  short       &rData )
{
    rStream.read( &rData, sizeof(rData) );
}

void Bu::ArchiveBinary::read( signed    short       &rData )
{
    rStream.read( &rData, sizeof(rData) );
}

void Bu::ArchiveBinary::read( unsigned  int         &rData )
{
    rStream.read( &rData, sizeof(rData) );
}

void Bu::ArchiveBinary::read( signed    int         &rData )
{
    rStream.read( &rData, sizeof(rData) );
}

void Bu::ArchiveBinary::read( unsigned  long        &rData )
{
    rStream.read( &rData, sizeof(rData) );
}

void Bu::ArchiveBinary::read( signed    long        &rData )
{
    rStream.read( &rData, sizeof(rData) );
}

void Bu::ArchiveBinary::read( unsigned  long long   &rData )
{
    rStream.read( &rData, sizeof(rData) );
}

void Bu::ArchiveBinary::read( signed    long long   &rData )
{
    rStream.read( &rData, sizeof(rData) );
}

void Bu::ArchiveBinary::read(           float       &rData )
{
    rStream.read( &rData, sizeof(rData) );
}

void Bu::ArchiveBinary::read(           double      &rData )
{
    rStream.read( &rData, sizeof(rData) );
}

void Bu::ArchiveBinary::read(           long double &rData )
{
    rStream.read( &rData, sizeof(rData) );
}

void Bu::ArchiveBinary::read(           Bu::Blob    &rData )
{
    int32_t iSize;
    read( iSize );
    char *pBuf = new char[iSize];
    rStream.read( pBuf, iSize );
    rData.set( pBuf, iSize );
    delete[] pBuf;
}

void Bu::ArchiveBinary::read(           Bu::Text    &rData )
{
    /*
    int32_t iSize;
    read( iSize );
    char *pBuf = new char[iSize];
    rStream.read( pBuf, iSize );
    rData.set( pBuf, iSize );
    delete[] pBuf;
    */
    throw Bu::ExceptionBase("Cannot read Bu::Text objects yet.");
}

void Bu::ArchiveBinary::close()
{
    rStream.close();
}

bool Bu::ArchiveBinary::isLoading()
{
    return bLoading;
}

void Bu::ArchiveBinary::setProperty( const Bu::Blob &rKey, const Bu::Variant &rValue )
{
    hProps.insert( rKey, rValue );
}

Bu::Variant Bu::ArchiveBinary::getProperty( const Bu::Blob &rKey ) const
{
    return hProps.get( rKey );
}