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