From 84c93fbf0f371bcd26893d1c33e3a5bf1a61223e Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 30 Sep 2024 10:23:55 -0700 Subject: Forgot about erase, it seems to be working now. --- src/stable/myriad.cpp | 24 +++++++++++++++++++++++- src/stable/myriad.h | 4 +++- 2 files changed, 26 insertions(+), 2 deletions(-) (limited to 'src/stable') diff --git a/src/stable/myriad.cpp b/src/stable/myriad.cpp index 0bd2ff2..eba1ebf 100644 --- a/src/stable/myriad.cpp +++ b/src/stable/myriad.cpp @@ -129,8 +129,30 @@ Bu::MyriadStream Bu::Myriad::open( Bu::Myriad::StreamId iStream, return Bu::MyriadStream( *this, pStream, eMode ); } -void Bu::Myriad::erase( Bu::Myriad::StreamId /*iStream*/ ) +void Bu::Myriad::erase( Bu::Myriad::StreamId iStream ) { + // For now, let's prevent you from erasing a stream if it's open. + Bu::MutexLocker l( mhStream ); + if( !hStream.has( iStream ) ) + { + throw Bu::MyriadException( Bu::MyriadException::noSuchStream, + "No such stream exists."); + } + Stream *pStream = hStream.get( iStream ); + Bu::MutexLocker sl( pStream->mAccess ); + if( pStream->iOpenCount > 0 ) + { + throw Bu::MyriadException( Bu::MyriadException::streamOpen, + "Cannot currently erase a stream while it is open."); + } + + for( Bu::Array::iterator i = pStream->aBlocks.begin(); i; i++ ) + { + releaseBlock( *i, false ); + } + pStream->aBlocks.clear(); + hStream.erase( iStream ); + delete pStream; } void Bu::Myriad::setSize( Bu::Myriad::StreamId iStream, diff --git a/src/stable/myriad.h b/src/stable/myriad.h index c3f682d..60c5a39 100644 --- a/src/stable/myriad.h +++ b/src/stable/myriad.h @@ -25,6 +25,7 @@ namespace Bu invalidParameter, invalidBackingStream, badMode, + streamOpen, }; subExceptionDeclEnd(); @@ -68,7 +69,8 @@ namespace Bu * 4 - 7: Size of stream in bytes * 8 - ...: List of blocks in stream (4 bytes per block */ - Myriad( Bu::Stream &rBacking, int32_t iBlockSize=-1, int32_t iPreallocateBlocks=-1 ); + Myriad( Bu::Stream &rBacking, int32_t iBlockSize=-1, + int32_t iPreallocateBlocks=-1 ); virtual ~Myriad(); MyriadStream create( Mode eMode, int32_t iPreallocateBytes=-1 ); -- cgit v1.2.3