aboutsummaryrefslogtreecommitdiff
path: root/src/myriad.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2010-05-25 17:45:03 +0000
committerMike Buland <eichlan@xagasoft.com>2010-05-25 17:45:03 +0000
commit24ab24777d7cd72b7ff35a9d02cb43e26f006b0d (patch)
tree09b1e2e72e05ff6e7502f02edb6d3fc6100cc741 /src/myriad.cpp
parentb4e1fa15d0c809439139db3a60a3969d848dcf77 (diff)
downloadlibbu++-24ab24777d7cd72b7ff35a9d02cb43e26f006b0d.tar.gz
libbu++-24ab24777d7cd72b7ff35a9d02cb43e26f006b0d.tar.bz2
libbu++-24ab24777d7cd72b7ff35a9d02cb43e26f006b0d.tar.xz
libbu++-24ab24777d7cd72b7ff35a9d02cb43e26f006b0d.zip
More myriad testing, fixes, arrangement, etc. UnitSuite add-ons, it has some
command line parameters now, I would like to also add an automatic paramter that would switch it to a computer-readable output mode for use in a larger testing framework.
Diffstat (limited to 'src/myriad.cpp')
-rw-r--r--src/myriad.cpp51
1 files changed, 45 insertions, 6 deletions
diff --git a/src/myriad.cpp b/src/myriad.cpp
index f5bc67b..2f5c14f 100644
--- a/src/myriad.cpp
+++ b/src/myriad.cpp
@@ -24,13 +24,28 @@ namespace Bu
24 } 24 }
25} 25}
26 26
27Bu::Myriad::Myriad( Bu::Stream &sStore ) : 27Bu::Myriad::Myriad( Bu::Stream &sStore, int iBlockSize, int iPreallocate ) :
28 sStore( sStore ), 28 sStore( sStore ),
29 iBlockSize( 0 ), 29 iBlockSize( iBlockSize ),
30 iBlocks( 0 ), 30 iBlocks( 0 ),
31 iUsed( 0 ), 31 iUsed( 0 ),
32 bHeaderChanged( false ) 32 bHeaderChanged( false )
33{ 33{
34 try
35 {
36 initialize();
37 }
38 catch( Bu::MyriadException &e )
39 {
40 if( e.getErrorCode() == MyriadException::emptyStream )
41 {
42 initialize( iBlockSize, iPreallocate );
43 }
44 else
45 {
46 throw;
47 }
48 }
34} 49}
35 50
36Bu::Myriad::~Myriad() 51Bu::Myriad::~Myriad()
@@ -69,18 +84,19 @@ void Bu::Myriad::initialize()
69 84
70 unsigned char buf[4]; 85 unsigned char buf[4];
71 if( sStore.read( buf, 4 ) < 4 ) 86 if( sStore.read( buf, 4 ) < 4 )
72 throw MyriadException("Input stream appears to be empty."); 87 throw MyriadException( MyriadException::emptyStream,
88 "Input stream appears to be empty.");
73 if( memcmp( buf, Myriad_MAGIC_CODE, 4 ) ) 89 if( memcmp( buf, Myriad_MAGIC_CODE, 4 ) )
74 { 90 {
75 throw MyriadException( 91 throw MyriadException( MyriadException::invalidFormat,
76 "Stream does not appear to be a valid Myriad format."); 92 "Stream does not appear to be a valid Myriad format.");
77 } 93 }
78 sStore.read( buf, 2 ); 94 sStore.read( buf, 2 );
79 if( buf[0] != 1 ) 95 if( buf[0] != 1 )
80 throw MyriadException( 96 throw MyriadException( MyriadException::badVersion,
81 "We can only handle version 1 for now."); 97 "We can only handle version 1 for now.");
82 if( buf[1] != 32 ) 98 if( buf[1] != 32 )
83 throw MyriadException( 99 throw MyriadException( MyriadException::invalidWordSize,
84 "We can only handle 32-bit words at the moment."); 100 "We can only handle 32-bit words at the moment.");
85 sStore.read( &iBlockSize, 4 ); 101 sStore.read( &iBlockSize, 4 );
86 int iStreams; 102 int iStreams;
@@ -342,12 +358,16 @@ int Bu::Myriad::findEmptyBlock()
342// sio << "Myriad: findEmptyBlock(): No empty blocks, adding new one." << sio.nl; 358// sio << "Myriad: findEmptyBlock(): No empty blocks, adding new one." << sio.nl;
343 359
344 bsBlockUsed.setSize( bsBlockUsed.getSize()+1, false ); 360 bsBlockUsed.setSize( bsBlockUsed.getSize()+1, false );
361 /*
345 sStore.setPos( iBlockSize*iBlocks ); 362 sStore.setPos( iBlockSize*iBlocks );
346 363
347 char *pBlock = new char[iBlockSize]; 364 char *pBlock = new char[iBlockSize];
348 memset( pBlock, 0, iBlockSize ); 365 memset( pBlock, 0, iBlockSize );
349 sStore.write( pBlock, iBlockSize ); 366 sStore.write( pBlock, iBlockSize );
350 delete[] pBlock; 367 delete[] pBlock;
368 */
369
370 sStore.setSize( (iBlocks+1)*iBlockSize );
351 371
352 return iBlocks++; 372 return iBlocks++;
353} 373}
@@ -400,6 +420,9 @@ Bu::Myriad::Stream *Bu::Myriad::findStream( int iId )
400 return *i; 420 return *i;
401 } 421 }
402 422
423 throw MyriadException( MyriadException::noSuchStream,
424 "The requested stream doesn't exist and cannot be opened." );
425
403 return NULL; 426 return NULL;
404} 427}
405 428
@@ -480,3 +503,19 @@ void Bu::Myriad::setStreamSize( Stream *pStream, long iSize )
480 } 503 }
481} 504}
482 505
506bool Bu::Myriad::isMyriad( Bu::Stream &sStore )
507{
508 sStore.setPos( 0 );
509
510 unsigned char buf[4];
511 if( sStore.read( buf, 4 ) < 4 )
512 throw MyriadException( MyriadException::emptyStream,
513 "Input stream appears to be empty.");
514 sStore.setPos( 0 );
515 if( memcmp( buf, Myriad_MAGIC_CODE, 4 ) )
516 {
517 return false;
518 }
519 return true;
520}
521