1 /*---------------------------------------------------------------------------*
2 Project: NintendoWare
3 File: io_FileStream.cpp
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 #include "precompiled.h"
19
20 #include <nw/io/io_FileStream.h>
21
22 #include <nw/types.h>
23 #include <nw/assert.h>
24 #include <nw/ut/ut_Inlines.h>
25 #include <nw/ut/ut_RuntimeTypeInfo.h>
26
27
28 namespace nw {
29 namespace io {
30
31 NW_UT_RUNTIME_TYPEINFO_DEFINITION(FileStream,IOStream);
32
33
34 /*!--------------------------------------------------------------------------*
35 Name: FileStream::Seek
36
37 @brief ファイルポインタの移動
38
39 @param[in] offset ファイルポインタ移動値を指定します。
40 @param[in] origin ファイルポインタ移動の基準点を指定します。
41 FILE_STREAM_SEEK_BEGIN - ファイルの先頭を基準
42 FILE_STREAM_SEEK_CURRENT - 現在の読み込み位置を基準
43 FILE_STREAM_SEEK_END - ファイルの終端を基準(offset <= 0で指定されるはずです)
44
45 @return None.
46 *---------------------------------------------------------------------------*/
47 void
Seek(s32,u32)48 FileStream::Seek( s32 /*offset*/, u32 /*origin*/ )
49 {
50 NW_ASSERTMSG( CanSeek(), "Stream don't support SEEK function\n" );
51 }
52
53
54 /*!--------------------------------------------------------------------------*
55 Name: FileStream::Cancel
56
57 @brief 非同期処理をキャンセルします。(同期関数)
58
59 @return None.
60 *---------------------------------------------------------------------------*/
61 void
Cancel(void)62 FileStream::Cancel( void )
63 {
64 NW_ASSERTMSG( CanCancel(), "Stream don't support CANCEL function\n" );
65 }
66
67
68 /*!--------------------------------------------------------------------------*
69 Name: FileStream::CancelAsync
70
71 @brief 非同期処理をキャンセルします。(非同期関数)
72
73 @param[in] callback
74 @param[in] arg
75
76 @return コマンドが正常に発行された場合には真を返します。
77 発行されなかった場合には偽を返します。
78 *---------------------------------------------------------------------------*/
79 bool
CancelAsync(IOStreamCallback,void *)80 FileStream::CancelAsync(
81 IOStreamCallback /*callback*/, void* /*arg*/ )
82 {
83 NW_ASSERTMSG( CanCancel(), "Stream don't support CANCEL function\n" );
84 NW_ASSERTMSG( CanAsync(), "Stream don't support ASYNC function\n" );
85 return true;
86 }
87
88
89
90
91 /*!--------------------------------------------------------------------------*
92 Name: FileStream::FilePosition::Skip
93
94 @brief ファイルポインタの移動。
95 ファイルの終端を越えた場合には、ファイルポインタは終端位置を示します。
96
97 @param[in] offset ファイルポインタ移動オフセット
98
99 @return 移動後のファイル位置を返します。
100 *---------------------------------------------------------------------------*/
101 u32
Skip(s32 offset)102 FileStream::FilePosition::Skip( s32 offset )
103 {
104 if ( offset != 0 )
105 {
106 s64 position = mPosition + offset;
107
108 position = ut::Clamp( position, static_cast<s64>(0), static_cast<s64>(mFileSize) );
109
110 mPosition = static_cast<u32>(position);
111 }
112 return mPosition;
113 }
114
115
116 /*!--------------------------------------------------------------------------*
117 Name: FileStream::FilePosition::Append
118
119 @brief データ追加によるファイルポインタの移動。
120 ファイルの終端を越えた場合には、その分ファイルサイズを増加します。
121
122 @param[in] offset ファイルポインタ移動オフセット
123
124 @return 移動後のファイル位置を返します。
125 *---------------------------------------------------------------------------*/
126 u32
Append(s32 offset)127 FileStream::FilePosition::Append( s32 offset )
128 {
129 s64 position = mPosition + offset;
130
131 if ( position < 0 )
132 {
133 mPosition = 0;
134 }
135 else
136 {
137 mPosition = static_cast<u32>(position);
138 mFileSize = ut::Max( mPosition, mFileSize );
139 }
140 return mPosition;
141 }
142
143
144 /*!--------------------------------------------------------------------------*
145 Name: FileStream::FilePosition::Seek
146
147 @brief ファイルポインタの移動
148
149 @param[in] offset ファイルポインタ移動値を指定します。
150 @param[in] origin ファイルポインタ移動の基準点を指定します。
151 FILE_STREAM_SEEK_BEGIN - ファイルの先頭を基準
152 FILE_STREAM_SEEK_CURRENT - 現在の読み込み位置を基準
153 FILE_STREAM_SEEK_END - ファイルの終端を基準(offset <= 0で指定されるはずです)
154
155 @return None.
156 *---------------------------------------------------------------------------*/
157 void
Seek(s32 offset,u32 origin)158 FileStream::FilePosition::Seek( s32 offset, u32 origin )
159 {
160 switch ( origin )
161 {
162 case FILE_STREAM_SEEK_BEGIN:
163 mPosition = 0;
164 break;
165 case FILE_STREAM_SEEK_CURRENT:
166 break;
167 case FILE_STREAM_SEEK_END:
168 mPosition = mFileSize;
169 break;
170 }
171 (void)Skip( offset );
172 }
173
174
175
176
177 } /* namespace io */
178 } /* namespace nw */
179
180