/*---------------------------------------------------------------------------* Project: NintendoWare File: SmFile.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: 1 $ *---------------------------------------------------------------------------*/ #ifndef SM_FILE_H_ #define SM_FILE_H_ #include #include "../include/SmBase.h" //------------------------------------------------------------------------------ // ファイルの読み込みを行うクラスです。 class SmFile { public: // コンストラクタ SmFile( bool autoFree = false ) : m_Buffer(NULL), m_Size(0), m_AutoFree( autoFree ), m_Allocator( NULL ){} // デストラクタ ~SmFile() { if ( m_AutoFree ) { Release(); } } // 指定されたファイルを読み込みます。 bool Read( const wchar_t* fileName, nw::os::IAllocator* allocator ) { NW_ASSERT(m_Buffer == NULL); NW_NULL_ASSERT( allocator ); m_Allocator = allocator; nn::fs::FileReader fileReader(fileName); if (fileReader.GetSize() <= 0) { return false; } this->m_Size = static_cast(fileReader.GetSize()); this->m_Buffer = static_cast(m_Allocator->Alloc(this->m_Size, 128)); if (this->m_Buffer == NULL) { this->m_Size = 0; return false; } fileReader.Read(this->m_Buffer, this->m_Size); fileReader.Finalize(); return true; } // 読み込んだファイルのバッファを取得します。 u8* Buffer() { return this->m_Buffer; } // 読み込んだファイルのサイズを取得します。 u32 Size() { return this->m_Size; } // 確保したメモリを解放します void Release() { if ( m_Buffer ) { m_Allocator->Free( m_Buffer ); m_Buffer = NULL; } } private: u8* m_Buffer; u32 m_Size; bool m_AutoFree; nw::os::IAllocator* m_Allocator; }; #endif // SM_FILE_H_