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

122 lines
2.7 KiB
Java
Raw Normal View History

/*******************************************************************************
2021-01-09 14:26:49 +01:00
* Copyright (c) 2015-2021 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;
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;
2020-11-28 10:22:22 +01:00
private NavigableMap<Long, IEvent[]> values;
2015-01-06 17:14:16 +01:00
2021-01-02 17:02:05 +01:00
public VCDSignal(String name) {
this(0, name, 1);
2015-01-06 17:14:16 +01:00
}
2021-01-02 17:02:05 +01:00
public VCDSignal(int id, String name) {
this(id,name,1);
2015-01-06 17:14:16 +01:00
}
2021-01-02 17:02:05 +01:00
public VCDSignal(int id, String name, int width) {
2015-01-06 17:14:16 +01:00
super(name);
fullName=name;
this.id=id;
this.width=width;
this.values=new TreeMap<>();
2015-01-06 17:14:16 +01:00
}
public VCDSignal(VCDSignal<T> o, int id, String name) {
2015-01-06 17:14:16 +01:00
super(name);
fullName=name;
this.id=id;
2020-11-28 10:22:22 +01:00
this.width=o.width;
this.values=o.values;
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;
}
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 new IEvent[] {};
else
return values.floorEntry(time).getValue();
2015-07-10 13:40:50 +02:00
}
@Override
public boolean isSame(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
2021-01-14 23:13:11 +01:00
public int getRowCount() {
2020-11-28 14:08:34 +01:00
return width;
2020-11-28 10:22:22 +01:00
}
2015-01-06 17:14:16 +01:00
2021-01-09 10:34:22 +01:00
@Override
public String getKind() {
return "signal";
}
2015-01-06 17:14:16 +01:00
}