aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Buland <mike@xagasoft.com>2024-09-30 10:23:55 -0700
committerMike Buland <mike@xagasoft.com>2024-09-30 10:23:55 -0700
commit84c93fbf0f371bcd26893d1c33e3a5bf1a61223e (patch)
treed27e8405e81c14762c083efc20e3b936b4bd7982 /src
parent76821551f312dd447a03748a01670f3718cd8345 (diff)
downloadlibbu++-84c93fbf0f371bcd26893d1c33e3a5bf1a61223e.tar.gz
libbu++-84c93fbf0f371bcd26893d1c33e3a5bf1a61223e.tar.bz2
libbu++-84c93fbf0f371bcd26893d1c33e3a5bf1a61223e.tar.xz
libbu++-84c93fbf0f371bcd26893d1c33e3a5bf1a61223e.zip
Forgot about erase, it seems to be working now.
Diffstat (limited to 'src')
-rw-r--r--src/stable/myriad.cpp24
-rw-r--r--src/stable/myriad.h4
-rw-r--r--src/tools/myriad.cpp18
3 files changed, 44 insertions, 2 deletions
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,
129 return Bu::MyriadStream( *this, pStream, eMode ); 129 return Bu::MyriadStream( *this, pStream, eMode );
130} 130}
131 131
132void Bu::Myriad::erase( Bu::Myriad::StreamId /*iStream*/ ) 132void Bu::Myriad::erase( Bu::Myriad::StreamId iStream )
133{ 133{
134 // For now, let's prevent you from erasing a stream if it's open.
135 Bu::MutexLocker l( mhStream );
136 if( !hStream.has( iStream ) )
137 {
138 throw Bu::MyriadException( Bu::MyriadException::noSuchStream,
139 "No such stream exists.");
140 }
141 Stream *pStream = hStream.get( iStream );
142 Bu::MutexLocker sl( pStream->mAccess );
143 if( pStream->iOpenCount > 0 )
144 {
145 throw Bu::MyriadException( Bu::MyriadException::streamOpen,
146 "Cannot currently erase a stream while it is open.");
147 }
148
149 for( Bu::Array<int32_t>::iterator i = pStream->aBlocks.begin(); i; i++ )
150 {
151 releaseBlock( *i, false );
152 }
153 pStream->aBlocks.clear();
154 hStream.erase( iStream );
155 delete pStream;
134} 156}
135 157
136void Bu::Myriad::setSize( Bu::Myriad::StreamId iStream, 158void 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
25 invalidParameter, 25 invalidParameter,
26 invalidBackingStream, 26 invalidBackingStream,
27 badMode, 27 badMode,
28 streamOpen,
28 }; 29 };
29 subExceptionDeclEnd(); 30 subExceptionDeclEnd();
30 31
@@ -68,7 +69,8 @@ namespace Bu
68 * 4 - 7: Size of stream in bytes 69 * 4 - 7: Size of stream in bytes
69 * 8 - ...: List of blocks in stream (4 bytes per block 70 * 8 - ...: List of blocks in stream (4 bytes per block
70 */ 71 */
71 Myriad( Bu::Stream &rBacking, int32_t iBlockSize=-1, int32_t iPreallocateBlocks=-1 ); 72 Myriad( Bu::Stream &rBacking, int32_t iBlockSize=-1,
73 int32_t iPreallocateBlocks=-1 );
72 virtual ~Myriad(); 74 virtual ~Myriad();
73 75
74 MyriadStream create( Mode eMode, int32_t iPreallocateBytes=-1 ); 76 MyriadStream create( Mode eMode, int32_t iPreallocateBytes=-1 );
diff --git a/src/tools/myriad.cpp b/src/tools/myriad.cpp
index 1dc73ec..346cd85 100644
--- a/src/tools/myriad.cpp
+++ b/src/tools/myriad.cpp
@@ -20,6 +20,7 @@ enum Mode
20 modeCreate, 20 modeCreate,
21 modeInfo, 21 modeInfo,
22 modeStreamNew, 22 modeStreamNew,
23 modeStreamErase,
23 modeStreamDump, 24 modeStreamDump,
24 modeStreamPut, 25 modeStreamPut,
25 modeStreamGet, 26 modeStreamGet,
@@ -44,6 +45,8 @@ public:
44 "Display some info about a Myriad file." ); 45 "Display some info about a Myriad file." );
45 addOption( eMode, 'n', "new", 46 addOption( eMode, 'n', "new",
46 "Create a new sub-stream in a Myriad file."); 47 "Create a new sub-stream in a Myriad file.");
48 addOption( eMode, 'e', "erase",
49 "Erase sub-stream in a Myriad file.");
47 addOption( eMode, 'd', "dump", 50 addOption( eMode, 'd', "dump",
48 "Display a hexdump of a stream from a Myriad file."); 51 "Display a hexdump of a stream from a Myriad file.");
49 addOption( eMode, "get", 52 addOption( eMode, "get",
@@ -67,6 +70,7 @@ public:
67 setOverride( "create", modeCreate ); 70 setOverride( "create", modeCreate );
68 setOverride( "info", modeInfo ); 71 setOverride( "info", modeInfo );
69 setOverride( "new", modeStreamNew ); 72 setOverride( "new", modeStreamNew );
73 setOverride( "erase", modeStreamErase );
70 setOverride( "dump", modeStreamDump ); 74 setOverride( "dump", modeStreamDump );
71 setOverride( "put", modeStreamPut ); 75 setOverride( "put", modeStreamPut );
72 setOverride( "get", modeStreamGet ); 76 setOverride( "get", modeStreamGet );
@@ -153,6 +157,20 @@ int main( int argc, char *argv[] )
153 } 157 }
154 break; 158 break;
155 159
160 case modeStreamErase:
161 if( !opts.sFile.isSet() )
162 {
163 sio << "Please specify a file manipulate." << sio.nl;
164 return 0;
165 }
166 else
167 {
168 File fOut( opts.sFile, File::Write|File::Read );
169 Myriad m( fOut );
170 m.erase( opts.iStream );
171 }
172 break;
173
156 case modeStreamDump: 174 case modeStreamDump:
157 if( !opts.sFile.isSet() ) 175 if( !opts.sFile.isSet() )
158 { 176 {