Alexander Hansen | 0119cd7 | 2025-01-14 14:15:39 +0100 | [diff] [blame^] | 1 | |
| 2 | #include "common/include/device_config.hpp" |
| 3 | |
| 4 | #include <regex> |
| 5 | #include <stdexcept> |
| 6 | |
| 7 | DeviceConfig::DeviceConfig(uint32_t vendorIANA, const std::string& compatible, |
| 8 | const std::string& configType, |
| 9 | const std::string& name) : |
| 10 | vendorIANA(vendorIANA), compatibleHardware(compatible), configName(name), |
| 11 | configType(configType) |
| 12 | { |
| 13 | std::regex reCompatible("([a-zA-Z0-9])+(\\.([a-zA-Z0-9])+)+"); |
| 14 | std::cmatch m; |
| 15 | |
| 16 | if (name.empty()) |
| 17 | { |
| 18 | throw std::invalid_argument( |
| 19 | "invalid EM config 'Name' string: '" + name + "'"); |
| 20 | } |
| 21 | |
| 22 | // check compatible string with regex |
| 23 | if (!std::regex_match(compatible.c_str(), m, reCompatible)) |
| 24 | { |
| 25 | throw std::invalid_argument( |
| 26 | "invalid compatible string: '" + compatible + "'"); |
| 27 | } |
| 28 | } |