From ccfc0b128c0eeee54ded44fc3700de54e9532213 Mon Sep 17 00:00:00 2001 From: Michael Bien Date: Wed, 21 Sep 2011 04:29:52 +0200 Subject: improved generic factory methods to allow getClass() to be used instead of Class.class. --- src/com/jogamp/opencl/util/pp/ArgType.java | 14 +++++++------- src/com/jogamp/opencl/util/pp/ForEach.java | 14 +++++++------- src/com/jogamp/opencl/util/pp/Reduction.java | 10 +++++----- 3 files changed, 19 insertions(+), 19 deletions(-) (limited to 'src/com/jogamp/opencl') diff --git a/src/com/jogamp/opencl/util/pp/ArgType.java b/src/com/jogamp/opencl/util/pp/ArgType.java index a7272254..a088f116 100644 --- a/src/com/jogamp/opencl/util/pp/ArgType.java +++ b/src/com/jogamp/opencl/util/pp/ArgType.java @@ -62,21 +62,21 @@ import static com.jogamp.common.nio.Buffers.*; } public String vectorType(int elements) { - return type() + (elements == 0 ? "" : elements); + return type() + (elements == 1 ? "" : elements); } public static ArgType valueOf(Class elementType) { - if (elementType.equals(ShortBuffer.class)) { + if (ShortBuffer.class.isAssignableFrom(elementType)) { return ArgType.SHORT; - } else if (elementType.equals(IntBuffer.class)) { + } else if (IntBuffer.class.isAssignableFrom(elementType)) { return ArgType.INT; - } else if (elementType.equals(LongBuffer.class)) { + } else if (LongBuffer.class.isAssignableFrom(elementType)) { return ArgType.LONG; - } else if (elementType.equals(FloatBuffer.class)) { + } else if (FloatBuffer.class.isAssignableFrom(elementType)) { return ArgType.FLOAT; - } else if (elementType.equals(DoubleBuffer.class)) { + } else if (DoubleBuffer.class.isAssignableFrom(elementType)) { return ArgType.DOUBLE; -// }else if(elementType.equals(ByteBuffer.class)) { +// }else if(ByteBuffer.class.isAssignableFrom(elementType)) { // ELEMENT_SIZE = SIZEOF_BYTE; } else { throw new IllegalArgumentException("unsupported buffer type " + elementType); diff --git a/src/com/jogamp/opencl/util/pp/ForEach.java b/src/com/jogamp/opencl/util/pp/ForEach.java index 8e9c8f07..cfb9b27c 100644 --- a/src/com/jogamp/opencl/util/pp/ForEach.java +++ b/src/com/jogamp/opencl/util/pp/ForEach.java @@ -50,7 +50,7 @@ public class ForEach implements CLResource { private final CLProgram program; private final CLWork1D foreach; - public ForEach(CLContext context, Class elementType, String body) { + public ForEach(CLContext context, Class elementType, String body) { StringBuilder src = new StringBuilder(512+body.length()); src.append("kernel void foreach("); @@ -67,15 +67,15 @@ public class ForEach implements CLResource { foreach = CLWork1D.create1D(program.createCLKernel("foreach")); } - public static ForEach create(CLContext context, String op, Class elementType) { + public static ForEach create(CLContext context, String op, Class elementType) { return new ForEach(context, elementType, op); } - public static ForEach create(CLCommandQueue queue, String op, Class elementType) { + public static ForEach create(CLCommandQueue queue, String op, Class elementType) { return create(queue.getContext(), op, elementType); } - public static CLTask>, B> createTask(B input, B output, String body, Class elementType) { + public static CLTask>, B> createTask(B input, B output, String body, Class elementType) { return new CLForEachTask(input, output, body, elementType); } @@ -104,7 +104,7 @@ public class ForEach implements CLResource { return output; } - private StringBuilder arg(StringBuilder builder, Class elementType, String name) { + private StringBuilder arg(StringBuilder builder, Class elementType, String name) { String type = ArgType.valueOf(elementType).type(); return builder.append("global").append(' ').append(type).append("* ").append(name); } @@ -123,10 +123,10 @@ public class ForEach implements CLResource { private final B input; private final B output; - private final Class elementType; + private final Class elementType; private final String body; - private CLForEachTask(B input, B output, String body, Class elementType) { + private CLForEachTask(B input, B output, String body, Class elementType) { this.input = input; this.output = output; this.elementType = elementType; diff --git a/src/com/jogamp/opencl/util/pp/Reduction.java b/src/com/jogamp/opencl/util/pp/Reduction.java index 5ef1bc74..c2d47f7c 100644 --- a/src/com/jogamp/opencl/util/pp/Reduction.java +++ b/src/com/jogamp/opencl/util/pp/Reduction.java @@ -96,15 +96,15 @@ public class Reduction implements CLResource { reduction = CLWork1D.create1D(program.createCLKernel("reduce")); } - public static Reduction create(CLContext context, Op op, Class elementType) { + public static Reduction create(CLContext context, Op op, Class elementType) { return new Reduction(context, op, elementType); } - public static Reduction create(CLCommandQueue queue, Op op, Class elementType) { + public static Reduction create(CLCommandQueue queue, Op op, Class elementType) { return create(queue.getContext(), op, elementType); } - public static CLTask>, B> createTask(B input, B output, Op op, Class elementType) { + public static CLTask>, B> createTask(B input, B output, Op op, Class elementType) { return new CLReductionTask(input, output, op, elementType); } @@ -349,10 +349,10 @@ public class Reduction implements CLResource { private final B input; private final B output; private final Op op; - private final Class elementType; + private final Class elementType; private final Integer KEY; - private CLReductionTask(B input, B output, Op op, Class elementType) { + private CLReductionTask(B input, B output, Op op, Class elementType) { this.input = input; this.output = output; this.op = op; -- cgit v1.2.3