diff options
author | Mike Buland <mbuland@penny-arcade.com> | 2022-04-20 11:14:47 -0700 |
---|---|---|
committer | Mike Buland <mbuland@penny-arcade.com> | 2022-04-20 11:14:47 -0700 |
commit | d10e6a5ca0905f0ef2836cd98aebfb48e7f1e8a3 (patch) | |
tree | 0235e978cc5ffa94d790a4e26b5cf1e5492cab2b /src/stable/archivebinary.cpp | |
parent | 819ff3d27012b4ec4a0a21c150c112a4dd28b14d (diff) | |
download | libbu++-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/archivebinary.cpp')
-rw-r--r-- | src/stable/archivebinary.cpp | 98 |
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 | |||
13 | Bu::ArchiveBinary::ArchiveBinary( Stream &rStream, bool bLoading ) : | ||
14 | bLoading( bLoading ), | ||
15 | rStream( rStream ), | ||
16 | nNextID( 1 ) | ||
17 | { | ||
18 | } | ||
19 | |||
20 | Bu::ArchiveBinary::~ArchiveBinary() | ||
21 | { | ||
22 | } | ||
23 | |||
24 | void 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 | |||
32 | void 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 | |||
41 | void Bu::ArchiveBinary::close() | ||
42 | { | ||
43 | rStream.close(); | ||
44 | } | ||
45 | |||
46 | bool Bu::ArchiveBinary::isLoading() | ||
47 | { | ||
48 | return bLoading; | ||
49 | } | ||
50 | |||
51 | uint32_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 | |||
59 | void 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 | |||
73 | void 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 | |||
89 | void Bu::ArchiveBinary::setProperty( const Bu::Blob &rKey, const Bu::Variant &rValue ) | ||
90 | { | ||
91 | hProps.insert( rKey, rValue ); | ||
92 | } | ||
93 | |||
94 | Bu::Variant Bu::ArchiveBinary::getProperty( const Bu::Blob &rKey ) const | ||
95 | { | ||
96 | return hProps.get( rKey ); | ||
97 | } | ||
98 | |||