gtouchable
Loading...
Searching...
No Matches
gelectronic.cc
Go to the documentation of this file.
1// gtouchable
2#include "gelectronic.h"
3
4// See header for API docs.
5
6// Constructor initializing GElectronic with specified address and mode.
7GElectronic::GElectronic(int c, int s, int ch, ComparisonMode comparison_mode) :
8 crate(c), slot(s), channel(ch), mode(comparison_mode) {
9 validateHAddress(c, s, ch);
10}
11
12
13void GElectronic::validateHAddress(int c, int s, int ch) {
14 if (c < 0 || s < 0 || ch < 0) {
15 throw std::invalid_argument("GElectronic hardware address components must be non-negative");
16 }
17}
18
19
20// Sets the hardware address.
21void GElectronic::setHAddress(int c, int s, int ch) {
22 validateHAddress(c, s, ch);
23 crate = c;
24 slot = s;
25 channel = ch;
26}
27
28// Returns the hardware address as a vector.
29std::vector<int> GElectronic::getHAddress() const {
30 return {crate, slot, channel};
31}
32
33// Equality operator comparing based on the mode.
34bool GElectronic::operator==(const GElectronic& ge) const {
35 if (mode == ComparisonMode::crate) {
36 return this->crate == ge.crate;
37 }
38 if (mode == ComparisonMode::crate_slot) {
39 return this->crate == ge.crate && this->slot == ge.slot;
40 }
41 return this->crate == ge.crate && this->slot == ge.slot && this->channel == ge.channel;
42}
43
44// Overloaded output stream operator for GElectronic.
45std::ostream& operator<<(std::ostream& stream, const GElectronic& ge) {
46 stream << " Crate: " << ge.crate;
47 stream << " Slot: " << ge.slot;
48 stream << " Channel: " << ge.channel;
49
50 return stream;
51}
std::ostream & operator<<(std::ostream &stream, const GElectronic &ge)
Defines GElectronic, a compact hardware address used by digitization and translation tables.
Represents an electronic module address (crate/slot/channel) with configurable comparison granularity...
Definition gelectronic.h:36
GElectronic(int c, int s, int ch, ComparisonMode comparison_mode)
Constructs a GElectronic with a specific hardware address and comparison mode.
Definition gelectronic.cc:7
void setHAddress(int c, int s, int ch)
Sets the hardware address fields (crate/slot/channel).
std::vector< int > getHAddress() const
Returns the hardware address as a vector of three integers.
ComparisonMode
Selects which hardware-address fields participate in comparison.
Definition gelectronic.h:39