TNB Library
TnbRapiFile.h
[詳解]
1#pragma once
11#include "TnbStr.h"
12#include "TnbFile.h"
13#include "TnbRapi.h"
14
15
16
17//TNB Library
18namespace TNB
19{
20
21
22
23#ifndef _TnbDOXYGEN //Document作成用シンボル
24
26struct TPhRapiCloseHandle
27{
28 void operator()(HANDLE P) { if ( CRapi::IsSupported() ) { ::CeCloseHandle(P); } }
29};
30
32typedef TNB::CPointerHandleBaseT<HANDLE, TPhRapiCloseHandle, (INT_PTR)INVALID_HANDLE_VALUE> CRapiHandleHandle;
33
35template<typename TYP>
36class CRapiFileApiT : public TYP
37{
38public:
40 CRapiFileApiT(void)
41 {
43 }
48 virtual HANDLE GetHandle(void) const
49 {
50 return m_hhFile;
51 }
52protected:
57 virtual void SetHandle(HANDLE h)
58 {
59 m_hhFile = h;
60 }
62 virtual BOOL ApiGetFileInformationByHandle(HANDLE hFile, LPBY_HANDLE_FILE_INFORMATION P) const
63 {
64 if ( ! CRapi::IsSupported() ) { return FALSE; }
65 BOOL r = TRUE;
66 Zero(*P);
67 P->dwFileAttributes = ::GetFileAttributes(GetOpenName());
68 r &= ::CeGetFileTime(hFile, &P->ftCreationTime, &P->ftLastAccessTime, &P->ftLastWriteTime);
69 P->nFileSizeLow = ::CeGetFileSize(hFile, &P->nFileSizeHigh);
70 ::SetLastError(::CeGetLastError());
71 return r;
72 }
74 virtual HANDLE ApiCreateFile(LPCTSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes,
75 DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile)
76 {
77 if ( ! CRapi::IsSupported() ) { return INVALID_HANDLE_VALUE; }
78 HANDLE h = ::CeCreateFile(CUnicode(lpFileName), dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
79 ::SetLastError(::CeGetLastError());
80 return h;
81 }
83 virtual DWORD ApiGetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh) const
84 {
85 if ( ! CRapi::IsSupported() ) { return 0; }
86 DWORD r = ::CeGetFileSize(hFile, lpFileSizeHigh);
87 ::SetLastError(::CeGetLastError());
88 return r;
89 }
91 virtual DWORD ApiSetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod) const
92 {
93 if ( ! CRapi::IsSupported() ) { return 0; }
94 DWORD r = ::CeSetFilePointer(hFile, lDistanceToMove, lpDistanceToMoveHigh, dwMoveMethod);
95 ::SetLastError(::CeGetLastError());
96 return r;
97 }
99 virtual BOOL ApiReadFile(HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, LPDWORD lpNumberOfBytesRead, LPOVERLAPPED lpOverlapped) const
100 {
101 if ( ! CRapi::IsSupported() ) { return FALSE; }
102 BOOL r = ::CeReadFile(hFile, lpBuffer, nNumberOfBytesToRead, lpNumberOfBytesRead, lpOverlapped);
103 ::SetLastError(::CeGetLastError());
104 return r;
105 }
107 virtual BOOL ApiSetFileTime(HANDLE hFile, CONST FILETIME *lpCreationTime, CONST FILETIME *lpLastAccessTime, CONST FILETIME *lpLastWriteTime)
108 {
109 if ( ! CRapi::IsSupported() ) { return FALSE; }
110 FILETIME f1 = *lpCreationTime;
111 FILETIME f2 = *lpLastAccessTime;
112 FILETIME f3 = *lpLastWriteTime;
113 BOOL r = ::CeSetFileTime(hFile, &f1, &f2, &f3);
114 ::SetLastError(::CeGetLastError());
115 return r;
116 }
118 virtual BOOL ApiSetEndOfFile(HANDLE hFile)
119 {
120 if ( ! CRapi::IsSupported() ) { return FALSE; }
121 BOOL r = ::CeSetEndOfFile(hFile);
122 ::SetLastError(::CeGetLastError());
123 return r;
124 }
126 virtual BOOL ApiWriteFile(HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, LPDWORD lpNumberOfBytesWritten, LPOVERLAPPED lpOverlapped)
127 {
128 if ( ! CRapi::IsSupported() ) { return FALSE; }
129 BOOL r = ::CeWriteFile(hFile, lpBuffer, nNumberOfBytesToWrite, lpNumberOfBytesWritten, lpOverlapped);
130 ::SetLastError(::CeGetLastError());
131 return r;
132 }
133private:
134 mutable CRapiHandleHandle m_hhFile;
135};
136
137// RAPI ファイルハンドル管理クラス
138//typedef CRapiFileApiT<CFileHandle> CRapiFileHandle;
139
140#endif // _TnbDOXYGEN
141
142
143
161#ifndef _TnbDOXYGEN //Document作成用シンボル
162typedef CRapiFileApiT<CFileReader> CRapiFileReader;
163#else
165 {typedef aa __a;};
166#endif
167
168
169
188#ifndef _TnbDOXYGEN //Document作成用シンボル
189typedef CRapiFileApiT<CFileWriter> CRapiFileWriter;
190#else
192 {typedef aa __a;};
193#endif
194
195
196
197
198}; // TNB
199
200
201
ファイル関係のヘッダ
RAPI 関係のヘッダ
文字列管理関係のヘッダ
ファイル読み込みクラス
Definition: TnbFile.h:338
ファイル書き込みクラス
Definition: TnbFile.h:475
ポインタハンドルテンプレートベースクラス
RAPI ファイル読み込みクラス
Definition: TnbRapiFile.h:165
RAPI ファイル書き込みクラス
Definition: TnbRapiFile.h:192
static bool IsSupported(void)
[確認] サポート確認.
Definition: TnbRapi.h:127
static bool Startup(void)
[設定] RAPI 初期化.
Definition: TnbRapi.h:81
TNB::CStrT< WCHAR > CUnicode
UNICODE文字列クラス
Definition: TnbStr.h:1771
void Zero(V &value)
[設定] ゼロクリア.
Definition: TnbDef.h:399
TNB Library
Definition: TnbDoxyTitle.txt:2
ファイルタイム型.
Definition: TnbTime.h:893