1c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez/*******************************************************************************
2c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * Copyright (c) 2008-2010 The Khronos Group Inc.
3c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *
4c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * Permission is hereby granted, free of charge, to any person obtaining a
5c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * copy of this software and/or associated documentation files (the
6c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * "Materials"), to deal in the Materials without restriction, including
7c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * without limitation the rights to use, copy, modify, merge, publish,
8c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * distribute, sublicense, and/or sell copies of the Materials, and to
9c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * permit persons to whom the Materials are furnished to do so, subject to
10c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * the following conditions:
11c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *
12c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * The above copyright notice and this permission notice shall be included
13c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * in all copies or substantial portions of the Materials.
14c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *
15c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
22c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez ******************************************************************************/
23c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
24c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez/*! \file
25c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *
26c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *   \brief C++ bindings for OpenCL 1.0 (rev 48) and OpenCL 1.1 (rev 33)
27c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *   \author Benedict R. Gaster and Laurent Morichetti
28c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *
29c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *   Additions and fixes from Brian Cole, March 3rd 2010.
30c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *
31c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *   \version 1.1
32c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *   \date June 2010
33c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *
34c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *   Optional extension support
35c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *
36c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *         cl
37c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *         cl_ext_device_fission
38c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *				#define USE_CL_DEVICE_FISSION
39c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez */
40c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
41c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez/*! \mainpage
42c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * \section intro Introduction
43c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * For many large applications C++ is the language of choice and so it seems
44c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * reasonable to define C++ bindings for OpenCL.
45c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *
46c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *
47c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * The interface is contained with a single C++ header file \em cl.hpp and all
48c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * definitions are contained within the namespace \em cl. There is no additional
49c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * requirement to include \em cl.h and to use either the C++ or original C
50c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * bindings it is enough to simply include \em cl.hpp.
51c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *
52c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * The bindings themselves are lightweight and correspond closely to the
53c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * underlying C API. Using the C++ bindings introduces no additional execution
54c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * overhead.
55c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *
56c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * For detail documentation on the bindings see:
57c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *
58c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * The OpenCL C++ Wrapper API 1.1 (revision 04)
59c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *  http://www.khronos.org/registry/cl/specs/opencl-cplusplus-1.1.pdf
60c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *
61c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * \section example Example
62c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *
63c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * The following example shows a general use case for the C++
64c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * bindings, including support for the optional exception feature and
65c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * also the supplied vector and string classes, see following sections for
66c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * decriptions of these features.
67c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *
68c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * \code
69c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * #define __CL_ENABLE_EXCEPTIONS
70c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *
71c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * #if defined(__APPLE__) || defined(__MACOSX)
72c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * #include <OpenCL/cl.hpp>
73c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * #else
74c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * #include <CL/cl.hpp>
75c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * #endif
76c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * #include <cstdio>
77c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * #include <cstdlib>
78c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * #include <iostream>
79c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *
80c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *  const char * helloStr  = "__kernel void "
81c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *                           "hello(void) "
82c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *                           "{ "
83c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *                           "  "
84c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *                           "} ";
85c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *
86c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *  int
87c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *  main(void)
88c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *  {
89c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *     cl_int err = CL_SUCCESS;
90c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *     try {
91c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *
92c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *       std::vector<cl::Platform> platforms;
93c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *       cl::Platform::get(&platforms);
94c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *       if (platforms.size() == 0) {
95c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *           std::cout << "Platform size 0\n";
96c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *           return -1;
97c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *       }
98c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *
99c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *       cl_context_properties properties[] =
100c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *          { CL_CONTEXT_PLATFORM, (cl_context_properties)(platforms[0])(), 0};
101c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *       cl::Context context(CL_DEVICE_TYPE_CPU, properties);
102c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *
103c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *       std::vector<cl::Device> devices = context.getInfo<CL_CONTEXT_DEVICES>();
104c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *
105c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *       cl::Program::Sources source(1,
106c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *           std::make_pair(helloStr,strlen(helloStr)));
107c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *       cl::Program program_ = cl::Program(context, source);
108c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *       program_.build(devices);
109c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *
110c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *       cl::Kernel kernel(program_, "hello", &err);
111c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *
112c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *       cl::Event event;
113c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *       cl::CommandQueue queue(context, devices[0], 0, &err);
114c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *       queue.enqueueNDRangeKernel(
115c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *           kernel,
116c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *           cl::NullRange,
117c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *           cl::NDRange(4,4),
118c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *           cl::NullRange,
119c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *           NULL,
120c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *           &event);
121c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *
122c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *       event.wait();
123c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *     }
124c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *     catch (cl::Error err) {
125c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *        std::cerr
126c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *           << "ERROR: "
127c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *           << err.what()
128c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *           << "("
129c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *           << err.err()
130c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *           << ")"
131c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *           << std::endl;
132c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *     }
133c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *
134c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *    return EXIT_SUCCESS;
135c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *  }
136c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *
137c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * \endcode
138c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *
139c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez */
140c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#ifndef CL_HPP_
141c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define CL_HPP_
142c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
143c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#ifdef _WIN32
144c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#include <windows.h>
145c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#include <malloc.h>
146c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#if defined(USE_DX_INTEROP)
147c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#include <CL/cl_d3d10.h>
148c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#endif
149c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#endif // _WIN32
150c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
151c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez//
152c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#if defined(USE_CL_DEVICE_FISSION)
153c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#include <CL/cl_ext.h>
154c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#endif
155c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
156c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#if defined(__APPLE__) || defined(__MACOSX)
157c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#include <OpenGL/OpenGL.h>
158c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#include <OpenCL/opencl.h>
159c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#else
160c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#include <GL/gl.h>
161c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#include <CL/opencl.h>
162c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#endif // !__APPLE__
163c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
164c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#if !defined(CL_CALLBACK)
165c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define CL_CALLBACK
166c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#endif //CL_CALLBACK
167c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
168c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#include <utility>
169c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
170c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#if !defined(__NO_STD_VECTOR)
171c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#include <vector>
172c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#endif
173c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
174c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#if !defined(__NO_STD_STRING)
175c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#include <string>
176c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#endif
177c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
178c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#if defined(linux) || defined(__APPLE__) || defined(__MACOSX)
179c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez# include <alloca.h>
180c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#endif // linux
181c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
182c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#include <cstring>
183c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
184c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez/*! \namespace cl
185c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *
186c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * \brief The OpenCL C++ bindings are defined within this namespace.
187c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *
188c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez */
189c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jereznamespace cl {
190c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
191c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __INIT_CL_EXT_FCN_PTR(name) \
192c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    if(!pfn_##name) { \
193c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        pfn_##name = (PFN_##name) \
194c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            clGetExtensionFunctionAddress(#name); \
195c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        if(!pfn_##name) { \
196c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        } \
197c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    }
198c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
199c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerezclass Program;
200c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerezclass Device;
201c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerezclass Context;
202c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerezclass CommandQueue;
203c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerezclass Memory;
204c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
205c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#if defined(__CL_ENABLE_EXCEPTIONS)
206c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#include <exception>
207c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez/*! \class Error
208c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * \brief Exception class
209c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez */
210c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerezclass Error : public std::exception
211c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez{
212c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerezprivate:
213c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    cl_int err_;
214c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    const char * errStr_;
215c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerezpublic:
216c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    /*! Create a new CL error exception for a given error code
217c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez     *  and corresponding message.
218c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez     */
219c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    Error(cl_int err, const char * errStr = NULL) : err_(err), errStr_(errStr)
220c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    {}
221c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
222c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    ~Error() throw() {}
223c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
224c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    /*! \brief Get error string associated with exception
225c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez     *
226c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez     * \return A memory pointer to the error message string.
227c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez     */
228c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    virtual const char * what() const throw ()
229c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    {
230c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        if (errStr_ == NULL) {
231c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            return "empty";
232c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        }
233c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        else {
234c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            return errStr_;
235c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        }
236c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    }
237c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
238c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    /*! \brief Get error code associated with exception
239c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez     *
240c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez     *  \return The error code.
241c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez     */
242c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    const cl_int err(void) const { return err_; }
243c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez};
244c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
245c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __ERR_STR(x) #x
246c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#else
247c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __ERR_STR(x) NULL
248c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#endif // __CL_ENABLE_EXCEPTIONS
249c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
250c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez//! \cond DOXYGEN_DETAIL
251c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#if !defined(__CL_USER_OVERRIDE_ERROR_STRINGS)
252c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __GET_DEVICE_INFO_ERR               __ERR_STR(clgetDeviceInfo)
253c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __GET_PLATFORM_INFO_ERR             __ERR_STR(clGetPlatformInfo)
254c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __GET_DEVICE_IDS_ERR                __ERR_STR(clGetDeviceIDs)
255c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __GET_PLATFORM_IDS_ERR              __ERR_STR(clGetPlatformIDs)
256c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __GET_CONTEXT_INFO_ERR              __ERR_STR(clGetContextInfo)
257c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __GET_EVENT_INFO_ERR                __ERR_STR(clGetEventInfo)
258c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __GET_EVENT_PROFILE_INFO_ERR        __ERR_STR(clGetEventProfileInfo)
259c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __GET_MEM_OBJECT_INFO_ERR           __ERR_STR(clGetMemObjectInfo)
260c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __GET_IMAGE_INFO_ERR                __ERR_STR(clGetImageInfo)
261c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __GET_SAMPLER_INFO_ERR              __ERR_STR(clGetSamplerInfo)
262c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __GET_KERNEL_INFO_ERR               __ERR_STR(clGetKernelInfo)
263c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __GET_KERNEL_WORK_GROUP_INFO_ERR    __ERR_STR(clGetKernelWorkGroupInfo)
264c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __GET_PROGRAM_INFO_ERR              __ERR_STR(clGetProgramInfo)
265c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __GET_PROGRAM_BUILD_INFO_ERR        __ERR_STR(clGetProgramBuildInfo)
266c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __GET_COMMAND_QUEUE_INFO_ERR        __ERR_STR(clGetCommandQueueInfo)
267c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
268c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __CREATE_CONTEXT_FROM_TYPE_ERR      __ERR_STR(clCreateContextFromType)
269c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __GET_SUPPORTED_IMAGE_FORMATS_ERR   __ERR_STR(clGetSupportedImageFormats)
270c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
271c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __CREATE_BUFFER_ERR                 __ERR_STR(clCreateBuffer)
272c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __CREATE_SUBBUFFER_ERR              __ERR_STR(clCreateSubBuffer)
273c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __CREATE_GL_BUFFER_ERR              __ERR_STR(clCreateFromGLBuffer)
274c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __GET_GL_OBJECT_INFO_ERR            __ERR_STR(clGetGLObjectInfo)
275c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __CREATE_IMAGE2D_ERR                __ERR_STR(clCreateImage2D)
276c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __CREATE_IMAGE3D_ERR                __ERR_STR(clCreateImage3D)
277c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __CREATE_SAMPLER_ERR                __ERR_STR(clCreateSampler)
278c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR __ERR_STR(clSetMemObjectDestructorCallback)
279c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
280c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __CREATE_USER_EVENT_ERR             __ERR_STR(clCreateUserEvent)
281c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __SET_USER_EVENT_STATUS_ERR         __ERR_STR(clSetUserEventStatus)
282c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __SET_EVENT_CALLBACK_ERR            __ERR_STR(clSetEventCallback)
283c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __WAIT_FOR_EVENTS_ERR               __ERR_STR(clWaitForEvents)
284c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
285c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __CREATE_KERNEL_ERR                 __ERR_STR(clCreateKernel)
286c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __SET_KERNEL_ARGS_ERR               __ERR_STR(clSetKernelArg)
287c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __CREATE_PROGRAM_WITH_SOURCE_ERR    __ERR_STR(clCreateProgramWithSource)
288c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __CREATE_PROGRAM_WITH_BINARY_ERR    __ERR_STR(clCreateProgramWithBinary)
289c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __BUILD_PROGRAM_ERR                 __ERR_STR(clBuildProgram)
290c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __CREATE_KERNELS_IN_PROGRAM_ERR     __ERR_STR(clCreateKernelsInProgram)
291c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
292c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __CREATE_COMMAND_QUEUE_ERR          __ERR_STR(clCreateCommandQueue)
293c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __SET_COMMAND_QUEUE_PROPERTY_ERR    __ERR_STR(clSetCommandQueueProperty)
294c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __ENQUEUE_READ_BUFFER_ERR           __ERR_STR(clEnqueueReadBuffer)
295c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __ENQUEUE_READ_BUFFER_RECT_ERR      __ERR_STR(clEnqueueReadBufferRect)
296c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __ENQUEUE_WRITE_BUFFER_ERR          __ERR_STR(clEnqueueWriteBuffer)
297c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __ENQUEUE_WRITE_BUFFER_RECT_ERR     __ERR_STR(clEnqueueWriteBufferRect)
298c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __ENQEUE_COPY_BUFFER_ERR            __ERR_STR(clEnqueueCopyBuffer)
299c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __ENQEUE_COPY_BUFFER_RECT_ERR       __ERR_STR(clEnqueueCopyBufferRect)
300c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __ENQUEUE_READ_IMAGE_ERR            __ERR_STR(clEnqueueReadImage)
301c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __ENQUEUE_WRITE_IMAGE_ERR           __ERR_STR(clEnqueueWriteImage)
302c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __ENQUEUE_COPY_IMAGE_ERR            __ERR_STR(clEnqueueCopyImage)
303c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR  __ERR_STR(clEnqueueCopyImageToBuffer)
304c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR  __ERR_STR(clEnqueueCopyBufferToImage)
305c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __ENQUEUE_MAP_BUFFER_ERR            __ERR_STR(clEnqueueMapBuffer)
306c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __ENQUEUE_MAP_IMAGE_ERR             __ERR_STR(clEnqueueMapImage)
307c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __ENQUEUE_UNMAP_MEM_OBJECT_ERR      __ERR_STR(clEnqueueUnMapMemObject)
308c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __ENQUEUE_NDRANGE_KERNEL_ERR        __ERR_STR(clEnqueueNDRangeKernel)
309c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __ENQUEUE_TASK_ERR                  __ERR_STR(clEnqueueTask)
310c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __ENQUEUE_NATIVE_KERNEL             __ERR_STR(clEnqueueNativeKernel)
311c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __ENQUEUE_MARKER_ERR                __ERR_STR(clEnqueueMarker)
312c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __ENQUEUE_WAIT_FOR_EVENTS_ERR       __ERR_STR(clEnqueueWaitForEvents)
313c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __ENQUEUE_BARRIER_ERR               __ERR_STR(clEnqueueBarrier)
314c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
315c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __ENQUEUE_ACQUIRE_GL_ERR            __ERR_STR(clEnqueueAcquireGLObjects)
316c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __ENQUEUE_RELEASE_GL_ERR            __ERR_STR(clEnqueueReleaseGLObjects)
317c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
318c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __UNLOAD_COMPILER_ERR               __ERR_STR(clUnloadCompiler)
319c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
320c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __FLUSH_ERR                         __ERR_STR(clFlush)
321c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __FINISH_ERR                        __ERR_STR(clFinish)
322c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
323c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __CREATE_SUB_DEVICES                __ERR_STR(clCreateSubDevicesEXT)
324c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#endif // __CL_USER_OVERRIDE_ERROR_STRINGS
325c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez//! \endcond
326c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
327c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez/*! \class string
328c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * \brief Simple string class, that provides a limited subset of std::string
329c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * functionality but avoids many of the issues that come with that class.
330c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez */
331c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerezclass string
332c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez{
333c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerezprivate:
334c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    ::size_t size_;
335c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    char * str_;
336c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerezpublic:
337c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    string(void) : size_(0), str_(NULL)
338c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    {
339c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    }
340c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
341c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    string(char * str, ::size_t size) :
342c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        size_(size),
343c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        str_(NULL)
344c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    {
345c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        str_ = new char[size_+1];
346c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        if (str_ != NULL) {
347c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            memcpy(str_, str, size_  * sizeof(char));
348c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            str_[size_] = '\0';
349c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        }
350c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        else {
351c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            size_ = 0;
352c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        }
353c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    }
354c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
355c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    string(char * str) :
356c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        str_(NULL)
357c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    {
358c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        size_= ::strlen(str);
359c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        str_ = new char[size_ + 1];
360c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        if (str_ != NULL) {
361c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            memcpy(str_, str, (size_ + 1) * sizeof(char));
362c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        }
363c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        else {
364c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            size_ = 0;
365c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        }
366c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    }
367c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
368c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    string& operator=(const string& rhs)
369c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    {
370c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        if (this == &rhs) {
371c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            return *this;
372c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        }
373c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
374c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        if (rhs.size_ == 0 || rhs.str_ == NULL) {
375c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            size_ = 0;
376c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            str_  = NULL;
377c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        }
378c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        else {
379c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            size_ = rhs.size_;
380c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            str_ = new char[size_ + 1];
381c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            if (str_ != NULL) {
382c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez                memcpy(str_, rhs.str_, (size_ + 1) * sizeof(char));
383c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            }
384c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            else {
385c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez                size_ = 0;
386c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            }
387c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        }
388c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
389c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        return *this;
390c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    }
391c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
392c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    string(const string& rhs)
393c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    {
394c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        *this = rhs;
395c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    }
396c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
397c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    ~string()
398c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    {
399c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        if (str_ != NULL) {
400c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            delete[] str_;
401c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        }
402c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    }
403c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
404c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    ::size_t size(void) const   { return size_; }
405c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    ::size_t length(void) const { return size(); }
406c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
407c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    const char * c_str(void) const { return (str_) ? str_ : "";}
408c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez};
409c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
410c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#if !defined(__USE_DEV_STRING) && !defined(__NO_STD_STRING)
411c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#include <string>
412c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jereztypedef std::string STRING_CLASS;
413c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#elif !defined(__USE_DEV_STRING)
414c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jereztypedef cl::string STRING_CLASS;
415c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#endif
416c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
417c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#if !defined(__USE_DEV_VECTOR) && !defined(__NO_STD_VECTOR)
418c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#include <vector>
419c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define VECTOR_CLASS std::vector
420c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#elif !defined(__USE_DEV_VECTOR)
421c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define VECTOR_CLASS cl::vector
422c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#endif
423c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
424c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#if !defined(__MAX_DEFAULT_VECTOR_SIZE)
425c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __MAX_DEFAULT_VECTOR_SIZE 10
426c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#endif
427c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
428c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez/*! \class vector
429c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * \brief Fixed sized vector implementation that mirroring
430c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * std::vector functionality.
431c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez */
432c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jereztemplate <typename T, unsigned int N = __MAX_DEFAULT_VECTOR_SIZE>
433c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerezclass vector
434c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez{
435c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerezprivate:
436c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    T data_[N];
437c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    unsigned int size_;
438c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    bool empty_;
439c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerezpublic:
440c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    vector() :
441c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        size_(-1),
442c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        empty_(true)
443c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    {}
444c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
445c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    ~vector() {}
446c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
447c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    unsigned int size(void) const
448c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    {
449c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        return size_ + 1;
450c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    }
451c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
452c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    void clear()
453c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    {
454c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        size_ = -1;
455c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        empty_ = true;
456c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    }
457c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
458c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    void push_back (const T& x)
459c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    {
460c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        if (size() < N) {
461c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            size_++;
462c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            data_[size_] = x;
463c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            empty_ = false;
464c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        }
465c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    }
466c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
467c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    void pop_back(void)
468c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    {
469c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        if (!empty_) {
470c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            data_[size_].~T();
471c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            size_--;
472c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            if (size_ == -1) {
473c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez                empty_ = true;
474c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            }
475c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        }
476c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    }
477c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
478c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    vector(const vector<T, N>& vec) :
479c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        size_(vec.size_),
480c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        empty_(vec.empty_)
481c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    {
482c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        if (!empty_) {
483c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            memcpy(&data_[0], &vec.data_[0], size() * sizeof(T));
484c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        }
485c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    }
486c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
487c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    vector(unsigned int size, const T& val = T()) :
488c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        size_(-1),
489c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        empty_(true)
490c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    {
491c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        for (unsigned int i = 0; i < size; i++) {
492c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            push_back(val);
493c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        }
494c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    }
495c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
496c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    vector<T, N>& operator=(const vector<T, N>& rhs)
497c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    {
498c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        if (this == &rhs) {
499c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            return *this;
500c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        }
501c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
502c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        size_  = rhs.size_;
503c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        empty_ = rhs.empty_;
504c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
505c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        if (!empty_) {
506c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            memcpy(&data_[0], &rhs.data_[0], size() * sizeof(T));
507c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        }
508c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
509c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        return *this;
510c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    }
511c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
512c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    bool operator==(vector<T,N> &vec)
513c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    {
514c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        if (empty_ && vec.empty_) {
515c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            return true;
516c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        }
517c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
518c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        if (size() != vec.size()) {
519c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            return false;
520c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        }
521c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
522c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        return memcmp(&data_[0], &vec.data_[0], size() * sizeof(T)) == 0 ? true : false;
523c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    }
524c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
525c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    operator T* ()             { return data_; }
526c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    operator const T* () const { return data_; }
527c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
528c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    bool empty (void) const
529c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    {
530c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        return empty_;
531c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    }
532c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
533c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    unsigned int max_size (void) const
534c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    {
535c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        return N;
536c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    }
537c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
538c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    unsigned int capacity () const
539c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    {
540c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        return sizeof(T) * N;
541c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    }
542c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
543c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    T& operator[](int index)
544c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    {
545c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        return data_[index];
546c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    }
547c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
548c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    T operator[](int index) const
549c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    {
550c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        return data_[index];
551c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    }
552c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
553c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    template<class I>
554c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    void assign(I start, I end)
555c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    {
556c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        clear();
557c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        while(start < end) {
558c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            push_back(*start);
559c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            start++;
560c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        }
561c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    }
562c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
563c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    /*! \class iterator
564c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez     * \brief Iterator class for vectors
565c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez     */
566c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    class iterator
567c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    {
568c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    private:
569c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        vector<T,N> vec_;
570c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        int index_;
571c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        bool initialized_;
572c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    public:
573c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        iterator(void) :
574c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            index_(-1),
575c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            initialized_(false)
576c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        {
577c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            index_ = -1;
578c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            initialized_ = false;
579c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        }
580c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
581c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        ~iterator(void) {}
582c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
583c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        static iterator begin(vector<T,N> &vec)
584c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        {
585c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            iterator i;
586c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
587c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            if (!vec.empty()) {
588c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez                i.index_ = 0;
589c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            }
590c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
591c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            i.vec_ = vec;
592c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            i.initialized_ = true;
593c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            return i;
594c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        }
595c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
596c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        static iterator end(vector<T,N> &vec)
597c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        {
598c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            iterator i;
599c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
600c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            if (!vec.empty()) {
601c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez                i.index_ = vec.size();
602c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            }
603c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            i.vec_ = vec;
604c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            i.initialized_ = true;
605c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            return i;
606c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        }
607c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
608c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        bool operator==(iterator i)
609c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        {
610c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            return ((vec_ == i.vec_) &&
611c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez                    (index_ == i.index_) &&
612c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez                    (initialized_ == i.initialized_));
613c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        }
614c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
615c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        bool operator!=(iterator i)
616c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        {
617c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            return (!(*this==i));
618c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        }
619c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
620c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        void operator++()
621c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        {
622c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            index_++;
623c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        }
624c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
625c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        void operator++(int x)
626c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        {
627c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            index_ += x;
628c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        }
629c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
630c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        void operator--()
631c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        {
632c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            index_--;
633c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        }
634c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
635c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        void operator--(int x)
636c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        {
637c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            index_ -= x;
638c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        }
639c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
640c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        T operator *()
641c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        {
642c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            return vec_[index_];
643c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        }
644c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    };
645c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
646c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    iterator begin(void)
647c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    {
648c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        return iterator::begin(*this);
649c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    }
650c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
651c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    iterator end(void)
652c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    {
653c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        return iterator::end(*this);
654c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    }
655c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
656c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    T& front(void)
657c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    {
658c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        return data_[0];
659c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    }
660c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
661c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    T& back(void)
662c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    {
663c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        return data_[size_];
664c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    }
665c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
666c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    const T& front(void) const
667c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    {
668c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        return data_[0];
669c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    }
670c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
671c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    const T& back(void) const
672c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    {
673c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        return data_[size_];
674c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    }
675c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez};
676c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
677c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez/*!
678c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * \brief size_t class used to interface between C++ and
679c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * OpenCL C calls that require arrays of size_t values, who's
680c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * size is known statically.
681c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez */
682c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jereztemplate <int N>
683c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerezstruct size_t : public cl::vector< ::size_t, N> { };
684c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
685c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jereznamespace detail {
686c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
687c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez// GetInfo help struct
688c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jereztemplate <typename Functor, typename T>
689c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerezstruct GetInfoHelper
690c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez{
691c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    static cl_int
692c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    get(Functor f, cl_uint name, T* param)
693c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    {
694c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        return f(name, sizeof(T), param, NULL);
695c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    }
696c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez};
697c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
698c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez// Specialized GetInfoHelper for VECTOR_CLASS params
699c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jereztemplate <typename Func, typename T>
700c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerezstruct GetInfoHelper<Func, VECTOR_CLASS<T> >
701c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez{
702c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    static cl_int get(Func f, cl_uint name, VECTOR_CLASS<T>* param)
703c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    {
704c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        ::size_t required;
705c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        cl_int err = f(name, 0, NULL, &required);
706c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        if (err != CL_SUCCESS) {
707c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            return err;
708c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        }
709c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
710c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        T* value = (T*) alloca(required);
711c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        err = f(name, required, value, NULL);
712c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        if (err != CL_SUCCESS) {
713c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            return err;
714c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        }
715c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
716c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        param->assign(&value[0], &value[required/sizeof(T)]);
717c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        return CL_SUCCESS;
718c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    }
719c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez};
720c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
721c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez// Specialized for getInfo<CL_PROGRAM_BINARIES>
722c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jereztemplate <typename Func>
723c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerezstruct GetInfoHelper<Func, VECTOR_CLASS<char *> >
724c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez{
725c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    static cl_int
726c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    get(Func f, cl_uint name, VECTOR_CLASS<char *>* param)
727c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    {
728c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez      cl_uint err = f(name, param->size() * sizeof(char *), &(*param)[0], NULL);
729c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez      if (err != CL_SUCCESS) {
730c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        return err;
731c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez      }
732c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
733c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez      return CL_SUCCESS;
734c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    }
735c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez};
736c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
737c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez// Specialized GetInfoHelper for STRING_CLASS params
738c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jereztemplate <typename Func>
739c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerezstruct GetInfoHelper<Func, STRING_CLASS>
740c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez{
741c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    static cl_int get(Func f, cl_uint name, STRING_CLASS* param)
742c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    {
743c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        ::size_t required;
744c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        cl_int err = f(name, 0, NULL, &required);
745c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        if (err != CL_SUCCESS) {
746c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            return err;
747c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        }
748c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
749c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        char* value = (char*) alloca(required);
750c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        err = f(name, required, value, NULL);
751c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        if (err != CL_SUCCESS) {
752c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            return err;
753c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        }
754c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
755c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        *param = value;
756c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        return CL_SUCCESS;
757c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    }
758c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez};
759c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
760c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __GET_INFO_HELPER_WITH_RETAIN(CPP_TYPE) \
761c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jereznamespace detail { \
762c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jereztemplate <typename Func> \
763c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerezstruct GetInfoHelper<Func, CPP_TYPE> \
764c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez{ \
765c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    static cl_int get(Func f, cl_uint name, CPP_TYPE* param) \
766c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    { \
767c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez      cl_uint err = f(name, sizeof(CPP_TYPE), param, NULL); \
768c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez      if (err != CL_SUCCESS) { \
769c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        return err; \
770c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez      } \
771c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez      \
772c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez      return ReferenceHandler<CPP_TYPE::cl_type>::retain((*param)()); \
773c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    } \
774c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez}; \
775c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez}
776c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
777c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
778c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __PARAM_NAME_INFO_1_0(F) \
779c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_platform_info, CL_PLATFORM_PROFILE, STRING_CLASS) \
780c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_platform_info, CL_PLATFORM_VERSION, STRING_CLASS) \
781c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_platform_info, CL_PLATFORM_NAME, STRING_CLASS) \
782c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_platform_info, CL_PLATFORM_VENDOR, STRING_CLASS) \
783c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_platform_info, CL_PLATFORM_EXTENSIONS, STRING_CLASS) \
784c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    \
785c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_TYPE, cl_device_type) \
786c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_VENDOR_ID, cl_uint) \
787c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_MAX_COMPUTE_UNITS, cl_uint) \
788c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, cl_uint) \
789c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_MAX_WORK_GROUP_SIZE, ::size_t) \
790c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_SIZES, VECTOR_CLASS< ::size_t>) \
791c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR, cl_uint) \
792c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT, cl_uint) \
793c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT, cl_uint) \
794c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG, cl_uint) \
795c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT, cl_uint) \
796c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE, cl_uint) \
797c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_MAX_CLOCK_FREQUENCY, cl_uint) \
798c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_ADDRESS_BITS, cl_bitfield) \
799c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_MAX_READ_IMAGE_ARGS, cl_uint) \
800c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_MAX_WRITE_IMAGE_ARGS, cl_uint) \
801c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_MAX_MEM_ALLOC_SIZE, cl_ulong) \
802c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_WIDTH, ::size_t) \
803c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_HEIGHT, ::size_t) \
804c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_WIDTH, ::size_t) \
805c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_HEIGHT, ::size_t) \
806c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_DEPTH, ::size_t) \
807c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_IMAGE_SUPPORT, cl_uint) \
808c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_MAX_PARAMETER_SIZE, ::size_t) \
809c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_MAX_SAMPLERS, cl_uint) \
810c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_MEM_BASE_ADDR_ALIGN, cl_uint) \
811c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE, cl_uint) \
812c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_SINGLE_FP_CONFIG, cl_device_fp_config) \
813c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_TYPE, cl_device_mem_cache_type) \
814c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE, cl_uint)\
815c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_SIZE, cl_ulong) \
816c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_GLOBAL_MEM_SIZE, cl_ulong) \
817c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE, cl_ulong) \
818c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_MAX_CONSTANT_ARGS, cl_uint) \
819c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_LOCAL_MEM_TYPE, cl_device_local_mem_type) \
820c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE, cl_ulong) \
821c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_ERROR_CORRECTION_SUPPORT, cl_bool) \
822c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_PROFILING_TIMER_RESOLUTION, ::size_t) \
823c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_ENDIAN_LITTLE, cl_bool) \
824c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_AVAILABLE, cl_bool) \
825c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_COMPILER_AVAILABLE, cl_bool) \
826c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_EXECUTION_CAPABILITIES, cl_device_exec_capabilities) \
827c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_QUEUE_PROPERTIES, cl_command_queue_properties) \
828c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_PLATFORM, cl_platform_id) \
829c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_NAME, STRING_CLASS) \
830c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_VENDOR, STRING_CLASS) \
831c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DRIVER_VERSION, STRING_CLASS) \
832c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_PROFILE, STRING_CLASS) \
833c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_VERSION, STRING_CLASS) \
834c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_EXTENSIONS, STRING_CLASS) \
835c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    \
836c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_context_info, CL_CONTEXT_REFERENCE_COUNT, cl_uint) \
837c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_context_info, CL_CONTEXT_DEVICES, VECTOR_CLASS<Device>) \
838c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_context_info, CL_CONTEXT_PROPERTIES, VECTOR_CLASS<cl_context_properties>) \
839c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    \
840c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_event_info, CL_EVENT_COMMAND_QUEUE, cl::CommandQueue) \
841c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_event_info, CL_EVENT_COMMAND_TYPE, cl_command_type) \
842c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_event_info, CL_EVENT_REFERENCE_COUNT, cl_uint) \
843c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_event_info, CL_EVENT_COMMAND_EXECUTION_STATUS, cl_uint) \
844c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    \
845c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_profiling_info, CL_PROFILING_COMMAND_QUEUED, cl_ulong) \
846c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_profiling_info, CL_PROFILING_COMMAND_SUBMIT, cl_ulong) \
847c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_profiling_info, CL_PROFILING_COMMAND_START, cl_ulong) \
848c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_profiling_info, CL_PROFILING_COMMAND_END, cl_ulong) \
849c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    \
850c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_mem_info, CL_MEM_TYPE, cl_mem_object_type) \
851c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_mem_info, CL_MEM_FLAGS, cl_mem_flags) \
852c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_mem_info, CL_MEM_SIZE, ::size_t) \
853c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_mem_info, CL_MEM_HOST_PTR, void*) \
854c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_mem_info, CL_MEM_MAP_COUNT, cl_uint) \
855c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_mem_info, CL_MEM_REFERENCE_COUNT, cl_uint) \
856c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_mem_info, CL_MEM_CONTEXT, cl::Context) \
857c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    \
858c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_image_info, CL_IMAGE_FORMAT, cl_image_format) \
859c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_image_info, CL_IMAGE_ELEMENT_SIZE, ::size_t) \
860c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_image_info, CL_IMAGE_ROW_PITCH, ::size_t) \
861c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_image_info, CL_IMAGE_SLICE_PITCH, ::size_t) \
862c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_image_info, CL_IMAGE_WIDTH, ::size_t) \
863c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_image_info, CL_IMAGE_HEIGHT, ::size_t) \
864c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_image_info, CL_IMAGE_DEPTH, ::size_t) \
865c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    \
866c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_sampler_info, CL_SAMPLER_REFERENCE_COUNT, cl_uint) \
867c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_sampler_info, CL_SAMPLER_CONTEXT, cl::Context) \
868c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_sampler_info, CL_SAMPLER_NORMALIZED_COORDS, cl_addressing_mode) \
869c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_sampler_info, CL_SAMPLER_ADDRESSING_MODE, cl_filter_mode) \
870c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_sampler_info, CL_SAMPLER_FILTER_MODE, cl_bool) \
871c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    \
872c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_program_info, CL_PROGRAM_REFERENCE_COUNT, cl_uint) \
873c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_program_info, CL_PROGRAM_CONTEXT, cl::Context) \
874c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_program_info, CL_PROGRAM_NUM_DEVICES, cl_uint) \
875c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_program_info, CL_PROGRAM_DEVICES, VECTOR_CLASS<cl_device_id>) \
876c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_program_info, CL_PROGRAM_SOURCE, STRING_CLASS) \
877c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_program_info, CL_PROGRAM_BINARY_SIZES, VECTOR_CLASS< ::size_t>) \
878c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_program_info, CL_PROGRAM_BINARIES, VECTOR_CLASS<char *>) \
879c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    \
880c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_program_build_info, CL_PROGRAM_BUILD_STATUS, cl_build_status) \
881c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_program_build_info, CL_PROGRAM_BUILD_OPTIONS, STRING_CLASS) \
882c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_program_build_info, CL_PROGRAM_BUILD_LOG, STRING_CLASS) \
883c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    \
884c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_kernel_info, CL_KERNEL_FUNCTION_NAME, STRING_CLASS) \
885c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_kernel_info, CL_KERNEL_NUM_ARGS, cl_uint) \
886c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_kernel_info, CL_KERNEL_REFERENCE_COUNT, cl_uint) \
887c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_kernel_info, CL_KERNEL_CONTEXT, cl::Context) \
888c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_kernel_info, CL_KERNEL_PROGRAM, cl::Program) \
889c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    \
890c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_kernel_work_group_info, CL_KERNEL_WORK_GROUP_SIZE, ::size_t) \
891c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_kernel_work_group_info, CL_KERNEL_COMPILE_WORK_GROUP_SIZE, cl::size_t<3>) \
892c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_kernel_work_group_info, CL_KERNEL_LOCAL_MEM_SIZE, cl_ulong) \
893c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    \
894c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_command_queue_info, CL_QUEUE_CONTEXT, cl::Context) \
895c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_command_queue_info, CL_QUEUE_DEVICE, cl::Device) \
896c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_command_queue_info, CL_QUEUE_REFERENCE_COUNT, cl_uint) \
897c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_command_queue_info, CL_QUEUE_PROPERTIES, cl_command_queue_properties)
898c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
899c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#if defined(CL_VERSION_1_1)
900c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __PARAM_NAME_INFO_1_1(F) \
901c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_context_info, CL_CONTEXT_NUM_DEVICES, cl_uint)\
902c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF, cl_uint) \
903c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR, cl_uint) \
904c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT, cl_uint) \
905c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_INT, cl_uint) \
906c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG, cl_uint) \
907c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT, cl_uint) \
908c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE, cl_uint) \
909c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF, cl_uint) \
910c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_DOUBLE_FP_CONFIG, cl_device_fp_config) \
911c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_HALF_FP_CONFIG, cl_device_fp_config) \
912c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_HOST_UNIFIED_MEMORY, cl_bool) \
913c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    \
914c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_mem_info, CL_MEM_ASSOCIATED_MEMOBJECT, cl::Memory) \
915c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_mem_info, CL_MEM_OFFSET, ::size_t) \
916c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    \
917c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_kernel_work_group_info, CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE, ::size_t) \
918c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_kernel_work_group_info, CL_KERNEL_PRIVATE_MEM_SIZE, cl_ulong) \
919c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    \
920c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_event_info, CL_EVENT_CONTEXT, cl::Context)
921c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#endif // CL_VERSION_1_1
922c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
923c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#if defined(USE_CL_DEVICE_FISSION)
924c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __PARAM_NAME_DEVICE_FISSION(F) \
925c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    F(cl_device_info, CL_DEVICE_PARENT_DEVICE_EXT, cl_device_id) \
926c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez	F(cl_device_info, CL_DEVICE_PARTITION_TYPES_EXT, VECTOR_CLASS<cl_device_partition_property_ext>) \
927c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez	F(cl_device_info, CL_DEVICE_AFFINITY_DOMAINS_EXT, VECTOR_CLASS<cl_device_partition_property_ext>) \
928c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez	F(cl_device_info, CL_DEVICE_REFERENCE_COUNT_EXT , cl_uint) \
929c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez	F(cl_device_info, CL_DEVICE_PARTITION_STYLE_EXT, VECTOR_CLASS<cl_device_partition_property_ext>)
930c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#endif // USE_CL_DEVICE_FISSION
931c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
932c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jereztemplate <typename enum_type, cl_int Name>
933c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerezstruct param_traits {};
934c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
935c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#define __DECLARE_PARAM_TRAITS(token, param_name, T) \
936c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerezstruct token;                                        \
937c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jereztemplate<>                                           \
938c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerezstruct param_traits<detail:: token,param_name>       \
939c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez{                                                    \
940c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    enum { value = param_name };                     \
941c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    typedef T param_type;                            \
942c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez};
943c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
944c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez__PARAM_NAME_INFO_1_0(__DECLARE_PARAM_TRAITS);
945c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#if defined(CL_VERSION_1_1)
946c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez__PARAM_NAME_INFO_1_1(__DECLARE_PARAM_TRAITS);
947c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#endif // CL_VERSION_1_1
948c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
949c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#if defined(USE_CL_DEVICE_FISSION)
950c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez__PARAM_NAME_DEVICE_FISSION(__DECLARE_PARAM_TRAITS);
951c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#endif // USE_CL_DEVICE_FISSION
952c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
953c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#undef __DECLARE_PARAM_TRAITS
954c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
955c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez// Convenience functions
956c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
957c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jereztemplate <typename Func, typename T>
958c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerezinline cl_int
959c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco JerezgetInfo(Func f, cl_uint name, T* param)
960c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez{
961c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    return GetInfoHelper<Func, T>::get(f, name, param);
962c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez}
963c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
964c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jereztemplate <typename Func, typename Arg0>
965c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerezstruct GetInfoFunctor0
966c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez{
967c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    Func f_; const Arg0& arg0_;
968c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    cl_int operator ()(
969c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        cl_uint param, ::size_t size, void* value, ::size_t* size_ret)
970c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    { return f_(arg0_, param, size, value, size_ret); }
971c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez};
972c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
973c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jereztemplate <typename Func, typename Arg0, typename Arg1>
974c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerezstruct GetInfoFunctor1
975c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez{
976c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    Func f_; const Arg0& arg0_; const Arg1& arg1_;
977c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    cl_int operator ()(
978c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        cl_uint param, ::size_t size, void* value, ::size_t* size_ret)
979c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    { return f_(arg0_, arg1_, param, size, value, size_ret); }
980c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez};
981c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
982c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jereztemplate <typename Func, typename Arg0, typename T>
983c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerezinline cl_int
984c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco JerezgetInfo(Func f, const Arg0& arg0, cl_uint name, T* param)
985c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez{
986c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    GetInfoFunctor0<Func, Arg0> f0 = { f, arg0 };
987c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    return GetInfoHelper<GetInfoFunctor0<Func, Arg0>, T>
988c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        ::get(f0, name, param);
989c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez}
990c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
991c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jereztemplate <typename Func, typename Arg0, typename Arg1, typename T>
992c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerezinline cl_int
993c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco JerezgetInfo(Func f, const Arg0& arg0, const Arg1& arg1, cl_uint name, T* param)
994c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez{
995c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    GetInfoFunctor1<Func, Arg0, Arg1> f0 = { f, arg0, arg1 };
996c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    return GetInfoHelper<GetInfoFunctor1<Func, Arg0, Arg1>, T>
997c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        ::get(f0, name, param);
998c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez}
999c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1000c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jereztemplate<typename T>
1001c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerezstruct ReferenceHandler
1002c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez{ };
1003c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1004c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jereztemplate <>
1005c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerezstruct ReferenceHandler<cl_device_id>
1006c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez{
1007c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    // cl_device_id does not have retain().
1008c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    static cl_int retain(cl_device_id)
1009c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    { return CL_INVALID_DEVICE; }
1010c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    // cl_device_id does not have release().
1011c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    static cl_int release(cl_device_id)
1012c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    { return CL_INVALID_DEVICE; }
1013c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez};
1014c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1015c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jereztemplate <>
1016c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerezstruct ReferenceHandler<cl_platform_id>
1017c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez{
1018c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    // cl_platform_id does not have retain().
1019c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    static cl_int retain(cl_platform_id)
1020c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    { return CL_INVALID_PLATFORM; }
1021c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    // cl_platform_id does not have release().
1022c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    static cl_int release(cl_platform_id)
1023c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    { return CL_INVALID_PLATFORM; }
1024c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez};
1025c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1026c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jereztemplate <>
1027c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerezstruct ReferenceHandler<cl_context>
1028c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez{
1029c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    static cl_int retain(cl_context context)
1030c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    { return ::clRetainContext(context); }
1031c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    static cl_int release(cl_context context)
1032c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    { return ::clReleaseContext(context); }
1033c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez};
1034c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1035c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jereztemplate <>
1036c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerezstruct ReferenceHandler<cl_command_queue>
1037c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez{
1038c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    static cl_int retain(cl_command_queue queue)
1039c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    { return ::clRetainCommandQueue(queue); }
1040c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    static cl_int release(cl_command_queue queue)
1041c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    { return ::clReleaseCommandQueue(queue); }
1042c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez};
1043c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1044c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jereztemplate <>
1045c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerezstruct ReferenceHandler<cl_mem>
1046c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez{
1047c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    static cl_int retain(cl_mem memory)
1048c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    { return ::clRetainMemObject(memory); }
1049c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    static cl_int release(cl_mem memory)
1050c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    { return ::clReleaseMemObject(memory); }
1051c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez};
1052c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1053c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jereztemplate <>
1054c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerezstruct ReferenceHandler<cl_sampler>
1055c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez{
1056c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    static cl_int retain(cl_sampler sampler)
1057c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    { return ::clRetainSampler(sampler); }
1058c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    static cl_int release(cl_sampler sampler)
1059c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    { return ::clReleaseSampler(sampler); }
1060c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez};
1061c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1062c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jereztemplate <>
1063c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerezstruct ReferenceHandler<cl_program>
1064c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez{
1065c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    static cl_int retain(cl_program program)
1066c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    { return ::clRetainProgram(program); }
1067c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    static cl_int release(cl_program program)
1068c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    { return ::clReleaseProgram(program); }
1069c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez};
1070c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1071c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jereztemplate <>
1072c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerezstruct ReferenceHandler<cl_kernel>
1073c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez{
1074c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    static cl_int retain(cl_kernel kernel)
1075c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    { return ::clRetainKernel(kernel); }
1076c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    static cl_int release(cl_kernel kernel)
1077c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    { return ::clReleaseKernel(kernel); }
1078c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez};
1079c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1080c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jereztemplate <>
1081c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerezstruct ReferenceHandler<cl_event>
1082c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez{
1083c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    static cl_int retain(cl_event event)
1084c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    { return ::clRetainEvent(event); }
1085c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    static cl_int release(cl_event event)
1086c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    { return ::clReleaseEvent(event); }
1087c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez};
1088c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1089c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jereztemplate <typename T>
1090c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerezclass Wrapper
1091c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez{
1092c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerezpublic:
1093c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    typedef T cl_type;
1094c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1095c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerezprotected:
1096c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    cl_type object_;
1097c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1098c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerezpublic:
1099c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    Wrapper() : object_(NULL) { }
1100c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1101c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    ~Wrapper()
1102c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    {
1103c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        if (object_ != NULL) { release(); }
1104c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    }
1105c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1106c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    Wrapper(const Wrapper<cl_type>& rhs)
1107c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    {
1108c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        object_ = rhs.object_;
1109c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        if (object_ != NULL) { retain(); }
1110c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    }
1111c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1112c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    Wrapper<cl_type>& operator = (const Wrapper<cl_type>& rhs)
1113c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    {
1114c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        if (object_ != NULL) { release(); }
1115c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        object_ = rhs.object_;
1116c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        if (object_ != NULL) { retain(); }
1117c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        return *this;
1118c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    }
1119c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1120c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    cl_type operator ()() const { return object_; }
1121c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1122c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    cl_type& operator ()() { return object_; }
1123c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1124c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerezprotected:
1125c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1126c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    cl_int retain() const
1127c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    {
1128c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        return ReferenceHandler<cl_type>::retain(object_);
1129c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    }
1130c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1131c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    cl_int release() const
1132c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    {
1133c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        return ReferenceHandler<cl_type>::release(object_);
1134c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    }
1135c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez};
1136c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1137c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#if defined(__CL_ENABLE_EXCEPTIONS)
1138c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerezstatic inline cl_int errHandler (
1139c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    cl_int err,
1140c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    const char * errStr = NULL) throw(Error)
1141c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez{
1142c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    if (err != CL_SUCCESS) {
1143c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        throw Error(err, errStr);
1144c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    }
1145c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    return err;
1146c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez}
1147c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#else
1148c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerezstatic inline cl_int errHandler (cl_int err, const char * errStr = NULL)
1149c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez{
1150c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    return err;
1151c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez}
1152c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#endif // __CL_ENABLE_EXCEPTIONS
1153c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1154c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez} // namespace detail
1155c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez//! \endcond
1156c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1157c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez/*! \stuct ImageFormat
1158c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * \brief ImageFormat interface fro cl_image_format.
1159c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez */
1160c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerezstruct ImageFormat : public cl_image_format
1161c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez{
1162c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    ImageFormat(){}
1163c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1164c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    ImageFormat(cl_channel_order order, cl_channel_type type)
1165c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    {
1166c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        image_channel_order = order;
1167c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        image_channel_data_type = type;
1168c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    }
1169c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1170c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    ImageFormat& operator = (const ImageFormat& rhs)
1171c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    {
1172c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        if (this != &rhs) {
1173c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            this->image_channel_data_type = rhs.image_channel_data_type;
1174c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            this->image_channel_order     = rhs.image_channel_order;
1175c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        }
1176c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        return *this;
1177c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    }
1178c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez};
1179c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1180c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez/*! \class Device
1181c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez * \brief Device interface for cl_device_id.
1182c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez */
1183c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerezclass Device : public detail::Wrapper<cl_device_id>
1184c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez{
1185c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerezpublic:
1186c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    Device(cl_device_id device) { object_ = device; }
1187c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1188c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    Device() : detail::Wrapper<cl_type>() { }
1189c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1190c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    Device(const Device& device) : detail::Wrapper<cl_type>(device) { }
1191c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1192c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    Device& operator = (const Device& rhs)
1193c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    {
1194c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        if (this != &rhs) {
1195c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            detail::Wrapper<cl_type>::operator=(rhs);
1196c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        }
1197c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        return *this;
1198c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    }
1199c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1200c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    template <typename T>
1201c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    cl_int getInfo(cl_device_info name, T* param) const
1202c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    {
1203c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        return detail::errHandler(
1204c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            detail::getInfo(&::clGetDeviceInfo, object_, name, param),
1205c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            __GET_DEVICE_INFO_ERR);
1206c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    }
1207c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1208c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    template <cl_int name> typename
1209c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    detail::param_traits<detail::cl_device_info, name>::param_type
1210c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    getInfo(cl_int* err = NULL) const
1211c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    {
1212c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        typename detail::param_traits<
1213c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            detail::cl_device_info, name>::param_type param;
1214c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        cl_int result = getInfo(name, &param);
1215c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        if (err != NULL) {
1216c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            *err = result;
1217c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        }
1218c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        return param;
1219c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    }
1220c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1221c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#if defined(USE_CL_DEVICE_FISSION)
1222c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez	cl_int createSubDevices(
1223c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez		const cl_device_partition_property_ext * properties,
1224c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez		VECTOR_CLASS<Device>* devices)
1225c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez	{
1226c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez		typedef CL_API_ENTRY cl_int
1227c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez			( CL_API_CALL * PFN_clCreateSubDevicesEXT)(
1228c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez				cl_device_id /*in_device*/,
1229c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez                const cl_device_partition_property_ext * /* properties */,
1230c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez                cl_uint /*num_entries*/,
1231c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez                cl_device_id * /*out_devices*/,
1232c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez                cl_uint * /*num_devices*/ ) CL_EXT_SUFFIX__VERSION_1_1;
1233c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1234c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez		static PFN_clCreateSubDevicesEXT pfn_clCreateSubDevicesEXT = NULL;
1235c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez		__INIT_CL_EXT_FCN_PTR(clCreateSubDevicesEXT);
1236c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1237c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez		cl_uint n = 0;
1238c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        cl_int err = pfn_clCreateSubDevicesEXT(object_, properties, 0, NULL, &n);
1239c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        if (err != CL_SUCCESS) {
1240c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            return detail::errHandler(err, __CREATE_SUB_DEVICES);
1241c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        }
1242c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1243c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id));
1244c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        err = pfn_clCreateSubDevicesEXT(object_, properties, n, ids, NULL);
1245c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        if (err != CL_SUCCESS) {
1246c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            return detail::errHandler(err, __CREATE_SUB_DEVICES);
1247c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        }
1248c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1249c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        devices->assign(&ids[0], &ids[n]);
1250c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        return CL_SUCCESS;
1251c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez 	}
1252c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#endif
1253c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez};
1254c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1255c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez/*! \class Platform
1256c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez *  \brief Platform interface.
1257c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez */
1258c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerezclass Platform : public detail::Wrapper<cl_platform_id>
1259c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez{
1260c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerezpublic:
1261c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    static const Platform null();
1262c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1263c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    Platform(cl_platform_id platform) { object_ = platform; }
1264c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1265c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    Platform() : detail::Wrapper<cl_type>()  { }
1266c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1267c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    Platform(const Platform& platform) : detail::Wrapper<cl_type>(platform) { }
1268c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1269c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    Platform& operator = (const Platform& rhs)
1270c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    {
1271c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        if (this != &rhs) {
1272c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            detail::Wrapper<cl_type>::operator=(rhs);
1273c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        }
1274c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        return *this;
1275c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    }
1276c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1277c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    cl_int getInfo(cl_platform_info name, STRING_CLASS* param) const
1278c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    {
1279c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        return detail::errHandler(
1280c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            detail::getInfo(&::clGetPlatformInfo, object_, name, param),
1281c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            __GET_PLATFORM_INFO_ERR);
1282c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    }
1283c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1284c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    template <cl_int name> typename
1285c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    detail::param_traits<detail::cl_platform_info, name>::param_type
1286c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    getInfo(cl_int* err = NULL) const
1287c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    {
1288c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        typename detail::param_traits<
1289c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            detail::cl_platform_info, name>::param_type param;
1290c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        cl_int result = getInfo(name, &param);
1291c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        if (err != NULL) {
1292c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            *err = result;
1293c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        }
1294c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        return param;
1295c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    }
1296c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1297c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    cl_int getDevices(
1298c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        cl_device_type type,
1299c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        VECTOR_CLASS<Device>* devices) const
1300c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    {
1301c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        cl_uint n = 0;
1302c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        cl_int err = ::clGetDeviceIDs(object_, type, 0, NULL, &n);
1303c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        if (err != CL_SUCCESS) {
1304c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
1305c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        }
1306c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1307c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id));
1308c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        err = ::clGetDeviceIDs(object_, type, n, ids, NULL);
1309c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        if (err != CL_SUCCESS) {
1310c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
1311c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        }
1312c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1313c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        devices->assign(&ids[0], &ids[n]);
1314c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        return CL_SUCCESS;
1315c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    }
1316c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1317c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#if defined(USE_DX_INTEROP)
1318c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez   /*! \brief Get the list of available D3D10 devices.
1319c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez     *
1320c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez     *  \param d3d_device_source.
1321c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez     *
1322c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez     *  \param d3d_object.
1323c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez     *
1324c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez     *  \param d3d_device_set.
1325c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez     *
1326c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez     *  \param devices returns a vector of OpenCL D3D10 devices found. The cl::Device
1327c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez     *  values returned in devices can be used to identify a specific OpenCL
1328c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez     *  device. If \a devices argument is NULL, this argument is ignored.
1329c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez     *
1330c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez     *  \return One of the following values:
1331c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez     *    - CL_SUCCESS if the function is executed successfully.
1332c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez     *
1333c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez     *  The application can query specific capabilities of the OpenCL device(s)
1334c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez     *  returned by cl::getDevices. This can be used by the application to
1335c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez     *  determine which device(s) to use.
1336c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez     *
1337c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez     * \note In the case that exceptions are enabled and a return value
1338c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez     * other than CL_SUCCESS is generated, then cl::Error exception is
1339c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez     * generated.
1340c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez     */
1341c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    cl_int getDevices(
1342c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        cl_d3d10_device_source_khr d3d_device_source,
1343c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        void *                     d3d_object,
1344c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        cl_d3d10_device_set_khr    d3d_device_set,
1345c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        VECTOR_CLASS<Device>* devices) const
1346c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    {
1347c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clGetDeviceIDsFromD3D10KHR)(
1348c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            cl_platform_id platform,
1349c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            cl_d3d10_device_source_khr d3d_device_source,
1350c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            void * d3d_object,
1351c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            cl_d3d10_device_set_khr d3d_device_set,
1352c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            cl_uint num_entries,
1353c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            cl_device_id * devices,
1354c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            cl_uint* num_devices);
1355c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1356c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        static PFN_clGetDeviceIDsFromD3D10KHR pfn_clGetDeviceIDsFromD3D10KHR = NULL;
1357c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        __INIT_CL_EXT_FCN_PTR(clGetDeviceIDsFromD3D10KHR);
1358c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1359c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        cl_uint n = 0;
1360c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        cl_int err = pfn_clGetDeviceIDsFromD3D10KHR(
1361c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            object_,
1362c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            d3d_device_source,
1363c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            d3d_object,
1364c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            d3d_device_set,
1365c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            0,
1366c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            NULL,
1367c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            &n);
1368c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        if (err != CL_SUCCESS) {
1369c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
1370c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        }
1371c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1372c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id));
1373c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        err = pfn_clGetDeviceIDsFromD3D10KHR(
1374c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            object_,
1375c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            d3d_device_source,
1376c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            d3d_object,
1377c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            d3d_device_set,
1378c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            n,
1379c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            ids,
1380c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            NULL);
1381c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        if (err != CL_SUCCESS) {
1382c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
1383c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        }
1384c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1385c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        devices->assign(&ids[0], &ids[n]);
1386c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        return CL_SUCCESS;
1387c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    }
1388c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez#endif
1389c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1390c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    static cl_int get(
1391c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        VECTOR_CLASS<Platform>* platforms)
1392c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    {
1393c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        cl_uint n = 0;
1394c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        cl_int err = ::clGetPlatformIDs(0, NULL, &n);
1395c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        if (err != CL_SUCCESS) {
1396c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
1397c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        }
1398c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1399c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        cl_platform_id* ids = (cl_platform_id*) alloca(
1400c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            n * sizeof(cl_platform_id));
1401c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        err = ::clGetPlatformIDs(n, ids, NULL);
1402c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        if (err != CL_SUCCESS) {
1403c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
1404c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        }
1405c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1406c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        platforms->assign(&ids[0], &ids[n]);
1407c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        return CL_SUCCESS;
1408c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    }
1409c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez};
1410c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1411c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerezstatic inline cl_int
1412c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco JerezUnloadCompiler()
1413c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez{
1414c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    return ::clUnloadCompiler();
1415c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez}
1416c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez
1417c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerezclass Context : public detail::Wrapper<cl_context>
1418c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez{
1419c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerezpublic:
1420c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez    Context(
1421c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        const VECTOR_CLASS<Device>& devices,
1422c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        cl_context_properties* properties = NULL,
1423c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez        void (CL_CALLBACK * notifyFptr)(
1424c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            const char *,
1425c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            const void *,
1426c6db1b3396384186aab5b685fe1fd540e17b3a62Francisco Jerez            ::size_t,
1427