1/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17public class CType {
18
19    String baseType;
20    boolean isConst;
21    boolean isPointer;
22
23    public CType() {
24    }
25
26    public CType(String baseType) {
27    setBaseType(baseType);
28    }
29
30    public CType(String baseType, boolean isConst, boolean isPointer) {
31    setBaseType(baseType);
32    setIsConst(isConst);
33    setIsPointer(isPointer);
34    }
35
36    public String getDeclaration() {
37    return baseType + (isPointer ? " *" : "");
38    }
39
40    public void setIsConst(boolean isConst) {
41    this.isConst = isConst;
42    }
43
44    public boolean isConst() {
45    return isConst;
46    }
47
48    public void setIsPointer(boolean isPointer) {
49    this.isPointer = isPointer;
50    }
51
52    public boolean isPointer() {
53    return isPointer;
54    }
55
56    public boolean isEGLHandle() {
57        if(baseType.equals("EGLContext")
58           || baseType.equals("EGLConfig")
59           || baseType.equals("EGLSurface")
60           || baseType.equals("EGLDisplay")) {
61               return true;
62        }
63        return false;
64    }
65
66    boolean isVoid() {
67    String baseType = getBaseType();
68    return baseType.equals("GLvoid") ||
69        baseType.equals("void");
70    }
71
72    public boolean isConstCharPointer() {
73        return isConst && isPointer && baseType.equals("char");
74    }
75
76    public boolean isTypedPointer() {
77    return isPointer() && !isVoid() && !isConstCharPointer();
78    }
79
80    public void setBaseType(String baseType) {
81    this.baseType = baseType;
82    }
83
84    public String getBaseType() {
85    return baseType;
86    }
87
88    @Override
89    public String toString() {
90    String s = "";
91    if (isConst()) {
92        s += "const ";
93    }
94    s += baseType;
95    if (isPointer()) {
96        s += "*";
97    }
98
99    return s;
100    }
101
102    @Override
103    public int hashCode() {
104    return baseType.hashCode() ^ (isPointer ? 2 : 0) ^ (isConst ? 1 : 0);
105    }
106
107    @Override
108    public boolean equals(Object o) {
109    if (o != null && o instanceof CType) {
110        CType c = (CType)o;
111        return baseType.equals(c.baseType) &&
112        isPointer() == c.isPointer() &&
113        isConst() == c.isConst();
114    }
115    return false;
116    }
117}
118