ctf: Throw CTFReaderException in the BitBuffer API
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core / src / org / eclipse / linuxtools / ctf / core / event / types / EnumDefinition.java
index e1565f92adb77c34dc314d9049364a5db30deac9..82d5230989c4a78c3cfaf7fb6c359f765d1364e2 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others
+ * Copyright (c) 2011, 2013 Ericsson, Ecole Polytechnique de Montreal 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
 
 package org.eclipse.linuxtools.ctf.core.event.types;
 
-import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
 
 /**
- * <b><u>EnumDefinition</u></b>
+ * A CTF enum definition.
+ *
+ * The definition of a enum point basic data type. It will take the data
+ * from a trace and store it (and make it fit) as an integer and a string.
+ *
+ * @version 1.0
+ * @author Matthew Khouzam
+ * @author Simon Marchi
  */
-public class EnumDefinition extends Definition {
+public class EnumDefinition extends SimpleDatatypeDefinition {
 
     // ------------------------------------------------------------------------
     // Attributes
@@ -47,7 +55,7 @@ public class EnumDefinition extends Definition {
 
         integerValue = declaration.getContainerType().createDefinition(
                 definitionScope, fieldName);
-        value = ((Long) integerValue.getValue()).toString();
+        value = declaration.query(integerValue.getValue());
     }
 
     // ------------------------------------------------------------------------
@@ -62,21 +70,27 @@ public class EnumDefinition extends Definition {
         return value;
     }
 
+    @Override
+    public String getStringValue(){
+        return getValue();
+    }
+
     /**
      * Gets the value of the enum in string format so "Enum a{DAY="0", NIGHT="1"}; will return 0
      * @return the value of the enum.
      */
-    public long getIntegerValue() {
+    @Override
+    public Long getIntegerValue() {
         return integerValue.getValue();
     }
 
     /**
      * Sets the value of the enum in string format so "Enum a{DAY="0", NIGHT="1"}; will set 0
-     * @param Value The value of the enum.
+     * @param value The value of the enum.
      */
-    public void setIntegerValue(long Value) {
-        integerValue.setValue(Value);
-        value = ((Long) integerValue.getValue()).toString();
+    public void setIntegerValue(long value) {
+        integerValue.setValue(value);
+        this.value = declaration.query(value);
     }
 
     @Override
@@ -89,10 +103,8 @@ public class EnumDefinition extends Definition {
     // ------------------------------------------------------------------------
 
     @Override
-    public void read(BitBuffer input) {
-        int align = (int) declaration.getAlignment();
-        int pos = input.position() + ((align-(input.position() % align))%align);
-        input.position(pos);
+    public void read(BitBuffer input) throws CTFReaderException {
+        alignRead(input, this.declaration);
         integerValue.read(input);
         long val = integerValue.getValue();
 
@@ -101,4 +113,10 @@ public class EnumDefinition extends Definition {
         value = declaration.query(val);
     }
 
+    @Override
+    public String toString() {
+        return "{ value = " + getValue() + //$NON-NLS-1$
+                ", container = " + integerValue.toString() + //$NON-NLS-1$
+                " }"; //$NON-NLS-1$
+    }
 }
This page took 0.027947 seconds and 5 git commands to generate.