Refactor signal #6
|
@ -1,3 +1,5 @@
|
||||||
|
use crate::VCD;
|
||||||
|
|
||||||
// Copyright (C) 2022 Yehowshua Immanuel
|
// Copyright (C) 2022 Yehowshua Immanuel
|
||||||
// This program is distributed under both the GPLV3 license
|
// This program is distributed under both the GPLV3 license
|
||||||
// and the YEHOWSHUA license, both of which can be found at
|
// and the YEHOWSHUA license, both of which can be found at
|
||||||
|
@ -28,6 +30,32 @@ pub(super) enum TimelineQueryResults {
|
||||||
String(String),
|
String(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct Signal<'a>(pub(super) &'a SignalEnum);
|
||||||
|
|
||||||
|
impl<'a> Signal<'a> {
|
||||||
|
pub fn name(&self) -> String {
|
||||||
|
let Signal(signal_enum) = &self;
|
||||||
|
signal_enum.name()
|
||||||
|
}
|
||||||
|
pub fn query_string_val_on_tmln(
|
||||||
|
&self,
|
||||||
|
desired_time: &BigUint,
|
||||||
|
tmstmps_encoded_as_u8s: &Vec<u8>,
|
||||||
|
vcd: &VCD,
|
||||||
|
) -> Result<String, SignalErrors> {
|
||||||
|
let Signal(signal_enum) = &self;
|
||||||
|
signal_enum.query_string_val_on_tmln(desired_time, tmstmps_encoded_as_u8s, &vcd.all_signals)
|
||||||
|
}
|
||||||
|
pub fn query_num_val_on_tmln(
|
||||||
|
&self,
|
||||||
|
desired_time: &BigUint,
|
||||||
|
tmstmps_encoded_as_u8s: &Vec<u8>,
|
||||||
|
vcd: &VCD,
|
||||||
|
) -> Result<BigUint, SignalErrors> {
|
||||||
|
let Signal(signal_enum) = &self;
|
||||||
|
signal_enum.query_num_val_on_tmln(desired_time, tmstmps_encoded_as_u8s, &vcd.all_signals)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(super) enum SignalEnum {
|
pub(super) enum SignalEnum {
|
||||||
|
@ -134,7 +162,7 @@ impl SignalEnum {
|
||||||
/// string_vals field of an instance of the Signal::Data variant
|
/// string_vals field of an instance of the Signal::Data variant
|
||||||
/// and gets a string value.
|
/// and gets a string value.
|
||||||
/// The function returns a tuple of the timestamp and string value.
|
/// The function returns a tuple of the timestamp and string value.
|
||||||
pub(super) fn time_and_str_val_at_event_idx(
|
fn time_and_str_val_at_event_idx(
|
||||||
&self,
|
&self,
|
||||||
event_idx: usize,
|
event_idx: usize,
|
||||||
tmstmps_encoded_as_u8s: &Vec<u8>,
|
tmstmps_encoded_as_u8s: &Vec<u8>,
|
||||||
|
@ -182,7 +210,7 @@ impl SignalEnum {
|
||||||
/// numerical value at the time pointed at by event_didx.
|
/// numerical value at the time pointed at by event_didx.
|
||||||
/// The function returns a tuple of the timestamp and numerical
|
/// The function returns a tuple of the timestamp and numerical
|
||||||
/// value.
|
/// value.
|
||||||
pub(super) fn time_and_num_val_at_event_idx(
|
fn time_and_num_val_at_event_idx(
|
||||||
&self,
|
&self,
|
||||||
event_idx: usize,
|
event_idx: usize,
|
||||||
tmstmps_encoded_as_u8s: &Vec<u8>,
|
tmstmps_encoded_as_u8s: &Vec<u8>,
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
use crate::Signal;
|
||||||
|
|
||||||
// Copyright (C) 2022 Yehowshua Immanuel
|
// Copyright (C) 2022 Yehowshua Immanuel
|
||||||
// This program is distributed under both the GPLV3 license
|
// This program is distributed under both the GPLV3 license
|
||||||
// and the YEHOWSHUA license, both of which can be found at
|
// and the YEHOWSHUA license, both of which can be found at
|
||||||
|
@ -114,6 +116,11 @@ impl VCD {
|
||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub fn get_signal<'a>(&'a self, idx: SignalIdx) -> Signal<'a> {
|
||||||
|
let SignalIdx(idx) = idx;
|
||||||
|
let signal_enum = &self.all_signals[idx];
|
||||||
|
return Signal(signal_enum)
|
||||||
|
}
|
||||||
// Takes a signal_idx as input and returns the corresponding signal if the
|
// Takes a signal_idx as input and returns the corresponding signal if the
|
||||||
// corresponding signal is of the Signal::Data variant, else the function the
|
// corresponding signal is of the Signal::Data variant, else the function the
|
||||||
// SignalIdx in the signal_alias field of Signal::Alias variant to index
|
// SignalIdx in the signal_alias field of Signal::Alias variant to index
|
||||||
|
|
Loading…
Reference in a new issue