File tree Expand file tree Collapse file tree 3 files changed +23
-2
lines changed
include/ReadoutCard/ParameterTypes Expand file tree Collapse file tree 3 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -34,6 +34,11 @@ class PciSequenceNumber
3434 // / \param string String of format "^#[0-9]+$"
3535 PciSequenceNumber (const std::string& string);
3636
37+ // / Constructs a PciSequenceNumber object using an int
38+ // / For example: 1, 4, 0
39+ // / \param number An int between 0-7
40+ PciSequenceNumber (const int & number);
41+
3742 // / Converts to a PciSequenceNumber object from a string that matches "^#[0-9]+$"
3843 // / For example: "#04"
3944 static boost::optional<PciSequenceNumber> fromString (std::string string);
Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ namespace
2727
2828int parseSequenceNumberString (const std::string& string)
2929{
30- std::regex expression (" ^[ \t ]*#[0-9 ]+[ \t ]*$" );
30+ std::regex expression (" ^[ \t ]*#[0-7 ]+[ \t ]*$" );
3131 if (std::regex_search (string, expression)) {
3232 return stoi (string.substr (string.find (' #' ) + 1 ));
3333 } else {
@@ -36,6 +36,16 @@ int parseSequenceNumberString(const std::string& string)
3636 }
3737}
3838
39+ std::string constructSequenceNumberString (const int & number)
40+ {
41+ if (number < 0 || number > 7 ) {
42+ BOOST_THROW_EXCEPTION (ParseException ()
43+ << ErrorInfo::Message (" Parsing PCI sequence number failed" ));
44+ }
45+
46+ return std::string (" #" + std::to_string (number));
47+ }
48+
3949} // namespace
4050
4151PciSequenceNumber::PciSequenceNumber (const std::string& string)
@@ -44,6 +54,12 @@ PciSequenceNumber::PciSequenceNumber(const std::string& string)
4454 mSequenceNumber = parseSequenceNumberString (string);
4555}
4656
57+ PciSequenceNumber::PciSequenceNumber (const int & number)
58+ {
59+ mSequenceNumberString = constructSequenceNumberString (number);
60+ mSequenceNumber = number;
61+ }
62+
4763std::string PciSequenceNumber::toString () const
4864{
4965 return mSequenceNumberString ;
Original file line number Diff line number Diff line change @@ -80,7 +80,7 @@ BOOST_AUTO_TEST_CASE(ParametersCardIdFromString)
8080 BOOST_CHECK (Parameters::cardIdFromString (" 12345" ) != cardId);
8181 }
8282 {
83- Parameters::CardIdType cardId = 12345 ;
83+ Parameters::CardIdType cardId = SerialId ( 12345 ) ;
8484 BOOST_CHECK (Parameters::cardIdFromString (" 42:0.0" ) != cardId);
8585 BOOST_CHECK (Parameters::cardIdFromString (" 12345" ) == cardId);
8686 }
You can’t perform that action at this time.
0 commit comments