From 8c4f7e02ab24c11384ec88f4455fa26ba95fbab5 Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Tue, 18 Jan 2011 10:24:29 +0100 Subject: [PATCH] Replace program sources and binaries typedefs with a wrapper class This allows easier initialization from strings while being backwards compatible. --- cl.hpp | 37 +++++++++++++++++++++++++++++++------ 1 files changed, 31 insertions(+), 6 deletions(-) diff --git a/cl.hpp b/cl.hpp index 99b86a6..c973e74 100755 --- a/cl.hpp +++ b/cl.hpp @@ -2386,8 +2386,33 @@ __GET_INFO_HELPER_WITH_RETAIN(cl::Kernel) class Program : public detail::Wrapper { public: - typedef VECTOR_CLASS > Binaries; - typedef VECTOR_CLASS > Sources; + template + class Container : public VECTOR_CLASS > + { + public: + typedef VECTOR_CLASS Type; + typedef VECTOR_CLASS Base; + + Container(::size_t count, std::pair value) + : Base(count, Type(value.first, value.first + value.second + 1)) + { + } + + Container(STRING_CLASS value) + : Base(1, Type(value.begin(), value.end())) + { + } + + Container(VECTOR_CLASS values) + { + for (size_type i=0; i Sources; + typedef Container Binaries; Program( const Context& context, @@ -2401,8 +2426,8 @@ public: const char** strings = (const char**) alloca(n * sizeof(const char*)); for (::size_t i = 0; i < n; ++i) { - strings[i] = sources[(int)i].first; - lengths[i] = sources[(int)i].second; + strings[i] = &sources[(int)i].front(); + lengths[i] = sources[(int)i].size(); } object_ = ::clCreateProgramWithSource( @@ -2427,8 +2452,8 @@ public: const unsigned char** images = (const unsigned char**) alloca(n * sizeof(const void*)); for (::size_t i = 0; i < n; ++i) { - images[i] = (const unsigned char*)binaries[(int)i].first; - lengths[i] = binaries[(int)i].second; + images[i] = &binaries[(int)i].front(); + lengths[i] = binaries[(int)i].size(); } object_ = ::clCreateProgramWithBinary( -- 1.7.3.1.msysgit.0