From 286dc953c1e0e4a75589e4068e29a317a03f23dd Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 25 May 2010 05:42:26 +0000 Subject: More myriad tests and features, passes perfectly so far. --- src/myriad.cpp | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 3 deletions(-) (limited to 'src/myriad.cpp') diff --git a/src/myriad.cpp b/src/myriad.cpp index 044e35e..9e128d1 100644 --- a/src/myriad.cpp +++ b/src/myriad.cpp @@ -352,8 +352,22 @@ int Bu::Myriad::findEmptyBlock() return iBlocks++; } -void Bu::Myriad::deleteStream( int /*iID*/ ) +void Bu::Myriad::deleteStream( int iId ) { + for( StreamArray::iterator i = aStreams.begin(); i; i++ ) + { + if( (*i)->iId == iId ) + { + Stream *pStream = *i; + for( BlockArray::iterator j = pStream->aBlocks.begin(); j; j++ ) + { + bsBlockUsed.setBit( *j, false ); + } + aStreams.erase( i ); + bHeaderChanged = true; + return; + } + } } Bu::MyriadStream Bu::Myriad::openStream( int iId ) @@ -426,9 +440,42 @@ void Bu::Myriad::syncBlock( Block *pBlock ) } } +int Bu::Myriad::streamAddBlock( Stream *pStream ) +{ + int iBlock = findEmptyBlock(); + pStream->aBlocks.append( iBlock ); + bsBlockUsed.setBit( iBlock ); + return iBlock; +} + void Bu::Myriad::setStreamSize( Stream *pStream, long iSize ) { - sio << "Oh man, you have to implement Bu::Myriad::setStreamSize!!! (line " - << __LINE__ << ")" << sio.nl; + if( pStream->iSize == iSize ) + { + return; + } + else if( pStream->iSize > iSize ) + { + // Shrink + for( int iNewSize = pStream->aBlocks.getSize()*iBlockSize; + iNewSize-64 > iSize; iNewSize -= iBlockSize ) + { + bsBlockUsed.setBit( pStream->aBlocks.last(), false ); + pStream->aBlocks.eraseLast(); + } + pStream->iSize = iSize; + bHeaderChanged = true; + } + else + { + // Grow + for( int iNewSize = pStream->aBlocks.getSize()*iBlockSize; + iNewSize < iSize; iNewSize += iBlockSize ) + { + streamAddBlock( pStream ); + } + pStream->iSize = iSize; + bHeaderChanged = true; + } } -- cgit v1.2.3