From 81378d71401f39ced7d275777a6813db0ff04117 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 18 Sep 2024 13:24:38 -0700 Subject: Open is more complete now. It's not fully tested. It should allow you to open and create arbitrary stream ids, truncate, exclusive mode, etc. --- src/stable/myriad.cpp | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) (limited to 'src/stable/myriad.cpp') diff --git a/src/stable/myriad.cpp b/src/stable/myriad.cpp index 4edd004..1bf2301 100644 --- a/src/stable/myriad.cpp +++ b/src/stable/myriad.cpp @@ -80,7 +80,31 @@ Bu::MyriadStream Bu::Myriad::create( Bu::Myriad::Mode eMode, Bu::MyriadStream Bu::Myriad::open( Bu::Myriad::StreamId iStream, Bu::Myriad::Mode eMode ) { + Stream *pStream = NULL; Bu::MutexLocker l( mhStream ); + if( (eMode&Create) ) + { + if( !hStream.has( iStream ) ) + { + if( (eMode&Exclusive) ) + { + throw Bu::MyriadException( MyriadException::noSuchStream, + "Stream exists."); + } + } + else + { + Bu::MutexLocker l( mAccess ); + if( iStream >= iLastUsedIndex ) + { + iLastUsedIndex = iStream; + } + pStream = new Stream( *this, iStream, 0 ); + pStream->aBlocks.append( __allocateBlock() ); + hStream.insert( pStream->iStream, pStream ); + bStructureChanged = true; + } + } if( !hStream.has( iStream ) ) { throw Bu::MyriadException( MyriadException::noSuchStream, @@ -94,7 +118,15 @@ Bu::MyriadStream Bu::Myriad::open( Bu::Myriad::StreamId iStream, "Backing stream does not support writing."); } } - return Bu::MyriadStream( *this, hStream.get( iStream ), eMode ); + if( pStream == NULL ) + { + pStream = hStream.get( iStream ); + } + if( (eMode&Truncate) ) + { + pStream->setSize( 0 ); + } + return Bu::MyriadStream( *this, pStream, eMode ); } void Bu::Myriad::erase( Bu::Myriad::StreamId /*iStream*/ ) @@ -461,6 +493,7 @@ void Bu::Myriad::writeHeader() Bu::MyriadStream sHeader( *this, hStream.get( 0 ), Bu::Myriad::Write ); sHeader.write( mbHeader.getString() ); + bStructureChanged = false; } int32_t Bu::Myriad::__calcHeaderSize() @@ -506,6 +539,7 @@ int32_t Bu::Myriad::allocateBlock() int32_t Bu::Myriad::__allocateBlock() { + bStructureChanged = true; if( lFreeBlocks.isEmpty() ) { // Increase the size of the backing stream @@ -528,6 +562,7 @@ void Bu::Myriad::releaseBlock( int32_t iBlockId, bool bBlank ) void Bu::Myriad::__releaseBlock( int32_t iBlockId, bool bBlank ) { + bStructureChanged = true; lFreeBlocks.append( iBlockId ); if( bBlank ) { @@ -602,8 +637,7 @@ Bu::Myriad::Stream::Stream( Bu::Myriad &rParent, Bu::Myriad::StreamId iStream, rParent( rParent ), iStream( iStream ), iSize( iSize ), - iOpenCount( 0 ), - bStructureChanged( false ) + iOpenCount( 0 ) { } -- cgit v1.2.3