GlueGen: src/java/com/jogamp/gluegen/cgram/types/TypeDictionary.java Source File

GlueGen v2.6.0-rc-20250712 GlueGen, Native Binding Generator for Java™ (public API).

TypeDictionary.java
Go to the documentation of this file.
1/*
2 * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * - Redistribution of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * - Redistribution in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * Neither the name of Sun Microsystems, Inc. or the names of
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * This software is provided "AS IS," without a warranty of any kind. ALL
20 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
21 * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
22 * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
23 * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
24 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
25 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
26 * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
27 * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
28 * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
29 * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
30 * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
31 *
32 * You acknowledge that this software is not designed or intended for use
33 * in the design, construction, operation or maintenance of any nuclear
34 * facility.
35 *
36 * Sun gratefully acknowledges that this software was originally authored
37 * and developed by Kenneth Bradley Russell and Christopher John Kline.
38 */
39
40package com.jogamp.gluegen.cgram.types;
41
42import java.util.*;
43
44import com.jogamp.gluegen.GlueGen;
45import com.jogamp.gluegen.JavaConfiguration;
46
47
48/** Utility class for recording names of typedefs and structs. */
49
50 public class TypeDictionary {
51 /** Mapping from type name to type.*/
52 private final HashMap<String, Type> map = new HashMap<String, Type>();
53
54 /**
55 * Create a mapping from a type to its name.
56 * @param name the name to which the type is defined
57 * @param type the type that can be referred to by the specified name.
58 */
59 public Type put(final String name, final Type type) {
60 return map.put(name, type);
61 }
62
63 /** Get the type corresponding to the given name. Returns null if no type
64 * was found corresponding to the given name. */
65 public Type get(final String name) {
66 return map.get(name);
67 }
68
69 public List<Type> getEqualSemantics(final Type s, final JavaConfiguration cfg, final boolean skipOpaque) {
70 final List<Type> res = new ArrayList<Type>();
71 if( !skipOpaque || null == cfg.typeInfo(s) ) {
72 final Set<Map.Entry<String, Type>> entries = entrySet();
73 for(final Iterator<Map.Entry<String, Type>> iter = entries.iterator(); iter.hasNext(); ) {
74 final Map.Entry<String, Type> entry = iter.next();
75 final Type t = entry.getValue();
76 if( s.equalSemantics(t) ) {
77 if( !skipOpaque || null == cfg.typeInfo(t) ) {
78 if( GlueGen.debug() ) {
79 System.err.println(" tls["+res.size()+"]: -> "+entry.getKey()+" -> "+t.getDebugString());
80 }
81 res.add(t);
82 }
83 }
84 }
85 }
86 return res;
87 }
88 public Type getEqualSemantics1(final Type s, final JavaConfiguration cfg, final boolean skipOpaque) {
89 final List<Type> tls = getEqualSemantics(s, cfg, skipOpaque);
90 if( tls.size() > 0 ) {
91 final Type res = tls.get(0);
92 if( GlueGen.debug() ) {
93 System.err.println(" tls.0: "+res.getDebugString());
94 }
95 return res;
96 } else {
97 return null;
98 }
99 }
100
101 //this method is broken
102 /**
103 * Get the names that correspond to the given type. There will be more than
104 * one name in the returned list if the type has been defined to multiple
105 * names. Returns null if no names were found for given type.
106 */
107// public Set/*<String>*/ get(Type type) {
108// if (reverseMapOutOfDate) {
109// rebuildReverseMap();
110// reverseMapOutOfDate = false;
111// }
112// // Don't let callers muck with the set.
113// return Collections.unmodifiableSet((Set)reverseMap.get(type));
114// }
115
116 /** Remove the mapping from the specified name to its associated type.*/
117 public Type remove(final String name) {
118 return map.remove(name);
119 }
120
121 /** Get all the names that map to Types.
122 * @return a Set of Strings that are the typedef names that map to Types in the dictionary.
123 */
124 public Set<String> keySet() {
125 return map.keySet();
126 }
127
128 public Set<Map.Entry<String, Type>> entrySet() {
129 return map.entrySet();
130 }
131
132 public boolean containsKey(final String key) {
133 return map.containsKey(key);
134 }
135
136 public boolean containsValue(final Type value) {
137 return map.containsValue(value);
138 }
139
140 public boolean isEmpty() {
141 return map.isEmpty();
142 }
143
144 /** Returns a collection of all the Types in the dictionary that are mapped via typedefs names. */
145 public Collection<Type> values() {
146 return map.values();
147 }
148
149 /** Build the mapping of from each Type to all the names by which is may be
150 * referenced. Warning: this is a slow operation!
151 */
152 /*
153 private void rebuildReverseMap() {
154 reverseMap.clear();
155 for (Iterator<String> it = map.keySet().iterator(); it.hasNext(); ) {
156 String name = (String)it.next();
157 Type type = (Type)map.get(name);
158 if (type == null) {
159 throw new IllegalStateException("Internal error; TypedefDictionary contains null Type for name \"" + name + "\"");
160 }
161 HashSet allNamesForType = (HashSet)reverseMap.get(type);
162 if (allNamesForType == null) {
163 allNamesForType = new HashSet<String>();
164 reverseMap.put(type, allNamesForType);
165 }
166 allNamesForType.add(name);
167 }
168 }
169*/
170 /**
171 * Dumps the dictionary contents to the specified output stream, annotated
172 * with the specified description. Useful for debugging.
173 */
174 /*
175 public void dumpDictionary(java.io.PrintStream out, String description) {
176 out.println("------------------------------------------------------------------------------");
177 out.println("TypeDictionary: " + (description == null ? "" : description));
178 out.println("------------------------------------------------------------------------------");
179 out.println("Forward mapping: ");
180 for (Iterator names = keySet().iterator(); names.hasNext(); ) {
181 String typeName = (String)names.next();
182 out.println(" [" + typeName + "]\t--> [" + get(typeName) + "]");
183 }
184 out.println("Reverse mapping: ");
185
186 // because the reverse mapping is built lazily upon query, we must force it to
187 // be built if it has not yet been built.
188 if (reverseMapOutOfDate) {
189 rebuildReverseMap();
190 reverseMapOutOfDate = false;
191 }
192 for (Iterator types = reverseMap.keySet().iterator(); types.hasNext(); ) {
193 Type type = (Type)types.next();
194 Set names = get(type);
195 out.println(" [" + type + "]\t--> " + names + "");
196 }
197 out.println("------------------------------------------------------------------------------");
198 }
199 */
200}
com.jogamp.gluegen.GlueGen
Glue code generator for C functions and data structures.
Definition: GlueGen.java:59
com.jogamp.gluegen.JavaConfiguration
Parses and provides access to the contents of .cfg files for the JavaEmitter.
Definition: JavaConfiguration.java:63
com.jogamp.gluegen.JavaConfiguration.typeInfo
TypeInfo typeInfo(Type type)
If this type should be considered opaque, returns the TypeInfo describing the replacement type.
Definition: JavaConfiguration.java:440
com.jogamp.gluegen.cgram.types.TypeDictionary
Utility class for recording names of typedefs and structs.
Definition: TypeDictionary.java:50
com.jogamp.gluegen.cgram.types.TypeDictionary.isEmpty
boolean isEmpty()
Definition: TypeDictionary.java:140
com.jogamp.gluegen.cgram.types.TypeDictionary.containsKey
boolean containsKey(final String key)
Definition: TypeDictionary.java:132
com.jogamp.gluegen.cgram.types.TypeDictionary.entrySet
Set< Map.Entry< String, Type > > entrySet()
Definition: TypeDictionary.java:128
com.jogamp.gluegen.cgram.types.TypeDictionary.getEqualSemantics
List< Type > getEqualSemantics(final Type s, final JavaConfiguration cfg, final boolean skipOpaque)
Definition: TypeDictionary.java:69
com.jogamp.gluegen.cgram.types.TypeDictionary.getEqualSemantics1
Type getEqualSemantics1(final Type s, final JavaConfiguration cfg, final boolean skipOpaque)
Definition: TypeDictionary.java:88
com.jogamp.gluegen.cgram.types.TypeDictionary.put
Type put(final String name, final Type type)
Create a mapping from a type to its name.
Definition: TypeDictionary.java:59
com.jogamp.gluegen.cgram.types.TypeDictionary.keySet
Set< String > keySet()
Get all the names that map to Types.
Definition: TypeDictionary.java:124
com.jogamp.gluegen.cgram.types.TypeDictionary.containsValue
boolean containsValue(final Type value)
Definition: TypeDictionary.java:136
com.jogamp.gluegen.cgram.types.TypeDictionary.values
Collection< Type > values()
Returns a collection of all the Types in the dictionary that are mapped via typedefs names.
Definition: TypeDictionary.java:145
com.jogamp.gluegen.cgram.types.Type
Models a C type.
Definition: Type.java:54
com.jogamp.gluegen.cgram.types.Type.equalSemantics
final boolean equalSemantics(final SemanticEqualityOp arg)
Semantic equality test for Types exclusive its given name.
Definition: Type.java:514
com.jogamp.gluegen.cgram.types.Type.getDebugString
final String getDebugString()
Definition: Type.java:285