///////////////////////////////////////////////////////////////////////////////
// LoadArrayAt
///////////////////////////////////////////////////////////////////////////////
void cHierDatabaseIter::LoadArrayAt(const cHierAddr& addr) //throw (eArchive, eHierDatabase)
{
    ASSERT( mpDb != 0);
    //
    // make sure the address is non-null
    //
    util_ThrowIfNull(addr, _T("cHierDatabaseIter::LoadArrayAt"));
    //
    // load the info and the array
    //
    mInfoAddr       = addr;
    util_ReadObject( mpDb, &mInfo, mInfoAddr );
    cHierAddr curAddr = mInfo.mArray;
    //
    // load in all the array entries...
    //
    mEntries.clear();
    while( ! curAddr.IsNull() )
    {
        mEntries.push_back( cHierEntry() );
        util_ReadObject( mpDb, &mEntries.back(), curAddr );
        curAddr = mEntries.back().mNext;
    }
    
    //
    // seek to the beginning of the array
    //
    SeekBegin();
}
void cFCODatabaseFileIter::SeekToGenre(cGenre::Genre genreId)
{
    for( SeekBegin(); ! Done(); Next() )
    {
        if( GetGenre() == genreId )
            return;
    }
}
예제 #3
0
///////////////////////////////////////////////////////////////////////////////
// SeekToArg
///////////////////////////////////////////////////////////////////////////////
bool    cCmdLineIter::SeekToArg(int argId) const
{
    for(SeekBegin(); ! Done(); Next())
    {
        if(ArgId() == argId)
            return true;
    }

    return false;

}
예제 #4
0
bool File::Initialize(string path, FILE_OPEN_MODE mode) {
	Close();
	_path = path;
	string openMode = "";
	switch (mode) {
		case FILE_OPEN_MODE_READ:
		{
			openMode = "rb";
			break;
		}
		case FILE_OPEN_MODE_TRUNCATE:
		{
			openMode = "w+b";
			break;
		}
		case FILE_OPEN_MODE_APPEND:
		{
			openMode = "a+b";
			break;
		}
		default:
		{
			FATAL("Invalid open mode");
			return false;
		}
	}

	_pFile = fopen(STR(_path), STR(openMode));

	if (_pFile == NULL) {
		int err = errno;
		FATAL("Unable to open file %s with mode `%s`. Error was: %s (%d)",
				STR(_path), STR(openMode), strerror(err), err);
		return false;
	}

	if (!SeekEnd())
		return false;

	_size = ftell64(_pFile);

	if (!SeekBegin())
		return false;

	return true;
}
//-----------------------------------------------------------------------------
// cFCODatabaseFileIter
//-----------------------------------------------------------------------------
cFCODatabaseFileIter::cFCODatabaseFileIter( cFCODatabaseFile& dbFile ) 
:   mDbFile( dbFile ) 
{   
    SeekBegin(); 
}
///////////////////////////////////////////////////////////////////////////////
// SeekToDirectory
///////////////////////////////////////////////////////////////////////////////
bool cDbDataSourceIter::SeekToDirectory( const cFCOName& parentName, bool bCreate )
{
	cDebug d( "cDbDataSourceIter::SeekToDirectory" );
	//
	// the first task is to ascend until we are in a directory that we can descend into to 
	// reach parentName...
	//
	cFCOName curParent = GetParentName();
	d.TraceDebug( _T("Entering... Seeking to %s (cwd = %s)\n"), parentName.AsString().c_str(), curParent.AsString().c_str() );
	int ascendCount ;
	switch( curParent.GetRelationship( parentName ) )
	{
		case cFCOName::REL_BELOW:
			//
			// we must ascend...
			//
			ascendCount = curParent.GetSize() - parentName.GetSize();
			d.TraceDetail( _T("\tAscending %d times...\n"), ascendCount );
			ASSERT( ascendCount > 0 );
			for( ; ascendCount > 0; ascendCount-- )
				Ascend();
			break;
		case cFCOName::REL_ABOVE:
			//
			// we are above the needed directory; nothing else to do here...
			//
			d.TraceDetail( _T("\tAbove; not ascending...\n") );
			break;
		case cFCOName::REL_EQUAL:
			//
			// we need to do nothing else here...
			//
			d.TraceDetail( _T("\tEqual; doing nothing...\n") );
			SeekBegin();
			return true;
		case cFCOName::REL_UNRELATED:
			//
			// we have to go all the way to the root...
			//
			d.TraceDetail( _T("\tUnrelated; seeking to root...\n") );
			SeekToRoot();
			break;
		default:
			// unreachable
			ASSERT( false );
			return false;
	}

	curParent = GetParentName();
	if( parentName.GetSize() == curParent.GetSize() )
		return true;
	//
	// now we will descend to the parent directory we are interested in...
	//
	cFCOName::iterator i(parentName);
	i.SeekTo( curParent.GetSize() );
	for(; (! i.Done()); i.Next() )
	{
		if( ! mDbIter.SeekTo( i.GetName() ) )
		{
			// this needs to be created!
			if( bCreate )
				mDbIter.CreateEntry( i.GetName() );
			else
				return false;
		}
		//
		// create the child array and descend
		//
		if( ! mDbIter.CanDescend() )
		{
			if( bCreate )
				mDbIter.CreateChildArray();
			else
				return false;
		}
		mDbIter.Descend();
	}
	return true;
}
예제 #7
0
파일: WaveFile.cpp 프로젝트: jerlich/rt-fsm
int CWaveFile::UpdateHeader( void )
/////////////////////////////////////////////////////////////////////////////
{
	MMRESULT Result;

	// ascend out of the data subchunk
	Result = Ascend( &m_mmckinfoSubchunk );
	if( Result )
		DPF(("UpdateHeader: Ascend data subchunk failed!\n"));
	//DPF(("fccType [%08lx] %lu\n", m_mmckinfoSubchunk.fccType, m_mmckinfoSubchunk.cksize ));

	// ascend out of the WAVE chunk, which automaticlly updates the cksize field
	Result = Ascend( &m_mmckinfoParent );
	if( Result )
		DPF(("UpdateHeader: Ascend WAVE chunk failed %ld!\n", Result ));
	//DPF(("fccType [%08lx] %lu\n", m_mmckinfoParent.fccType, m_mmckinfoParent.cksize ));

	//MMSYSERR_INVALPARAM 
	// force write to disk
	Result = Flush( MMIO_EMPTYBUF );
	if( Result )
		DPF(("UpdateHeader: Flush failed!\n"));

	// if a compressed format, then update the fact chunk
	if( m_FormatEx.wFormatTag != WAVE_FORMAT_PCM )
	{
		DWORD		dwSampleLength;
		MMCKINFO	mmckinfoFact;

		// move to start of file
		SeekBegin( 0 );

		// find the WAVE chunk
		m_mmckinfoParent.fccType = mmioFOURCC('W','A','V','E');
		if( Descend( (LPMMCKINFO)&m_mmckinfoParent, NULL, MMIO_FINDRIFF ) )
		{
			Close();
			return( FALSE );
		}

		// Now, find the fact chunk 
		mmckinfoFact.ckid = mmioFOURCC('f','a','c','t');
		if( Descend( &mmckinfoFact, &m_mmckinfoParent, MMIO_FINDCHUNK ) )
		{
			Close();
			return( FALSE );
		}

		// compute out the number of samples
		dwSampleLength = GetSampleCount();

		// write the fact chunk
		if( Write( (HPSTR)&dwSampleLength, sizeof( DWORD )) != (LONG)sizeof( DWORD ) )
		{
			Close();
			return( FALSE );
		}

		// Ascend out of the fact subchunk.
		if( Ascend( &mmckinfoFact ) )
			DPF(("Ascend Failed\n"));
		// Ascend out of the WAVE chunk.
		if( Ascend( &m_mmckinfoParent ) )
			DPF(("Ascend Failed\n"));
	}

	return( TRUE );
}