diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/stable/myriad.cpp | 40 |
1 files changed, 37 insertions, 3 deletions
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, | |||
80 | Bu::MyriadStream Bu::Myriad::open( Bu::Myriad::StreamId iStream, | 80 | Bu::MyriadStream Bu::Myriad::open( Bu::Myriad::StreamId iStream, |
81 | Bu::Myriad::Mode eMode ) | 81 | Bu::Myriad::Mode eMode ) |
82 | { | 82 | { |
83 | Stream *pStream = NULL; | ||
83 | Bu::MutexLocker l( mhStream ); | 84 | Bu::MutexLocker l( mhStream ); |
85 | if( (eMode&Create) ) | ||
86 | { | ||
87 | if( !hStream.has( iStream ) ) | ||
88 | { | ||
89 | if( (eMode&Exclusive) ) | ||
90 | { | ||
91 | throw Bu::MyriadException( MyriadException::noSuchStream, | ||
92 | "Stream exists."); | ||
93 | } | ||
94 | } | ||
95 | else | ||
96 | { | ||
97 | Bu::MutexLocker l( mAccess ); | ||
98 | if( iStream >= iLastUsedIndex ) | ||
99 | { | ||
100 | iLastUsedIndex = iStream; | ||
101 | } | ||
102 | pStream = new Stream( *this, iStream, 0 ); | ||
103 | pStream->aBlocks.append( __allocateBlock() ); | ||
104 | hStream.insert( pStream->iStream, pStream ); | ||
105 | bStructureChanged = true; | ||
106 | } | ||
107 | } | ||
84 | if( !hStream.has( iStream ) ) | 108 | if( !hStream.has( iStream ) ) |
85 | { | 109 | { |
86 | throw Bu::MyriadException( MyriadException::noSuchStream, | 110 | throw Bu::MyriadException( MyriadException::noSuchStream, |
@@ -94,7 +118,15 @@ Bu::MyriadStream Bu::Myriad::open( Bu::Myriad::StreamId iStream, | |||
94 | "Backing stream does not support writing."); | 118 | "Backing stream does not support writing."); |
95 | } | 119 | } |
96 | } | 120 | } |
97 | return Bu::MyriadStream( *this, hStream.get( iStream ), eMode ); | 121 | if( pStream == NULL ) |
122 | { | ||
123 | pStream = hStream.get( iStream ); | ||
124 | } | ||
125 | if( (eMode&Truncate) ) | ||
126 | { | ||
127 | pStream->setSize( 0 ); | ||
128 | } | ||
129 | return Bu::MyriadStream( *this, pStream, eMode ); | ||
98 | } | 130 | } |
99 | 131 | ||
100 | void Bu::Myriad::erase( Bu::Myriad::StreamId /*iStream*/ ) | 132 | void Bu::Myriad::erase( Bu::Myriad::StreamId /*iStream*/ ) |
@@ -461,6 +493,7 @@ void Bu::Myriad::writeHeader() | |||
461 | 493 | ||
462 | Bu::MyriadStream sHeader( *this, hStream.get( 0 ), Bu::Myriad::Write ); | 494 | Bu::MyriadStream sHeader( *this, hStream.get( 0 ), Bu::Myriad::Write ); |
463 | sHeader.write( mbHeader.getString() ); | 495 | sHeader.write( mbHeader.getString() ); |
496 | bStructureChanged = false; | ||
464 | } | 497 | } |
465 | 498 | ||
466 | int32_t Bu::Myriad::__calcHeaderSize() | 499 | int32_t Bu::Myriad::__calcHeaderSize() |
@@ -506,6 +539,7 @@ int32_t Bu::Myriad::allocateBlock() | |||
506 | 539 | ||
507 | int32_t Bu::Myriad::__allocateBlock() | 540 | int32_t Bu::Myriad::__allocateBlock() |
508 | { | 541 | { |
542 | bStructureChanged = true; | ||
509 | if( lFreeBlocks.isEmpty() ) | 543 | if( lFreeBlocks.isEmpty() ) |
510 | { | 544 | { |
511 | // Increase the size of the backing stream | 545 | // Increase the size of the backing stream |
@@ -528,6 +562,7 @@ void Bu::Myriad::releaseBlock( int32_t iBlockId, bool bBlank ) | |||
528 | 562 | ||
529 | void Bu::Myriad::__releaseBlock( int32_t iBlockId, bool bBlank ) | 563 | void Bu::Myriad::__releaseBlock( int32_t iBlockId, bool bBlank ) |
530 | { | 564 | { |
565 | bStructureChanged = true; | ||
531 | lFreeBlocks.append( iBlockId ); | 566 | lFreeBlocks.append( iBlockId ); |
532 | if( bBlank ) | 567 | if( bBlank ) |
533 | { | 568 | { |
@@ -602,8 +637,7 @@ Bu::Myriad::Stream::Stream( Bu::Myriad &rParent, Bu::Myriad::StreamId iStream, | |||
602 | rParent( rParent ), | 637 | rParent( rParent ), |
603 | iStream( iStream ), | 638 | iStream( iStream ), |
604 | iSize( iSize ), | 639 | iSize( iSize ), |
605 | iOpenCount( 0 ), | 640 | iOpenCount( 0 ) |
606 | bStructureChanged( false ) | ||
607 | { | 641 | { |
608 | } | 642 | } |
609 | 643 | ||