/*---------------------------------------------------------------------------* Project: NintendoWare File: snd_SequenceSoundFile.cpp Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Revision: 13145 $ *---------------------------------------------------------------------------*/ #include "precompiled.h" #include #include #include // strlen, strncmp namespace nw { namespace snd { namespace internal { // // SequenceSoundFile::FileHeader // const SequenceSoundFile::DataBlock* SequenceSoundFile::FileHeader::GetDataBlock() const { return reinterpret_cast( GetBlock( ElementType_SequenceSoundFile_DataBlock ) ); } const SequenceSoundFile::LabelBlock* SequenceSoundFile::FileHeader::GetLabelBlock() const { return reinterpret_cast( GetBlock( ElementType_SequenceSoundFile_LabelBlock ) ); } // // SequenceSoundFile::LabelBlockBody // const SequenceSoundFile::LabelInfo* SequenceSoundFile::LabelBlockBody::GetLabelInfo( int index ) const { NW_ASSERT( index < GetLabelCount() ); return reinterpret_cast( labelInfoReferenceTable.GetReferedItem( index ) ); } const char* SequenceSoundFile::LabelBlockBody::GetLabel( int index ) const { const LabelInfo* labelInfo = GetLabelInfo( index ); return labelInfo->label; } const char* SequenceSoundFile::LabelBlockBody::GetLabelByOffset( u32 offset ) const { // 線形探索 for ( int i = 0; i < GetLabelCount(); i++ ) { const LabelInfo* labelInfo = GetLabelInfo( i ); if ( labelInfo->referToSequenceData.offset == offset ) { return labelInfo->label; } } return NULL; } bool SequenceSoundFile::LabelBlockBody::GetOffset( int index, u32* offsetPtr ) const { const LabelInfo* labelInfo = GetLabelInfo( index ); *offsetPtr = labelInfo->referToSequenceData.offset; return true; } bool SequenceSoundFile::LabelBlockBody::GetOffsetByLabel( const char* label, u32* offsetPtr ) const { const std::size_t labelLength = std::strlen( label ); // 線形探索 for ( int i = 0; i < GetLabelCount(); i++ ) { const LabelInfo* labelInfo = GetLabelInfo( i ); if ( std::strncmp( label, labelInfo->label, labelLength ) == 0 ) { *offsetPtr = labelInfo->referToSequenceData.offset; return true; } } return false; } } // namespace nw::snd::internal } // namespace nw::snd } // namespace nw