JOCL v2.6.0-rc-20250722
JOCL, OpenCL® API Binding for Java™ (public API).
CLVersion.java
Go to the documentation of this file.
1/*
2 * Copyright 2009 - 2010 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28
29/*
30 * Created on Thursday, June 24 2010 05:38
31 */
32package com.jogamp.opencl;
33
34import java.util.regex.Matcher;
35import java.util.regex.Pattern;
36
37/**
38 * Version of an OpenCL Implementation.
39 * All comparison operations use the {@link #getSpecVersion()} for comparison.
40 * @author Michael Bien
41 */
42public class CLVersion implements Comparable<CLVersion> {
43
44 private final static Pattern pattern = Pattern.compile("OpenCL (?:C )?(\\d+)\\.(\\d+)(.*)");
45
46 public final static CLVersion CL_1_0 = new CLVersion("OpenCL 1.0");
47 public final static CLVersion CL_1_1 = new CLVersion("OpenCL 1.1");
48 public final static CLVersion CL_1_2 = new CLVersion("OpenCL 1.2");
49 public final static CLVersion CL_2_0 = new CLVersion("OpenCL 2.0");
50 public final static CLVersion CL_2_1 = new CLVersion("OpenCL 2.1");
51
52 /**
53 * The full version String is defined as:
54 * <code>OpenCL[space][major_version].[minor_version][space][platform-specific information]</code>
55 */
56 public final String fullversion;
57 /**
58 * The platform specific part of the version string.
59 * @see #fullversion
60 */
61 public final String implversion;
62 /**
63 * Minor version number.
64 * @see #fullversion
65 */
66 public final short minor;
67 /**
68 * Mayor version number.
69 * @see #fullversion
70 */
71 public final short major;
72
73 protected CLVersion(final String version) {
74 this.fullversion = version;
75 final Matcher matcher = pattern.matcher(version);
76 matcher.matches();
77 major = Short.parseShort(matcher.group(1));
78 minor = Short.parseShort(matcher.group(2));
79
80 if(matcher.groupCount() == 4) {//first group == whole string
81 implversion = matcher.group(3).substring(1);
82 }else{
83 implversion = "";
84 }
85 }
86
87 public int compareTo(final CLVersion other) {
88 return compareTo(other.major, other.minor);
89 }
90
91 private int compareTo(final int otherMajor, final int otherMinor) {
92 if(otherMajor == major && otherMinor == minor) {
93 return 0;
94 }else if(this.major > otherMajor || (this.major == otherMajor && this.minor > otherMinor)) {
95 return 1;
96 }else{
97 return -1;
98 }
99 }
100
101 public boolean isAtLeast(final CLVersion other) {
102 return this.compareTo(other) >= 0;
103 }
104
105 public boolean isAtLeast(final int major, final int minor) {
106 return this.compareTo(major, minor) >= 0;
107 }
108
109 public boolean isEqual(final CLVersion other) {
110 return this.isEqual(other.major, other.minor);
111 }
112
113 public boolean isEqual(final int major, final int minor) {
114 return this.major == major && this.minor == minor;
115 }
116
117 /**
118 * Returns <code>'"OpenCL " + major + "." + minor'</code>.
119 */
120 public String getSpecVersion() {
121 return "OpenCL " + major + '.' + minor;
122 }
123
124 /**
125 * Returns the full, unfiltered version string.
126 * @see #fullversion
127 */
128 public String getFullVersion() {
129 return fullversion;
130 }
131
132 /**
133 * @see #implversion
134 */
135 public String getImplVersion() {
136 return implversion;
137 }
138
139 /**
140 * @see #major
141 */
142 public short getMajor() {
143 return major;
144 }
145
146 /**
147 * @see #minor
148 */
149 public short getMinor() {
150 return minor;
151 }
152
153 @Override
154 public String toString() {
155 return getFullVersion();
156 }
157
158 @Override
159 public int hashCode() {
160 return fullversion.hashCode();
161 }
162
163 /**
164 * Returns true if both {@link #fullversion} Strings match.
165 */
166 @Override
167 public boolean equals(final Object obj) {
168 return obj != null && obj.getClass() == getClass() && fullversion.equals(((CLVersion)obj).fullversion);
169 }
170
171
172}
Version of an OpenCL Implementation.
Definition: CLVersion.java:42
boolean isEqual(final CLVersion other)
Definition: CLVersion.java:109
String getSpecVersion()
Returns '"OpenCL " + major + "." + minor'.
Definition: CLVersion.java:120
final String implversion
The platform specific part of the version string.
Definition: CLVersion.java:61
static final CLVersion CL_2_1
Definition: CLVersion.java:50
static final CLVersion CL_1_2
Definition: CLVersion.java:48
static final CLVersion CL_1_1
Definition: CLVersion.java:47
boolean isEqual(final int major, final int minor)
Definition: CLVersion.java:113
static final CLVersion CL_2_0
Definition: CLVersion.java:49
String getFullVersion()
Returns the full, unfiltered version string.
Definition: CLVersion.java:128
int compareTo(final CLVersion other)
Definition: CLVersion.java:87
static final CLVersion CL_1_0
Definition: CLVersion.java:46
final short major
Mayor version number.
Definition: CLVersion.java:71
final String fullversion
The full version String is defined as: OpenCL[space][major_version].
Definition: CLVersion.java:56
CLVersion(final String version)
Definition: CLVersion.java:73
boolean isAtLeast(final int major, final int minor)
Definition: CLVersion.java:105
boolean equals(final Object obj)
Returns true if both fullversion Strings match.
Definition: CLVersion.java:167
final short minor
Minor version number.
Definition: CLVersion.java:66
boolean isAtLeast(final CLVersion other)
Definition: CLVersion.java:101