aboutsummaryrefslogtreecommitdiff
path: root/src/stable/archivebinary.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/stable/archivebinary.cpp')
-rw-r--r--src/stable/archivebinary.cpp98
1 files changed, 98 insertions, 0 deletions
diff --git a/src/stable/archivebinary.cpp b/src/stable/archivebinary.cpp
new file mode 100644
index 0000000..3f05947
--- /dev/null
+++ b/src/stable/archivebinary.cpp
@@ -0,0 +1,98 @@
1/*
2 * Copyright (C) 2007-2019 Xagasoft, All rights reserved.
3 *
4 * This file is part of the libbu++ library and is released under the
5 * terms of the license contained in the file LICENSE.
6 */
7
8#include "bu/archivebinary.h"
9#include "bu/stream.h"
10
11#include "bu/sio.h"
12
13Bu::ArchiveBinary::ArchiveBinary( Stream &rStream, bool bLoading ) :
14 bLoading( bLoading ),
15 rStream( rStream ),
16 nNextID( 1 )
17{
18}
19
20Bu::ArchiveBinary::~ArchiveBinary()
21{
22}
23
24void Bu::ArchiveBinary::write( const void *pData, size_t nSize )
25{
26 if( nSize == 0 || pData == NULL )
27 return;
28
29 rStream.write( (const char *)pData, nSize );
30}
31
32void Bu::ArchiveBinary::read( void *pData, size_t nSize )
33{
34 if( nSize == 0 || pData == NULL )
35 return;
36
37 if( (size_t)rStream.read( (char *)pData, nSize ) < nSize )
38 throw Bu::ExceptionBase("Insufficient data to unarchive object.");
39}
40
41void Bu::ArchiveBinary::close()
42{
43 rStream.close();
44}
45
46bool Bu::ArchiveBinary::isLoading()
47{
48 return bLoading;
49}
50
51uint32_t Bu::ArchiveBinary::getID( const void *ptr )
52{
53 if( hPtrID.has( (ptrdiff_t)ptr ) )
54 return hPtrID.get( (ptrdiff_t)ptr );
55 hPtrID.insert( (ptrdiff_t)ptr, nNextID );
56 return nNextID++;
57}
58
59void Bu::ArchiveBinary::assocPtrID( void **ptr, uint32_t id )
60{
61 if( hPtrID.has( id ) )
62 {
63 *ptr = (void *)hPtrID.get( id );
64 return;
65 }
66
67 if( !hPtrDest.has( id ) )
68 hPtrDest.insert( id, List<void **>() );
69
70 hPtrDest[id].getValue().append( ptr );
71}
72
73void Bu::ArchiveBinary::readID( const void *ptr, uint32_t id )
74{
75 hPtrID.insert( id, (ptrdiff_t)ptr );
76
77 if( hPtrDest.has( id ) )
78 {
79 Bu::List<void **> &l = hPtrDest.get( id );
80 for( Bu::List<void **>::iterator i = l.begin(); i != l.end(); i++ )
81 {
82 *(*i) = (void *)ptr;
83 }
84
85 hPtrDest.erase( id );
86 }
87}
88
89void Bu::ArchiveBinary::setProperty( const Bu::Blob &rKey, const Bu::Variant &rValue )
90{
91 hProps.insert( rKey, rValue );
92}
93
94Bu::Variant Bu::ArchiveBinary::getProperty( const Bu::Blob &rKey ) const
95{
96 return hProps.get( rKey );
97}
98