2015-01-21 21:58:35 +01:00
|
|
|
/*******************************************************************************
|
2015-10-22 00:25:12 +02:00
|
|
|
* Copyright (c) 2015 MINRES Technologies GmbH and others.
|
2015-01-21 21:58:35 +01:00
|
|
|
* 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;
|
|
|
|
|
2018-10-15 09:13:41 +02:00
|
|
|
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;
|
2015-01-10 00:23:46 +01:00
|
|
|
import com.minres.scviewer.database.IWaveformDb;
|
2015-01-21 21:58:35 +01:00
|
|
|
import com.minres.scviewer.database.IWaveformEvent;
|
2015-01-06 17:14:16 +01:00
|
|
|
|
2018-11-05 18:21:54 +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;
|
2018-11-05 18:21:54 +01:00
|
|
|
|
|
|
|
private final T dummy = null;
|
2015-01-06 17:14:16 +01:00
|
|
|
|
2015-01-10 00:23:46 +01:00
|
|
|
private IWaveformDb db;
|
2015-01-06 17:14:16 +01:00
|
|
|
|
2018-11-05 18:21:54 +01:00
|
|
|
private TreeMap<Long, T> values;
|
2015-01-06 17:14:16 +01:00
|
|
|
|
2015-01-10 00:23:46 +01:00
|
|
|
public VCDSignal(IWaveformDb db, String name) {
|
|
|
|
this(db, 0, name, 1);
|
2015-01-06 17:14:16 +01:00
|
|
|
}
|
|
|
|
|
2015-01-10 00:23:46 +01:00
|
|
|
public VCDSignal(IWaveformDb db, int id, String name) {
|
|
|
|
this(db, id,name,1);
|
2015-01-06 17:14:16 +01:00
|
|
|
}
|
|
|
|
|
2015-01-10 00:23:46 +01:00
|
|
|
public VCDSignal(IWaveformDb db, int id, String name, int width) {
|
2015-01-06 17:14:16 +01:00
|
|
|
super(name);
|
2015-01-10 00:23:46 +01:00
|
|
|
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")
|
2018-11-05 18:21:54 +01:00
|
|
|
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;
|
2015-01-10 00:23:46 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-11-05 18:21:54 +01:00
|
|
|
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
|
2018-11-05 18:21:54 +01:00
|
|
|
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
|
2018-11-05 18:21:54 +01:00
|
|
|
public T getWaveformValueBeforeTime(Long time) {
|
2018-10-15 09:13:41 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-10-22 00:02:58 +02:00
|
|
|
@Override
|
2018-11-05 18:21:54 +01:00
|
|
|
public Boolean equals(IWaveform other) {
|
2015-10-22 00:02:58 +02:00
|
|
|
return(other instanceof VCDSignal<?> && this.getId()==other.getId());
|
|
|
|
}
|
|
|
|
|
2018-11-05 18:21:54 +01:00
|
|
|
@Override
|
|
|
|
public Class<?> getType() {
|
|
|
|
return dummy.getClass();
|
|
|
|
}
|
|
|
|
|
2015-01-06 17:14:16 +01:00
|
|
|
|
|
|
|
|
|
|
|
}
|