001/* 002 * To change this template, choose Tools | Templates 003 * and open the template in the editor. 004 */ 005 006package com.nativelibs4java.opencl.util; 007 008public enum OpenCLType { 009 Int(Integer.class), Char(Character.class), Long(Long.class), Short(Short.class), Byte(Byte.class), Double(Double.class), Float(Float.class), Half(null); 010 011 OpenCLType(Class<?> type) { 012 this.type = type; 013 } 014 public final Class<?> type; 015 016 public String toCType() { 017 if (this == Byte) 018 return "char"; 019 if (this == Char) 020 return "short"; 021 return name().toLowerCase(); 022 } 023 public static OpenCLType fromClass(Class<? extends Number> valueType) { 024 if (valueType == Integer.TYPE || valueType == Integer.class) 025 return Int; 026 if (valueType == java.lang.Long.TYPE || valueType == Long.class) 027 return Long; 028 if (valueType == java.lang.Short.TYPE || valueType == Short.class) 029 return Short; 030 if (valueType == java.lang.Double.TYPE || valueType == Double.class) 031 return Double; 032 if (valueType == java.lang.Float.TYPE || valueType == Float.class) 033 return Float; 034 if (valueType == java.lang.Byte.TYPE || valueType == Byte.class) 035 return Byte; 036 037 if (!valueType.isPrimitive()) 038 throw new IllegalArgumentException("Value type is not a primitive: '" + valueType.getName() + "' !"); 039 040 throw new IllegalArgumentException("Primitive type not handled: '" + valueType.getName() + "' !"); 041 } 042}