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

129 lines
2.9 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;
2020-11-28 10:22:22 +01:00
import com.minres.scviewer.database.IEvent;
2015-01-06 17:14:16 +01:00
import com.minres.scviewer.database.IWaveform;
import com.minres.scviewer.database.IWaveformDb;
2020-11-28 14:08:34 +01:00
import com.minres.scviewer.database.WaveformType;
2015-01-06 17:14:16 +01:00
2020-11-28 10:22:22 +01:00
public class VCDSignal<T extends IEvent> extends HierNode implements IWaveform {
2015-01-06 17:14:16 +01:00
private long id;
private String fullName;
private final int width;
private IWaveformDb db;
2015-01-06 17:14:16 +01:00
2020-11-28 10:22:22 +01:00
private NavigableMap<Long, IEvent[]> 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;
2020-11-28 10:22:22 +01:00
this.values=new TreeMap<Long, IEvent[]>();
2015-01-06 17:14:16 +01:00
}
2020-11-28 10:22:22 +01:00
public VCDSignal(VCDSignal<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<?>);
2020-11-28 10:22:22 +01:00
VCDSignal<T> o = (VCDSignal<T>)other;
this.width=o.width;
this.values=o.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 IWaveformDb getDb() {
return db;
}
public void addSignalChange(Long time, T value){
2020-11-28 10:22:22 +01:00
if(values.containsKey(time)) {
IEvent[] oldV = values.get(time);
IEvent[] newV = new IEvent[oldV.length+1];
System.arraycopy(oldV, 0, newV, 0, oldV.length);
newV[oldV.length]=value;
values.put(time, newV);
} else {
values.put(time, new IEvent[] {value});
}
2015-01-06 17:14:16 +01:00
}
@Override
2020-11-28 10:22:22 +01:00
public NavigableMap<Long, IEvent[]> getEvents() {
2015-01-06 17:14:16 +01:00
return values;
}
@Override
2020-11-28 10:22:22 +01:00
public IEvent[] getEventsAtTime(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
2020-11-28 10:22:22 +01:00
public IEvent[] getEventsBeforeTime(Long time) {
Entry<Long, IEvent[]> 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
2020-11-28 14:08:34 +01:00
public WaveformType getType() {
return WaveformType.SIGNAL;
}
2020-11-28 10:22:22 +01:00
@Override
2020-11-28 14:08:34 +01:00
public int getWidth() {
return width;
2020-11-28 10:22:22 +01:00
}
2015-01-06 17:14:16 +01:00
}