source: dev/trunk/jenga/include/common/File.h@ 387

Last change on this file since 387 was 323, checked in by dai_9181, 17 years ago

Fileクラスを追加
ESC_DELEGATEを追加

File size: 875 bytes
RevLine 
[323]1#pragma once
2#pragma warning(disable : 4996)
3
4#include <vector>
5#include <string>
6
7#include <stdlib.h>
8#include <windows.h>
9
10#include <jenga/include/common/Exception.h>
11
12
13namespace Jenga{
14namespace Common{
15
16
17class File
18{
19 const std::string filePath;
20public:
21 File( const std::string &filePath )
22 : filePath( filePath )
23 {
24 }
25
26 std::string Read()
27 {
28 HANDLE hFile = CreateFile( filePath.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
29 if( hFile == INVALID_HANDLE_VALUE )
30 {
31 Jenga::Throw( filePath + " がオープンできません" );
32 }
33 int size = GetFileSize( hFile, NULL );
34
35 char *temp = static_cast<char *>(calloc( size + 1, 1 ));
36 DWORD dummy;
37 ReadFile( hFile, temp, size, &dummy, NULL );
38 CloseHandle(hFile);
39
40 std::string result = temp;
41 free( temp );
42
43 return result;
44 }
45};
46
47
48}}
Note: See TracBrowser for help on using the repository browser.