1 /*---------------------------------------------------------------------------* 2 Project: NintendoWare 3 File: io_FileStream.h 4 5 Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc. All rights reserved. 6 7 These coded instructions, statements, and computer programs contain 8 proprietary information of Nintendo of America Inc. and/or Nintendo 9 Company Ltd., and are protected by Federal copyright law. They may 10 not be disclosed to third parties or copied or duplicated in any form, 11 in whole or in part, without the prior written consent of Nintendo. 12 13 $Revision: 13145 $ 14 *---------------------------------------------------------------------------*/ 15 16 #ifndef NW_IO_FILE_STREAM_H_ 17 #define NW_IO_FILE_STREAM_H_ 18 19 #include <nw/io/io_IOStream.h> 20 21 namespace nw { 22 namespace io { 23 24 enum 25 { 26 FILE_STREAM_SEEK_BEGIN, 27 FILE_STREAM_SEEK_CURRENT, 28 FILE_STREAM_SEEK_END 29 }; 30 31 32 //------------------------------------------------- 33 // ファイルストリーム 34 //------------------------------------------------- 35 class FileStream : public IOStream 36 { 37 //------ publicメンバ -------------------------- 38 public: 39 NW_UT_RUNTIME_TYPEINFO; // ダウンキャスト用の実行時型情報を埋め込みます 40 41 // ファイルサイズを取得します。 42 virtual u32 GetSize() const = 0; 43 44 // ファイルポインタを移動します。 45 virtual void Seek( s32 offset, u32 origin ); 46 47 // 非同期処理のキャンセル 48 virtual void Cancel( void ); 49 virtual bool CancelAsync( IOStreamCallback callback, void* arg ); 50 51 virtual bool CanSeek ( void ) const = 0; 52 virtual bool CanCancel( void ) const = 0; 53 54 virtual u32 Tell() const = 0; IsEof()55 bool IsEof() const { return Tell() >= GetSize(); } 56 57 //------ protectedメンバ -------------------------- 58 protected: 59 //--- コンストラクタ/デストラクタ ----------- FileStream()60 /* ctor */ FileStream() : IOStream() {} 61 62 //----------------------------- 63 // ファイル読み込み位置管理用クラス 64 //----------------------------- 65 class FilePosition 66 { 67 public: FilePosition()68 /* ctor */ FilePosition() : mFileSize(0), mPosition(0) {} SetFileSize(u32 fileSize)69 void SetFileSize( u32 fileSize ) { mFileSize = fileSize; } GetFileSize()70 u32 GetFileSize() const { return mFileSize; } 71 72 u32 Skip( s32 offset ); 73 u32 Append( s32 offset ); 74 void Seek( s32 offset, u32 origin ); Tell()75 u32 Tell() const { return mPosition; } 76 private: 77 u32 mFileSize; // ファイルサイズ 78 u32 mPosition; // 読み込み位置 79 }; 80 }; 81 82 83 } /* namespace io */ 84 } /* namespace nw */ 85 86 87 88 /* NW_IO_FILE_STREAM_H_ */ 89 #endif 90