From 469bbcf0701e1eb8a6670c23145b0da87357e178 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sun, 25 Mar 2012 20:00:08 +0000 Subject: Code is all reorganized. We're about ready to release. I should write up a little explenation of the arrangement. --- src/stable/archive.cpp | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 src/stable/archive.cpp (limited to 'src/stable/archive.cpp') diff --git a/src/stable/archive.cpp b/src/stable/archive.cpp new file mode 100644 index 0000000..d300a87 --- /dev/null +++ b/src/stable/archive.cpp @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2007-2011 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/archive.h" +#include "bu/stream.h" +#include "bu/archival.h" + +#include "bu/sio.h" + +Bu::Archive::Archive( Stream &rStream, bool bLoading ) : + bLoading( bLoading ), + rStream( rStream ), + nNextID( 1 ) +{ +} + +Bu::Archive::~Archive() +{ +} + +void Bu::Archive::write( const void *pData, size_t nSize ) +{ + if( nSize == 0 || pData == NULL ) + return; + + rStream.write( (const char *)pData, nSize ); +} + +void Bu::Archive::read( void *pData, size_t nSize ) +{ + if( nSize == 0 || pData == NULL ) + return; + + if( rStream.read( (char *)pData, nSize ) < nSize ) + throw Bu::ExceptionBase("Insufficient data to unarchive object."); +} + +void Bu::Archive::close() +{ + rStream.close(); +} + +bool Bu::Archive::isLoading() +{ + return bLoading; +} + +uint32_t Bu::Archive::getID( const void *ptr ) +{ + if( hPtrID.has( (ptrdiff_t)ptr ) ) + return hPtrID.get( (ptrdiff_t)ptr ); + hPtrID.insert( (ptrdiff_t)ptr, nNextID ); + return nNextID++; +} + +void Bu::Archive::assocPtrID( void **ptr, uint32_t id ) +{ + if( hPtrID.has( id ) ) + { + *ptr = (void *)hPtrID.get( id ); + return; + } + + if( !hPtrDest.has( id ) ) + hPtrDest.insert( id, List() ); + + hPtrDest[id].getValue().append( ptr ); +} + +void Bu::Archive::readID( const void *ptr, uint32_t id ) +{ + hPtrID.insert( id, (ptrdiff_t)ptr ); + + if( hPtrDest.has( id ) ) + { + Bu::List &l = hPtrDest.get( id ); + for( Bu::List::iterator i = l.begin(); i != l.end(); i++ ) + { + *(*i) = (void *)ptr; + } + + hPtrDest.erase( id ); + } +} + -- cgit v1.2.3