18 #include <boost/lexical_cast.hpp> 19 #include <boost/filesystem.hpp> 26 std::ifstream file_stream(__FILE__);\ 27 std::stringstream buffer;\ 28 buffer << file_stream.rdbuf();\ 35 std::string current_path = __FILE__;\ 36 boost::filesystem::path p( current_path );\ 37 boost::filesystem::path dir = p.parent_path();\ 38 auto full_path = boost::filesystem::canonical( dir );\ 45 abi::__cxa_demangle(typeid(*this).name(), 0, 0, NULL);\ 76 #define OCL_DEBUG(err, ...) \ 77 do { if (DEBUG_ON) std::cout << __func__ <<\ 81 " OpenCL Status: " <<\ 82 jaspl::ocl::CLErrorToString( err ) << std::endl; } while (0) 88 template <
typename T> std::string get_type_name () {
90 char* type_name = abi::__cxa_demangle(
typeid(T).name(), 0, 0, &status);
91 std::string type_str = std::string( type_name );
99 template <
typename T> std::string get_type_name ( T& to_check ) {
101 char* type_name = abi::__cxa_demangle(
typeid(*to_check).name(), 0, 0, &status);
102 std::string type_str = std::string( type_name );
110 template <
typename T>
void check_if_arithmetic() {
111 if ( !std::is_arithmetic<T>::value ) {
113 std::string err_mesg = __FUNCTION__;
114 err_mesg +=
"cannot initialize from non-arithmetic type ";
115 err_mesg += get_type_name<T>();
116 throw std::invalid_argument(err_mesg);
123 template <
typename T>
128 template <
typename C>
static one test( __typeof__(&C::operator[]) ) ;
130 template <
typename C>
static two test(...);
133 enum { value =
sizeof(test<T>(0)) ==
sizeof(char) };
137 template <
typename T>
143 template <
typename C>
static one test(decltype(&C::data)*) ;
144 template <
typename C>
static two test(...);
147 enum { value =
sizeof(test<T>(0)) ==
sizeof(char) };
151 template <
typename T>
157 template <
typename C>
static one test(decltype(&C::size)*) ;
158 template <
typename C>
static two test(...);
161 enum { value =
sizeof(test<T>(0)) ==
sizeof(char) };
165 template <
typename T,
typename... Args>
167 template <
typename C,
typename = decltype( std::declval<C>().data (std::declval<Args>()...) )>
168 static std::true_type test(
int);
169 template <
typename C>
170 static std::false_type test(...);
173 static constexpr
bool value = decltype(test<T>(0))::value;
187 template<
typename C>
static yes test(
typename C::const_iterator*);
188 template<
typename C>
static no test(...);
190 static const bool value =
sizeof(test<T>(0)) ==
sizeof(yes);
194 template <
typename T>
196 template<
typename C>
static char (&f(
typename std::enable_if<
197 std::is_same<decltype(
static_cast<typename C::const_iterator (C::*)() const
>(&C::begin)),
198 typename C::const_iterator(C::*)()
const>::value,
void>::type*))[1];
200 template<
typename C>
static char (&f(...))[2];
202 template<
typename C>
static char (&g(
typename std::enable_if<
203 std::is_same<decltype(
static_cast<typename C::const_iterator (C::*)() const
>(&C::end)),
204 typename C::const_iterator(C::*)()
const>::value,
void>::type*))[1];
206 template<
typename C>
static char (&g(...))[2];
208 static bool const beg_value =
sizeof(f<T>(0)) == 1;
209 static bool const end_value =
sizeof(g<T>(0)) == 1;
214 template <
typename T>
218 has_begin_end<T>::beg_value &&\
219 has_begin_end<T>::end_value &&\
225 template <
typename T>
void check_for_accesor ( T& to_check ) {
228 std::string err_mesg = __func__;
229 err_mesg +=
"\nType ";
230 err_mesg += get_type_name<T>();
231 err_mesg +=
" lacks accessor operator, []";
232 throw std::invalid_argument(err_mesg);
238 std::string CLErrorToString(cl_int error);
239 std::string CLErrorToString(cl_int* error);
240 void PrintOCLDebugInfo();
246 #endif // JTYPETRAITS_H