summaryrefslogtreecommitdiff
path: root/src/archive.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2007-06-04 23:49:26 +0000
committerMike Buland <eichlan@xagasoft.com>2007-06-04 23:49:26 +0000
commitb7e40536df9bf9bbad3b2b7a59f33ebad25fc981 (patch)
tree1555062abe0e01e8d6d5b9b63ba81ab3c3d0168c /src/archive.cpp
parent326125aee0b8cd807a6a1d158398078ff6bfb1e1 (diff)
downloadlibbu++-b7e40536df9bf9bbad3b2b7a59f33ebad25fc981.tar.gz
libbu++-b7e40536df9bf9bbad3b2b7a59f33ebad25fc981.tar.bz2
libbu++-b7e40536df9bf9bbad3b2b7a59f33ebad25fc981.tar.xz
libbu++-b7e40536df9bf9bbad3b2b7a59f33ebad25fc981.zip
Added rudimentary object tracking to Archive, and rearranged the hash and
archive dependancies a little. I'll add docs for object tracking later...
Diffstat (limited to 'src/archive.cpp')
-rw-r--r--src/archive.cpp41
1 files changed, 40 insertions, 1 deletions
diff --git a/src/archive.cpp b/src/archive.cpp
index c759477..7208bae 100644
--- a/src/archive.cpp
+++ b/src/archive.cpp
@@ -2,7 +2,8 @@
2 2
3Bu::Archive::Archive( Stream &rStream, bool bLoading ) : 3Bu::Archive::Archive( Stream &rStream, bool bLoading ) :
4 bLoading( bLoading ), 4 bLoading( bLoading ),
5 rStream( rStream ) 5 rStream( rStream ),
6 nNextID( 1 )
6{ 7{
7} 8}
8 9
@@ -345,3 +346,41 @@ Bu::Archive &Bu::operator>>( Bu::Archive &ar, std::string &s )
345 return ar; 346 return ar;
346} 347}
347 348
349uint32_t Bu::Archive::getID( const void *ptr )
350{
351 if( hPtrID.has( (int)ptr ) )
352 return hPtrID.get( (int)ptr );
353 hPtrID.insert( (int)ptr, nNextID );
354 return nNextID++;
355}
356
357void Bu::Archive::assocPtrID( void **ptr, uint32_t id )
358{
359 if( hPtrID.has( id ) )
360 {
361 *ptr = (void *)hPtrID.get( id );
362 return;
363 }
364
365 if( !hPtrDest.has( id ) )
366 hPtrDest.insert( id, List<void **>() );
367
368 hPtrDest[id].value().append( ptr );
369}
370
371void Bu::Archive::readID( const void *ptr, uint32_t id )
372{
373 hPtrID.insert( id, (int)ptr );
374
375 if( hPtrDest.has( id ) )
376 {
377 Bu::List<void **> &l = hPtrDest.get( id );
378 for( Bu::List<void **>::iterator i = l.begin(); i != l.end(); i++ )
379 {
380 *(*i) = (void *)ptr;
381 }
382
383 hPtrDest.erase( id );
384 }
385}
386