Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MITuple.java')
-rw-r--r--dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MITuple.java43
1 files changed, 36 insertions, 7 deletions
diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MITuple.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MITuple.java
index 444a80a2847..682f5b341ac 100644
--- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MITuple.java
+++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MITuple.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2009 QNX Software Systems and others.
+ * Copyright (c) 2000, 2014 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -8,19 +8,25 @@
* Contributors:
* QNX Software Systems - Initial API and implementation
* Wind River Systems - Modified for new DSF Reference Implementation
+ * Vladimir Prus (Mentor Graphics) - Add getMIValue method.
*******************************************************************************/
package org.eclipse.cdt.dsf.mi.service.command.output;
+import java.util.HashMap;
+import java.util.Map;
+
/**
* GDB/MI tuple value.
*/
public class MITuple extends MIValue {
- final static MIResult[] nullResults = new MIResult[0];
- final static MIValue[] nullValues = new MIValue[0];
- MIResult[] results = nullResults;
- MIValue[] values = nullValues;
+ final private static MIResult[] NULL_RESULTS = new MIResult[0];
+ final private static MIValue[] NULL_VALUES = new MIValue[0];
+
+ private MIResult[] results = NULL_RESULTS;
+ private MIValue[] values = NULL_VALUES;
+ private Map<String, MIValue> name2value;
public MIResult[] getMIResults() {
return results;
@@ -28,20 +34,43 @@ public class MITuple extends MIValue {
public void setMIResults(MIResult[] res) {
results = res;
+ name2value = null;
}
public MIValue[] getMIValues() {
return values;
}
+ /** Return the value of the specified field of this tuple.
+ *
+ * @since 4.6
+ */
+ public MIValue getField(String name) {
+ if (name2value == null) {
+ name2value = new HashMap<String, MIValue>();
+ for (MIResult r : results) {
+ name2value.put(r.getVariable(), r.getMIValue());
+ }
+ }
+ return name2value.get(name);
+ }
+
public void setMIValues(MIValue[] vals) {
values = vals;
}
@Override
public String toString() {
+ return toString("{", "}"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // Return comma-separated values, with start and end prepended and appended
+ // Intentionally package private, should only be used by ourselves and
+ // MIResultRecord.
+ String toString(String start, String end)
+ {
StringBuffer buffer = new StringBuffer();
- buffer.append('{');
+ buffer.append(start);
for (int i = 0; i < results.length; i++) {
if (i != 0) {
buffer.append(',');
@@ -54,7 +83,7 @@ public class MITuple extends MIValue {
}
buffer.append(values[i].toString());
}
- buffer.append('}');
+ buffer.append(end);
return buffer.toString();
}
}

Back to the top