SCViewer/plugins/com.minres.scviewer.databas.../src/com/minres/scviewer/database/vcd/VCDSignal.java

131 lines
2.8 KiB
Java
Raw Normal View History

/*******************************************************************************
2015-10-22 00:25:12 +02:00
* Copyright (c) 2015 MINRES Technologies GmbH 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* MINRES Technologies GmbH - initial API and implementation
*******************************************************************************/
2015-01-06 17:14:16 +01:00
package com.minres.scviewer.database.vcd;
import java.util.Map.Entry;
2015-01-20 18:50:15 +01:00
import java.util.NavigableMap;
import java.util.TreeMap;
2015-01-06 17:14:16 +01:00
import com.minres.scviewer.database.HierNode;
import com.minres.scviewer.database.ISignal;
import com.minres.scviewer.database.IWaveform;
import com.minres.scviewer.database.IWaveformDb;
import com.minres.scviewer.database.IWaveformEvent;
2015-01-06 17:14:16 +01:00
public class VCDSignal<T> extends HierNode implements ISignal<T> {
2015-01-06 17:14:16 +01:00
private long id;
private String fullName;
private final String kind = "signal";
private final int width;
private final T dummy = null;
2015-01-06 17:14:16 +01:00
private IWaveformDb db;
2015-01-06 17:14:16 +01:00
private TreeMap<Long, T> values;
2015-01-06 17:14:16 +01:00
public VCDSignal(IWaveformDb db, String name) {
this(db, 0, name, 1);
2015-01-06 17:14:16 +01:00
}
public VCDSignal(IWaveformDb db, int id, String name) {
this(db, id,name,1);
2015-01-06 17:14:16 +01:00
}
public VCDSignal(IWaveformDb db, int id, String name, int width) {
2015-01-06 17:14:16 +01:00
super(name);
this.db=db;
2015-01-06 17:14:16 +01:00
fullName=name;
this.id=id;
this.width=width;
2015-01-20 18:50:15 +01:00
this.values=new TreeMap<Long, T>();
2015-01-06 17:14:16 +01:00
}
@SuppressWarnings("unchecked")
public VCDSignal(ISignal<T> other, int id, String name) {
2015-01-06 17:14:16 +01:00
super(name);
fullName=name;
this.id=id;
assert(other instanceof VCDSignal<?>);
2015-01-20 18:50:15 +01:00
this.width=((VCDSignal<? extends IWaveformEvent>)other).width;
2015-01-06 17:14:16 +01:00
this.values=((VCDSignal<T>)other).values;
this.db=other.getDb();
2015-01-06 17:14:16 +01:00
}
@Override
public String getFullName() {
return fullName;
}
public void setId(int id) {
this.id=id;
}
@Override
public Long getId() {
return id;
}
@Override
public String getKind() {
return kind;
}
public int getWidth() {
return width;
}
@Override
public IWaveformDb getDb() {
return db;
}
public void addSignalChange(Long time, T value){
values.put(time, value);
2015-01-06 17:14:16 +01:00
}
@Override
2015-01-20 18:50:15 +01:00
public NavigableMap<Long, T> getEvents() {
2015-01-06 17:14:16 +01:00
return values;
}
@Override
public T getWaveformValueAtTime(Long time) {
2015-01-20 18:50:15 +01:00
return values.get(time);
2015-01-06 17:14:16 +01:00
}
2015-07-10 13:40:50 +02:00
@Override
public T getWaveformValueBeforeTime(Long time) {
Entry<Long, T> e = values.floorEntry(time);
if(e==null)
return null;
else
return values.floorEntry(time).getValue();
2015-07-10 13:40:50 +02:00
}
@Override
public Boolean equals(IWaveform other) {
return( other instanceof VCDSignal<?> && this.getId().equals(other.getId()));
}
@Override
public Class<?> getType() {
return dummy.getClass();
}
2015-01-06 17:14:16 +01:00
}