blob: 7bcbf8526e011d695ce47255bfeb6538fa30e3eb (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
package org.eclipse.cdt.internal.corext.template;
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.eclipse.cdt.internal.corext.template.c.CFunctionContextType;
import org.eclipse.cdt.internal.corext.template.c.CGlobalContextType;
import org.eclipse.cdt.internal.corext.template.c.CStructureContextType;
import org.eclipse.cdt.internal.corext.template.c.CppFunctionContextType;
import org.eclipse.cdt.internal.corext.template.c.CppGlobalContextType;
import org.eclipse.cdt.internal.corext.template.c.CppStructureContextType;
/**
* A singleton to keep track of all known context types.
*/
public class ContextTypeRegistry {
/** the singleton */
private static ContextTypeRegistry fInstance;
/** all known context types */
private final Map fContextTypes= new HashMap();
/**
* Returns the single instance of this class.
*/
public static ContextTypeRegistry getInstance() {
if (fInstance == null)
fInstance= new ContextTypeRegistry();
return fInstance;
}
/**
* Adds a context type to the registry.
*/
public void add(ContextType contextType) {
fContextTypes.put(contextType.getName(), contextType);
}
/**
* Removes a context type from the registry.
*/
public void remove(ContextType contextType) {
fContextTypes.remove(contextType.getName());
}
/**
* Returns the context type if the name is valid, <code>null</code> otherwise.
*/
public ContextType getContextType(String name) {
return (ContextType) fContextTypes.get(name);
}
/**
* Returns an iterator over the registered context type names.
*/
public Iterator iterator() {
return fContextTypes.keySet().iterator();
}
// XXX bootstrap with C and C++ types
private ContextTypeRegistry() {
add(new CGlobalContextType());
add(new CStructureContextType());
add(new CFunctionContextType());
add(new CppGlobalContextType());
add(new CppStructureContextType());
add(new CppFunctionContextType());
}
}
|