00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
#ifndef WT_COFFEE_WIN_H
00022
#define WT_COFFEE_WIN_H
00023
00024
00025
#ifndef _WIN32_WINNT
00026 #define _WIN32_WINNT 0x0400
00027
#endif
00028
#include <windows.h>
00029
00030
00031
#ifndef ULONG_PTR
00032 typedef unsigned long ULONG_PTR;
00033
#endif
00034
00035
#ifndef INVALID_SET_FILE_POINTER
00036 #define INVALID_SET_FILE_POINTER ((DWORD)-1)
00037
#endif
00038
00039
#ifdef _MSC_VER
00040
#pragma warning ( disable:4355 )
00041
#endif
00042
00043
00044
#include <wefts_coffee_base.h>
00045
#include <wefts_os_windows.h>
00046
00047
namespace Wefts {
00048
00087 class OSFileFuncWin :
public OSFileFuncBase
00088 {
00089
protected:
00090
00091 HANDLE
m_handle;
00092 HANDLE
m_evtComplete;
00093
00094 LARGE_INTEGER
m_liSize;
00095 LARGE_INTEGER
m_liPos;
00096
00097
file_size_t internal_rw(
void *buffer,
const file_size_t len,
bool rw,
bool bFile );
00098 bool m_bOvlFiles;
00099
00100
public:
00101
OSFileFuncWin(
void *descriptor = 0 );
00102
00103 ~OSFileFuncWin() { CloseHandle(
m_evtComplete ); }
00104
00105
virtual CffStatus open(
00106 std::string filespec,
00107 OpenMode openMode = OM_RO,
00108 LockMode lockMode = LM_SHARED
00109 );
00110
00111
virtual CffStatus create(
00112 std::string filespec,
00113 CreateMode cMode = CM_ARCHIVE,
00114 LockMode lockMode = LM_EXCLUSIVE
00115 );
00116
00117
00121 inline virtual void getDescriptor(
void *data )
const
00122
{
00123 *static_cast<HANDLE *>(data) =
m_handle;
00124 }
00125
00128 inline virtual void setDescriptor(
void *data )
00129 {
00130
m_handle = *static_cast<HANDLE *>(data);
00131 }
00132
00133 virtual file_size_t read(
void *buffer,
const file_size_t len ) {
00134
return OSFileFuncWin::internal_rw( buffer, len,
true,
true );
00135 }
00136
00137 virtual file_size_t write(
void *buffer,
const file_size_t len )
00138 {
00139
return OSFileFuncWin::internal_rw( buffer, len,
false,
true );
00140 }
00141
00142
virtual file_size_t seek(
00143
const file_size_t position,
00144
const SeekWhence swFrom= SW_FROM_BEGIN
00145 );
00146
00147
virtual CffStatus close();
00148
00150 inline virtual void setStdIn() {
00151
m_handle = GetStdHandle( STD_INPUT_HANDLE );
00152
00153
if ( GetFileType(
m_handle ) == FILE_TYPE_CHAR )
00154
m_bOvlFiles =
false;
00155 }
00156
00158 inline virtual void setStdOut(){
00159
m_handle = GetStdHandle( STD_OUTPUT_HANDLE );
00160
00161
if ( GetFileType(
m_handle ) == FILE_TYPE_CHAR )
00162
m_bOvlFiles =
false;
00163 }
00164
00166 inline virtual void setStdErr(){
00167
m_handle = GetStdHandle( STD_ERROR_HANDLE );
00168
00169
if ( GetFileType(
m_handle ) == FILE_TYPE_CHAR )
00170
m_bOvlFiles =
false;
00171 }
00172 };
00173
00175
typedef OSFileFuncWin OSFileFunc;
00176
00178 }
00179
00180
#endif
00181
00182