clover: Build fix for FreeBSD.
[mesa.git] / src / gallium / state_trackers / clover / core / error.hpp
1 //
2 // Copyright 2013 Francisco Jerez
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining a
5 // copy of this software and associated documentation files (the "Software"),
6 // to deal in the Software without restriction, including without limitation
7 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 // and/or sell copies of the Software, and to permit persons to whom the
9 // Software is furnished to do so, subject to the following conditions:
10 //
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 // OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 // OTHER DEALINGS IN THE SOFTWARE.
21 //
22
23 #ifndef CLOVER_CORE_ERROR_HPP
24 #define CLOVER_CORE_ERROR_HPP
25
26 #include "CL/cl.h"
27
28 #include <stdexcept>
29 #include <string>
30
31 namespace clover {
32 class command_queue;
33 class context;
34 class device;
35 class event;
36 class hard_event;
37 class soft_event;
38 class kernel;
39 class memory_obj;
40 class buffer;
41 class root_buffer;
42 class sub_buffer;
43 class image;
44 class image2d;
45 class image3d;
46 class platform;
47 class program;
48 class sampler;
49
50 ///
51 /// Class that represents an error that can be converted to an
52 /// OpenCL status code.
53 ///
54 class error : public std::runtime_error {
55 public:
56 error(cl_int code, std::string what = "") :
57 std::runtime_error(what), code(code) {
58 }
59
60 cl_int get() const {
61 return code;
62 }
63
64 protected:
65 cl_int code;
66 };
67
68 class build_error : public error {
69 public:
70 build_error(const std::string &what = "") :
71 error(CL_COMPILE_PROGRAM_FAILURE, what) {
72 }
73 };
74
75 template<typename O>
76 class invalid_object_error;
77
78 template<>
79 class invalid_object_error<command_queue> : public error {
80 public:
81 invalid_object_error(std::string what = "") :
82 error(CL_INVALID_COMMAND_QUEUE, what) {}
83 };
84
85 template<>
86 class invalid_object_error<context> : public error {
87 public:
88 invalid_object_error(std::string what = "") :
89 error(CL_INVALID_CONTEXT, what) {}
90 };
91
92 template<>
93 class invalid_object_error<device> : public error {
94 public:
95 invalid_object_error(std::string what = "") :
96 error(CL_INVALID_DEVICE, what) {}
97 };
98
99 template<>
100 class invalid_object_error<event> : public error {
101 public:
102 invalid_object_error(std::string what = "") :
103 error(CL_INVALID_EVENT, what) {}
104 };
105
106 template<>
107 class invalid_object_error<soft_event> : public error {
108 public:
109 invalid_object_error(std::string what = "") :
110 error(CL_INVALID_EVENT, what) {}
111 };
112
113 template<>
114 class invalid_object_error<kernel> : public error {
115 public:
116 invalid_object_error(std::string what = "") :
117 error(CL_INVALID_KERNEL, what) {}
118 };
119
120 template<>
121 class invalid_object_error<memory_obj> : public error {
122 public:
123 invalid_object_error(std::string what = "") :
124 error(CL_INVALID_MEM_OBJECT, what) {}
125 };
126
127 template<>
128 class invalid_object_error<buffer> : public error {
129 public:
130 invalid_object_error(std::string what = "") :
131 error(CL_INVALID_MEM_OBJECT, what) {}
132 };
133
134 template<>
135 class invalid_object_error<root_buffer> : public error {
136 public:
137 invalid_object_error(std::string what = "") :
138 error(CL_INVALID_MEM_OBJECT, what) {}
139 };
140
141 template<>
142 class invalid_object_error<sub_buffer> : public error {
143 public:
144 invalid_object_error(std::string what = "") :
145 error(CL_INVALID_MEM_OBJECT, what) {}
146 };
147
148 template<>
149 class invalid_object_error<image> : public error {
150 public:
151 invalid_object_error(std::string what = "") :
152 error(CL_INVALID_MEM_OBJECT, what) {}
153 };
154
155 template<>
156 class invalid_object_error<image2d> : public error {
157 public:
158 invalid_object_error(std::string what = "") :
159 error(CL_INVALID_MEM_OBJECT, what) {}
160 };
161
162 template<>
163 class invalid_object_error<image3d> : public error {
164 public:
165 invalid_object_error(std::string what = "") :
166 error(CL_INVALID_MEM_OBJECT, what) {}
167 };
168
169 template<>
170 class invalid_object_error<platform> : public error {
171 public:
172 invalid_object_error(std::string what = "") :
173 error(CL_INVALID_PLATFORM, what) {}
174 };
175
176 template<>
177 class invalid_object_error<program> : public error {
178 public:
179 invalid_object_error(std::string what = "") :
180 error(CL_INVALID_PROGRAM, what) {}
181 };
182
183 template<>
184 class invalid_object_error<sampler> : public error {
185 public:
186 invalid_object_error(std::string what = "") :
187 error(CL_INVALID_SAMPLER, what) {}
188 };
189
190 class invalid_wait_list_error : public error {
191 public:
192 invalid_wait_list_error(std::string what = "") :
193 error(CL_INVALID_EVENT_WAIT_LIST, what) {}
194 };
195 }
196
197 #endif