summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Bien <[email protected]>2011-09-21 04:29:52 +0200
committerMichael Bien <[email protected]>2011-09-21 04:29:52 +0200
commitccfc0b128c0eeee54ded44fc3700de54e9532213 (patch)
tree1a020a32bb638ff1d506764c4ecbdd8f53eefd8b
parent18ae1f1e3c0ec5037e2790bcc517a564d30807d3 (diff)
improved generic factory methods to allow getClass() to be used instead of Class.class.
-rw-r--r--src/com/jogamp/opencl/util/pp/ArgType.java14
-rw-r--r--src/com/jogamp/opencl/util/pp/ForEach.java14
-rw-r--r--src/com/jogamp/opencl/util/pp/Reduction.java10
3 files changed, 19 insertions, 19 deletions
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 <B extends Buffer> ArgType valueOf(Class<B> 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<B extends Buffer> implements CLResource {
private final CLProgram program;
private final CLWork1D foreach;
- public ForEach(CLContext context, Class<B> elementType, String body) {
+ public ForEach(CLContext context, Class<? extends B> elementType, String body) {
StringBuilder src = new StringBuilder(512+body.length());
src.append("kernel void foreach(");
@@ -67,15 +67,15 @@ public class ForEach<B extends Buffer> implements CLResource {
foreach = CLWork1D.create1D(program.createCLKernel("foreach"));
}
- public static <B extends Buffer> ForEach<B> create(CLContext context, String op, Class<B> elementType) {
+ public static <B extends Buffer> ForEach<B> create(CLContext context, String op, Class<? extends B> elementType) {
return new ForEach<B>(context, elementType, op);
}
- public static <B extends Buffer> ForEach<B> create(CLCommandQueue queue, String op, Class<B> elementType) {
+ public static <B extends Buffer> ForEach<B> create(CLCommandQueue queue, String op, Class<? extends B> elementType) {
return create(queue.getContext(), op, elementType);
}
- public static <B extends Buffer> CLTask<CLResourceQueueContext<ForEach<B>>, B> createTask(B input, B output, String body, Class<B> elementType) {
+ public static <B extends Buffer> CLTask<CLResourceQueueContext<ForEach<B>>, B> createTask(B input, B output, String body, Class<? extends B> elementType) {
return new CLForEachTask<B>(input, output, body, elementType);
}
@@ -104,7 +104,7 @@ public class ForEach<B extends Buffer> implements CLResource {
return output;
}
- private StringBuilder arg(StringBuilder builder, Class<B> elementType, String name) {
+ private StringBuilder arg(StringBuilder builder, Class<? extends B> 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<B extends Buffer> implements CLResource {
private final B input;
private final B output;
- private final Class<B> elementType;
+ private final Class<? extends B> elementType;
private final String body;
- private CLForEachTask(B input, B output, String body, Class<B> elementType) {
+ private CLForEachTask(B input, B output, String body, Class<? extends B> 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<B extends Buffer> implements CLResource {
reduction = CLWork1D.create1D(program.createCLKernel("reduce"));
}
- public static <B extends Buffer> Reduction<B> create(CLContext context, Op op, Class<B> elementType) {
+ public static <B extends Buffer> Reduction<B> create(CLContext context, Op op, Class<? extends B> elementType) {
return new Reduction<B>(context, op, elementType);
}
- public static <B extends Buffer> Reduction<B> create(CLCommandQueue queue, Op op, Class<B> elementType) {
+ public static <B extends Buffer> Reduction<B> create(CLCommandQueue queue, Op op, Class<? extends B> elementType) {
return create(queue.getContext(), op, elementType);
}
- public static <B extends Buffer> CLTask<CLResourceQueueContext<Reduction<B>>, B> createTask(B input, B output, Op op, Class<B> elementType) {
+ public static <B extends Buffer> CLTask<CLResourceQueueContext<Reduction<B>>, B> createTask(B input, B output, Op op, Class<? extends B> elementType) {
return new CLReductionTask<B>(input, output, op, elementType);
}
@@ -349,10 +349,10 @@ public class Reduction<B extends Buffer> implements CLResource {
private final B input;
private final B output;
private final Op op;
- private final Class<B> elementType;
+ private final Class<? extends B> elementType;
private final Integer KEY;
- private CLReductionTask(B input, B output, Op op, Class<B> elementType) {
+ private CLReductionTask(B input, B output, Op op, Class<? extends B> elementType) {
this.input = input;
this.output = output;
this.op = op;