56
|
1 |
/*
|
|
2 |
* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
* Integer-to-string mapping table for parameters
|
|
17 |
*
|
|
18 |
*/
|
|
19 |
package com.nokia.tracecompiler.model;
|
|
20 |
|
|
21 |
import java.util.ArrayList;
|
|
22 |
import java.util.Iterator;
|
|
23 |
|
|
24 |
/**
|
|
25 |
* Integer-to-string mapping table for parameters
|
|
26 |
*
|
|
27 |
*/
|
|
28 |
public class TraceConstantTable extends TraceObject implements
|
|
29 |
Iterable<TraceConstantTableEntry> {
|
|
30 |
|
|
31 |
/**
|
|
32 |
* Table entries
|
|
33 |
*/
|
|
34 |
private ArrayList<TraceConstantTableEntry> entries = new ArrayList<TraceConstantTableEntry>();
|
|
35 |
|
|
36 |
/**
|
|
37 |
* Table type
|
|
38 |
*/
|
|
39 |
private String type = TraceParameter.UDEC32;
|
|
40 |
|
|
41 |
/**
|
|
42 |
* Parameter reference count
|
|
43 |
*/
|
|
44 |
private ArrayList<TraceParameter> parameterReferences = new ArrayList<TraceParameter>();
|
|
45 |
|
|
46 |
/**
|
|
47 |
* Creates a new constant table
|
|
48 |
*
|
|
49 |
* @param model
|
|
50 |
* the trace model
|
|
51 |
*/
|
|
52 |
TraceConstantTable(TraceModel model) {
|
|
53 |
setModel(model);
|
|
54 |
model.addConstantTable(this);
|
|
55 |
}
|
|
56 |
|
|
57 |
/**
|
|
58 |
* Gets the type
|
|
59 |
*
|
|
60 |
* @return the type
|
|
61 |
*/
|
|
62 |
public String getType() {
|
|
63 |
return type;
|
|
64 |
}
|
|
65 |
|
|
66 |
/**
|
|
67 |
* Sets the constant type
|
|
68 |
*
|
|
69 |
* @param type
|
|
70 |
* the parameter type
|
|
71 |
*/
|
|
72 |
public void setType(String type) {
|
|
73 |
this.type = type;
|
|
74 |
}
|
|
75 |
|
|
76 |
/*
|
|
77 |
* (non-Javadoc)
|
|
78 |
*
|
|
79 |
* @see com.nokia.tracecompiler.model.TraceObject#setName(java.lang.String)
|
|
80 |
*/
|
|
81 |
@Override
|
|
82 |
public void setName(String name) throws TraceCompilerException {
|
|
83 |
super.setName(name);
|
|
84 |
// Note: Currently name changes are disabled when a table is referenced
|
|
85 |
// by parameters. If enabled at some point, a notification about this
|
|
86 |
// needs to be sent to the parameters
|
|
87 |
}
|
|
88 |
|
|
89 |
/**
|
|
90 |
* Adds a constant table entry to this table. This is called from the
|
|
91 |
* constant table entry constructor, to this is not public. Generates a
|
|
92 |
* objectAdded event to model listeners
|
|
93 |
*
|
|
94 |
* @see TraceModelListener#objectAdded(TraceObject, TraceObject)
|
|
95 |
* @param entry
|
|
96 |
* the table entry
|
|
97 |
*/
|
|
98 |
void addEntry(TraceConstantTableEntry entry) {
|
|
99 |
entries.add(entry);
|
|
100 |
getModel().notifyObjectAdded(this, entry);
|
|
101 |
}
|
|
102 |
|
|
103 |
/**
|
|
104 |
* Removes the given constant table entry. Creates a objectRemoved event to
|
|
105 |
* the model listeners
|
|
106 |
*
|
|
107 |
* @see TraceModelListener#objectRemoved(TraceObject, TraceObject)
|
|
108 |
* @param entry
|
|
109 |
* the entry to be removed
|
|
110 |
* @throws TraceCompilerException
|
|
111 |
*/
|
|
112 |
public void removeEntry(TraceConstantTableEntry entry) throws TraceCompilerException {
|
|
113 |
if (entries.remove(entry)) {
|
|
114 |
getModel().notifyObjectRemoved(this, entry);
|
|
115 |
entry.reset();
|
|
116 |
}
|
|
117 |
}
|
|
118 |
|
|
119 |
/**
|
|
120 |
* Gets the entry which has given ID
|
|
121 |
*
|
|
122 |
* @param id
|
|
123 |
* the id
|
|
124 |
* @return the entry or null
|
|
125 |
*/
|
|
126 |
public TraceConstantTableEntry findEntryByID(int id) {
|
|
127 |
TraceConstantTableEntry retval = null;
|
|
128 |
for (TraceConstantTableEntry entry : entries) {
|
|
129 |
if (entry.getID() == id) {
|
|
130 |
retval = entry;
|
|
131 |
break;
|
|
132 |
}
|
|
133 |
}
|
|
134 |
return retval;
|
|
135 |
}
|
|
136 |
|
|
137 |
/**
|
|
138 |
* Gets the entry which has the given name
|
|
139 |
*
|
|
140 |
* @param name
|
|
141 |
* the name
|
|
142 |
* @return the entry or null
|
|
143 |
*/
|
|
144 |
public TraceConstantTableEntry findEntryByName(String name) {
|
|
145 |
TraceConstantTableEntry retval = null;
|
|
146 |
for (TraceConstantTableEntry entry : entries) {
|
|
147 |
if (entry.getName().equals(name)) {
|
|
148 |
retval = entry;
|
|
149 |
break;
|
|
150 |
}
|
|
151 |
}
|
|
152 |
return retval;
|
|
153 |
}
|
|
154 |
|
|
155 |
/**
|
|
156 |
* Gets the constant table entries
|
|
157 |
*
|
|
158 |
* @return the entries iterator
|
|
159 |
*/
|
|
160 |
public Iterator<TraceConstantTableEntry> getEntries() {
|
|
161 |
return entries.iterator();
|
|
162 |
}
|
|
163 |
|
|
164 |
/*
|
|
165 |
* (non-Javadoc)
|
|
166 |
*
|
|
167 |
* @see java.lang.Iterable#iterator()
|
|
168 |
*/
|
|
169 |
public Iterator<TraceConstantTableEntry> iterator() {
|
|
170 |
return entries.iterator();
|
|
171 |
}
|
|
172 |
|
|
173 |
/**
|
|
174 |
* Determines if there are any entries in this table
|
|
175 |
*
|
|
176 |
* @return true if there are entries
|
|
177 |
*/
|
|
178 |
public boolean hasEntries() {
|
|
179 |
return !entries.isEmpty();
|
|
180 |
}
|
|
181 |
|
|
182 |
/**
|
|
183 |
* Adds a parameter reference
|
|
184 |
*
|
|
185 |
* @param parameter
|
|
186 |
* the parameter to be added
|
|
187 |
*/
|
|
188 |
void addParameterReference(TraceParameter parameter) {
|
|
189 |
parameterReferences.add(parameter);
|
|
190 |
}
|
|
191 |
|
|
192 |
/**
|
|
193 |
* Removes a parameter reference
|
|
194 |
*
|
|
195 |
* @param parameter
|
|
196 |
* the reference to be removed
|
|
197 |
*/
|
|
198 |
void removeParameterReference(TraceParameter parameter) {
|
|
199 |
parameterReferences.remove(parameter);
|
|
200 |
}
|
|
201 |
|
|
202 |
/**
|
|
203 |
* Checks if there are parameter references
|
|
204 |
*
|
|
205 |
* @return true if this table is referenced from parameters
|
|
206 |
*/
|
|
207 |
public boolean hasParameterReferences() {
|
|
208 |
return !parameterReferences.isEmpty();
|
|
209 |
}
|
|
210 |
|
|
211 |
/**
|
|
212 |
* Gets the parameter references
|
|
213 |
*
|
|
214 |
* @return the iterator of the references
|
|
215 |
*/
|
|
216 |
public Iterator<TraceParameter> getParameterReferences() {
|
|
217 |
return parameterReferences.iterator();
|
|
218 |
}
|
|
219 |
|
|
220 |
/**
|
|
221 |
* Gets the largest constant ID + 1
|
|
222 |
*
|
|
223 |
* @return the ID
|
|
224 |
*/
|
|
225 |
public int getNextEntryID() {
|
|
226 |
int max = 0;
|
|
227 |
for (TraceConstantTableEntry entry : entries) {
|
|
228 |
int id = entry.getID();
|
|
229 |
if (id > max) {
|
|
230 |
max = id;
|
|
231 |
}
|
|
232 |
}
|
|
233 |
return max + 1;
|
|
234 |
}
|
|
235 |
|
|
236 |
/*
|
|
237 |
* (non-Javadoc)
|
|
238 |
*
|
|
239 |
* @see com.nokia.tracecompiler.model.TraceObject#reset()
|
|
240 |
*/
|
|
241 |
@Override
|
|
242 |
void reset() {
|
|
243 |
for (TraceConstantTableEntry entry : entries) {
|
|
244 |
// Model listeners are not notified on reset, but if the
|
|
245 |
// entry itself implements a delete notification interface,
|
|
246 |
// it must be called to do appropriate cleanup
|
|
247 |
notifyOnDelete(entry);
|
|
248 |
entry.reset();
|
|
249 |
}
|
|
250 |
super.reset();
|
|
251 |
}
|
|
252 |
|
|
253 |
}
|