-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCLSource.hpp
112 lines (99 loc) · 1.99 KB
/
CLSource.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#ifndef TCL_SOURCE_HPP
#define TCL_SOURCE_HPP
#include <string>
#include <fstream>
#include <iostream>
namespace tcl
{
/**
* ソースコードの種類
*/
enum class SourceType
{
Text, /// オンライン
Binary /// オフライン
};
/**
* ソースコードを扱うためのクラス
*/
class CLSource
{
private:
SourceType type;
std::string fileName;
std::string code;
std::string kernelName;
private:
void OpenFile()
{
std::ifstream ifst(fileName, std::ifstream::binary);
if (ifst.fail())
{
throw L"ファイルの読み込みに失敗しました";
}
code = std::string(
std::istreambuf_iterator<char>(ifst),
std::istreambuf_iterator<char>());
ifst.close();
}
public:
/**
* ソースコードの文字列を返す
* \return ソースコードの文字列
*/
inline const std::string& Code() const {
return code;
}
/**
* ソースコードの長さを返す
* \return ソースコードの長さ
* \note Code().size()と同じ
*/
inline const std::size_t Size() const {
return code.size();
}
/**
* ファイル名を返す
* \return ファイル名
*/
inline const std::string FileName() const {
return fileName;
}
/**
* ソースコードの種類を返す
* \return ソースコードの種類
*/
inline const SourceType Type() const {
return type;
}
/**
* カーネルの名前を返す
* \return カーネルの名前
*/
inline const std::string& KernelName() const{
return kernelName;
}
public:
/**
* ソースコードを管理するためのクラス
* \param[in] filename ファイル名
* \param[in] kernelName カーネル名
* \param[in] type ソースコードの種類
*/
CLSource(const std::string& filename, const std::string& kernelName, const SourceType type)
: fileName(filename), kernelName(kernelName), type(type)
{
OpenFile();
}
/**
* ソースコードを管理するためのクラス
* \param[in] code ソースコードの文字列
* \param[in] kernelName カーネル名
*/
CLSource(const std::string& code, const std::string& kernelName)
: kernelName(kernelName), type(SourceType::Text), code(code), fileName("")
{
}
};
}
#endif