imc_rs/
channel.rs

1/// ChannelIdentifier describes how a channel can be identified
2#[derive(Debug, Clone)]
3pub enum ChannelIdentifier {
4    // Unique identifier for the channel
5    //Id(u16),
6    /// Order number of the channel (order of acquisition)
7    Order(i16),
8    /// Name of the channel
9    Name(String),
10    /// Label given to the channel
11    Label(String),
12}
13
14impl ChannelIdentifier {
15    /// Create a channel identifier based on the exact label.
16    pub fn label(label: &str) -> Self {
17        Self::Label(label.into())
18    }
19
20    /// Create a channel identifier based on the exact channel name.
21    pub fn name(name: &str) -> Self {
22        Self::Name(name.into())
23    }
24
25    /// Create a channel identifier based on the order in which the channel was acquired.
26    pub fn order(order: i16) -> Self {
27        Self::Order(order)
28    }
29}
30
31impl AsRef<ChannelIdentifier> for ChannelIdentifier {
32    fn as_ref(&self) -> &ChannelIdentifier {
33        self
34    }
35}
36
37impl From<&ChannelIdentifier> for ChannelIdentifier {
38    fn from(identifier: &ChannelIdentifier) -> Self {
39        identifier.clone()
40    }
41}
42
43impl From<&AcquisitionChannel> for ChannelIdentifier {
44    fn from(acq_channel: &AcquisitionChannel) -> Self {
45        ChannelIdentifier::Name(acq_channel.channel_name.to_owned())
46    }
47}
48
49/// AcquisitionChannel represents a single channel acquired, forming part of an acquisition
50#[derive(Debug, Clone)]
51pub struct AcquisitionChannel {
52    id: u16,
53    channel_name: String,
54    order_number: i16,
55    acquisition_id: u16,
56    channel_label: String,
57}
58
59impl AcquisitionChannel {
60    pub(crate) fn new(
61        id: u16,
62        acquisition_id: u16,
63        order_number: i16,
64        name: &str,
65        label: &str,
66    ) -> Self {
67        AcquisitionChannel {
68            id,
69            acquisition_id,
70            order_number,
71            channel_name: name.to_string(),
72            channel_label: label.to_string(),
73        }
74    }
75
76    /// Returns whether the specified channel identifier matches this channel
77    pub fn is(&self, identifier: &ChannelIdentifier) -> bool {
78        match identifier {
79            ChannelIdentifier::Order(order) => {
80                if self.order_number() == *order {
81                    return true;
82                }
83            }
84            ChannelIdentifier::Name(name) => {
85                if self.name() == name {
86                    return true;
87                }
88            }
89            ChannelIdentifier::Label(label) => {
90                if self.label() == label {
91                    return true;
92                }
93            }
94        }
95
96        false
97    }
98
99    /// Returns the ID associated with the channel
100    #[inline]
101    pub fn id(&self) -> u16 {
102        self.id
103    }
104
105    /// Returns the acquisition ID to which this channel belongs
106    #[inline]
107    pub fn acquisition_id(&self) -> u16 {
108        self.acquisition_id
109    }
110
111    /// Returns the given name of the channel
112    #[inline]
113    pub fn name(&self) -> &str {
114        &self.channel_name
115    }
116
117    /// Returns the position in the order in which this channel was acquired
118    #[inline]
119    pub fn order_number(&self) -> i16 {
120        self.order_number
121    }
122
123    /// Returns the label given to the channel
124    #[inline]
125    pub fn label(&self) -> &str {
126        &self.channel_label
127    }
128}