/*======================================================================================

	Program:		Range Imaging Toolkit (RITK)
	Module:			cl_utils.h
	Version:		
	Date:			

	Copyright (c) 2010-2011
	Pattern Recognition Lab, 
    University Erlangen-Nuremberg, Germany
    All rights reserved.

	This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
	See RITKCopyright.txt for more information.

	http://www5.informatik.uni-erlangen.de/research/software/ritk

========================================================================================*/

#ifndef CL_UTILS_H__
#define CL_UTILS_H__

#include "CL/cl.h"
#include <iostream>


/// routine to get an error String from cl_int error type
char* getErrorMessage(cl_int err);

/// the SafeCall routine to check for successfull function call
#define clSafeCall(err)		__clSafeCall(err, __FILE__, __LINE__)

/// is called everytime an error occurs
#define clDie(msg)																				\
	{																							\
		std::cerr << __FILE__ << "(" << __LINE__ << ") : clDie() error : ";						\
		std::cerr << msg;																		\
		std::cerr << std::endl;																	\
		exit(-1);																				\
	}

/// the Definition of the clSafeCall routine
inline void __clSafeCall( cl_int err, const char *file, const int line )
{
	if( err != CL_SUCCESS ) {
		std::cerr << file << "(" << line << ") : clSafeCall() error #(" << err << ") : " << getErrorMessage(err) << std::endl;
		exit(-1);
	}
}



/// creates available OpenCL context from type deviceType
cl_context createAvailableContext(cl_device_type deviceType);
/// Checks if Context is a valid context concerning OpenCL Version etc.
bool checkIfContextValid(cl_context);




#endif // CL_UTILS_H__